Reference

cl_khr_fp16(3clc)

Optional half floating-point support.

NAME

cl_khr_fp16 - Optional half floating-point support.

#pragma OPENCL EXTENSION cl_khr_fp16 : enable

DESCRIPTION

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 LanguageDescriptionAPI type for application
half22-component half-precision floating-point vectorcl_half2
half33-component half-precision floating-point vectorcl_half3
half44-component half-precision floating-point vectorcl_half4
half88-component half-precision floating-point vectorcl_half8
half1616-component half-precision floating-point vectorcl_half16

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 LanguagevalueMacro for application
#define HALF_DIG3HALF_DIG
#define HALF_MANT_DIG11HALF_MANT_DIG
#define HALF_MAX_10_EXP+4HALF_MAX_10_EXP
#define HALF_MAX_EXP+16HALF_MAX_EXP
#define HALF_MIN_10_EXP-4HALF_MIN_10_EXP
#define HALF_MIN_EXP-13HALF_MIN_EXP
#define HALF_RADIX2HALF_RADIX
#define HALF_MAX0x1.ffcp15hHALF_MAX
#define HALF_MIN0x1.0p-14hHALF_MIN
#define HALF_EPSILON0x1.0p-10hHALF_EPSILON

The following constants are also available. They are of type half and are accurate within the precision of the half type.

ConstantDescription
M_E_HValue of e
M_LOG2E_HValue of log2 e
M_LOG10E_HValue of log10 e
M_LN2_HValue of ln 2
M_LN10_HValue of ln 10
M_PI_HValue of π
M_PI_2_HValue of π / 2
M_PI_4_HValue of π / 4
M_1_PI_HValue of 1 / π
M_2_PI_HValue of 2 / π
M_2_SQRTPI_HValue of 2 / √π
M_SQRT2_HValue of √2
M_SQRT1_2_HValue 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.

SPECIFICATION

OpenCL Specification[1]

SEE ALSO

EXTENSION(3clc), clGetDeviceInfo(3clc), mathFunctions(3clc), commonFunctions(3clc), geometricFunctions(3clc), relationalFunctions(3clc), vectorDataLoadandStoreFunctions(3clc), asyncCopyFunctions(3clc), imageFunctions(3clc)

AUTHORS

The Khronos Group

COPYRIGHT

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.

NOTES

1.

OpenCL Specification

page 14, section 9.5 - Half Floating-Point

History