How can the OpenCL error code -44 CL_INVALID_PROGRAM appear if program is valid?

Viewed 431

In some seemingly random, but reproducible occasions, program.build(...) returns error -44 which means CL_INVALID_PROGRAM, so program is supposed to be invalid. However program is declared in the line above, only depending on context and source. I have checked that source is valid (no errors in kernel_code) and context only depends on device and device is also valid (tested on Nvidia Titan Xp and GTX 960M). How can program not be valid then?

Context context = Context(device);
string kernel_code = opencl_code();
Program::Sources source;
source.push_back({ kernel_code.c_str(), kernel_code.length() });
Program program = Program(context, source);
int error = program.build("-cl-fast-relaxed-math -w");
1 Answers

Usually because you already brought the driver into an unstable state earlier in your application. You need to pay utmost attention to threading issues (including which APIs are guaranteed to be threadsafe and which are not) and potential heap corruptions (use after free, buffer overflows) when dealing with the graphic APIs, the implementations behind are easily corrupted.

CL_INVALID_PROGRAM and other errors are often misleading, and occur at an apparently unrelated point in time. Specifically, they just indicate that any internal error check has failed, but are rarely mapped in a meaningful way.

If you can actually reproduce this in a minimal, reproducible example (that means: not in the context of a full application, and without any multi threading) then your best hope is to file a bug with NVidia.

If not reproducible in a minimal example, then it's almost certain that you caused undefined behavior somewhere else in your application.

Related