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 on the AMD SDK, and I think that NVidia doesn’ support it as well.

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

You are correct. I suggest filing a bug against any implementation that fails.

In the meantime you can create a dummy CL buffer with a very small size and pass it instead of NULL.

Of course this workaround will not work if your kernel actually tests the argument against NULL.

It is what I do now, it is not very elegant but it works ! I just use an ‘int’ to tell if the buffer is a dummy one or not…

I have do a post for AMD and I will for NVidia too…