Create buffer on OpenCL device

// initialize OpenCL device
ClooDevice device = ClooDevice.CompatibleDevices.Where(x => x.Available && x.CompilerAvailable).OrderByDescending(x => x.MaxComputeUnits).First();
ClooContext context = ClooContext.FromDevice(device);
ClooCommandQueue queue = context.CreateCommandQueue();
ClooProgramCore program = ClooProgramCore.Create(context);

// create buffer on GPU and set all values to "1"
ClooBuffer<byte> buffer = new ClooBuffer<byte>(context, ComputeMemoryFlags.ReadWrite | ComputeMemoryFlags.AllocateHostPointer, 1024 * 1024);
program.SetValue(queue, buffer, 1);

// we haven't read buffer from device yet, so buffer should be still empty
int sum;
sum = buffer.HostBuffer.Sum(x => x); // should be 0

// read buffer from device
buffer.ReadFromDevice(queue);
sum = buffer.HostBuffer.Sum(x => x); // should be 1048576

Last edited Mar 24, 2011 at 8:33 PM by hanswolff, version 1

Comments

No comments yet.