CL_INVALID_OPERATION when calling clCreateProgramWithIL

Hi, the following call to clCreateProgramWithIL returns the error code -59 (CL_INVALID_OPERATION)

#ifdef CL_VERSION_2_2

	cl_int err = 0;
	std::vector<cl_uchar> spirv = readSPIRVFromFile(path);
	program = clCreateProgramWithIL(context, (const void*), spirv.size(), &err);

	if (err != CL_SUCCESS)
		printf("Error: Failed to create program with IL %d\n", err);

I’ve been using this good example as reference SimpleOpenCLSamples/main.cpp at master · bashbaug/SimpleOpenCLSamples · GitHub
and the code for readSPIRVFromFile was taken directly from there (shown below).

static std::vector<cl_uchar> readSPIRVFromFile(const std::string& filename)
	std::ifstream is(filename, std::ios::binary);
	std::vector<cl_uchar> ret;

	if (!is.good())
		printf("Couldn't open file '%s'\n", filename.c_str());
		return ret;

	size_t filesize = 0;
	is.seekg(0, std::ios::end);
	filesize = (size_t)is.tellg();
	is.seekg(0, std::ios::beg);

	ret.insert(ret.begin(), std::istreambuf_iterator<char>(is), std::istreambuf_iterator<char>());

	return ret;

Does anyone have any idea why the clCreateProgramWithIL call returns CL_INVALID_OPERATION? The documentation doesn’t say that this method should be able to return that error code which makes me think that this could be something to do with my hardware setup. I’m using a GTX 3060ti with updated drivers which should be modern enough to support OpenCL 2.2, and I’m also enforcing a minimum version of OpenCL 2.2 in CMakeLists.txt. I’m using clang and llvm-spirv builds from only a couple days and they seem to compile my kernel file to .spv correctly. At this point I’m out of ideas, would appreciate any suggestions. Cheers.

So I realise my mistake, I was looking at the documentation for OpenCL 2.2 when I should have been looking at the OpenCL 3.0 documentation, as that’s the version being run on my device (RTX 3060ti). The device version can be queried using the CL_DEVICE_VERSION enum and clGetDeviceInfo method.
It seems NVIDIA has chosen not to implement the clCreateProgramWithIL method in their OpenCL 3.0 release so this method can’t be used.

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