c - OpenCL buffers and data calculation -
if want format code opencl should consider when doing so? buffers should using? , if want know how data kernel use doing this, how able calculate it?
int a[100000] int b[100000] for(int i=1; i<100000 -1); i++) { b[i] = a[i-1] + a[i+1] - 2*a[i] }
all appreciated
you need 2 buffers , b. example:
cl_int error = cl_success; cl_mem a_buffer = clcreatebuffer(context, cl_mem_read_only | cl_mem_copy_host_ptr, sizeof(int)*100000, a, &error); cl_mem b_buffer = clcreatebuffer(context, cl_mem_read_write | cl_mem_copy_host_ptr, sizeof(int)*100000, b, &error);
if want each kernel work 1 element of b, global work size equal 99999.
your kernel might somehow (in case 1 thread works 1 value, might not need such parallelism, it's example):
kernel void your_kernel(global int* a, global int* b) { int = get_global_id(0); b[i] = a[i-1] + a[i+1] - 2*a[i]; }
Comments
Post a Comment