Proper usage of clCreateProgramWithIL

I am trying to figure out how to properly use the clCreateProgramWithIL function of the OpenCL C API.

More specifically, I am working on a project where I need to get a .cl file from a user, compile it to LLVM IR, instrument the LLVM IR bitcode (using the LLVM IR C++ API) for profiling purposes and then run the instrumented kernels on any device. It seems like clCreateProgramWithIL is what I need, but after using it followed by clBuildProgram, the latter always fails with the following error:

CL_BUILD_PROGRAM_FAILURE
error: undefined reference to `get_global_id()'
error: backend compiler failed build.

I tried converting LLVM IR to SPIR-V with llvm-spirv but I got the same error. Isn’t clBuildProgram supposed to link the intermediate representation (LLVM IR or SPIR-V) with the OpenCL runtime library? Am I misusing the clCreateProgramWithIL function? I can not find any instructions or examples as to how to use it properly.

Hi, I am struggling with the same issue, to me it is unclear how to use clCreateProgramWithIL or clCreateProgramWithBinary. I assumed one needed to compile OpenCL with a SPIR-V compiler but can’t find any information on this.

Hello!

I wrote a sample that demonstrates how to use clCreateProgramWithIL here:

The README describes the steps I used to generate a SPIR-V file from OpenCL C source, but since SPIR-V is an intermediate representation other methods are possible, too.

If you have further questions don’t hesitate to ask - thanks!

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.