CL_KHR_FP16(3clc)

πŸ“¦
version 1.0~svn33624 Β· 3 versions
, in ubuntu jammy, ubuntu noble

πŸ’– CL_KHR_FP16 πŸ’–

okay bestie, welcome to the OpenCL Manual, page for CL_KHR_FP16(3clc) β€” we're talking optional half floating-point support and it's giving tiny-but-mighty ✨


🌸 NAME 🌸

cl_khr_fp16 β€” optional half floating-point support, bestie πŸ’…

To even use it, you gotta include this directive:

#pragma OPENCL EXTENSION cl_khr_fp16 :
enable

πŸ¦‹ DESCRIPTION πŸ¦‹

so like, this extension adds support for half scalar and vector types as built-in types that you can use for arithmetic operations, conversions, etc. If your application wants to use half and halfn types, you literally have to include that directive up there. no directive, no halfsies. periodt. πŸ‘‘

The list of built-in scalar and vector data types gets 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) so your application can use them. Here's the built-in vector data types for halfn as defined in the OpenCL C programming language, plus the matching data type available to the application:

  • half2 β€” 2-component half-precision floating-point vector β†’ API type for application: cl_half2
  • half3 β€” 3-component half-precision floating-point vector β†’ API type for application: cl_half3
  • half4 β€” 4-component half-precision floating-point vector β†’ API type for application: cl_half4
  • half8 β€” 8-component half-precision floating-point vector β†’ API type for application: cl_half8
  • half16 β€” 16-component half-precision floating-point vector β†’ API type for application: cl_half16

The relational, equality, logical and logical unary operators(3clc) can be used with half scalar and halfn vector types, and they shall produce a scalar int and vector shortn result respectively. yes queen, the operators work 🫢

The OpenCL compiler accepts an h and H suffix on floating point literals, indicating the literal is typed as a half. cute, right? πŸ’–

The macro names given in the following list must use the values specified. These constant expressions are suitable for use in #if preprocessing directives. πŸ”₯

Here's the table describing 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 🌈

  • 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

An 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. lowkey the move πŸ‘€


✨ SPECIFICATION ✨

OpenCL Specification[1]


πŸŽ€ SEE ALSO πŸŽ€


πŸ‘‘ AUTHORS πŸ‘‘

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 following condition: the above copyright notice and this permission notice shall be included in all copies or substantial portions of the Materials.

bestie this part is not vibe-only, it's the actual legal dealio, so keep that notice in all copies or substantial portions, fr fr 🫢

πŸ“ NOTES πŸ“

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

k that's the whole page, you ate it πŸ’… mwah! this iconic lil' slice of the OpenCL Manual was served up by The Khronos Group, dated 01/14/2021, filed under CL_KHR_FP16(3clc) β€” go forth and half-precision, bestie πŸ¦‹βœ¨

πŸ“¦ where this page comes from