cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

spectral
Adept II

Passing NULL pointer to the kernel ?

The OpenCL specification (1.0.43) seems to indicate that it's legal to pass a NULL pointer to an OpenCL kernel:

"A NULL value can also be specified if the argument is a buffer object in which case a NULL value will be used as the value for the argument declared as a pointer to __global or __constant memory in the kernel." and "The memory object specified as argument value must be a buffer object (or NULL) if the argument is declared to be a pointer of a built-in or user defined type with the __global or __constant qualifier."

But I got a crash when I do this !

 

ERROR: clSetKernelArg(-38)

 

In my case, sometimes I have nothing to pass to the kernel... how should I do ?

0 Likes
4 Replies
spectral
Adept II

Take a look here :

http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/clSetKernelArg.html

 

I use the Kernel class from cl.hpp !!

0 Likes

I have also try this, but I got a crash !

 

cl_kernel k = (cl_kernel)kernel;

::clSetKernelArg(k, 5, 0, NULL);

::clSetKernelArg(k, 6, 0, NULL);



0 Likes

Are you getting a crash or the -38 error?

Could you provide a testcase to reproduce the issue?

0 Likes
rick_weber
Adept II

Have you tried:

void* ptr = NULL;

::clSetKernelArg(k, 5, sizeof(cl_mem), &ptr);

If the argument is declared with the __local qualifier, the arg_value entry must be NULL. If the argument is of type sampler_t, the arg_value entry must be a pointer to the sampler object. For all other kernel arguments, the arg_value entry must be a pointer to the actual data to be used as argument value.

I'm not really sure why you would declare a parameter as __local instead of just putting it in the function body. If you do what I suggested, you should get __global type* param, where param == NULL.

0 Likes