Kernel build failure The kernel seems to fail when putting a for loop inside of an if.

I am currently trying to port a program from CUDA to OpenCL for performance benchmarking purposes.

I am having trouble building my OpenCL kernel…

it seems that my code will break on things that I feel it should not…

The following code builds:

[codebox]

unsigned int tid = get_global_id(0);

if( tid < no_of_nodes && g_graph_mask[tid])

{

}

for(int i = 0; i < 20; i++)

{

}

[/codebox]

However this following code fails to build:

[codebox]

unsigned int tid = get_global_id(0);

if( tid < no_of_nodes && g_graph_mask[tid])

{

for(int i = 0; i < 20; i++)

{

}

}

[/codebox]

both of which are inside of the same method signature.

I’m using a GeForce GTX 280 (driver version 190.29)

Does anyone know why this wouldn’t work? The log seems to say nothing and the build error is -42, which I think corresponds to a bad binary (which is weird because I’m importing the source.)

Thank you for the help!

What does the build log say? I find the error codes to be useful but limited. The build log will give you more information about syntax errors.

I think the C binding is clGetBuildInfo.

There is a similar one for C++, and it requires a templated argument to return a string.

I tried using clGetBuildInfo but it appears not to display anything.

[codebox]

char buildString[1000];

err = clGetProgramBuildInfo(kernel1Program, GPUDevices[0], CL_PROGRAM_BUILD_LOG, sizeof(char) * 1000, buildString, NULL);

if(err != CL_SUCCESS)

printf(“Could not get build log.\n”);

printf("%s\n", buildString);

[/codebox]

this seems to only print an empty line when I run it. I have also tried using &buildString in the call to clGetProgramBuildInfo to see if it made a difference, and it resulted in the same empty string.

Try this to set your log buffer length. This is an example from online. Buffers aren’t always one size fits all . :mellow:

resultCL = clGetProgramBuildInfo(oclHandles.program,

                                    oclHandles.devices[0], 

                                    CL_PROGRAM_BUILD_LOG, 

                                    0, 

                                    NULL, 

                                    &length);

    if(resultCL != CL_SUCCESS) 

        throw(string("InitCL()::Error: Getting Program build info(clGetProgramBuildInfo)"));

	char* buffer = (char*)malloc(length);

    resultCL = clGetProgramBuildInfo(oclHandles.program, 

                                    oclHandles.devices[0], 

                                    CL_PROGRAM_BUILD_LOG, 

                                    length, 

                                    buffer, 

                                    NULL);

When I do this, the value of length that is returned is 1 (which I suspect is just the \0 terminator for the string). I know that I can build kernels because I was able to build the examples that came in the sdk.

That exhausts my knowledge.

I’ve never had an empty build log. Even if building succeeds a message about binaries exists (sorry for the vague nature but I don’t remember the exact message).

Thanks for the help. I was finally able to get a successful build, although the logs never seemed to print out anything, so it was a lot of trial and error. I think part of the problem might have been the fact that I was reading from a bool array.

After I changed all the bool* to int* and true and false to 1 and 0, respectively, the problem went away. The specification says that you can’t write if the type is less than 32 bits wide, but it never mentioned bools in the list of forbidden types.