Till now we discussed how to create an image. The OpenCL provides APIs to transfer image data to device image buffer before the kernel is launched. Similarly, there is a function which transfers the image computed data back to the host memory. The clEnqueueWriteImage
function copies the data from host to device memory as follows:
cl_int clEnqueueWriteImage (cl_command_queue command_queue, cl_mem image,cl_bool blocking_write,const size_t *origin,const size_t *region,size_t row_pitch,size_t slice_pitch,const void * ptr,cl_uint num_events_in_wait_list,const cl_event *event_wait_list,cl_event *event)
The clEnqueueReadImage
function copies the data back from device to host memory as follows:
cl_int clEnqueueReadImage (cl_command_queue command_queue,cl_mem image,cl_bool blocking_read,const size_t *origin,const size_t *region,size_t row_pitch,size_t slice_pitch,void *ptr,cl_uint num_events_in_wait_list,const cl_event *event_wait_list,cl_event *event)