Appendix C: Application Data Types
附录C:应用程序数据类型
This section documents the provided host application types and constant definitions. The documented material describes the commonly defined data structures, types and constant values available to all platforms and architectures. The addition of these details demonstrates our commitment to maintaining a portable programming environment and potentially deters changes to the supplied headers.
本节记录了提供的主机应用程序类型和常量定义。文件化材料描述了所有平台和架构可用的常用数据结构、类型和常量值。添加这些细节表明了我们对维护可移植编程环境的承诺,并可能阻止对所提供头的更改。
Supported Application Scalar Data Types
支持的应用程序标量数据类型
The following application scalar types are provided for application convenience.
为了应用程序的方便,提供了以下应用程序标量类型。
cl_char
cl_uchar
cl_short
cl_ushort
cl_int
cl_uint
cl_long
cl_ulong
cl_half
cl_float
cl_double
Supported Application Vector Data Types
支持的应用程序矢量数据类型
Application vector types are unions used to create vectors of the above application scalar types. The following application vector types are provided for application convenience.
应用程序向量类型是用于创建上述应用程序标量类型的向量的联合。为了应用方便,提供了以下应用向量类型。
cl_char<n>
cl_uchar<n>
cl_short<n>
cl_ushort<n>
cl_int<n>
cl_uint<n>
cl_long<n>
cl_ulong<n>
cl_half<n>
cl_float<n>
cl_double<n>
n can be 2, 3, 4, 8 or 16.
n可以是2、3、4、8或16。
The application scalar and vector data types are defined in the cl_platform.h header file.
应用程序标量和向量数据类型在cl_platform.h头文件中定义。
Alignment of Application Data Types
应用程序数据类型的对齐
The user is responsible for ensuring that pointers passed into and out of OpenCL kernels are natively aligned relative to the data type of the parameter as defined in the kernel language and SPIR-V specifications. This implies that OpenCL buffers created with CL_MEM_USE_HOST_PTR need to provide an appropriately aligned host memory pointer that is aligned to the data types used to access these buffers in a kernel(s), that SVM allocations must correctly align and that pointers into SVM allocations must also be correctly aligned. The user is also responsible for ensuring image data passed is aligned to the granularity of the data representing a single pixel (e.g. image_num_channels * sizeof(image_channel_data_type)) except for CL_RGB and CL_RGBx images where the data must be aligned to the granularity of a single channel in a pixel (i.e. sizeof(image_channel_data_type)). This implies that OpenCL images created with CL_MEM_USE_HOST_PTR must align correctly. The image alignment value can be queried using the CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT query. In addition, source pointers for clEnqueueWriteImage and other operations that copy to the OpenCL runtime, as well as destination pointers for clEnqueueReadImage and other operations that copy from the OpenCL runtime must follow the same alignment rules.
用户有责任确保传入和传出OpenCL内核的指针与内核语言和SPIR-V规范中定义的参数数据类型原生对齐。这意味着使用CL_MEM_USE_HOST_PTR创建的OpenCL缓冲区需要提供一个适当对齐的主机内存指针,该指针与用于访问内核中这些缓冲区的数据类型对齐,SVM分配必须正确对齐,指向SVM分配的指针也必须正确对齐。用户还负责确保传递的图像数据与表示单个像素的数据的粒度对齐(例如,image_num_channel*sizeof(image_channel_data_type)),但CL_RGB和CL_RGBx图像除外,在这些图像中,数据必须与像素中单个通道的粒度对齐(即sizeof(image_channel_data-type))。这意味着使用CL_MEM_USE_HOST_PTR创建的OpenCL图像必须正确对齐。可以使用CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT查询来查询图像对齐值。此外,clEnqueueWriteImage和其他复制到OpenCL运行时的操作的源指针,以及clEnqueueReadImage和其他从OpenCL运行时间复制的操作的目标指针必须遵循相同的对齐规则。
OpenCL makes no requirement about the alignment of OpenCL application defined data types outside of buffers and images, except that the underlying vector primitives (e.g. __cl_float4) where defined shall be directly accessible as such using appropriate named fields in the cl_type union (see Vector Components. Nevertheless, it is recommended that the cl_platform.h header should attempt to naturally align OpenCL defined application data types (e.g. cl_float4) according to their type.
OpenCL对缓冲区和图像之外的OpenCL应用程序定义的数据类型的对齐没有要求,除了定义的底层向量基元(例如__cl_float4)应使用cl_type联合中的适当命名字段直接访问(参见向量组件)。尽管如此,建议cl_platform.h头应尝试根据其类型自然对齐OpenCL定义的应用程序数据类型(例如cl_float4)。
Vector Literals
向量文本
Application vector literals may be used in assignments of individual vector components. Literal usage follows the convention of the underlying application compiler.
应用程序向量文本可用于分配单个向量分量。字面用法遵循底层应用程序编译器的约定。
cl_float2 foo = { .s[1] = 2.0f };
cl_int8 bar = {
{ 2, 4, 6, 8, 10, 12, 14, 16 }};
Vector Components
向量分量
The components of application vector types can be addressed using the <vector_name>.s[<index>] notation.
应用程序向量类型的组件可以使用<vector_name>.s[<index>]表示法进行寻址。
For example:
例如:
foo.s[0] = 1.0f; // Sets the 1st vector component of foo
pos.s[6] = 2; // Sets the 7th vector component of bar
In some cases vector components may also be accessed using the following notations. These notations are not guaranteed to be supported on all implementations, so their use should be accompanied by a check of the corresponding preprocessor symbol.
在某些情况下,向量分量也可以使用以下符号进行访问。这些符号不能保证在所有实现上都得到支持,因此在使用它们的同时应该检查相应的预处理器符号。
Named Vector Components Notation
命名向量分量表示法
Vector data type components may be accessed using the .sN, .sn or .xyzw field naming convention, similar to how they are used within the OpenCL C language. Use of the .xyzw field naming convention only allows accessing of the first 4 component fields. Support of these notations is identified by the CL_HAS_NAMED_VECTOR_FIELDS preprocessor symbol. For example:
向量数据类型组件可以使用.sN、.sN或.xyzw字段命名约定进行访问,类似于它们在OpenCL C语言中的使用方式。使用.xyzw字段命名约定只允许访问前4个组件字段。这些符号的支持由CL_HAS_NAMED_VECTOR_FIELDS预处理器符号标识。例如:
#ifdef CL_HAS_NAMED_VECTOR_FIELDS
cl_float4 foo;
cl_int16 bar;
foo.x = 1.0f; // Set first component
foo.s0 = 1.0f; // Same as above
bar.z = 3; // Set third component
bar.se = 11; // Same as bar.s[0xe]
bar.sD = 12; // Same as bar.s[0xd]
#endif
Vector data type components may also be accessed using the .rgba field naming convention, similar to how they are used within the OpenCL C 3.0 language. Use of the .rgba field naming convention only allows accessing of the first 4 component fields. Support of these notations is identified by the CL_HAS_NAMED_RGBA_VECTOR_FIELDS preprocessor symbol. For example:
向量数据类型组件也可以使用.rgba字段命名约定进行访问,类似于它们在OpenCL C 3.0语言中的使用方式。使用.rgba字段命名约定只允许访问前4个组件字段。这些符号的支持由CL_HAS_NAMED_RGBA_VECTOR_FIELDS 预处理器符号标识。例如:
#ifdef CL_HAS_NAMED_RGBA_VECTOR_FIELDS
cl_float4 foo;
cl_int16 bar;
foo.r = 1.0f; // Set first component
bar.b = 3; // Set third component
#endif
Unlike the OpenCL C language type usage of named vector fields, only one component field may be accessed at a time. This restriction prevents the ability to swizzle or replicate components as is possible with the OpenCL C language types. Attempting to access beyond the number of components for a type also results in a failure.
与OpenCL C语言对命名向量字段的类型使用不同,一次只能访问一个组件字段。这种限制阻止了像OpenCL C语言类型那样快速或复制组件的能力。尝试访问超过某个类型的组件数量也会导致失败。
foo.xy // illegal - illegal field name combination
bar.s1234 // illegal - illegal field name combination
foo.s7 // illegal - no component s7
High/Low Vector Component Notation
高/低向量分量表示法
Vector data type components may be accessed using the .hi and .lo notation similar to that supported within the language types. Support of this notation is identified by the CL_HAS_HI_LO_VECTOR_FIELDS preprocessor symbol. For example:
向量数据类型组件可以使用与语言类型中支持的符号类似的.hi和.lo符号进行访问。此符号的支持由CL_HAS_HI_LO_VECTOR_FIELDS预处理器符号标识。例如:
#ifdef CL_HAS_HI_LO_VECTOR_FIELDS
cl_float4 foo;
cl_float2 new_hi = 2.0f, new_lo = 4.0f;
foo.hi = new_hi;
foo.lo = new_lo;
#endif
Native Vector Type Notation
原生向量类型表示法
Certain native vector types are defined for providing a mapping of vector types to architecturally built-in vector types. Unlike the above described application vector types, these native types are supported on a limited basis depending on the supporting architecture and compiler.
某些原生向量类型被定义用于提供向量类型到架构内置向量类型的映射。与上述应用程序向量类型不同,这些本机类型在有限的基础上得到支持,具体取决于支持的架构和编译器。
These types are not unions, but rather convenience mappings to the underlying architectures' built-in vector types. The native types share the name of their application counterparts but are preceded by a double underscore "__".
这些类型不是联合,而是与底层架构的内置向量类型的方便映射。本机类型共享其应用程序对应物的名称,但前面有一个双下划线“__”。
For example, __cl_float4 is the native built-in vector type equivalent of the cl_float4 application vector type. The __cl_float4 type may provide direct access to the architectural built-in __m128 or vector float type, whereas the cl_float4 is treated as a union.
例如,__cl_float4是与cl_fload4应用程序向量类型等效的本机内置向量类型。__cl_float4类型可以直接访问架构内置的__m128或向量浮点类型,而cl_floate4则被视为一个联合。
In addition, the above described application data types may have native vector data type members for access convenience. The native components are accessed using the .vN sub-vector notation, where N is the number of elements in the sub-vector. In cases where the native type is a subset of a larger type (more components), the notation becomes an index based array of the sub-vector type.
此外,为了便于访问,上述应用数据类型可以具有本机向量数据类型成员。使用.vN子向量表示法访问本机组件,其中N是子向量中的元素数。如果本机类型是更大类型(更多组件)的子集,则表示法将成为子向量类型的基于索引的数组。
Support of the native vector types is identified by a __CL_TYPEN__ preprocessor symbol matching the native type name. For example:
原生向量类型的支持由与原生类型名称匹配的__CL_TYPEN__预处理器符号标识。例如:
#ifdef __CL_FLOAT4__ // Check for native cl_float4 type
cl_float8 foo;
__cl_float4 bar; // Use of native type
bar = foo.v4[1]; // Access the second native float4 vector
#endif
Implicit Conversions
隐式转换
Implicit conversions between application vector types are not supported.
不支持应用程序向量类型之间的隐式转换。
Explicit Casts
显式Casts
Explicit casting of application vector types (cl_typen) is not supported. Explicit casting of native vector types (__cl_typen) is defined by the external compiler.
不支持应用程序向量类型(cl_typen)的显式强制转换。本机向量类型(__cl_typen)的显式转换由外部编译器定义。
Other Operators and Functions
其他运算符和功能
The behavior of standard operators and function on both application vector types (cl_typen) and native vector types (__cl_typen) is defined by the external compiler.
标准运算符和函数在应用程序向量类型(cl_typen)和本机向量类型(__cl_typen)上的行为由外部编译器定义。
Application Constant Definitions
应用程序常量定义
In addition to the above application type definitions, the following literal definitions are also available.
除了上述应用程序类型定义外,还可以使用以下文本定义。
| CL_CHAR_BIT | Bit width of a character 字符的位宽 |
|---|---|
| Maximum value of a type
| |
| Minimum value of a type
| |
| Maximum value of a type
| |
| Minimum value of a type
| |
| Maximum value of a type
| |
| Maximum value of a type
| |
| Minimum value of a type
| |
| Maximum value of a type
| |
| Maximum value of a type
| |
| Minimum value of a type
| |
| Maximum value of a type
| |
| Maximum value of a type
| |
| Minimum value of a type
| |
| Maximum value of a type
| |
| Number of decimal digits of precision for the type
| |
| Number of digits in the mantissa of type
| |
| Maximum positive integer such that 10 raised to this power minus one can be represented as a normalized floating-point number of type
| |
| Maximum exponent value of type
| |
| Minimum negative integer such that 10 raised to this power minus one can be represented as a normalized floating-point number of type
| |
| Minimum exponent value of type
| |
| Base value of type
| |
| Maximum value of type
| |
| Minimum value of type
| |
| Minimum positive floating-point number of type | |
| missing before version 1.2. Also see cl_khr_fp64. | Number of decimal digits of precision for the type
|
| missing before version 1.2. Also see cl_khr_fp64. | Number of digits in the mantissa of type
|
| missing before version 1.2. Also see cl_khr_fp64. | Maximum positive integer such that 10 raised to this power minus one can be represented as a normalized floating-point number of type
|
| missing before version 1.2. Also see cl_khr_fp64. | Maximum exponent value of type
|
| missing before version 1.2. Also see cl_khr_fp64. | Minimum negative integer such that 10 raised to this power minus one can be represented as a normalized floating-point number of type
|
| missing before version 1.2. Also see cl_khr_fp64. | Minimum exponent value of type
|
| missing before version 1.2. Also see cl_khr_fp64. | Base value of type
|
| missing before version 1.2. Also see cl_khr_fp64. | Maximum value of type
|
| missing before version 1.2. Also see cl_khr_fp64. | Minimum value of type
|
| missing before version 1.2. Also see cl_khr_fp64. | Minimum positive floating-point number of type cl_double类型的最小正浮点数,使得1.0+cl_DL_EPSILON!=1是真的。 |
| missing before version 1.1. | Macro expanding to a value representing NaN 宏扩展到表示NaN的值 |
| missing before version 1.1. | Largest representative value of type
|
| missing before version 1.1. | Largest representative value of type
|
| missing before version 1.1. | Maximum value of type
|
| missing before version 1.1. | Macro expanding to a value representing infinity 宏扩展到表示无穷大的值 |
These literal definitions are defined in the cl_platform.h header.
这些文本定义在cl_platform.h标头中定义。
405




被折叠的 条评论
为什么被折叠?



