OpenCL™规范 5.3.7. 映射图像对象

5.3.7. Mapping Image Objects
5.3.7. 映射图像对象

To enqueue a command to map a region in the image object given by image into the host address space and returns a pointer to this mapped region, call the function

要将一个命令排入队列,将图像对象中由图像给出的区域映射到主机地址空间,并返回指向该映射区域的指针,请调用函数

// Provided by CL_VERSION_1_0
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);
  • command_queue must be a valid host command-queue.

  • command_queue必须是有效的主机命令队列。

  • image is a valid image object. The OpenCL context associated with command_queue and image must be the same.

  • image是有效的图像对象。与command_queue和image关联的OpenCL上下文必须相同。

  • blocking_map indicates if the map operation is blocking or non-blocking.

  • blocking_map指示映射操作是阻塞还是非阻塞。

  • map_flags is a bit-field and is described in the Memory Map Flags table.

  • ​map_flags是一个位字段,在Memory map flags表中进行了描述。

  • origin defines the (xyz) offset in pixels in the 1D, 2D or 3D image, the (xy) offset and the image index in the 2D image array or the (x) offset and the image index in the 1D image array. If image is a 2D image object, origin[2] must be 0. If image is a 1D image or 1D image buffer object, origin[1] and origin[2] must be 0. If image is a 1D image array object, origin[2] must be 0. If image is a 1D image array object, origin[1] describes the image index in the 1D image array. If image is a 2D image array object, origin[2] describes the image index in the 2D image array.

  • origin定义1D、2D或3D图像中以像素为单位的(x,y,z)偏移、2D图像阵列中的(x、y)偏移和图像索引或1D图像阵列中(x)偏移和图象索引。如果图像是2D图像对象,则origin[2]必须为0。如果图像是1D图像或1D图像缓冲区对象,则origin[1]和原点[2]必须为0。如果图像是1D图像阵列对象,则origin[2]必须为0。如果图像是1D图像阵列对象,origin[1]描述1D图像数组中的图像索引。如果图像是2D图像阵列对象,origin[2]描述2D图像阵列中的图像索引。

  • region defines the (widthheightdepth) in pixels of the 1D, 2D or 3D rectangle, the (widthheight) 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 image is a 2D image object, region[2] must be 1. If image is a 1D image or 1D image buffer object, region[1] and region[2] must be 1. If 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图像阵列的(宽)和图像数量。如果图像是2D图像对象,则region[2]必须为1。如果图像是1D图像或1D图像缓冲对象,则region[1]和region[2]必须为1。如果图像是1D图像阵列对象,则region[2]必须为1。region中的值不能为0。

  • image_row_pitch returns the scan-line pitch in bytes for the mapped region. This must be a non-NULL value.

  • image_row_pitch返回映射区域的扫描线间距(以字节为单位)。这必须是一个非NULL值。

  • image_slice_pitch returns the size in bytes of each 2D slice of a 3D image or the size of each 1D or 2D image in a 1D or 2D image array for the mapped region. For a 1D and 2D image, zero is returned if this argument is not NULL. For a 3D image, 1D and 2D image array, image_slice_pitch must be a non-NULL value.

  • image_slice_pitch返回以字节为单位的3D图像的每个2D切片的大小或映射区域的1D或2D图像阵列中的每个1D或二维图像的大小。对于1D和2D图像,如果此参数不为NULL,则返回零。对于3D图像、1D和2D图像阵列,image_slice_pitch必须是非NULL值。

  • event_wait_list and num_events_in_wait_list specify events that need to complete before clEnqueueMapImage can be executed. If event_wait_list is NULL, then clEnqueueMapImage does not wait on any event to complete. If event_wait_list is NULLnum_events_in_wait_list must be 0. If event_wait_list is not NULL, 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指定在执行clEnqueueMapImage之前需要完成的事件。如果event_wait_list为NULL,则clEnqueueMapImage不等待任何事件完成。如果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 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 not NULLevent must not refer to an element of the event_wait_list array.

  • event返回一个标识此命令的事件对象,可用于查询或排队等待此命令完成。如果事件为NULL或排队不成功,则不会创建任何事件,因此无法查询此命令的状态或等待此命令完成。如果event_wait_list和event不为NULL,则event不能引用event_wail_list数组的元素。

  • errcode_ret will return an appropriate error code. If errcode_ret is NULL, no error code is returned.

  • errcode_ret将返回相应的错误代码。如果errcode_ret为NULL,则不会返回任何错误代码。

