OK, so I highlighted this for a very specific problem.
I had the impression that you could pass OpenCL any data types in the array buffer; ints, chars, your own custom structures, unless it is just data and does not contain pointers to a bunch of objects that the GPU cannot retrieve.
Now I tried this, and I think that it works for a large int array, but not for my array of structures. In particular,
cl_mem log_buffer = clCreateBuffer(context, CL_MEM_READ_WRITE,
num_elements * sizeof(int), NULL, NULL);
int* error_codes_in = (int*)malloc(num_elements * sizeof(int));
for (i = 0; i < num_elements; i++) {
error_codes_in[i] = i;
}
error = clEnqueueWriteBuffer(command_queue, log_buffer, CL_TRUE,
0, num_elements * sizeof(int), error_codes_in, 0, NULL, NULL);
this works fine, and I get an array of numbers on the GPU and can successfully process them in parallel.
However, when I use my own structure of my own:
typedef struct {
float position[2];
float velocity[2];
float radius;
float resultant_force[2];
} ocl_element_2d_t;
(also defined in the kernel, as)
const char* kernel_string =
"typedef struct { float position[2]; float velocity[2]; float radius; float resultant_force[2]; } ocl_element_2d_t;"...
and I use the same / very similar code to write to the GPU version of my struct array:
cl_mem gpu_buffer = clCreateBuffer(context, CL_MEM_READ_WRITE,
num_elements * sizeof(ocl_element_2d_t), NULL, NULL);
error = clEnqueueWriteBuffer(command_queue, (cl_mem)gpu_buffer, CL_TRUE,
0, num_elements * sizeof(ocl_element_2d_t), host_buffer, 0, NULL, NULL);
, ( 350) float . : CL_SUCCESS.
, ? , GPU , , . , - 64- (OS X Lion) i7 ( ), GPU 32-, ? ATI Radeon HD 5750, , 128- ( , , .)
? FORTRAN 7 , , ?