OpenCL, SPIR-V Intermade Langue usage doubt


I am doing my final degree project about a script that optimize OpenCL projects, changing the kernels from OpenCL to SPIR-V and optimizing in different ways the SPIR-V to evaluate all the times and compare them.

I was initially using only projects which host are written in C, because change the host kernel creation to SPIRV is just change the command clCreateProgramWithSource() to clCreateProgramWithIL(), and also create the parameters to fit the new command, but is not difficult.

I want to ask if it is possible to do this also in C++, I mean, the way how I can change the C++ host to use a SPIR-V kernel instead of a OpenCL kernel.

I have seen that the function used is cl::Program program(context, kernel). I can just use in the parameter kernel a SPIR-V kernel instead of a OpenCL kernel or do i have to change more things to make it work well?

If someone is interested in the project and can help me, contact me at, I will be very thankful because I have more doubts about other things and if an expert could help me it will make me much easier to finish correctly my project.


Hi Enrique!

The OpenCL C++ bindings does include support for clCreateProgramWithIL via this interface:

     * Program constructor to allow construction of program from SPIR-V or another IL.
     * Valid for either OpenCL >= 2.1 or when CL_HPP_USE_IL_KHR is defined.
        const vector<char>& IL,
        bool build = false,
        cl_int* err = NULL)

Note that you will need to define CL_HPP_TARGET_OPENCL_VERSION to be greater than or equal to 210 to compile for OpenCL 2.1 or you will need to define CL_HPP_USE_IL_KHR to use the cl_khr_il_program extension in order to use this function.

You can also call the C function clCreateProgramWithIL then wrap the result in a C++ cl::Program object if you’d prefer. This what I ended up doing in my SPIR-V sample, because I wanted to conditionally call the OpenCL 2.1 function or the extension function depending on the capabilities of the device.

Good luck!

1 Like

It worked to me!
Many thanks for the help