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");