If blocking_map is CL_TRUEclEnqueueMapImage does not return until the specified region in image is mapped into the host address space and the application can access the contents of the mapped region using the pointer returned by clEnqueueMapImage.

​如果blocking_map为CL_TRUE,则clEnqueueMapImage不会返回,直到映像中的指定区域映射到主机地址空间,并且应用程序可以使用clEnqueueMappingImage返回的指针访问映射区域的内容。

If blocking_map is CL_FALSE i.e. map operation is non-blocking, the pointer to the mapped region returned by clEnqueueMapImage cannot be used until the map command has completed. The event argument returns an event object which can be used to query the execution status of the map command. When the map command is completed, the application can access the contents of the mapped region using the pointer returned by clEnqueueMapImage.

​如果blocking_map为CL_FALSE,即map操作为非blocking,则在map命令完成之前,无法使用clEnqueueMapImage返回的指向映射区域的指针。事件参数返回一个事件对象,该对象可用于查询map命令的执行状态。map命令完成后,应用程序可以使用clEnqueueMapImage返回的指针访问映射区域的内容。

clEnqueueMapImage will return a pointer to the mapped region. The errcode_ret is set to CL_SUCCESS.

clEnqueueMapImage将返回一个指向映射区域的指针。errcode_ret设置为CL_SUCCESS。

NULL pointer is returned otherwise with one of the following error values returned in errcode_ret:

