cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

boxerab
Challenger

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?

Thanks!

0 Likes
1 Solution
dipak
Staff

Hi,

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

          5.6.2.4 Application Scenarios and Recommended OpenCL Paths

Regards,

View solution in original post

0 Likes
2 Replies
dipak
Staff

Hi,

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

          5.6.2.4 Application Scenarios and Recommended OpenCL Paths

Regards,

0 Likes
boxerab
Challenger

Thanks, Dipak.

0 Likes