opencl - How do you read arguments passed to a native kernel? -
i have native kernel setup don't know how convert void* argument useful. in native kernel of snippet, how int (7) or int[] (16 ints set 0)?
void __stdcall nativekernel(void * args) { int a1 = (*(int*)args); cout << "a1-->: "<< a1 << endl; // gibberish } void kernelcaller() { const int dim1size = 16; int dim1[dim1size] = {}; cl_int status = 0; cl_mem mem_d1 = clcreatebuffer(*context, 0, sizeof(int)*dim1size, null, &status); clenqueuewritebuffer(*queue, mem_d1, cl_true, 0, sizeof(int)*dim1size, dim1, 0, null, null); const void* args[2] = {(void*)7, null}; cl_mem mem_list[1] = {mem_d1}; const void* args_mem_loc[1] = {&args[1]}; cl_event run; status = clenqueuenativekernel(*queue, nativekernel, args, 2, 1, mem_list, args_mem_loc, 0, null, &run); status = clenqueuereadbuffer(*queue, mem_d1, cl_true, 0, sizeof(int)*dim1size, dim1, 1, &run, null); for(auto = 0; != dim1size; i++) cout << dim1[i] << " "; }
instead of playing hard void*
suggest use struct
create parameter structure like:
struct myparams{ int int a[3]; };
and create , fill 1 struct myparams
in program , pass address kernelcaller
struct myparams params; params.a=3; status = clenqueuenativekernel(*queue, nativekernel, (void*)¶ms, 2, 1, mem_list, args_mem_loc, 0, null, &run);
and in nativekernel
unbox void*
parameter struct:
struct myparams *params=(myparams*)args;
beware: in example above passed pointer of stack...you might not want ;)
Comments
Post a Comment