These are the data types available in the OpenCL C programming language used to create kernels that are executed on OpenCL device(s). The OpenCL C programming language (also referred to as OpenCL C) is based on the ISO/IEC 9899:1999 C language specification (a.k.a. C99 specification) with specific extensions and restrictions. Please refer to the ISO/IEC 9899:1999 specification for a detailed description of the language grammar. This section describes modifications and restrictions to ISO/IEC 9899:1999 supported in OpenCL C.
Most built-in scalar 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 scalar 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 |
---|---|---|
bool | A conditional data type which is either true or false .
The value true expands to the integer constant 1 and the value false expands to the integer constant 0.
|
n/a |
char | A signed two's complement 8-bit integer. | cl_char |
unsigned char, |
An unsigned 8-bit integer. | cl_uchar |
short | A signed two's complement 16-bit integer. | cl_short |
unsigned short, |
An unsigned 16-bit integer. | cl_ushort |
int | A signed two's complement 32-bit integer. | cl_int |
unsigned int, |
An unsigned 32-bit integer. | cl_uint |
long | A signed two's complement 64-bit integer. | cl_long |
unsigned long, |
An unsigned 64-bit integer. | cl_ulong |
float | A single precision float. The float data type must conform to the IEEE 754 single precision storage format. | cl_float |
half | A 16-bit float. The half data type must conform to the IEEE 754-2008 half precision storage format. | cl_half |
size_t |
The unsigned integer type of the result of the sizeof operator. This is a 32-bit unsigned integer if CL_DEVICE_ADDRESS_BITS
defined in clGetDeviceInfo
is 32-bits and is a 64-bit unsigned integer if CL_DEVICE_ADDRESS_BITS is 64-bits.
|
n/a |
ptrdiff_t | A signed integer type that is the result of subtracting two pointers. This is a 32-bit signed integer if CL_DEVICE_ADDRESS_BITS defined in clGetDeviceInfo is 32-bits and is a 64-bit signed integer if CL_DEVICE_ADDRESS_BITS is 64-bits. | n/a |
intptr_t | A signed integer type with the property that any valid pointer to void can be converted to this type, then converted back to pointer to void, and the result will compare equal to the original pointer. | n/a |
uintptr_t | An unsigned integer type with the property that any valid pointer to void can be converted to this type, then converted back to pointer to void, and the result will compare equal to the original pointer. | n/a |
void | The void type comprises an empty set of values; it is an incomplete type that cannot be completed. | void |
OpenCL 1.0 adds support for double precision and half floating-point as optional extensions. The double data type must confirm to the IEEE-754 double precision storage format.
An application that wants to use double will need to include the #pragma OPENCL EXTENSION cl_khr_fp64 : enable directive before any double precision data type is declared in the kernel code. 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 |
---|---|---|
double | A double precision float. | cl_double |
double2 | A 2-component double vector. | cl_double2 |
double4 | A 4-component double vector. | cl_double4 |
double8 | An 8-component double vector. | cl_double8 |
double16 | A 16-component double vector. | cl_double16 |
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 |
---|---|---|
half2 | A 2-component half-precision floating-point vector. | cl_half2 |
half4 | A 4-component half-precision floating-point vector. | cl_half4 |
half8 | An 8-component half-precision floating-point vector. | cl_half8 |
half16 | A 16-component half-precision floating-point vector. | cl_half16 |
Macros and Limits, Vector Data Types, Reserved Data Types, Other Data Types, Abstract Data Types, cl_khr_fp16, cl_khr_fp64