image_channel_data_type含义
在穿件image对象的时候,需要传入一个cl_image_format参数,该参数结果包含image_channel_order和image_channel_data_type两个成员。前一个成员表示的是image对象含有的内容及其顺序,如下表
这个很好理解,表示是的image对象的数据表示了哪些图像通道内容以及其顺序。
然后image_channel_data_type的可用值如下:
这个成员表示了两层含义:
- 后面部分表示每一个channel的数据在实际物理内存中是如何存储,比如INT8, SHORT_565, FLOAT等,可能更加实际一点的理解的话就是:如果把这个image对象的数据用在host上处理的话,应该按照什么样的数据类型来解读这些数据。
- 前面部分表示这些数据要以什么样的格式来在kernel中读写,比如UNORM则表示要以0~1.0范围的浮点来读写,对应read_imagef和write_imagef, SIGNED则表示要以对应的有符号整数范围来读写,对应read_imagei和write_imagei;HALF则表示以half float来读写,对应read_imagef和write_imagef。
例如:
- CL_UNORM_INT8:数据的实际物理存储为8位的int类型,但是在kernel中应该以read_imagef和write_imagef来进行读写操作,且值的范围为0~1.0(如果是SNORM则为-1.0~1.0). 而这之间的转换则由GPU中专用的硬件完成,效率相当高
- CL_SIGNED_INT16:数据的实际物理存储为16为的int,在kernel中以以read_imagei和write_imagei来进行读写操作.
参考:
As far as storage is concerned, these types are identical. In both cases, each pixel channel value will be stored as an 8-bit integer, with values in the range 0-255. The difference comes when reading/writing the image from a kernel.
For the CL_UNSIGNED_INT8 type, you will use the
read_imageui
andwrite_imageui
functions to access the image. These functions will return (or accept) an unsigned integer, with values in the same range as the storage type.
For the CL_UNORM_INT8 type, you will use the
read_imagef
andwrite_imagef
functions to access to the image. These functions will return (or accept) a normalised floating point value, in the range 0.0f - 1.0f. Some devices (e.g. most GPUs) have hardware support for normalising texture values, so the conversion between integer and normalised floating point values will be very efficient.