clCreateBufferNV from the OpenCL extension cl_nv_create_buffer returning unknown error code

Dear Developers,

You provide OpenCL together with CUDA, so I hope I have chosen the right Category. I’ve got a question concerning the OpenCL extionsion cl_nv_create_buffer, which I want to use on the Nvidia Graphics Cards “TITAN Xp” and “Tesla K20c” (both using the Driver version 384.111):

I’m quite sure I have created the function pointer in order to get the “clCreateBufferNV”-function via “clGetExtensionFunctionAdress” correctly and passing the right parameters, because the code compiles and “clCreateBufferNV” get’s called. See code below if you want to assure. But I’m getting an error code -30 when calling “clCreateBufferNV”. What does that error code mean in context of cl_nv_create_buffer (I can’t find an error code list)?

Does my Driver even support “clCreateBufferNV”? When I look at http://on-demand.gputechconf.com/gtc/2018/presentation/s8837-opencl-nvidia-recent-improvements-future-plans.pdf it looks like this is rather a future plan of Nvidia than something that’s already implemented. But as stated before, the creating the function pointer via “clGetExtensionFunctionAdress” seems to work…

Greatings from Bayreuth and thanks for your help,
Fabian Häusl

Code:
cl_mem (clCreateBufferNV)(cl_context,cl_mem_flags, cl_mem_flags_NV, std::size_t, void, cl_int*) = (cl_mem ()(cl_context,cl_mem_flags, cl_mem_flags_NV, std::size_t, void, cl_int*)) clGetExtensionFunctionAddress(“clCreateBufferNV”);
cl::Buffer buffer_data = clCreateBufferNV(context, CL_MEM_READ_WRITE , CL_MEM_PINNED_NV, (std::size_t)size, (void*)ptr_data, &error);

I think the -30 error code is most likely intended to be interpreted the same way you would interpret any OpenCL error code, i.e. the same way you would interpret the error as if it were returned by clCreateBuffer. That is -30 = INVALID_VALUE. No, I’m not able to tell you precisely what that means, or what argument it is referring to, as I am unable to duplicate your error.

The following code appears to work correctly for me (throws no errors):

$ cat t1.cpp
#include <CL/opencl.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
  cl_platform_id platform;
  cl_device_id device;
  cl_context context;
  cl_mem mem1[1];
  cl_int err;

  err = clGetPlatformIDs(1, &platform, NULL);
  if (err != CL_SUCCESS) {printf("%d: %d\n", __LINE__, err); return -1;}
  err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 1, &device, NULL);
  if (err != CL_SUCCESS) {printf("%d: %d\n", __LINE__, err); return -1;}
  context = clCreateContext(NULL, 1, &device, NULL, NULL, &err);
  if (err != CL_SUCCESS) {printf("%d: %d\n", __LINE__, err); return -1;}
  size_t mem_size = 0x20000000;  // 512MB
  int i = 0;
  cl_mem (*clCreateBufferNV)(cl_context,cl_mem_flags, cl_mem_flags_NV, size_t, void*, cl_int*) = (cl_mem (*)(cl_context,cl_mem_flags, cl_mem_flags_NV, size_t, void*, cl_int*)) clGetExtensionFunctionAddress("clCreateBufferNV");
  if (clCreateBufferNV == NULL) {printf("invalid function pointer request\n"); return -1;}

  mem1[i] = clCreateBufferNV(context, CL_MEM_READ_WRITE , CL_MEM_PINNED_NV, (size_t)mem_size, NULL, &err);
  if (err != CL_SUCCESS) {printf("%d: %d\n", __LINE__, err); return -1;}
}
$ nvcc -o t1 t1.cpp -lOpenCL
t1.cpp: In function ‘int main(int, char**)’:
t1.cpp:19:177: warning: ‘void* clGetExtensionFunctionAddress(const char*)’ is deprecated [-Wdeprecated-declarations]
 m_flags, cl_mem_flags_NV, size_t, void*, cl_int*) = (cl_mem (*)(cl_context,cl_mem_flags, cl_mem_flags_NV, size_t, void*, cl_int*)) clGetExtens
                                                                                                                                    ^
In file included from /usr/local/cuda-10.0/bin/..//include/CL/opencl.h:42:0,
                 from t1.cpp:1:
/usr/local/cuda-10.0/bin/..//include/CL/cl.h:1228:1: note: declared here
 clGetExtensionFunctionAddress(const char * /* func_name */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
 ^
t1.cpp:19:177: warning: ‘void* clGetExtensionFunctionAddress(const char*)’ is deprecated [-Wdeprecated-declarations]
 m_flags, cl_mem_flags_NV, size_t, void*, cl_int*) = (cl_mem (*)(cl_context,cl_mem_flags, cl_mem_flags_NV, size_t, void*, cl_int*)) clGetExtens
                                                                                                                                    ^
In file included from /usr/local/cuda-10.0/bin/..//include/CL/opencl.h:42:0,
                 from t1.cpp:1:
/usr/local/cuda-10.0/bin/..//include/CL/cl.h:1228:1: note: declared here
 clGetExtensionFunctionAddress(const char * /* func_name */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
 ^
t1.cpp:19:225: warning: ‘void* clGetExtensionFunctionAddress(const char*)’ is deprecated [-Wdeprecated-declarations]
 , cl_int*) = (cl_mem (*)(cl_context,cl_mem_flags, cl_mem_flags_NV, size_t, void*, cl_int*)) clGetExtensionFunctionAddress("clCreateBufferNV");
                                                                                                                                             ^
In file included from /usr/local/cuda-10.0/bin/..//include/CL/opencl.h:42:0,
                 from t1.cpp:1:
/usr/local/cuda-10.0/bin/..//include/CL/cl.h:1228:1: note: declared here
 clGetExtensionFunctionAddress(const char * /* func_name */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
 ^
$ ./t1
$

The test case here is Ubuntu 16.04, CUDA 10.0, driver 418.40.04, Tesla V100

You may wish to try a newer GPU driver on your setup. I don’t have a convenient setup with driver version 384.111 to test, and I’m not able to find out whether that driver supports this capability. Since the GTC slides you linked say the functionality will be available in production in and after Q2 2018, and the R384 driver branch predates that, I wouldn’t be surprised if the functionality wasn’t checked into R384. At least, I wouldn’t expect it to be in 384.111 based on that note. 384.111 was released on January 4, 2018:

https://www.nvidia.com/download/driverResults.aspx/128737/en-us

I also won’t be able to tell you which drivers have this functionality and which don’t. I suggest you use a recent driver for your GPU. That’s good practice in general, and its also generally helpful to test on the latest driver when you are having an issue. Things get fixed all the time.

I also understand you may be using a university or other facility research cluster for which updating the GPU driver is not a trivial matter or under your direct control. However, 384.111 is quite old, and hopefully (if that is the case) you can get your IT staff to update the driver.

Thanks for your fast reply and your helpful code example. It also threw a -30 error on our university cluster, but worked fine on the private computer of a colleague, who uses the same hardware with a more up-to-date driver (driver 399.24). So I think it really was the drivers fault and I will ask the IT staff for an update as you suggested.

Thanks again for your good support. Kind regards,
Fabian