logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

cl_khr_fp16 - Optional half floating-point support.

Authors

TheKhronosGroup

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:

       ┌─────────────────────────┬─────────────────────────────┬──────────────────────────┐
       │ TypeinOpenCLLanguageDescriptionAPItypeforapplication │
       ├─────────────────────────┼─────────────────────────────┼──────────────────────────┤
       │ half2                   │ 2-component half-precision  │ cl_half2                 │
       │                         │ floating-point vector       │                          │
       ├─────────────────────────┼─────────────────────────────┼──────────────────────────┤
       │ half3                   │ 3-component half-precision  │ cl_half3                 │
       │                         │ floating-point vector       │                          │
       ├─────────────────────────┼─────────────────────────────┼──────────────────────────┤
       │ half4                   │ 4-component half-precision  │ cl_half4                 │
       │                         │ floating-point vector       │                          │
       ├─────────────────────────┼─────────────────────────────┼──────────────────────────┤
       │ half8                   │ 8-component half-precision  │ cl_half8                 │
       │                         │ floating-point vector       │                          │
       ├─────────────────────────┼─────────────────────────────┼──────────────────────────┤
       │ half16                  │ 16-component half-precision │ cl_half16                │
       │                         │ 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.
       MacroinOpenCLLanguagevalueMacroforapplication
       #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.
       ┌──────────────┬──────────────────┐
       │ ConstantDescription      │
       ├──────────────┼──────────────────┤
       │ 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.

Name

       cl_khr_fp16 - Optional half floating-point support.

       #pragma OPENCL EXTENSION cl_khr_fp16 : enable

Notes

        1. OpenCL Specification
           page 14, section 9.5 - Half Floating-Point

The Khronos Group                                  11/18/2024                                  CL_KHR_FP16(3clc)

See Also

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

Specification

OpenCLSpecification[1]

See Also