cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

Paccone
Journeyman III

Kernel doesn't load in program object

Hi I'm a newbie I'm missing something when try to load a kernel into program object.

The opencl initialization runs fine, until it gets to load the kernel:

// Wait what a kernel!
char kernelio[] = "__kernel void karmelo(__global const int a, __global int b)  {b = a + 1;}";

// count bytes
size_t kdim;
for(kdim = 0; kernelio[kdim] != '\0'; kdim++);
cout << "kernel read" << endl;
   
// Insert kernel in program object
cl_program program = clCreateProgramWithSource(contesto, 1, (const char **)&kernelio,
    (const size_t *)&kdim, &context_err);

cout << "kernel inserted in program object" << endl;


When launch the binary, I get only the "kernel read" response message, followed by "Segmentation fault" and end.

I cant figure out the issue!



0 Likes
4 Replies
nou
Exemplar

__global must be pointer so

__kernel void kernelo(__global int *a, __global int b)
{
     b[get_global_id(0)] = a[get_global_id(0)] + 1;
}

0 Likes

Thank you I changed the kernel string this way but the result is exactly the same before:

char kernelio[] =
    "__kernel void karmelo(__global int* a, __global int* b) {b[get_global_id(0)] = a[get_global_id(0)] + 1;}";


The trouble lies all in those sets of code. I think it concerns with array deferentiation or sistax misses in "address-poiter" parameters of clCreateProgramWithSource



0 Likes

I can get it work if I change the method to insert kernel in the string.

I replace this:

// Wait what a kernel!
    char kernelio[] =
    "__kernel void karmelo(__global int* a, __global int* b) {b[get_global_id(0)] = a[get_global_id(0)] + 1;}";
    // count bytes
    size_t kdim;
    for(kdim = 0; kernelio[kdim] != '\0'; kdim++);
    cout << "kernel read" << endl;


with this:

// Load the kernel source code into the array source_str
    FILE *fp;
        char *source_str;
        size_t source_size;
 
        fp = fopen("vector_add_kernel.cl", "r");
        if (!fp) {
            fprintf(stderr, "Failed to load kernel.\n");
            exit(1);
        }
        source_str = (char*)malloc(1000);
        source_size = fread( source_str, 1, 1000, fp);

        fclose( fp );



that i found in an example.

It loads still this kernel, but from file:

__kernel void karmelo(__global int* a, __global int* b) {b[get_global_id(0)] = a[get_global_id(0)] + 1;}


The final well behaving code chunk is:

// Load the kernel source code into the array source_str
    FILE *fp;
        char *source_str;
        size_t source_size;
 
        fp = fopen("vector_add_kernel.cl", "r");
        if (!fp) {
            fprintf(stderr, "Failed to load kernel.\n");
            exit(1);
        }
        source_str = (char*)malloc(1000);
        source_size = fread( source_str, 1, 1000, fp);
        fclose( fp );

   
    // Insert kernel in program object
    cl_program program =
    clCreateProgramWithSource(contesto, 1, (const char **)&source_str,
        (const size_t *)&source_size, NULL);

    cout << "kernel inserted in program object" << endl;



and the issue more than before seems to be in pointer dereference.



0 Likes

Found.

seem that pointer to kernel string must be a pure pointer, not an array.

0 Likes