#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||
|half3||3-component half-precision floating-point vector||
|half4||4-component half-precision floating-point vector||
|half8||8-component half-precision floating-point vector||
|half16||16-component half-precision floating-point vector||
The relational, equality, logical and logical unary operators(3clc) 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.
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(3clc) for an OpenCL device that supports half precision floating-point.
The Khronos Group
Copyright © 2007-2011 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.
- page 14, section 9.5 - Half Floating-Point