5.3.6. Copying Between Image and Buffer Objects
5.3.6. 在图像和缓冲区对象之间复制
To enqueue a command to copy an image object to a buffer object, call the function
要将一个将图像对象复制到缓冲区对象的命令排入队列,请调用函数
// Provided by CL_VERSION_1_0
cl_int clEnqueueCopyImageToBuffer(
cl_command_queue command_queue,
cl_mem src_image,
cl_mem dst_buffer,
const size_t* src_origin,
const size_t* region,
size_t dst_offset,
cl_uint num_events_in_wait_list,
const cl_event* event_wait_list,
cl_event* event);
-
command_queue must be a valid host command-queue. The OpenCL context associated with command_queue, src_image and dst_buffer must be the same.
-
command_queue必须是有效的主机命令队列。与command_queue、src_image和dst_buffer关联的OpenCL上下文必须相同。
-
src_image is a valid image object.
-
src_image是一个有效的图像对象。
-
dst_buffer is a valid buffer object.
-
dst_buffer是一个有效的缓冲区对象。
-
src_origin defines the (x, y, z) offset in pixels in the 1D, 2D or 3D image, the (x, y) offset and the image index in the 2D image array or the (x) offset and the image index in the 1D image array. If src_image is a 2D image object, src_origin[2] must be 0. If src_image is a 1D image or 1D image buffer object, src_origin[1] and src_origin[2] must be 0. If src_image is a 1D image array object, src_origin[2] must be 0. If src_image is a 1D image array object, src_origin[1] describes the image index in the 1D image array. If src_image is a 2D image array object, src_origin[2] describes the image index in the 2D image array. If src_image is a mipmapped image, the mip level to read is determined from src_origin as described in Specifying Mipmap Levels to Image Operations
-
src_origin定义1D、2D或3D图像中以像素为单位的(x,y,z)偏移量、2D图像阵列中的(x、y)偏移量和图像索引或1D图像阵列中(x)偏移量与图像索引。如果src_image是2D图像对象,则src_origin[2]必须为0。如果src_image是1D图像或1D图像缓冲区对象,则src_origin[1]和src_origin[2]必须为0。如果src_image是1D图像数组对象,则src_origin[2]必须为0。如果src_image是1D图像阵列对象,则src_origin[1]描述1D图像数组中的图像索引。如果src_image是2D图像阵列对象,则src_origin[2]描述2D图像阵列中的图像索引。如果src_image是Mipmap映像,则要读取的mip级别是根据src_origin确定的,如“为映像操作指定Mipmap级别”中所述
-
region defines the (width, height, depth) in pixels of the 1D, 2D or 3D rectangle, the (width, height) in pixels of the 2D rectangle and the number of images of a 2D image array or the (width) in pixels of the 1D rectangle and the number of images of a 1D image array. If src_image is a 2D image object, region[2] must be 1. If src_image is a 1D image or 1D image buffer object, region[1] and region[2] must be 1. If src_image is a 1D image array object, region[2] must be 1. The values in region cannot be 0.
-
region定义1D、2D或3D矩形的(宽度、高度、深度)(以像素为单位)、2D矩形的(宽、高)和2D图像阵列的图像数量或1D矩形的(高)和1D图像阵列的(宽)和图像数量。如果src_image是2D图像对象,则region[2]必须为1。如果src_image是1D图像或1D图像缓冲区对象,则region[1]和region[2]必须为1。如果src_image是1D图像阵列对象,则region[2]必须为1。region中的值不能为0。
-
dst_offset refers to the offset where to begin copying data into dst_buffer. The size in bytes of the region to be copied referred to as dst_cb is computed as width × height × depth × bytes/image element if src_image is a 3D image object, is computed as width × height × bytes/image element if src_image is a 2D image, is computed as width × height × arraysize × bytes/image element if src_image is a 2D image array object, is computed as width × bytes/image element if src_image is a 1D image or 1D image buffer object and is computed as width × arraysize × bytes/image element if src_image is a 1D image array object.
-
dst_offset是指开始将数据复制到dst_buffer中的偏移量。如果src_image是3D图像对象,则被称为dst_cb的要复制的区域的大小(以字节为单位)被计算为width×height×depth×bytes/image元素,如果src_image是2D图像,则被计算为width=height×bytes/image元素;如果src_images是2D图像阵列对象,则计算为width=high×arraysize×bytes/image元素;如果src_image是1D图像或1D图像缓冲对象,则其被计算为width×byts/image元;如果src_image是一维图像阵列对象则被计算为由width×arraysize。
-
event_wait_list and num_events_in_wait_list specify events that need to complete before this particular command can be executed. If event_wait_list is
NULL
, then this particular command does not wait on any event to complete. If event_wait_list isNULL
, num_events_in_wait_list must be 0. If event_wait_list is notNULL
, the list of events pointed to by event_wait_list must be valid and num_events_in_wait_list must be greater than 0. The events specified in event_wait_list act as synchronization points. The context associated with events in event_wait_list and command_queue must be the same. The memory associated with event_wait_list can be reused or freed after the function returns. -
event_wait_list和num_events_in_wait_list指定在执行此特定命令之前需要完成的事件。如果event_wait_list为NULL,则此特定命令不等待任何事件完成。如果event_wait_list为NULL,则num_events_in_wait_list必须为0。如果event_wait_list不为NULL,则event_wail_list指向的事件列表必须有效,并且num_events_in_wait_list必须大于0。event_wait_list中指定的事件充当同步点。与event_wait_list和command_queue中的事件关联的上下文必须相同。函数返回后,可以重用或释放与event_wait_list关联的内存。
-
event returns an event object that identifies this copy command and can be used to query or queue a wait for this command to complete. If event is
NULL
or the enqueue is unsuccessful, no event will be created and therefore it will not be possible to query the status of this command or to wait for this command to complete. If event_wait_list and event are notNULL
, event must not refer to an element of the event_wait_list array. -
event返回一个事件对象,该对象标识此复制命令,可用于查询或排队等待此命令完成。如果事件为NULL或排队不成功,则不会创建任何事件,因此无法查询此命令的状态或等待此命令完成。如果event_wait_list和event不为NULL,则event不能引用event_wail_list数组的元素。
clEnqueueCopyImageToBuffer returns CL_SUCCESS if the function is executed successfully. Otherwise, it returns one of the following errors:
如果函数执行成功,clEnqueueCopyImageToBuffer将返回CL_SUCCESS。否则,它将返回以下错误之一:
-
CL_INVALID_COMMAND_QUEUE if command_queue is not a valid host command-queue.
-
CL_INVALID_COMMAND_QUEUE(如果命令队列不是有效的主机命令队列)。
-
CL_INVALID_CONTEXT if the context associated with command_queue, src_image and dst_buffer are not the same or if the context associated with command_queue and events in event_wait_list are not the same.
-
CL_INVALID_CONTEXT如果与command_queue、src_image和dst_buffer关联的上下文不相同,或者与command_ queue关联的上下文和event_wait_list中的事件不相同。
-
CL_INVALID_MEM_OBJECT if src_image is not a valid image object or dst_buffer is not a valid buffer object or if src_image is a 1D image buffer object created from dst_buffer.
-
CL_INVALID_MEM_OBJECT如果src_image不是有效的图像对象或dst_buffer不是有效的缓冲对象,或者如果src_image是从dst_bufper创建的1D图像缓冲对象。
-
CL_INVALID_VALUE if src_origin or region is
NULL
. -
如果src_origin或region为NULL,则CL_INVALID_VALUE。
-
CL_INVALID_VALUE if the 1D, 2D or 3D rectangular region specified by src_origin and src_origin + region refers to a region outside src_image, or if the region specified by dst_offset and dst_offset + dst_cb to a region outside dst_buffer.
-
CL_INVALID_VALUE如果由src_origin和src_origin+region指定的1D、2D或3D矩形区域指的是src_image之外的区域,或者如果由dst_offset和dst_offset+dst_cb指定的区域是dst_buffer之外的区域。
-
CL_INVALID_VALUE if values in src_origin and region do not follow rules described in the argument description for src_origin and region.
-
CL_INVALID_VALUE,如果src_origin和region中的值不遵循src_original和region的参数描述中描述的规则。
-
CL_INVALID_EVENT_WAIT_LIST if event_wait_list is
NULL
and num_events_in_wait_list > 0, or event_wait_list is notNULL
and num_events_in_wait_list is 0, or if event objects in event_wait_list are not valid events. -
CL_INVALID_EVENT_WAIT_LIST如果event_wait_list为NULL且num_events_in_wait_list>0,或者event_wait_list不为NULL且num_events_in_wait_list为0,或者如果event_wait_list中的事件对象不是有效事件。
-
CL_MISALIGNED_SUB_BUFFER_OFFSET if dst_buffer is a sub-buffer object and offset specified when the sub-buffer object is created is not aligned to CL_DEVICE_MEM_BASE_ADDR_ALIGN value for device associated with queue. This error code is missing before version 1.1.
-
CL_MISALIGNED_SUB_BUFFER_OFFSET(如果dst_buffer是子缓冲区对象,并且创建子缓冲区时指定的偏移量未与队列相关设备的CL_DEVICE_MEM_BASE_ADDR_ALIGN值对齐)。1.1版本之前缺少此错误代码。
-
CL_INVALID_IMAGE_SIZE if image dimensions (image width, height, specified or compute row and/or slice pitch) for src_image are not supported by device associated with queue.
-
CL_INVALID_IMAGE_SIZE如果与队列相关联的设备不支持src_image的图像尺寸(图像宽度、高度、指定或计算行或切片间距)。
-
CL_IMAGE_FORMAT_NOT_SUPPORTED if image format (image channel order and data type) for src_image are not supported by device associated with queue.
-
如果与队列关联的设备不支持src_image的图像格式(图像通道顺序和数据类型),则CL_IMAGE_FORMAT_NOT_SUPPORTED。
-
CL_MEM_OBJECT_ALLOCATION_FAILURE if there is a failure to allocate memory for data store associated with src_image or dst_buffer.
-
如果为与src_image或dst_buffer相关联的数据存储分配内存失败,则CL_MEM_OBJECT_ALLOCATION_FAILURE。
-
CL_INVALID_OPERATION if the device associated with command_queue does not support images (i.e. CL_DEVICE_IMAGE_SUPPORT specified in the Device Queries table is CL_FALSE).
-
CL_INVALID_OPERATION,如果与command_queue关联的设备不支持映像(即,在设备查询表中指定的CL_DEVICE_IMAGE_SUPPORT为CL_FALSE)。
-
CL_OUT_OF_RESOURCES if there is a failure to allocate resources required by the OpenCL implementation on the device.
-
CL_OUT_OF_RESOURCES,如果在设备上分配OpenCL实现所需的资源失败。
-
CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the OpenCL implementation on the host.
-
CL_OUT_OF_HOST_MEMORY,如果在主机上分配OpenCL实现所需的资源失败。
-
CL_INVALID_MIP_LEVEL if the cl_khr_mipmap_image extension is supported, and the mip level specified in src_origin is not a valid level for src_image,
-
CL_INVALID_MIP_LEVEL如果支持cl_khr_mipmap_image扩展,并且src_origin中指定的MIP级别不是src_image的有效级别,
To enqueue a command to copy a buffer object to an image object, call the function
要将一个将缓冲区对象复制到图像对象的命令排入队列,请调用函数
// Provided by CL_VERSION_1_0
cl_int clEnqueueCopyBufferToImage(
cl_command_queue command_queue,
cl_mem src_buffer,
cl_mem dst_image,
size_t src_offset,
const size_t* dst_origin,
const size_t* region,
cl_uint num_events_in_wait_list,
const cl_event* event_wait_list,
cl_event* event);
-
command_queue must be a valid host command-queue. The OpenCL context associated with command_queue, src_buffer and dst_image must be the same.
-
command_queue必须是有效的主机命令队列。与command_queue、src_buffer和dst_image关联的OpenCL上下文必须相同。
-
src_buffer is a valid buffer object.
-
src_buffer是一个有效的缓冲区对象。
-
dst_image is a valid image object.
-
dst_image是一个有效的图像对象。
-
src_offset refers to the offset where to begin copying data from src_buffer.
-
src_offset是指开始从src_buffer复制数据的偏移量。
-
dst_origin defines the (x, y, z) offset in pixels in the 1D, 2D or 3D image, the (x, y) offset and the image index in the 2D image array or the (x) offset and the image index in the 1D image array. If dst_image is a 2D image object, dst_origin[2] must be 0. If dst_image is a 1D image or 1D image buffer object, dst_origin[1] and dst_origin[2] must be 0. If dst_image is a 1D image array object, dst_origin[2] must be 0. If dst_image is a 1D image array object, dst_origin[1] describes the image index in the 1D image array. If dst_image is a 2D image array object, dst_origin[2] describes the image index in the 2D image array. If dst_image is a mipmapped image, the mip level to write is determined from dst_origin as described in Specifying Mipmap Levels to Image Operations
-
dst_origin定义1D、2D或3D图像中以像素为单位的(x,y,z)偏移、2D图像阵列中的(x、y)偏移和图像索引或1D图像阵列中(x)偏移和图象索引。如果dst_image是2D图像对象,则dst_origin[2]必须为0。如果dst_image是1D图像或1D图像缓冲区对象,则dst_origin[1]和dst_origin[2]必须为0。如果dst_image是1D图像数组对象,则dst_origin[2]必须为0。如果dst_image是1D图像阵列对象,则dst_origin[1]描述1D图像数组中的图像索引。如果dst_image是2D图像阵列对象,则dst_origin[2]描述2D图像阵列中的图像索引。如果dst_image是Mipmap映像,则要写入的mip级别由dst_origin确定,如“为映像操作指定Mipmap级别”中所述
-
region defines the (width, height, depth) in pixels of the 1D, 2D or 3D rectangle, the (width, height) in pixels of the 2D rectangle and the number of images of a 2D image array or the (width) in pixels of the 1D rectangle and the number of images of a 1D image array. If dst_image is a 2D image object, region[2] must be 1. If dst_image is a 1D image or 1D image buffer object, region[1] and region[2] must be 1. If dst_image is a 1D image array object, region[2] must be 1. The values in region cannot be 0.
-
region定义1D、2D或3D矩形的(宽度、高度、深度)(以像素为单位)、2D矩形的(宽、高)和2D图像阵列的图像数量或1D矩形的(高)和1D图像阵列的(宽)和图像数量。如果dst_image是2D图像对象,则region[2]必须为1。如果dst_image是1D图像或1D图像缓冲区对象,则region[1]和region[2]必须为1。如果dst_image是1D图像数组对象,则region[2]必须为1。区域中的值不能为0。
-
event_wait_list and num_events_in_wait_list specify events that need to complete before this particular command can be executed. If event_wait_list is
NULL
, then this particular command does not wait on any event to complete. If event_wait_list isNULL
, num_events_in_wait_list must be 0. If event_wait_list is notNULL
, the list of events pointed to by event_wait_list must be valid and num_events_in_wait_list must be greater than 0. The events specified in event_wait_list act as synchronization points. The context associated with events in event_wait_list and command_queue must be the same. The memory associated with event_wait_list can be reused or freed after the function returns. -
event_wait_list和num_events_in_wait_list指定在执行此特定命令之前需要完成的事件。如果event_wait_list为NULL,则此特定命令不等待任何事件完成。如果event_wait_list为NULL,则num_events_in_wait_list必须为0。如果event_wait_list不为NULL,则event_wail_list指向的事件列表必须有效,并且num_events_in_wait_list必须大于0。event_wait_list中指定的事件充当同步点。与event_wait_list和command_queue中的事件关联的上下文必须相同。函数返回后,可以重用或释放与event_wait_list关联的内存。
-
event returns an event object that identifies this copy command and can be used to query or queue a wait for this command to complete. If event is
NULL
or the enqueue is unsuccessful, no event will be created and therefore it will not be possible to query the status of this command or to wait for this command to complete. If event_wait_list and event are notNULL
, event must not refer to an element of the event_wait_list array. -
event返回一个事件对象,该对象标识此复制命令,可用于查询或排队等待此命令完成。如果事件为NULL或排队不成功,则不会创建任何事件,因此无法查询此命令的状态或等待此命令完成。如果event_wait_list和event不为NULL,则event不能引用event_wail_list数组的元素。
The size in bytes of the region to be copied from src_buffer referred to as src_cb is computed as width × height × depth × bytes/image element if dst_image is a 3D image object, is computed as width × height × bytes/image element if dst_image is a 2D image, is computed as width × height × arraysize × bytes/image element if dst_image is a 2D image array object, is computed as width × bytes/image element if dst_image is a 1D image or 1D image buffer object and is computed as width × arraysize × bytes/image element if dst_image is a 1D image array object.
如果dst_image是3D图像对象,则被称为src_cb的要从src_buffer复制的区域的大小(以字节为单位)被计算为width×height×depth×bytes/image元素,如果dst_image是2D图像,则被计算为width×height×bytes/image元素;如果dst_image是2D图像阵列对象,则计算为width×height×arraysize×bytes/image元素。如果dst_image是1D图像或1D图像缓冲对象,则将被计算为width×bytes/image元;如果dst_image是1D图像阵列对象,计算为width×arraysize x bytes/image元素。
clEnqueueCopyBufferToImage returns CL_SUCCESS if the function is executed successfully. Otherwise, it returns one of the following errors:
如果函数执行成功,clEnqueueCopyBufferToImage将返回CL_SUCCESS。否则,它将返回以下错误之一:
-
CL_INVALID_COMMAND_QUEUE if command_queue is not a valid host command-queue.
-
CL_INVALID_COMMAND_QUEUE(如果命令队列不是有效的主机命令队列)。
-
CL_INVALID_CONTEXT if the context associated with command_queue, src_buffer and dst_image are not the same or if the context associated with command_queue and events in event_wait_list are not the same.
-
CL_INVALID_CONTEXT如果与command_queue、src_buffer和dst_image关联的上下文不相同,或者如果与command _queue关联的语境与event_wait_list中的事件不相同。
-
CL_INVALID_MEM_OBJECT if src_buffer is not a valid buffer object or dst_image is not a valid image object or if dst_image is a 1D image buffer object created from src_buffer.
-
CL_INVALID_MEM_OBJECT如果src_buffer不是有效的缓冲对象或dst_image不是有效的图像对象,或者如果dst_iimage是从src_buff创建的1D图像缓冲对象。
-
CL_INVALID_VALUE if dst_origin or region is
NULL
. -
如果dst_origin或region为NULL,则CL_INVALID_VALUE。
-
CL_INVALID_VALUE if the 1D, 2D or 3D rectangular region specified by dst_origin and dst_origin + region refer to a region outside dst_image, or if the region specified by src_offset and src_offset + src_cb refer to a region outside src_buffer.
-
CL_INVALID_VALUE如果由dst_origin和dst_origin+区域指定的1D、2D或3D矩形区域指的是dst_image之外的区域,或者如果由src_offset和src_offset+src_cb指定的区域是指src_buffer之外的区域。
-
CL_INVALID_VALUE if values in dst_origin and region do not follow rules described in the argument description for dst_origin and region.
-
CL_INVALID_VALUE,如果dst_origin和region中的值不遵循dst_origing和region的参数描述中描述的规则。
-
CL_INVALID_EVENT_WAIT_LIST if event_wait_list is
NULL
and num_events_in_wait_list > 0, or event_wait_list is notNULL
and num_events_in_wait_list is 0, or if event objects in event_wait_list are not valid events. -
CL_INVALID_EVENT_WAIT_LIST如果event_wait_list为NULL且num_events_in_wait_list>0,或者event_wait_list不为NULL且num_events_in_wait_list为0,或者如果event_wait_list中的事件对象不是有效事件。
-
CL_MISALIGNED_SUB_BUFFER_OFFSET if src_buffer is a sub-buffer object and offset specified when the sub-buffer object is created is not aligned to CL_DEVICE_MEM_BASE_ADDR_ALIGN value for device associated with queue. This error code is missing before version 1.1.
-
CL_MISALIGNED_SUB_BUFFER_OFFSET(如果src_buffer是子缓冲区对象,并且创建子缓冲区时指定的偏移量未与队列相关设备的CL_DEVICE_MEM_BASE_ADDR_ALIGN值对齐)。1.1版本之前缺少此错误代码。
-
CL_INVALID_IMAGE_SIZE if image dimensions (image width, height, specified or compute row and/or slice pitch) for dst_image are not supported by device associated with queue.
-
CL_INVALID_IMAGE_SIZE如果与队列相关联的设备不支持dst_image的图像尺寸(图像宽度、高度、指定或计算行和/或切片间距)。
-
CL_IMAGE_FORMAT_NOT_SUPPORTED if image format (image channel order and data type) for dst_image are not supported by device associated with queue.
-
如果与队列关联的设备不支持dst_IMAGE的图像格式(图像通道顺序和数据类型),则CL_IMAGE_FORMAT_NOT_SUPPORTED。
-
CL_MEM_OBJECT_ALLOCATION_FAILURE if there is a failure to allocate memory for data store associated with src_buffer or dst_image.
-
如果为与src_buffer或dst_image关联的数据存储分配内存失败,则CL_MEM_OBJECT_ALLOCATION_FAILURE。
-
CL_INVALID_OPERATION if the device associated with command_queue does not support images (i.e. CL_DEVICE_IMAGE_SUPPORT specified in the Device Queries table is CL_FALSE).
-
CL_INVALID_OPERATION,如果与command_queue关联的设备不支持映像(即,在设备查询表中指定的CL_DEVICE_IMAGE_SUPPORT为CL_FALSE)。
-
CL_OUT_OF_RESOURCES if there is a failure to allocate resources required by the OpenCL implementation on the device.
-
CL_OUT_OF_RESOURCES,如果在设备上分配OpenCL实现所需的资源失败。
-
CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the OpenCL implementation on the host.
-
CL_OUT_OF_HOST_MEMORY,如果在主机上分配OpenCL实现所需的资源失败。
-
CL_INVALID_MIP_LEVEL if the cl_khr_mipmap_image extension is supported, and the mip level specified in dst_origin is not a valid level for dst_image,
-
CL_INVALID_MIP_LEVEL如果支持cl_khr_mipmap_image扩展,并且在dst_origin中指定的MIP级别不是dst_image的有效级别,