/ / clEnqueueFillBuffer не вдається заповнити - opencl, gpu-програмування

clEnqueueFillBuffer не вдається заповнити - opencl, gpu-programming

У мене на пристрої створена буферна частина, і я хотів би ініціалізувати значення всередині цього буфера. OpenCL 1.2 забезпечує функцію clEnqueueFillBuffer (http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clEnqueueFillBuffer.html) для цього типу операцій.

Виклик цієї функції не може правильно ініціалізувати мою пам'ять, але не повертає жодного коду помилки, який дозволяє припустити, що функція не вдалася.

Ось код, який я використовую:

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, %un", i, *g );
}
delete [] grid;

І висновок такий:

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

Було б досить просто написати ядро, щоб заповнити буфер, але в ідеалі я хотів би, щоб це працювало.

Хтось може бачити, де я помиляюся, чи це помилка драйвера?

Відповіді:

0 для відповіді № 1

Ви встановили буфер за допомогою CL_MEM_READ_ONLY прапор. Встановіть його CL_MEM_READ_WRITE так що ви можете записати значення в нього.