否则将返回NULL指针,并在errcode_ret中返回以下错误值之一:

  • CL_INVALID_COMMAND_QUEUE if command_queue is not a valid host command-queue.

  • CL_INVALID_COMMAND_QUEUE(如果命令队列不是有效的主机命令队列)。

  • CL_INVALID_CONTEXT if context associated with command_queue and image are not the same or if context associated with command_queue and events in event_wait_list are not the same.

  • CL_INVALID_CONTEXT如果与command_queue和image关联的上下文不相同,或者与command_ queue关联的上下文和event_wait_list中的事件不相同。

  • CL_INVALID_MEM_OBJECT if image is not a valid image object.

  • CL_INVALID_MEM_OBJECT(如果图像不是有效的图像对象)。

  • CL_INVALID_VALUE if origin or region is NULL.

  • CL_INVALID_VALUE(如果原点或区域为NULL)。

  • CL_INVALID_VALUE if region being mapped given by (originorigin + region) is out of bounds or if values specified in map_flags are not valid.

  • CL_INVALID_VALUE如果由(原点,原点+区域)给定的映射区域超出界限,或者如果map_flags中指定的值无效。

  • CL_INVALID_VALUE if values in origin and region do not follow rules described in the argument description for origin and region.

  • CL_INVALID_VALUE,如果原点和区域中的值不遵循原点和区域的参数描述中描述的规则。

  • CL_INVALID_VALUE if image_row_pitch is NULL.

  • 如果image_row_pitch为NULL,则CL_INVALID_VALUE。

  • CL_INVALID_VALUE if image is a 3D image, 1D or 2D image array object and image_slice_pitch is NULL.

  • CL_INVALID_VALUE(如果图像是3D图像、1D或2D图像阵列对象并且image_slice_pitch为NULL)。

  • CL_INVALID_EVENT_WAIT_LIST if event_wait_list is NULL and num_events_in_wait_list > 0, or event_wait_list is not NULL 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_INVALID_IMAGE_SIZE if image dimensions (image width, height, specified or compute row and/or slice pitch) for image are not supported by device associated with queue.

  • CL_INVALID_IMAGE_SIZE如果与队列相关联的设备不支持图像的图像尺寸(图像宽度、高度、指定或计算行或切片间距)。

  • CL_IMAGE_FORMAT_NOT_SUPPORTED if image format (image channel order and data type) for image are not supported by device associated with queue.

  • 如果与队列关联的设备不支持图像的图像格式(图像通道顺序和数据类型),则CL_IMAGE_FORMAT_NOT_SUPPORTED。

  • CL_MAP_FAILURE if there is a failure to map the requested region into the host address space. This error cannot occur for image objects created with CL_MEM_USE_HOST_PTR or CL_MEM_ALLOC_HOST_PTR.

  • CL_MAP_FAILURE(如果无法将请求的区域映射到主机地址空间)。对于使用CL_MEM_USE_HOST_PTR或CL_MEM_ALLOC_HOST_PTR创建的图像对象,不会发生此错误。

  • CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST if the map operation is blocking and the execution status of any of the events in event_wait_list is a negative integer value. This error code is missing before version 1.1.

  • CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST,如果映射操作正在阻塞并且event_WAIT_LIST中任何事件的执行状态为负整数值。1.1版本之前缺少此错误代码。

  • CL_MEM_OBJECT_ALLOCATION_FAILURE if there is a failure to allocate memory for data store associated with 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_INVALID_OPERATION if image has been created with CL_MEM_HOST_WRITE_ONLY or CL_MEM_HOST_NO_ACCESS and CL_MAP_READ is set in map_flags or if image has been created with CL_MEM_HOST_READ_ONLY or CL_MEM_HOST_NO_ACCESS and CL_MAP_WRITE or CL_MAP_WRITE_INVALIDATE_REGION is set in map_flags.

  • CL_INVALID_OPERATION如果图像是用CL_MEM_HOST_WRITE_ONLY或CL_MEM_MOST_NO_ACCESS创建的,并且CL_MAP_READ设置在MAP_flags中,或者如果图像是使用CL_MEM_HOST_READ_ONLY、CL_MEM_HOST_NO_ACCESS创建并且CL_MAP_WRITE或CL_MAP_WRITE_INVALIDATE_REGION设置在map_flags中。

  • 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_OPERATION if mapping would lead to overlapping regions being mapped for writing.

  • CL_INVALID_OPERATION,如果映射会导致为写入而映射的重叠区域。

The pointer returned maps a 1D, 2D or 3D region starting at origin and is at least region[0] pixels in size for a 1D image, 1D image buffer or 1D image array, (image_row_pitch × region[1]) pixels in size for a 2D image or 2D image array, and (image_slice_pitch × region[2]) pixels in size for a 3D image. The result of a memory access outside this region is undefined.

返回的指针映射从原点开始的1D、2D或3D区域,并且对于1D图像、1D图像缓冲区或1D图像阵列,其大小至少为region[0]像素,对于2D图像或2D图像阵列,大小至少为(image_row_pitch×region[1])像素,对于3D图像,其大小为(image_slice_pitch×region[2])像素。此区域外的内存访问结果未定义。

If the image object is created with CL_MEM_USE_HOST_PTR set in mem_flags, the following will be true:

​如果创建图像对象时在mem_flags中设置了CL_MEM_USE_HOST_PTR,则以下情况将为真:

  • The host_ptr specified in clCreateImageclCreateImageWithPropertiesclCreateImage2D, or clCreateImage3D is guaranteed to contain the latest bits in the region being mapped when the clEnqueueMapImage command has completed.

  • clCreateImage、clCreateImageWithProperties、clCreateImage2D或clCreateImage3D中指定的host_ptr保证在clEnqueueMapImage命令完成后包含要映射的区域中的最新位。

  • The pointer value returned by clEnqueueMapImage will be derived from the host_ptr specified when the image object is created.

  • ​clEnqueueMapImage返回的指针值将从创建图像对象时指定的host_ptr派生。

Mapped image objects are unmapped using clEnqueueUnmapMemObject. This is described in Unmapping Mapped Memory Objects.

​使用clEnqueueUnmapMemObject取消映射映射的图像对象。这在“取消映射映射的内存对象”中有描述。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值