Problem maybe in clBuildProgram


I initially build, compile and execute my openCL program in my AMD notebook. But, now i need to execute in GPU card, and our GPU Card is in a machine that have NVIDA CArd. When i compile my program in a GPU NVDIA, don’t show the error message, in true show the set of chars that i show bellow: ====================================================================================================================================================================================================

The code bellow work in my AMD, but i think that don’t work well in NVDIA CARD.

cl_int erro_compila_kernel = clBuildProgram(program, 1, &device, NULL, NULL, NULL);

//Verifica se houve erro na compilação de todos os Kernels atribuidos a Program.
if( erro_compila_kernel != CL_SUCCESS )
	char buff_erro[0x10000];
	clGetProgramBuildInfo( program,

Kernel compilado com sucesso.

A other strange thing is that, when i configured the NVDIA SDK, accused that only one OPenCL source is avaliable, GPU works with opencl, but MultiCore don’t.


What is the value of erro_compila_kernel? What build log is printed above? Can you show it? If you don’t see a build log, try doing this instead:

char *buff_erro;
cl_int errcode;
size_t build_log_len;
errcode = clGetProgramBuildInfo( program, device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_len);
if(errcode) { printf("clGetProgramBuildInfo failed at line %d
", __LINE__); exit(-1); }

buf_erro = malloc(build_log_len);
if(!buf_erro) { printf("malloc failed at line %d
", __LINE__); exit(-2);}

errcode = clGetProgramBuildInfo( program, device, CL_PROGRAM_BUILD_LOG, build_log_len, buf_erro, NULL);
if(errcode) { printf("clGetProgramBuildInfo failed at line %d
", __LINE__); exit(-3); }

printf("Build log: 
", buf_erro);


The value of erro_compila_kernel is 0 (false), entering in if clausule.
It ends up printing the build log, but the content of build log, is a lot of ‘=’ chars.
Don’t displays any decipherable error message.

And, a thing that i think is very strange is that my code work well in my AMD note when it’s run in CPU, but when i run in a other machine that have a GPU, this occurs.

Do you know what can is happening?

Very Thanks,

If erro_compila_kernel was zero then it’s equal to CL_SUCCESS. That doesn’t make sense. Can you check again the value returned by clBuildProgram()?

Also, copy the code I showed earlier and run it instead. Maybe the build log will look correctly now.


I used your code and the errors showed better than my code, thanks.
But, i got what’s going.
The buffer of command don’t showed all errors.
So, i put the errors messages in a file and checked what was happening.
In a research that i did a person had a same problem that i have currently, but the people that answer the question don’t showed how solve only what’s going.

The problem dont occurs when i run my code in CPU, only in GPU.
When i load my .h and .cpp files in a array of chars , i put manualy the ‘\0’ char in the end of vector to certify that there is the final of file, for later be compiled in kernel.

But, even with ‘\0’ the rest of vector ( trash of memory ) going to be compiled in kernel, and so, generating error.

Do you know how can i send only what’s in the file for be compiled?

The error log shows that is:

:1: error: expected identifier or ‘(’
ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍýýýý««««««««#include <C:/Documents and Settings/All Users/Dados de aplicativos/NVIDIA Corporation/NVIDIA GPU Computing SDK/OpenCL/src/Intervalar/intervalar_metodos.h>

Very Thanks,

Luiz Drumond

So the problem is that the source code you pass to clCreateProgramWithSource() contains some garbage? How are you reading that source code from a file?


But the problem don’t is in load the file, but in file in a vector. Whether i’m allocating a vector with 10000 of chars and my code use only 8000 with ‘\0’ in the end, the compilation processo is ignoring ‘\0’ at the end of vector and send whole of vector, including the 2000 positions that don’t was used, that have garbage of memory.
This problem don’t occurs in CPU, but when i set to run in GPU occurs.

Sorry my english, don’t is very good.

And, very thanks for whole help that you give me in this and others posts.

I forgot to put the code that i load my .cpp, .h and kernel to be compiled.

The code as follow bellow:

ifstream arquivo;
char *intervalar_metodos_arquivo = (char *) malloc(10000 * sizeof(char));
int i = 0;
//------ intervalar_metodos.cpp“intervalar_metodos.cpp”);

	intervalar_metodos_arquivo[i] = arquivo.get();

intervalar_metodos_arquivo[i] = '\0';

The way you are reading the file looks mostly okay, except it won’t work well for long files.

Just in case the problem is in how you read the file, here’s a quick way to do it:

size_t length;
char* source;
ifstream arquivo("intervalar_metodos.cpp");

     // Error message here: could not open file

// get length of file
arquivo.seekg(0, ios::end);
length = length.tellg();
length.seekg(0, ios::beg);

// allocate memory
source = new char[length + 1];

// read file, length);

// add null termination to string
source[length] = 0;