title: OpenCL: Creating image2d_t from float* buffer
body: <p>I'm trying to learn OpenCL with examples available from online. I wrote a HelloWorld matrix multiplication program to multiply float* A &amp; float* B OpenCL device matrices. </p>
  
  <p>Now I would like to change float* B to image2d_t B and compare the execution speed with the former HelloWorld code.</p>
  
  <p>Is it possible to create an image2d_t object from an float* object in OpenCL?</p>
  
  <p>Note:The float* array's are stored in row-major format.</p>
  
  <p>Edit: Adding source code:</p>
  
  <p>Based on @Dithermaster's suggestion, I've created an cl image object and trying to copy from buffer to image.</p>
  
  <p>I'm getting segmentation fault in <code>clEnqueueCopyBufferToImage</code></p>
  
  <pre><code>int main(void) {
  
    // Initialize OpenCL parameters here
    ........................
    //
  
    const size_t arr_width = 1024;
    const size_t arr_height = 1024;
  
    // Populate host array with some dummy data
    float* host_arr = (float*)malloc(sizeof(float)*arr_width*arr_height);
    for (size_t i=0; i&lt;arr_width*arr_height; ++i) { host_arr[i] = 1.0f; }
  
    cl_image_format clImageFormat;
    clImageFormat.image_channel_order = CL_RGBA;
    clImageFormat.image_channel_data_type = CL_FLOAT;
    cl_int errNum;
    const size_t dst_origin[3] = {0,0,0};
    const size_t region[3] = {arr_width,arr_height,1};
  
    // Copy the array to the device
    cl_mem device_arr = clCreateBuffer(cl.context, CL_MEM_READ_WRITE, arr_width*arr_height*sizeof(float), NULL, NULL);
    clEnqueueWriteBuffer(cl.queue, device_c, CL_TRUE, 0, arr_width*arr_height*sizeof(float), host_c, 0, NULL, NULL);
  
    // Create image in device &amp; copy array to image
    cl_mem device_img = clCreateImage2D(cl.context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, &amp;clImageFormat, arr_width, arr_height, 0, NULL, &amp;errNum);
    clEnqueueCopyBufferToImage(cl.queue, device_arr, device_img, 0, dst_origin, region, 0, NULL, NULL); ----&gt; Segmentation fault
  
    // Clean-up
    ................................
    //
    return 0;
  }
  </code></pre>