clBuildProgram error messages?

I’ve got OpenCL happily building a program. When the program is incorrect I get CL_BUILD_PROGRAM_FAILURE back, which is good.

But is there a way to get a more detailed error message back from the (internal) compiler?

e.g. GLSL had glGetShaderInfoLog() and CUDA had a real compiler. I had thought it might come back in the context notification callback (which is really horrible to manage when you need to throw an exception on ret != CL_SUCCESS) but I don’t see any messages.

yes, you can read out the debug messages with clGetProgramBuildInfo. Please read the opencl documentation section 5.4.5.

here’s a “little” hint:

inline void build(CDevice &device, const char* options = "")

					{

							// build

							cl_int ret_val = clBuildProgram(program, 1, &device.device_id, options, NULL, NULL);

	

							// avoid abortion due to CL_BILD_PROGRAM_FAILURE

							if (ret_val != CL_SUCCESS && ret_val != CL_BUILD_PROGRAM_FAILURE)

									CL_CHECK_ERROR(ret_val);

	

							cl_build_status build_status;

							CL_CHECK_ERROR(clGetProgramBuildInfo(program, device.device_id, CL_PROGRAM_BUILD_STATUS, sizeof(cl_build_status), &build_status, NULL));

							if (build_status == CL_SUCCESS)

									return;

	

							char *build_log;

							size_t ret_val_size;

							CL_CHECK_ERROR(clGetProgramBuildInfo(program, device.device_id, CL_PROGRAM_BUILD_LOG, 0, NULL, &ret_val_size));

							build_log = new char[ret_val_size+1];

							CL_CHECK_ERROR(clGetProgramBuildInfo(program, device.device_id, CL_PROGRAM_BUILD_LOG, ret_val_size, build_log, NULL));

	

							// to be carefully, terminate with 

inline void build(CDevice &device, const char* options = “”)

				{

						// build

						cl_int ret_val = clBuildProgram(program, 1, &device.device_id, options, NULL, NULL);



						// avoid abortion due to CL_BILD_PROGRAM_FAILURE

						if (ret_val != CL_SUCCESS && ret_val != CL_BUILD_PROGRAM_FAILURE)

								CL_CHECK_ERROR(ret_val);



						cl_build_status build_status;

						CL_CHECK_ERROR(clGetProgramBuildInfo(program, device.device_id, CL_PROGRAM_BUILD_STATUS, sizeof(cl_build_status), &build_status, NULL));

						if (build_status == CL_SUCCESS)

								return;



						char *build_log;

						size_t ret_val_size;

						CL_CHECK_ERROR(clGetProgramBuildInfo(program, device.device_id, CL_PROGRAM_BUILD_LOG, 0, NULL, &ret_val_size));

						build_log = new char[ret_val_size+1];

						CL_CHECK_ERROR(clGetProgramBuildInfo(program, device.device_id, CL_PROGRAM_BUILD_LOG, ret_val_size, build_log, NULL));



						// to be carefully, terminate with \0

					  // there's no information in the reference whether the string is 0 terminated or not

					  build_log[ret_val_size] = '\0';



						std::cout << "BUILD LOG: '" << filepath << "'" << std::endl;

						std::cout << build_log << std::endl;



						delete[] build_log;

				}

						  // there's no information in the reference whether the string is 0 terminated or not

						  build_log[ret_val_size] = '

inline void build(CDevice &device, const char* options = “”)

				{

						// build

						cl_int ret_val = clBuildProgram(program, 1, &device.device_id, options, NULL, NULL);



						// avoid abortion due to CL_BILD_PROGRAM_FAILURE

						if (ret_val != CL_SUCCESS && ret_val != CL_BUILD_PROGRAM_FAILURE)

								CL_CHECK_ERROR(ret_val);



						cl_build_status build_status;

						CL_CHECK_ERROR(clGetProgramBuildInfo(program, device.device_id, CL_PROGRAM_BUILD_STATUS, sizeof(cl_build_status), &build_status, NULL));

						if (build_status == CL_SUCCESS)

								return;



						char *build_log;

						size_t ret_val_size;

						CL_CHECK_ERROR(clGetProgramBuildInfo(program, device.device_id, CL_PROGRAM_BUILD_LOG, 0, NULL, &ret_val_size));

						build_log = new char[ret_val_size+1];

						CL_CHECK_ERROR(clGetProgramBuildInfo(program, device.device_id, CL_PROGRAM_BUILD_LOG, ret_val_size, build_log, NULL));



						// to be carefully, terminate with \0

					  // there's no information in the reference whether the string is 0 terminated or not

					  build_log[ret_val_size] = '\0';



						std::cout << "BUILD LOG: '" << filepath << "'" << std::endl;

						std::cout << build_log << std::endl;



						delete[] build_log;

				}
';

	

							std::cout << "BUILD LOG: '" << filepath << "'" << std::endl;

							std::cout << build_log << std::endl;

	

							delete[] build_log;

					}

Evidently I missed that in the manual. :">

Thanks!

Hi there,

I have a similar problem.

Trying to run a simple OpenCL app on an iMac with an nVidia card, I get the message
“cvmsErrorCompilerFailure: LLVM compiler has failed to compile a function.”
with the error code CL_BUILD_PROGRAM_FAILURE.

But this only happens when the GPU is selected as a device,
when the CPU is selected, the kernel compiles and the program runs fine.

Is there a difference between the language restrictions for CPU and GPU compilation of the kernel?
The kernel contains a median image filter utilizing a little bubblesort function.

Greetings from Germany and merry xmas!

Konstantin Dols