Optional half floating-point support.
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
This extension adds support for half scalar and vector types as built-in types that can be used for arithmetic operations, conversions, etc.
An application that wants to use half
and halfn
types will need to include the directive shown above.
The list of built-in scalar and vector data types are extended to include the types in the table below.
The built-in vector data types for halfn
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 types for halfn
as defined in the OpenCL C programming language and the corresponding data type available to the application:
Type in OpenCL Language | Description | API type for application |
---|---|---|
half2 |
2-component half-precision floating-point vector |
cl_half2 |
half3 |
3-component half-precision floating-point vector |
cl_half3 |
half4 |
4-component half-precision floating-point vector |
cl_half4 |
half8 |
8-component half-precision floating-point vector |
cl_half8 |
half16 |
16-component half-precision floating-point vector |
cl_half16 |
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
.
The macro names given in the following list must use the values specified.
These constant expressions are suitable for use in #if
preprocessing directives.
The following table also describes the corresponding macro names available to the application.
Macro in OpenCL Language | value | Macro for application |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The following constants are also available.
They are of type half
and are accurate within the precision of the half
type.
Constant | Description |
---|---|
|
Value of e |
|
Value of log2 e |
|
Value of log10 e |
|
Value of ln 2 |
|
Value of ln 10 |
|
Value of π |
|
Value of π / 2 |
|
Value of π / 4 |
|
Value of 1 / π |
|
Value of 2 / π |
|
Value of 2 / √π |
|
Value of √2 |
|
Value of 1 / √2 |
Ann application may query the configuration information using the op-code CL_DEVICE_HALF_FP_CONFIG
with clGetDeviceInfo
for an OpenCL device that supports half precision floating-point.
The implicit conversion rules specified in section 6.2.1 now include the half
scalar and halfn
vector data types.
The explicit casts described in section 6.2.2 are extended to take a half
scalar data type and a halfn
vector data type.
The explicit conversion functions described in section 6.2.3 are extended to take a half
scalar data type and a halfn
vector data type.
The as_typen() function for re-interpreting types as described in section 6.2.4.2 is extended to allow conversion-free casts between shortn
, ushortn
and halfn
scalar and vector data types.