cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

pydeveloper94
Journeyman III

clCreateKernel creating segmentation fault

Jump to solution

When I try to create a kernel, my program returns a segmentation fault. In my code, I do all of the correct error checking, but clCreateKernel gives a segfault. Why is this happening?

Here is the device information:


1. Device: Loveland


1.1 Hardware version: OpenCL 1.2 AMD-APP (1214.3)


1.2 Software version: 1214.3


1.3 OpenCL C version: OpenCL C 1.2


1.4 Parallel compute units: 2


Here is the related code:


typedef struct cl_container {


    cl_command_queue command_queue;


    cl_context       context;


    cl_device_id     device;


    cl_kernel        kernel;


    cl_platform_id   platform;


    cl_program       program;


} cl_container;



static int


initialize_cl(cl_container *container, char *kernel_source)


{


    // Initialize OpenCL variables


    cl_uint platforms;


    cl_uint devices;


    cl_int error;



    // Initialize platform


    error = clGetPlatformIDs(


        1,


        &(container->platform),


        &platforms);


    printf("platform error: %d\n", error); // prints 0 or CL_SUCCESS




    // Initialize device


    error = clGetDeviceIDs(


        container->platform,


        CL_DEVICE_TYPE_GPU,


        1,


        &(container->device),


        NULL);


    printf("device error: %d\n", error); // prints 0 or CL_SUCCESS




    // Initialize context


    cl_context_properties context_properties[] = {


        CL_CONTEXT_PLATFORM,


        (cl_context_properties) container->platform,


        0


    };


    container->context = clCreateContext(


        context_properties,


        1,


        &(container->device),


        NULL,


        NULL,


        &error);



    printf("context error: %d\n", error); // prints 0 or CL_SUCCESS



    // Create the command queue


    container->command_queue = clCreateCommandQueue(


        container->context,


        container->device,


        0,


        &error);


    printf("command queue error: %d\n", error); // prints 0 or CL_SUCCESS




    // Create the program


    container->program = clCreateProgramWithSource(


        container->context,


        1,


        (const char**)&kernel_source,


        NULL,


        &error);


    printf("program error: %d\n", error); // prints 0 or CL_SUCCESS




    clBuildProgram(


        container->program,


        1,


        NULL,


        NULL,


        NULL,


        NULL);


    printf("program build error: %d\n", error); // prints 0 or CL_SUCCESS




    size_t log_size;


    clGetProgramBuildInfo(


        container->program,


        container->device,


        CL_PROGRAM_BUILD_LOG,


        0,


        NULL,


        &log_size);




    char *log = (char *) malloc(log_size);


    clGetProgramBuildInfo(


        container->program,


        container->device,


        CL_PROGRAM_BUILD_LOG,


        log_size,


        log,


        NULL);


    printf(log); // prints nothing



    // Create the kernel -- SegFault's here


    container->kernel = clCreateKernel(


        container->program,


       KERNEL_NAME,


        &error);



    printf("kernel created\n");



    return 1;


}


Here are the related valgrind and gdb logs:

GDB:


Program received signal SIGSEGV, Segmentation fault.


0x00007fffeed6d48e in ?? () from /opt/AMDAPP/lib/x86_64/libamdocl64.so



bt



#0  0x00007fffeed6d48e in ?? () from /opt/AMDAPP/lib/x86_64/libamdocl64.so


#1  0x00007fffeed5205e in clCreateKernel ()


   from /opt/AMDAPP/lib/x86_64/libamdocl64.so


#2  0x00007ffff14748eb in initialize_epitope_cl (


Valgrind:


==19081== Process terminating with default action of signal 11 (SIGSEGV)


==19081==  Access not within mapped region at address 0x8


==19081==    at 0xCD2E48E: ??? (in /opt/AMDAPP/lib/x86_64/libamdocl64.so)


==19081==    by 0xCD1305D: clCreateKernel (in /opt/AMDAPP/lib/x86_64/libamdocl64.so)


0 Likes
1 Solution

Accepted Solutions
amd_support
Staff
Staff

Re: clCreateKernel creating segmentation fault

Jump to solution

Hi pydeveloper94,

The problem here is with third argument of clBuildProgram(). Could you replace third argument of clBuildProgram() as

NULL -->> &(container->device)

and try it again.

Since the second argument of clBuildProgram() specifies the number of devices in device_list which you mentioned correct and hence third argument should be pointer to a list of devices.

Please update your status if you still see some issue.

Thanks,

AMD_Support

View solution in original post

2 Replies
amd_support
Staff
Staff

Re: clCreateKernel creating segmentation fault

Jump to solution

Hi pydeveloper94,

The problem here is with third argument of clBuildProgram(). Could you replace third argument of clBuildProgram() as

NULL -->> &(container->device)

and try it again.

Since the second argument of clBuildProgram() specifies the number of devices in device_list which you mentioned correct and hence third argument should be pointer to a list of devices.

Please update your status if you still see some issue.

Thanks,

AMD_Support

View solution in original post

pydeveloper94
Journeyman III

Re: Re: clCreateKernel creating segmentation fault

Jump to solution

You are correct, here is the definition for clBuildProgram, in case someone else is curious. Thank you for the help.


cl_int clBuildProgram (


    cl_program program,


    cl_uint num_devices,


    const cl_device_id *device_list,


    const char *options,


    void (*pfn_notify)(cl_program, void *user_data),


    void *user_data)


0 Likes