5 Replies Latest reply on Sep 14, 2012 2:06 PM by yurtesen

    How to debug libOpenCL?


      Hello All,


      I install OpenCL from AMD distributed to /opt  directory on  the Linux Operation system. LibOpenCL cannot debugged after I programming include OpenCL. How to set flag compile library source code in order to debugging the libOpenCL?. I have problem in funcion the clEnqueueMapBuffer show  a coredump errors.


      Thank in advance,

      Chatsiri Rattana.

        • Re: How to debug libOpenCL?

          You should check for returned error code after each opencl call. (a previous failed operation can cause this)

          You can try to run your program with valgrind (this might give out a lot of unrelated messages also).


          I would guess one of the variables you supply to clEnqueueMapBuffer is wrong. Maybe you might have given wrong size?


          Can you provide a small test case/code where you have this problem?

            • Re: How to debug libOpenCL?

              I map an error code ( number -30 )with cl.h file. It mean invalid value in variables. Debug print address and size of them represent correct value.

              • First step for create buffer. I need to move data on buffer name buffer_input to buffer_output. Buffer_elements defines size 254 characters.

              114             cl_mem buffer_input = clCreateBuffer(platdevices->context,

              115                     CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,

              116                     sizeof(char) * buffer_elements * platdevices->num_devices,

              117                     (void*)platdevices->input_str.c_str(),

              118                     &err);


              120             cl_mem buffer_output =   clCreateBuffer(platdevices->context,

              121                     CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,

              122                     sizeof(char) * buffer_elements * platdevices->num_devices,

              123                     (void*)platdevices->output_str.c_str(),

              124                     &err);


              130             platdevices->mem_input_buffers->push_back(buffer_input);

              131             platdevices->mem_copy_buffers->push_back(buffer_output);


              • Second step, Code across some step OpenCL  mechanism  initializing.

              70           cl_mem  mem_copy = platdevices->mem_copy_buffers->back();                                         

              71           void *  mapped_memory =  clEnqueueMapBuffer(platdevices->queues.back(),                           

              72                                                       mem_copy,

              73                                                       CL_TRUE,

              74                                                       CL_MAP_READ,                                          

              75                                                       0,

              76                                                       sizeof(char) * buffer_elements  * platdevices->num_devices,

              77                                                       0,

              78                                                       NULL,                                                 

              79                                                       NULL,                                                 

              80                                                       &err); 


              If Library can be set debug mode in order to see an internal value of  clEnqueueMapBuffer, It's very good for testing code

                • Re: How to debug libOpenCL?

                  I recommend check the results stored in &err because when something invalid occurs and memory is not actually allocated, your program just continue working until you tell it to map something from a place which doesnt exist, only then it will crash.


                  after every call which takes &err.

                  if (err != CL_SUCCESS) exit;     

                  - is all you need to debug your code ( sure between if and exit, print the code )

                    • Re: How to debug libOpenCL?

                      Programs declare try-catch function support error code.  Testing buffer by initial size of buffer more than 254 (char scalar type). It's represent error code -30. My view ,It's look like non deterministic state for creating and mapping buffer.


                      82           if(err != CL_SUCCESS)                                                                              

                      83             throw clutil_exception(err, "clEnqueueMapBuffer");                                               

                      84         }catch(std::runtime_error ex)                                                                        

                      85         {

                      86           std::cout<< ex.what() <<std::endl;

                      87         } 


                      My question. Is possibly of declare buffer in context over size of input data?  Buffer should be specify size more than input data.

                      Debug with gdb and backtrace command line represent below.


                      Program received signal SIGSEGV, Segmentation fault.

                      [Switching to Thread 0x7ffff7fd5700 (LWP 16444)]

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

                      (gdb) backtrace

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

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

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

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

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

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

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

                      #7  0x00007ffff70d7e9a in start_thread (arg=0x7ffff7fd5700) at pthread_create.c:308

                      #8  0x00007ffff73df4bd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:112

                      #9  0x0000000000000000 in ?? ()