I actually succeeded now in creating a library of my noise-generation code to be used in a kernel. I learned now something about OpenCL Nvidia driver that isn’t obvious from the error messages.
- my NVIDIA GeForce GTX 1050 doesn’t support the OpenCL intermediate language. So I couldn’t use
clCreateProgramWithIL. Version OpenCL 3.0 CUDA 11.4.112 and Profile: FULL_PROFILE but no IL support. - I have to include all sources in the library as one big string. Then OpenCL can compile and link them as a library.
- The header files are just
cl_programobjects that are not compiled. That means that for each header file you want to add you must just doclCreateProgramWithSourceand notclBuildProgramorclCompileProgram. - Code can’t be double. That means that you need to make sure that function/definitions in your library are not copied in your final kernel code. I had a random numbers generator code both in my lib and in my kernel included and this doesn’t work.
But finally it works. Now I can compile beforehand my noise generator functions in a OpenCL library and use it in any kernel I like. Sadly the GTX 1050 doesn’t support IL so I have to compile the library every time I start the application.
For curious people my code is here
https://github.com/devent/anl-opencl/blob/develop/anlopencl/src/test/cpp/OpenCLContext.cpp#L252