2 Replies Latest reply on Jul 22, 2014 8:26 PM by boxerab

    Want to re-use image


      I have created an image via


      cl_mem preprocessIn = clCreateImage (context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, &format, &desc,rgbaBuffer,&error_code);


      I would like to keep the preprocessIn image for multiple kernel runs, and just update the host memory buffer rgbaBuffer.


      Is this possible?



        • Re: Want to re-use image


          As per your example, it'll create a image in device memory and initialize the contents from the host memory buffer. So, updating the host memory buffer will not update the image stored in device.

          There are several ways you can transfer data from host to device memory or even you can access the host memory directly from the kernel. But, if the memory object is needed to be access heavily by the kernels, then it is better to place it in device memory and copy the data from host to device as necessary. Your program flow may be look like:


          image_dev = createImage() // in device memory // one time operation


          // copy the data from host to device [FYI: there are other ways to achieve the same]

          img_ptr = clEnqueueMapImage(image_dev, CL_MAP_WRITE)

          // write the data using img_ptr as normal pointer

          clEnqueueUnmapMemObject( image_dev, img_ptr)


          // Access image_dev by several kernels


          Note: synchronization is required (e.g. blocking call for mapping/un-mapping) to ensure that reading from and writing to image data are not done same time.


          For details, I recommend you to go through the following sections in AMD APP OpenCL programming guide:

          5.5 OpenCL Memory Objects

          5.6 OpenCL Data Transfer Optimization

           Application Scenarios and Recommended OpenCL Paths



          • Re: Want to re-use image

            Thanks, Dipak.