---
name: "cl_khr_fp16"
section: "3clc"
platform: "linux"
package: "opencl-1.2-man-doc"
version: "1.0~svn33624-5.1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/cl_khr_fp16"
---

# 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 **half***n* 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 **half***n* 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**(3clc)](/operators/3clc.md) can be used with **half** scalar and **half***n* vector types and shall produce a scalar **int** and vector **short***n* 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** |
| #define HALF\_DIG | 3 | **HALF\_DIG** |
| #define HALF\_MANT\_DIG | 11 | **HALF\_MANT\_DIG** |
| #define HALF\_MAX\_10\_EXP | +4 | **HALF\_MAX\_10\_EXP** |
| #define HALF\_MAX\_EXP | +16 | **HALF\_MAX\_EXP** |
| #define HALF\_MIN\_10\_EXP | -4 | **HALF\_MIN\_10\_EXP** |
| #define HALF\_MIN\_EXP | -13 | **HALF\_MIN\_EXP** |
| #define HALF\_RADIX | 2 | **HALF\_RADIX** |
| #define HALF\_MAX | 0x1.ffcp15h | **HALF\_MAX** |
| #define HALF\_MIN | 0x1.0p-14h | **HALF\_MIN** |
| #define HALF\_EPSILON | 0x1.0p-10h | **HALF\_EPSILON** |

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

| | |
| --- | --- |
| **Constant** | **Description** |
| M\_E\_H | Value of e |
| M\_LOG2E\_H | Value of log2 e |
| M\_LOG10E\_H | Value of log10 e |
| M\_LN2\_H | Value of ln 2 |
| M\_LN10\_H | Value of ln 10 |
| M\_PI\_H | Value of π |
| M\_PI\_2\_H | Value of π / 2 |
| M\_PI\_4\_H | Value of π / 4 |
| M\_1\_PI\_H | Value of 1 / π |
| M\_2\_PI\_H | Value of 2 / π |
| M\_2\_SQRTPI\_H | Value of 2 / √π |
| M\_SQRT2\_H | Value of √2 |
| M\_SQRT1\_2\_H | Value of 1 / √2 |

Ann application may query the configuration information using the op-code **CL\_DEVICE\_HALF\_FP\_CONFIG** with [**clGetDeviceInfo**(3clc)](/clGetDeviceInfo/3clc.md) for an OpenCL device that supports half precision floating-point.

## SPECIFICATION

**OpenCL Specification**\[1\]

## SEE ALSO

[**EXTENSION**(3clc)](/EXTENSION/3clc.md), [**clGetDeviceInfo**(3clc)](/clGetDeviceInfo/3clc.md), [**mathFunctions**(3clc)](/mathFunctions/3clc.md), [**commonFunctions**(3clc)](/commonFunctions/3clc.md), [**geometricFunctions**(3clc)](/geometricFunctions/3clc.md), [**relationalFunctions**(3clc)](/relationalFunctions/3clc.md), [**vectorDataLoadandStoreFunctions**(3clc)](/vectorDataLoadandStoreFunctions/3clc.md), [**asyncCopyFunctions**(3clc)](/asyncCopyFunctions/3clc.md), [**imageFunctions**(3clc)](/imageFunctions/3clc.md)

## 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
