clEnqueueWriteBuffer causes segmentation fault

I am developing OpenCL code to run my application simultaneously on multiple platforms. For testing purpose I am using only one platform (AMD APP) with Cayman device (dual gpu card) and OpenCL 1.2 version.
While developing, I am getting segmentation fault in the following bold line:

maxSize = 3;
blockSize = 64;
for(icount = 0; icount < numDevices; icount++)
          //printf("Initializing Memory Buffer on device : %s
", device_name[icount]);
          start_itr = (icount * maxSize);
          end_itr = start_itr + (maxSize -1);
      [b]clret = clEnqueueWriteBuffer(queue[icount], d_new_input_2d[icount], CL_TRUE, 0, maxSize * blockSize * sizeof(char), &hNewInputPerBlock[(start_itr * blockSize)], 0, NULL, NULL);[/b]

As I think, :slight_smile: each OpenCL API’s routines return error number if there is any mistake in its parameters. So what could be reason for segmentation fault in these routines :oops: ?

Thanks !

Most probably a wrong pointer or an array overflow.
In particular, check the size parameter. It seems dubious (shouldn’t it take start_itr into account?)

I checked the size parameter and buffer overflow, everything is fine.
Regarding the start_ptr, size parameter need not to include this.

One doubt i have about OpenCL implementation for multiple platform to run my applications simultaneously on all available devices across all the available platforms. Please correct me, if my implementation is wrong. To do so, I declared the OpenCL data structures as following:

cl_platform_id          *platforms = NULL;  //OpenCL Platform IDs (single pointer)
cl_uint                      num_platforms;       //Storing number of platforms
cl_device_id             **devices = NULL;   //OpenCL Device IDs (double pointer)
cl_uint                      *num_devices;      //Storing number of devices for each platform
cl_context                 *context = NULL;   //OpenCL context pointer of size equal to number of available platforms (single pointer)
[b]cl_command_queue  *command_queue1; //OpenCL command queues (single pointer)[/b]
cl_uint                       *num_command_queues; //Storing number of command queues
cl_int                         platform_id = -1;   //Counter variable to count number of platforms 
[b]cl_mem                     *d_new_input_2d;  //OpenCL device buffer (single pointer)[/b]

My doubt is in two declarations (command queues and device buffer). As i mentioned that i am developing OpenCL code for multiple platforms, considering this point in my mind,

  1. can i declare command queues as a single pointer of size equal to number of available OpenCL devices across all available platforms?
  2. can i declare device buffer as a single pointer of size equal to number of available OpenCL devices across all available platforms?

I found the reason of getting segmentation fault in clEnqueuWriteBuffer() function.
the first parameter, command queue was NULL value, due to that I was getting segmentation fault.