yum-mirror/glslang
git clone https://git.yummers.dev/yum-mirror/glslang
8e12361e
main
1#version 450 core 2#extension GL_KHR_memory_scope_semantics : enable 3#extension GL_KHR_cooperative_matrix : enable 4#extension GL_EXT_shader_explicit_arithmetic_types : enable 5#extension GL_EXT_buffer_reference : enable 6 7layout (local_size_x = 64, local_size_y = 1, local_size_z = 1) in; 8 9const int X = 8; 10layout(constant_id = 0) const int Y = 2; 11const int Z = X*Y; 12 13coopmat<float16_t, gl_ScopeSubgroup, Z, 8, gl_MatrixUseAccumulator> mC; 14coopmat<float16_t, gl_ScopeSubgroup, Z, 8, gl_MatrixUseAccumulator> mC2[3]; 15 16layout(constant_id = 1) const float F = 3.0; 17 18const coopmat<float, gl_ScopeSubgroup, Z, 8, gl_MatrixUseAccumulator> mD = coopmat<float, gl_ScopeSubgroup, Z, 8, gl_MatrixUseAccumulator>(0.0); 19const coopmat<float16_t, gl_ScopeSubgroup, 8, 8, gl_MatrixUseAccumulator> mD2 = coopmat<float16_t, gl_ScopeSubgroup, 8, 8, gl_MatrixUseAccumulator>(1); 20 21struct S { int a; int b; int c; }; 22 23const S s = S(12, 23, 34); 24 25layout(set = 0, binding = 0, buffer_reference) coherent buffer Block { 26 float y[1024*1024]; 27 float x[]; 28} block; 29 30layout(set = 0, binding = 0) coherent buffer Block16 { 31 float16_t arr[256][256]; 32 float16_t y[1024*1024]; 33 float16_t x[]; 34 35 Block b; 36} block16; 37 38coopmat<float16_t, gl_ScopeSubgroup, 8, 8, gl_MatrixUseAccumulator> f16(coopmat<float16_t, gl_ScopeSubgroup, 8, 8, gl_MatrixUseAccumulator> m) { return -m; } 39coopmat<float, gl_ScopeSubgroup, 8, 8, gl_MatrixUseAccumulator> f32(coopmat<float, gl_ScopeSubgroup, 8, 8, gl_MatrixUseAccumulator> m) { return -m; } 40 41layout(constant_id = 2) const int SC = 1; 42coopmat<float16_t, gl_ScopeSubgroup, SC, SC, gl_MatrixUseAccumulator> scm[SC][SC]; 43 44// sized for coopmat<float16_t, gl_ScopeSubgroup, 16, 16, gl_MatrixUseAccumulator> 45shared uvec4 shmatrix[16*16*2/16]; 46 47void main() 48{ 49 coopmat<float, gl_ScopeSubgroup, 16, (2>1?8:4), gl_MatrixUseAccumulator> m = coopmat<float, gl_ScopeSubgroup, 16, (2>1?8:4), gl_MatrixUseAccumulator>(0.0); 50 51 m = m + m; 52 m = m - m; 53 m = -m; 54 m = 2.0*m; 55 m = m*2.0; 56 57 coopmat<float16_t, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator> m2 = coopmat<float16_t, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator>(m); 58 59 float x = m[1]; 60 m[0] = x; 61 62 coopMatLoad(m, block.x, 16, 128, gl_CooperativeMatrixLayoutRowMajor); 63 coopMatStore(m, block.x, 16, 128, gl_CooperativeMatrixLayoutRowMajor); 64 coopMatLoad(m2, block16.x, 16, 128, gl_CooperativeMatrixLayoutRowMajor); 65 coopMatStore(m2, block16.x, 16, 128, gl_CooperativeMatrixLayoutRowMajor); 66 coopMatLoad(m, block16.b.x, 16, 128, gl_CooperativeMatrixLayoutRowMajor); 67 coopMatStore(m, block16.b.x, 16, 128, gl_CooperativeMatrixLayoutRowMajor); 68 69 coopmat<float16_t, gl_ScopeSubgroup, 16, 8, gl_MatrixUseA> A; 70 coopmat<float16_t, gl_ScopeSubgroup, 8, 8, gl_MatrixUseB> B; 71 coopmat<float, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator> C; 72 coopmat<float, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator> D; 73 D = coopMatMulAdd(A, B, C); 74 75 int l = D.length(); 76 77 coopmat<float16_t, gl_ScopeSubgroup, 8, 8, gl_MatrixUseAccumulator> E; 78 79 coopmat<float16_t, gl_ScopeSubgroup, Z, Z, gl_MatrixUseAccumulator> F = coopmat<float16_t, gl_ScopeSubgroup, Z, Z, gl_MatrixUseAccumulator>(0.0); 80 81 coopmat<float, gl_ScopeSubgroup, 16, (2>1?8:4), gl_MatrixUseAccumulator> a[5]; 82 a[3][0] = 1.0; 83 84 float md1 = mD[1]; 85 86 md1 += (m += m)[1234]; 87 88 mC2[1] = mC2[2]; 89 90 coopMatLoad(m, block.y, 16, 128, gl_CooperativeMatrixLayoutRowMajor); 91 coopMatStore(m, block.y, 16, 128, gl_CooperativeMatrixLayoutRowMajor); 92 coopMatLoad(m2, block16.y, 16, 128, gl_CooperativeMatrixLayoutRowMajor); 93 coopMatStore(m2, block16.y, 16, 128, gl_CooperativeMatrixLayoutRowMajor); 94 95 coopmat<float16_t, gl_ScopeSubgroup, 8, 8, gl_MatrixUseAccumulator> p1; 96 coopmat<float, gl_ScopeSubgroup, 8, 8, gl_MatrixUseAccumulator> p2; 97 98 p1 = f16(p1); 99 p2 = f32(p2); 100 101 p1 = coopmat<float16_t, gl_ScopeSubgroup, 8, 8, gl_MatrixUseAccumulator>(0.0); 102 p2 = coopmat<float, gl_ScopeSubgroup, 8, 8, gl_MatrixUseAccumulator>(0.0); 103 104 p1 /= p1; 105 106 p1 *= float16_t(2.0); 107 p2 *= 4.0; 108 109 coopmat<float16_t, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator> ms; 110 coopMatLoad(ms, shmatrix, 1, 2, gl_CooperativeMatrixLayoutRowMajor); 111 coopMatStore(ms, shmatrix, 1, 2, gl_CooperativeMatrixLayoutRowMajor); 112 113 coopMatLoad(ms, block16.arr[8], 1, 2, gl_CooperativeMatrixLayoutRowMajor); 114 coopMatStore(ms, block16.arr[16], 1, 2, gl_CooperativeMatrixLayoutRowMajor); 115 116 coopmat<int8_t, gl_ScopeSubgroup, 8, 8, gl_MatrixUseA> ms8A; 117 coopmat<int8_t, gl_ScopeSubgroup, 8, 8, gl_MatrixUseB> ms8B; 118 coopmat<int8_t, gl_ScopeSubgroup, 8, 8, gl_MatrixUseAccumulator> ms8C; 119 coopMatMulAdd(ms8A, ms8B, ms8C); 120 coopMatMulAdd(ms8A, ms8B, ms8C, 0); 121 coopMatMulAdd(ms8A, ms8B, ms8C, gl_MatrixOperandsSaturatingAccumulation); 122 123 coopmat<int16_t, gl_ScopeSubgroup, 8, 8, gl_MatrixUseA> m16; 124 coopMatStore(m16, shmatrix, 1, 2, gl_CooperativeMatrixLayoutRowMajor); 125}