|
| 1 | +Name |
| 2 | + |
| 3 | + EXT_bfloat16 |
| 4 | + |
| 5 | +Name Strings |
| 6 | + |
| 7 | + GL_EXT_bfloat16 |
| 8 | + |
| 9 | +Contact |
| 10 | + |
| 11 | + Jeff Bolz, NVIDIA (jbolz 'at' nvidia.com) |
| 12 | + |
| 13 | +Contributors |
| 14 | + |
| 15 | +Status |
| 16 | + |
| 17 | + Complete. |
| 18 | + |
| 19 | +Version |
| 20 | + |
| 21 | + Last Modified: February 25, 2025 |
| 22 | + Revision: 1 |
| 23 | + |
| 24 | +Dependencies |
| 25 | + |
| 26 | + This extension can be applied to OpenGL GLSL versions 4.50 |
| 27 | + (#version 450) and higher. |
| 28 | + |
| 29 | + This extension can be applied to OpenGL ES ESSL versions 3.20 |
| 30 | + (#version 320) and higher. |
| 31 | + |
| 32 | + This extension is written against the OpenGL Shading Language |
| 33 | + Specification, version 4.60.8, dated August 14, 2023. |
| 34 | + |
| 35 | + This extension interacts with GL_KHR_cooperative_matrix. |
| 36 | + |
| 37 | +Overview |
| 38 | + |
| 39 | + This extension introduces a new floating point type known as "bfloat16" or |
| 40 | + "e8m7". This type is primarily intended for machine learning usage and only |
| 41 | + a few operations are supported, including loading from and storing to memory, |
| 42 | + conversion to/from other types, and optionally cooperative matrix and/or |
| 43 | + dot product support. |
| 44 | + |
| 45 | + Mapping to SPIR-V |
| 46 | + ----------------- |
| 47 | + |
| 48 | + For informational purposes (non-normative), the following is an |
| 49 | + expected way for an implementation to map GLSL constructs to SPIR-V |
| 50 | + constructs: |
| 51 | + |
| 52 | + bfloat16_t -> OpTypeFloat 16 FPEncodingBFloat16KHR |
| 53 | + dot -> OpDot |
| 54 | + bfloat16BitsToIntEXT, |
| 55 | + bfloat16BitsToUintEXT, |
| 56 | + intBitsToBFloat16EXT, |
| 57 | + uintBitsToBFloat16EXT -> OpBitcast |
| 58 | + |
| 59 | + |
| 60 | +Modifications to the OpenGL Shading Language Specification, Version 4.60 |
| 61 | + |
| 62 | + Including the following lines in a shader can be used to control the |
| 63 | + language features described in this extension: |
| 64 | + |
| 65 | + #extension GL_EXT_bfloat16 : <behavior> |
| 66 | + |
| 67 | + where <behavior> is as specified in section 3.3. |
| 68 | + GL_EXT_bfloat16 must be enabled to use the bfloat16_t types. |
| 69 | + |
| 70 | + New preprocessor #defines are added to the OpenGL Shading Language: |
| 71 | + |
| 72 | + #define GL_EXT_bfloat16 1 |
| 73 | + |
| 74 | + Modify Section 3.6, Keywords |
| 75 | + |
| 76 | + (add to list of keywords) |
| 77 | + |
| 78 | + bfloat16_t bf16vec2 bf16vec3 bf16vec4 |
| 79 | + |
| 80 | + Modify Section 4.1, Basic Types |
| 81 | + |
| 82 | + Add entries to the table of Transparent Types: |
| 83 | + |
| 84 | + bfloat16_t a floating-point scalar with a leading sign bit, 8 exponent bits, and 7 mantissa bits |
| 85 | + bf16vec2 a two-component bfloat16_t vector |
| 86 | + bf16vec3 a three-component bfloat16_t vector |
| 87 | + bf16vec4 a four-component bfloat16_t vector |
| 88 | + |
| 89 | + bfloat types must not be used in input or output storage classes. |
| 90 | + |
| 91 | + Modify Section 4.1.10, Implicit Conversions |
| 92 | + |
| 93 | + Add the following implicit conversions: |
| 94 | + |
| 95 | + Type of expression Can be implicitly converted to |
| 96 | + |
| 97 | + bfloat16_t float32_t, float64_t |
| 98 | + |
| 99 | + (and all corresponding vector promotions) |
| 100 | + |
| 101 | + Modify Section 4.1.X, Cooperative Matrix Types, from GL_KHR_cooperative_matrix |
| 102 | + |
| 103 | + The component type of a cooperative matrix can be bfloat16_t. |
| 104 | + |
| 105 | + Modify Section 4.11, Specialization-Constant Qualifier |
| 106 | + |
| 107 | + The constant_id qualifier can be applied to bfloat16_t variables. |
| 108 | + |
| 109 | + Modify Section 5.4.1, Conversion and Scalar Constructors |
| 110 | + |
| 111 | + Add constructors for bfloat16_t to convert to and from every other floating |
| 112 | + point and integer type, and all corresponding vector constructors. |
| 113 | + There are no conversion to or from boolean types. |
| 114 | + |
| 115 | + Modify Section 5.9, Expressions |
| 116 | + |
| 117 | + Arithmetic operators are not supported on bfloat16_t, or vectors of that |
| 118 | + type, or cooperative matrices of that type. |
| 119 | + |
| 120 | + Modify Chapter 8, Built-In Functions |
| 121 | + |
| 122 | + Add "genBFType" as an alias for bfloat16_t, bf16vec2, bf16vec3, bf16vec4. |
| 123 | + |
| 124 | + Add a bfloat16 overload for 'dot': |
| 125 | + |
| 126 | + bloat16_t dot(genBFType x, genBFType y); |
| 127 | + |
| 128 | + Add bitcast functions: |
| 129 | + |
| 130 | + genI16Type bfloat16BitsToIntEXT(genBFType value); |
| 131 | + genU16Type bfloat16BitsToUintEXT(genBFType value); |
| 132 | + genBFType intBitsToBFloat16EXT(genI16Type value); |
| 133 | + genBFType uintBitsToBFloat16EXT(genU16Type value); |
| 134 | + |
| 135 | + Modify Section 8.X, Cooperative Matrix Functions |
| 136 | + |
| 137 | + Add overloads for cooperative matrix load and store functions: |
| 138 | + |
| 139 | + void coopMatLoad(out coopmat m, volatile coherent bfloat16_t[] buf, uint element, uint stride, int matrixLayout); |
| 140 | + void coopMatLoad(out coopmat m, volatile coherent bf16vec2[] buf, uint element, uint stride, int matrixLayout); |
| 141 | + void coopMatLoad(out coopmat m, volatile coherent bf16vec4[] buf, uint element, uint stride, int matrixLayout); |
| 142 | + |
| 143 | + void coopMatStore(coopmat m, volatile coherent out bfloat16_t[] buf, uint element, uint stride, int matrixLayout); |
| 144 | + void coopMatStore(coopmat m, volatile coherent out bf16vec2[] buf, uint element, uint stride, int matrixLayout); |
| 145 | + void coopMatStore(coopmat m, volatile coherent out bf16vec4[] buf, uint element, uint stride, int matrixLayout); |
| 146 | + |
| 147 | + Modify Chapter 9, Shading Language Grammar for Core Profile |
| 148 | + |
| 149 | + (Add to token list) |
| 150 | + |
| 151 | + BFLOAT16_T BF16VEC2 BF16VEC3 BF16VEC4 |
| 152 | + |
| 153 | + (Add to type_specifier_non_array) |
| 154 | + |
| 155 | + BFLOAT16_T BF16VEC2 BF16VEC3 BF16VEC4 |
| 156 | + |
| 157 | +Issues |
| 158 | + |
| 159 | + (1) Why no conversions to/from boolean types? |
| 160 | + |
| 161 | + RESOLVED: glslang uses OpFUnordNotEqual to convert float->bool, and this is |
| 162 | + not supported for the new types. |
| 163 | + |
| 164 | +Revision History |
| 165 | + |
| 166 | + Revision 1 |
| 167 | + - Internal revisions. |
0 commit comments