yum-mirror/glslang

git clone https://git.yummers.dev/yum-mirror/glslang

Jeff BolzImplement GL_EXT_float8_e5m2_e4m305cfcc16

main
4.4 KiB169 linesraw
1#version 450 core
2
3#extension GL_EXT_bfloat16 : require
4#extension GL_EXT_float_e5m2 : require
5#extension GL_KHR_cooperative_matrix : enable
6#extension GL_NV_cooperative_matrix2 : enable
7#extension GL_KHR_memory_scope_semantics : enable
8#extension GL_EXT_shader_explicit_arithmetic_types : enable
9#extension GL_EXT_scalar_block_layout : enable
10
11layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
12
13const floate5m2_t bc10 = floate5m2_t(10);
14const fe5m2vec2 b2c20 = fe5m2vec2(20);
15layout(constant_id = 1) const floate5m2_t bsc10 = floate5m2_t(10);
16
17struct S { floate5m2_t b; };
18const S sc = S(bc10);
19
20const floate5m2_t bca[2] = {bc10, bc10};
21
22shared floate5m2_t bfs[10];
23
24layout(scalar) buffer B {
25    fe5m2vec3 b3;
26    fe5m2vec2 b2;
27    floate5m2_t b1;
28} buf;
29
30floate5m2_t funcfe5m2(floate5m2_t x)
31{
32    return x;
33}
34
35floate5m2_t funcf32(float32_t x)
36{
37    return floate5m2_t(x);
38}
39
40floate5m2_t funcf64(float64_t x)
41{
42    return floate5m2_t(x);
43}
44
45void main()
46{
47    float f = 2.0;
48    floate5m2_t b = floate5m2_t(1.0);
49    floate5m2_t(f);
50    fe5m2vec2 b2 = fe5m2vec2(f);
51
52    uint8_t u8 = uint8_t(5);
53    uint16_t u16 = uint16_t(5);
54    uint32_t u32 = 5;
55    uint64_t u64 = 5;
56    int8_t i8 = int8_t(6);
57    int16_t i16 = int16_t(6);
58    int32_t i32 = 6;
59    int64_t i64 = 6;
60    floate5m2_t fe5m2 = floate5m2_t(7);
61    float16_t f16 = float16_t(7);
62    float32_t f32 = 7;
63    float64_t f64 = 7;
64    b = floate5m2_t(u8);
65    b = floate5m2_t(u16);
66    b = floate5m2_t(u32);
67    b = floate5m2_t(u64);
68    b = floate5m2_t(i8);
69    b = floate5m2_t(i16);
70    b = floate5m2_t(i32);
71    b = floate5m2_t(i64);
72    b = floate5m2_t(fe5m2);
73    b = floate5m2_t(f16);
74    b = floate5m2_t(f32);
75    b = floate5m2_t(f64);
76    u8 = uint8_t(b);
77    u16 = uint16_t(b);
78    u32 = uint32_t(b);
79    u64 = uint64_t(b);
80    i8 = int8_t(b);
81    i16 = int16_t(b);
82    i32 = int32_t(b);
83    i64 = int64_t(b);
84    fe5m2 = floate5m2_t(b);
85    f16 = float16_t(b);
86    f32 = float32_t(b);
87    f64 = float64_t(b);
88
89    f16 = b;
90    f32 = b;
91    f64 = b;
92
93    b = buf.b1;
94    b2 = buf.b2;
95    fe5m2vec3 b3 = buf.b3;
96
97    coopmat<floate5m2_t, gl_ScopeSubgroup, 16, 16, gl_MatrixUseA> cmA = coopmat<floate5m2_t, gl_ScopeSubgroup, 16, 16, gl_MatrixUseA>(3.0);
98
99    coopmat<float, gl_ScopeSubgroup, 16, 16, gl_MatrixUseA> cmAf = coopmat<float, gl_ScopeSubgroup, 16, 16, gl_MatrixUseA>(cmA);
100
101    funcfe5m2(b);
102    funcf32(b);
103    funcf64(b);
104
105    int8_t i8_1 = floate5m2BitsToIntEXT(b);
106    i8vec2 i8_2 = floate5m2BitsToIntEXT(b2);
107    i8vec3 i8_3 = floate5m2BitsToIntEXT(fe5m2vec3(b2, b));
108    i8vec4 i8_4 = floate5m2BitsToIntEXT(fe5m2vec4(b2, b2));
109
110    uint8_t u8_1 = floate5m2BitsToUintEXT(b);
111    u8vec2  u8_2 = floate5m2BitsToUintEXT(b2);
112    u8vec3  u8_3 = floate5m2BitsToUintEXT(fe5m2vec3(b2, b));
113    u8vec4  u8_4 = floate5m2BitsToUintEXT(fe5m2vec4(b2, b2));
114
115    floate5m2_t f8_1 = intBitsToFloate5m2EXT(i8_1);
116    fe5m2vec2   f8_2 = intBitsToFloate5m2EXT(i8_2);
117    fe5m2vec3   f8_3 = intBitsToFloate5m2EXT(i8_3);
118    fe5m2vec4   f8_4 = intBitsToFloate5m2EXT(i8_4);
119
120    f8_1 = uintBitsToFloate5m2EXT(u8_1);
121    f8_2 = uintBitsToFloate5m2EXT(u8_2);
122    f8_3 = uintBitsToFloate5m2EXT(u8_3);
123    f8_4 = uintBitsToFloate5m2EXT(u8_4);
124}
125
126floate5m2_t func2(fe5m2vec4 v[2], int i)
127{
128    floate5m2_t b;
129    b = (fe5m2vec2(v[0]))[i];
130    b = (fe5m2vec2(v[1])).y;
131
132    v[i].z = v[i][i];
133
134    S s;
135    s.b = b;
136
137    b = (i != 0) ? b : floate5m2_t(2);
138
139    if (i == 2) {
140        b = v[0].x;
141    } else {
142        b = v[1].y;
143    }
144
145    return b;
146}
147
148void saturatedconverts()
149{
150    float f = 1.0;
151    vec2 f2 = vec2(f);
152    floate5m2_t b;
153    fe5m2vec2 b2;
154    uint32_t u;
155    int32_t i;
156    saturatedConvertEXT(b, f);
157    saturatedConvertEXT(b2, f2);
158    saturatedConvertEXT(b, u);
159    saturatedConvertEXT(b, i);
160
161    coopmat<float16_t, gl_ScopeSubgroup, 16, 16, gl_MatrixUseAccumulator> matf16C;
162    coopmat<float16_t, gl_ScopeSubgroup, 16, 16, gl_MatrixUseA> matf16A;
163    coopmat<floate5m2_t, gl_ScopeSubgroup, 16, 16, gl_MatrixUseA> mate5m2A;
164
165    mate5m2A = coopmat<floate5m2_t, gl_ScopeSubgroup, 16, 16, gl_MatrixUseA>(matf16A);
166    mate5m2A = coopmat<floate5m2_t, gl_ScopeSubgroup, 16, 16, gl_MatrixUseA>(matf16C);
167    saturatedConvertEXT(mate5m2A, matf16A);
168    saturatedConvertEXT(mate5m2A, matf16C);
169}