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, and ulong followed by a literal value n that defines the number of elements in the vector. Supported values of n are 2, 4, 8, and 16.
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 |
|---|---|---|
charn
|
A 8-bit signed two's complement integer vector. |
cl_charn
|
ucharn
|
A 8-bit unsigned integer vector. |
cl_ucharn
|
shortn
|
A 16-bit signed two's complement integer vector. |
cl_shortn
|
ushortn
|
A 16-bit unsigned integer vector. |
cl_ushortn
|
intn
|
A 32-bit signed two's complement integer vector. | cl_int |
uintn
|
A 32-bit unsigned integer vector. |
cl_uintn
|
longn
|
A 64-bit signed two's complement integer vector. |
cl_longn
|
ulongn
|
A 64-bit unsigned integer vector. |
cl_ulongn
|
floatn
|
A float vector |
cl_floatn
|
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.
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, Scalar Data Types, Reserved Data Types, Other Data Types, Abstract Data Types, cl_khr_fp16, cl_khr_fp64
Copyright © 2007-2009 The Khronos Group Inc.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and/or associated documentation files (the
"Materials"), to deal in the Materials without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Materials, and to
permit persons to whom the Materials are furnished to do so, subject to
the condition that this copyright notice and permission notice shall be included
in all copies or substantial portions of the Materials.