Built-in vector data types.
The char
, unsigned char
, short
, unsigned short
, integer
, unsigned integer
, long
, unsigned long
, and float
vector data types are supported.
The vector data type is defined with the type name i.e.
char
, uchar
, short
, ushort
, int
, uint
, float
, long
, or ulong
followed by a literal value n that defines the number of elements in the vector.
Supported values of n are 2, 3, 4, 8, and 16 for all vector data types.
The built-in vector data types are also declared as appropriate types in the OpenCL API (and header files) that can be used by an application. The following table describes the built-in vector data type in the OpenCL C programming language and the corresponding data type available to the application:
Type in OpenCL Language | Description | API type for application |
---|---|---|
|
A vector of n 8-bit signed two’s complement integer values. |
|
|
A vector of n 8-bit unsigned integer values. |
|
|
A vector of n 16-bit signed two’s complement integer values. |
|
|
A vector of n 16-bit unsigned integer values. |
|
|
A vector of n 32-bit signed two’s complement integer values. |
|
|
A vector of n 32-bit unsigned integer values. |
|
|
A vector of n 64-bit signed two’s complement integer values. |
|
|
A vector of n 64-bit unsigned integer values. |
|
|
A vector of n 32-bit floating-point values. |
|
|
A vector of n 64-bit floating-point values. |
|
Built-in vector data types are supported by the OpenCL implementation even if the underlying compute device does not support any or all of the vector data types. These are to be converted by the device compiler to appropriate instructions that use underlying built-in types supported natively by the compute device.
The double
vector type is an optional type that is supported if CL_DEVICE_DOUBLE_FP_CONFIG
for a device is not zero.
See clGetDeviceInfo
.
The half
floating-point is supported as an optional extension.
An application that wants to use half
and halfn
will need to include the #pragma OPENCL EXTENSION cl_khr_fp16 : enable directive.
This will extended the list of built-in vector and scalar data types to include the following:
Type in OpenCL Language | Description | API type for application |
---|---|---|
|
A 2-component half-precision floating-point vector. |
|
|
A 3-component half-precision floating-point vector. |
|
|
A 4-component half-precision floating-point vector. |
|
|
An 8-component half-precision floating-point vector. |
|
|
A 16-component half-precision floating-point vector. |
|
The relational, equality, logical and logical unary operators can be used with half
scalar and halfn
vector types and shall produce a scalar int
and vector shortn
result respectively.
The OpenCL compiler accepts an h and H suffix on floating point literals, indicating the literal is typed as a half
.