I have a buffer created device side and I would like to initialise the values inside this buffer. OpenCL 1.2 provides the function clEnqueueFillBuffer (http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clEnqueueFillBuffer.html) for this type of operation.
Calling this function fails to initialise my memory correctly but does not return any error code to suggest that the function failed.
Here is the code I use:
int initGridSize = 64*64*64; // initial 3D volume size
cl_uint initVoxelValue = 255; // initial value of each voxel in the volume
// create the buffer on the device
cl_mem buff = clCreateBuffer(context, CL_MEM_READ_ONLY, initGridSize*sizeof(cl_uint), NULL, &err);
if(err < 0) {
perror("Couldn't create a buffer object");
exit(1);
}
// Fill the buffer with the initial value
err = clEnqueueFillBuffer(queue, buff, &initVoxelValue, sizeof(cl_uint), 0, initGridSize*sizeof(cl_uint), 0, NULL, NULL);
if(err != CL_SUCCESS) {
perror("Couldn't fill a buffer object");
exit(1);
}
clFinish(queue);
// create a host side buffer and read the device side buffer into the host buffer
cl_uint *grid = new cl_uint [ initGridSize ];
err = clEnqueueReadBuffer(queue, buff, CL_TRUE, 0, initGridSize*sizeof(cl_int), &grid[0], 0, NULL, NULL);
if (err != CL_SUCCESS)
{
perror("Couldn't read a buffer object");
exit(1);
}
// print the first 11 values in the buffer
cl_uint *g = grid;
for( int i=0; i<11; i++, g++ )
{
printf("Voxel %i, %u\n", i, *g );
}
delete [] grid;
And the output is this:
Voxel 0, 0
Voxel 1, 0
Voxel 2, 0
Voxel 3, 0
Voxel 4, 0
Voxel 5, 0
Voxel 6, 0
Voxel 7, 0
Voxel 8, 0
Voxel 9, 0
Voxel 10, 0
It would be simple enough to write a kernel to fill the buffer, but ideally I would like to get this working.
Can anyone see where I'm going wrong, or is this a driver bug?
CL_PLATFORM_PROFILE: FULL_PROFILE CL_PLATFORM_VERSION: OpenCL 1.2 (Apr 25 2014 22:04:25)- Ben'