pinotto
pinotto

Reputation: 55

OpenCL kernel definition error clBuildProgram(CL_BUILD_PROGRAM_FAILURE)?

running an openCl application it gives me this error:

ERROR: clBuildProgram(CL_BUILD_PROGRAM_FAILURE)

this is the kernel definition, one error is in the log2 function,

another error is in char* bits = &(char_array[64*(n/m)*(index-1)+it*64]);

another error is in max[it] = *count

and the last error is in if(max[i] > *result){*result = max[i];}.

could you tell me how to correct the definition? Thanks

__kernel void vadd(
    __global char* char_array,
    int m,
    int n,
    __global long* result)
{ 

    int index = get_global_id(0);
    int max_n = n/m;
    if(index == m-1){
        max_n = n - (n/m)*(m-1);
    }

    int max[ max_n ];
    int offset = log2(m);
    for (int it=0; it < max_n; it++)
    {
        char* bits = &(char_array[64*(n/m)*(index-1)+it*64]);
        int count=0;
        for(int i=offset; i<=64; i++)
        {
            if(bits[i]=='0'){
                count++;
            }else{break;}
        }
        max[it] = count;
    }

    *result = 0;
    for(int i=0; i<max_n;i++)
    {
        if(max[i] > *result){*result = max[i];}
    }
    *result = *result +1;
}

Upvotes: 0

Views: 540

Answers (1)

pmdj
pmdj

Reputation: 23438

A mistake on this line:

char* bits = &(char_array[64*(n/m)*(index-1)+it*64]);

is that char* bits when declaring a local variable actually means __private char*, whereas char_array is defined as __global char*. You'll want to make sure that bits uses the same type.

The others aren't immediately obvious to me, but I recommend you add the complete kernel build output to your question as this will help narrow it down.

Upvotes: 1

Related Questions