Read读(从设备到主机)
// 将缓存对象中的数据读到内存对象中 cl_int clEnqueueReadBuffer ( cl_command_queue command_queue, //命令队列 cl_mem buffer, // 缓存对象 cl_bool blocking_read, //CL_TRUE 或 CL_FALSE 是否阻塞 size_t offset, // 偏置位置 size_t size, //大小 void *ptr, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event )
// 将图像对象中的数据读到内存对象中 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 )
// 参考: https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/clEnqueueReadImage.html
write写从主机到设备
// 将主机内存写到缓存对象中 cl_int clEnqueueWriteBuffer ( cl_command_queue command_queue, // 命令队列 cl_mem buffer, cl_bool blocking_write, size_t offset, size_t size, const void *ptr, // host memory cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event ) // 将主机内存写到图像对象中 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 input_row_pitch , size_t input_slice_pitch , const void * ptr , //主机地址 cl_uint num_events_in_wait_list , const cl_event *event_wait_list , cl_event *event )
内存映射命令
参考:https://www.khronos.org/registry/OpenCL/sdk/2.0/docs/man/xhtml/clEnqueueMapBuffer.html
// 将缓存对象中的区域映射到主机内存 // 返回映射指针 void * clEnqueueMapBuffer ( cl_command_queue command_queue, //命令队列 cl_mem buffer, //缓存对象 cl_bool blocking_map, cl_map_flags map_flags, // 映射标签 size_t offset, size_t size, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event, cl_int *errcode_ret ) // 将图像对象中的区域映射到主机内存 // 返回映射指针 void * clEnqueueMapImage ( cl_command_queue command_queue , //命令 cl_mem image , //图像对象 cl_bool blocking_map , cl_map_flags map_flags , const size_t * origin , const size_t * region , size_t *image_row_pitch , size_t *image_slice_pitch , cl_uint num_events_in_wait_list , const cl_event *event_wait_list , cl_event *event , cl_int *errcode_ret ) //解映射(将主机内存中存在的内存对象) cl_int clEnqueueUnmapMemObject ( cl_command_queue command_queue , //命令队列 cl_mem memobj, //缓存对象 或 图像对象 void *mapped_ptr, //映射指针 cl_uint num_events_in_wait_list , const cl_event *event_wait_list , cl_event *event )
cl_map_flags | Description |
---|---|
CL_MAP_READ |
This flag specifies that the region being mapped in the memory object is being mapped for reading. The pointer returned by |
CL_MAP_WRITE |
This flag specifies that the region being mapped in the memory object is being mapped for writing. The pointer returned by |
CL_MAP_WRITE_INVALIDATE_REGION |
This flag specifies that the region being mapped in the memory object is being mapped for writing. The contents of the region being mapped are to be discarded. This is typically the case when the region being mapped is overwritten by the host. This flag allows the implementation to no longer guarantee that the pointer returned by
|
内存对象间复制
参考:https://www.khronos.org/registry/OpenCL/sdk/2.0/docs/man/xhtml/clEnqueueCopyBuffer .html
clEnqueueCopyBuffer : 缓存对象--->缓存对象
clEnqueueCopyImage: 图像对象---->图像对象
clEnqueueCopyBufferToImage: 缓存对象--->图像对象
clEnqueueCopyImageToBuffer
clEnqueueCopyBufferRect