## table of contents

CL_KHR_FP16(3clc) | OpenCL Manual | CL_KHR_FP16(3clc) |

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

01/14/2021 | The Khronos Group |