Skip to content

Commit 8dc241b

Browse files
committed
GLSL_QCOM_multiple_wait_queues
1 parent a899a43 commit 8dc241b

13 files changed

Lines changed: 308 additions & 6 deletions

File tree

SPIRV/GlslangToSpv.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,6 +1466,10 @@ spv::LoopControlMask TGlslangToSpvTraverser::TranslateLoopControl(const glslang:
14661466
operands.push_back(loopNode.getPartialCount());
14671467
}
14681468
}
1469+
if (loopNode.getMultipleWaitQueuesQCOM() != loopNode.noMultipleQaitQueues) {
1470+
control = control | spv::LoopControlMask::MultipleWaitQueuesQCOM;
1471+
operands.push_back(loopNode.getMultipleWaitQueuesQCOM());
1472+
}
14691473

14701474
return control;
14711475
}

SPIRV/doc.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,7 @@ const char* LoopControlString(int cont)
784784
case (int)LoopControlShift::IterationMultiple: return "IterationMultiple";
785785
case (int)LoopControlShift::PeelCount: return "PeelCount";
786786
case (int)LoopControlShift::PartialCount: return "PartialCount";
787+
case (int)LoopControlShift::MultipleWaitQueuesQCOM: return "MultipeWaitQueuesQCOM";
787788

788789
case LoopControlCeiling:
789790
default: return "Bad";

Test/baseResults/460.frag.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
ERROR: 0:22: 'attribute' : required extension not requested: Possible extensions include:
33
GL_EXT_control_flow_attributes
44
GL_EXT_control_flow_attributes2
5+
GL_QCOM_multiple_wait_queues
56
ERROR: 0:23: 'attribute' : required extension not requested: GL_EXT_control_flow_attributes
67
ERROR: 0:30: 'dependency_length' : must be positive
78
ERROR: 0:31: 'dependency_length' : must be positive
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
spv.qcom.multiple_wait_queues.comp
2+
// Module Version 10300
3+
// Generated by (magic number): 8000b
4+
// Id's are bound by 115
5+
6+
Capability Shader
7+
Capability VulkanMemoryModelKHR
8+
Capability CooperativeMatrixKHR
9+
Extension "SPV_KHR_cooperative_matrix"
10+
Extension "SPV_KHR_vulkan_memory_model"
11+
1: ExtInstImport "GLSL.std.450"
12+
MemoryModel Logical VulkanKHR
13+
EntryPoint GLCompute 4 "main"
14+
ExecutionMode 4 LocalSize 64 2 2
15+
Source GLSL 450
16+
SourceExtension "GL_KHR_cooperative_matrix"
17+
SourceExtension "GL_KHR_memory_scope_semantics"
18+
SourceExtension "GL_QCOM_multiple_wait_queues"
19+
Name 4 "main"
20+
Name 11 "coop_matmul(u1;u1;"
21+
Name 9 "row"
22+
Name 10 "col"
23+
Name 13 "step"
24+
Name 21 "TOTAL_K"
25+
Name 24 "subMatrixAStart"
26+
Name 30 "subMatrixBStart"
27+
Name 37 "TILE_M"
28+
Name 41 "matA"
29+
Name 43 "InputA"
30+
MemberName 43(InputA) 0 "x"
31+
Name 45 "inputA"
32+
Name 52 "TILE_N"
33+
Name 56 "matB"
34+
Name 58 "InputB"
35+
MemberName 58(InputB) 0 "x"
36+
Name 60 "inputB"
37+
Name 68 "matC"
38+
Name 73 "TILE_K"
39+
Name 83 "subMatrixAStart"
40+
Name 88 "subMatrixBStart"
41+
Name 105 "param"
42+
Name 106 "param"
43+
Name 109 "InputC"
44+
MemberName 109(InputC) 0 "x"
45+
Name 111 "inputC"
46+
Decorate 21(TOTAL_K) SpecId 0
47+
Decorate 37(TILE_M) SpecId 3
48+
Decorate 42 ArrayStride 4
49+
Decorate 43(InputA) Block
50+
MemberDecorate 43(InputA) 0 NonWritable
51+
MemberDecorate 43(InputA) 0 Offset 0
52+
Decorate 45(inputA) NonWritable
53+
Decorate 45(inputA) Binding 0
54+
Decorate 45(inputA) DescriptorSet 0
55+
Decorate 52(TILE_N) SpecId 4
56+
Decorate 57 ArrayStride 4
57+
Decorate 58(InputB) Block
58+
MemberDecorate 58(InputB) 0 NonWritable
59+
MemberDecorate 58(InputB) 0 Offset 0
60+
Decorate 60(inputB) NonWritable
61+
Decorate 60(inputB) Binding 1
62+
Decorate 60(inputB) DescriptorSet 0
63+
Decorate 73(TILE_K) SpecId 7
64+
Decorate 108 ArrayStride 4
65+
Decorate 109(InputC) Block
66+
MemberDecorate 109(InputC) 0 NonWritable
67+
MemberDecorate 109(InputC) 0 Offset 0
68+
Decorate 111(inputC) NonWritable
69+
Decorate 111(inputC) Binding 2
70+
Decorate 111(inputC) DescriptorSet 0
71+
Decorate 114 BuiltIn WorkgroupSize
72+
2: TypeVoid
73+
3: TypeFunction 2
74+
6: TypeInt 32 0
75+
7: TypePointer Function 6(int)
76+
8: TypeFunction 2 7(ptr) 7(ptr)
77+
14: 6(int) Constant 0
78+
21(TOTAL_K): 6(int) SpecConstant 1
79+
22: TypeBool
80+
26: 6(int) Constant 16
81+
35: TypeFloat 32
82+
36: 6(int) Constant 3
83+
37(TILE_M): 6(int) SpecConstant 1
84+
38: 6(int) Constant 8
85+
39: TypeCooperativeMatrixKHR 35(float) 36 37(TILE_M) 38 14
86+
40: TypePointer Function 39
87+
42: TypeRuntimeArray 35(float)
88+
43(InputA): TypeStruct 42
89+
44: TypePointer StorageBuffer 43(InputA)
90+
45(inputA): 44(ptr) Variable StorageBuffer
91+
46: TypeInt 32 1
92+
47: 46(int) Constant 0
93+
49: TypePointer StorageBuffer 35(float)
94+
52(TILE_N): 6(int) SpecConstant 1
95+
53: 6(int) Constant 1
96+
54: TypeCooperativeMatrixKHR 35(float) 36 38 52(TILE_N) 53
97+
55: TypePointer Function 54
98+
57: TypeRuntimeArray 35(float)
99+
58(InputB): TypeStruct 57
100+
59: TypePointer StorageBuffer 58(InputB)
101+
60(inputB): 59(ptr) Variable StorageBuffer
102+
63: 46(int) Constant 1
103+
65: 6(int) Constant 2
104+
66: TypeCooperativeMatrixKHR 35(float) 36 37(TILE_M) 52(TILE_N) 65
105+
67: TypePointer Function 66
106+
73(TILE_K): 6(int) SpecConstant 1
107+
108: TypeRuntimeArray 35(float)
108+
109(InputC): TypeStruct 108
109+
110: TypePointer StorageBuffer 109(InputC)
110+
111(inputC): 110(ptr) Variable StorageBuffer
111+
112: TypeVector 6(int) 3
112+
113: 6(int) Constant 64
113+
114: 112(ivec3) ConstantComposite 113 65 65
114+
4(main): 2 Function None 3
115+
5: Label
116+
105(param): 7(ptr) Variable Function
117+
106(param): 7(ptr) Variable Function
118+
Store 105(param) 14
119+
Store 106(param) 14
120+
107: 2 FunctionCall 11(coop_matmul(u1;u1;) 105(param) 106(param)
121+
Return
122+
FunctionEnd
123+
11(coop_matmul(u1;u1;): 2 Function None 8
124+
9(row): 7(ptr) FunctionParameter
125+
10(col): 7(ptr) FunctionParameter
126+
12: Label
127+
13(step): 7(ptr) Variable Function
128+
24(subMatrixAStart): 7(ptr) Variable Function
129+
30(subMatrixBStart): 7(ptr) Variable Function
130+
41(matA): 40(ptr) Variable Function
131+
56(matB): 55(ptr) Variable Function
132+
68(matC): 67(ptr) Variable Function
133+
83(subMatrixAStart): 7(ptr) Variable Function
134+
88(subMatrixBStart): 7(ptr) Variable Function
135+
Store 13(step) 14
136+
Branch 15
137+
15: Label
138+
LoopMerge 17 18 0
139+
Branch 19
140+
19: Label
141+
20: 6(int) Load 13(step)
142+
23: 22(bool) ULessThan 20 21(TOTAL_K)
143+
BranchConditional 23 16 17
144+
16: Label
145+
25: 6(int) Load 9(row)
146+
27: 6(int) IMul 25 26
147+
28: 6(int) Load 13(step)
148+
29: 6(int) IAdd 27 28
149+
Store 24(subMatrixAStart) 29
150+
31: 6(int) Load 10(col)
151+
32: 6(int) IMul 31 26
152+
33: 6(int) Load 13(step)
153+
34: 6(int) IAdd 32 33
154+
Store 30(subMatrixBStart) 34
155+
48: 6(int) Load 24(subMatrixAStart)
156+
50: 49(ptr) AccessChain 45(inputA) 47 48
157+
51: 39 CooperativeMatrixLoadKHR 50 47 26 None
158+
Store 41(matA) 51
159+
61: 6(int) Load 30(subMatrixBStart)
160+
62: 49(ptr) AccessChain 60(inputB) 47 61
161+
64: 54 CooperativeMatrixLoadKHR 62 63 26 None
162+
Store 56(matB) 64
163+
69: 39 Load 41(matA)
164+
70: 54 Load 56(matB)
165+
71: 66 Load 68(matC)
166+
72: 66 CooperativeMatrixMulAddKHR 69 70 71
167+
Store 68(matC) 72
168+
Branch 18
169+
18: Label
170+
74: 6(int) Load 13(step)
171+
75: 6(int) IAdd 74 73(TILE_K)
172+
Store 13(step) 75
173+
Branch 15
174+
17: Label
175+
Store 13(step) 14
176+
Branch 76
177+
76: Label
178+
LoopMerge 78 79 2
179+
Branch 80
180+
80: Label
181+
81: 6(int) Load 13(step)
182+
82: 22(bool) ULessThan 81 21(TOTAL_K)
183+
BranchConditional 82 77 78
184+
77: Label
185+
84: 6(int) Load 9(row)
186+
85: 6(int) IMul 84 26
187+
86: 6(int) Load 13(step)
188+
87: 6(int) IAdd 85 86
189+
Store 83(subMatrixAStart) 87
190+
89: 6(int) Load 10(col)
191+
90: 6(int) IMul 89 26
192+
91: 6(int) Load 13(step)
193+
92: 6(int) IAdd 90 91
194+
Store 88(subMatrixBStart) 92
195+
93: 6(int) Load 83(subMatrixAStart)
196+
94: 49(ptr) AccessChain 45(inputA) 47 93
197+
95: 39 CooperativeMatrixLoadKHR 94 47 26 None
198+
Store 41(matA) 95
199+
96: 6(int) Load 88(subMatrixBStart)
200+
97: 49(ptr) AccessChain 60(inputB) 47 96
201+
98: 54 CooperativeMatrixLoadKHR 97 63 26 None
202+
Store 56(matB) 98
203+
99: 39 Load 41(matA)
204+
100: 54 Load 56(matB)
205+
101: 66 Load 68(matC)
206+
102: 66 CooperativeMatrixMulAddKHR 99 100 101
207+
Store 68(matC) 102
208+
Branch 79
209+
79: Label
210+
103: 6(int) Load 13(step)
211+
104: 6(int) IAdd 103 73(TILE_K)
212+
Store 13(step) 104
213+
Branch 76
214+
78: Label
215+
Return
216+
FunctionEnd
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#version 450 core
2+
#extension GL_KHR_memory_scope_semantics : enable
3+
4+
#extension GL_KHR_cooperative_matrix : enable
5+
#extension GL_QCOM_multiple_wait_queues : enable
6+
7+
layout(constant_id = 0) const uint TOTAL_K = 1;
8+
9+
layout(constant_id = 3) const uint TILE_M = 1;
10+
layout(constant_id = 4) const uint TILE_N = 1;
11+
layout(constant_id = 7) const uint TILE_K = 1;
12+
13+
layout(set=0, binding=0) readonly buffer InputA { float x[]; } inputA;
14+
layout(set=0, binding=1) readonly buffer InputB { float x[]; } inputB;
15+
layout(set=0, binding=2) readonly buffer InputC { float x[]; } inputC;
16+
17+
layout(local_size_x = 64, local_size_y = 2, local_size_z = 2) in;
18+
19+
#define STRIDE_A 16
20+
#define STRIDE_B 16
21+
22+
void coop_matmul(uint row, uint col)
23+
{
24+
coopmat<float, gl_ScopeSubgroup, TILE_M, 8, gl_MatrixUseA> matA;
25+
coopmat<float, gl_ScopeSubgroup, 8, TILE_N, gl_MatrixUseB> matB;
26+
coopmat<float, gl_ScopeSubgroup, TILE_M, TILE_N, gl_MatrixUseAccumulator> matC;
27+
uint step;
28+
29+
[[multiple_wait_queuesQCOM]]
30+
for (step = 0; step < TOTAL_K; step += TILE_K) {
31+
uint subMatrixAStart = row * STRIDE_A + step;
32+
uint subMatrixBStart = col * STRIDE_B + step;
33+
34+
coopMatLoad(matA, inputA.x, subMatrixAStart, STRIDE_A, gl_CooperativeMatrixLayoutRowMajor); // Global to CoopMat
35+
coopMatLoad(matB, inputB.x, subMatrixBStart, STRIDE_B, gl_CooperativeMatrixLayoutColumnMajor); // Global to CoopMat
36+
37+
matC = coopMatMulAdd(matA, matB, matC);
38+
}
39+
40+
[[multiple_wait_queuesQCOM(2)]]
41+
for (step = 0; step < TOTAL_K; step += TILE_K) {
42+
uint subMatrixAStart = row * STRIDE_A + step;
43+
uint subMatrixBStart = col * STRIDE_B + step;
44+
45+
coopMatLoad(matA, inputA.x, subMatrixAStart, STRIDE_A, gl_CooperativeMatrixLayoutRowMajor); // Global to CoopMat
46+
coopMatLoad(matB, inputB.x, subMatrixBStart, STRIDE_B, gl_CooperativeMatrixLayoutColumnMajor); // Global to CoopMat
47+
48+
matC = coopMatMulAdd(matA, matB, matC);
49+
}
50+
}
51+
52+
void main()
53+
{
54+
coop_matmul(0, 0);
55+
}

glslang/Include/intermediate.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,8 @@ class TIntermLoop : public TIntermNode {
12661266
maxIterations(iterationsInfinite),
12671267
iterationMultiple(1),
12681268
peelCount(0),
1269-
partialCount(0)
1269+
partialCount(0),
1270+
multipleWaitQueuesQCOM(noMultipleQaitQueues)
12701271
{ }
12711272

12721273
virtual TIntermLoop* getAsLoopNode() { return this; }
@@ -1318,6 +1319,12 @@ class TIntermLoop : public TIntermNode {
13181319
}
13191320
unsigned int getPartialCount() const { return partialCount; }
13201321

1322+
static const unsigned int noMultipleQaitQueues = 0xFFFFFFFF;
1323+
void setMultipleWaitQueuesQCOM(unsigned int numQ) {
1324+
multipleWaitQueuesQCOM = numQ;
1325+
}
1326+
unsigned int getMultipleWaitQueuesQCOM() const { return multipleWaitQueuesQCOM; }
1327+
13211328
protected:
13221329
TIntermNode* body; // code to loop over
13231330
TIntermNode* test; // exit condition associated with loop, could be 0 for 'for' loops
@@ -1331,6 +1338,7 @@ class TIntermLoop : public TIntermNode {
13311338
unsigned int iterationMultiple; // as per the SPIR-V specification
13321339
unsigned int peelCount; // as per the SPIR-V specification
13331340
unsigned int partialCount; // as per the SPIR-V specification
1341+
unsigned int multipleWaitQueuesQCOM;
13341342
};
13351343

13361344
//

glslang/MachineIndependent/Versions.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ void TParseVersions::initializeExtensionBehavior()
339339
extensionBehavior[E_GL_QCOM_image_processing2] = EBhDisable;
340340
extensionBehavior[E_GL_QCOM_tile_shading] = EBhDisable;
341341
extensionBehavior[E_GL_QCOM_cooperative_matrix_conversion] = EBhDisable;
342+
extensionBehavior[E_GL_QCOM_multiple_wait_queues] = EBhDisable;
342343

343344
// AEP
344345
extensionBehavior[E_GL_ANDROID_extension_pack_es31a] = EBhDisable;
@@ -497,6 +498,7 @@ void TParseVersions::getPreamble(std::string& preamble)
497498
"#define GL_QCOM_image_processing2 1\n"
498499
"#define GL_QCOM_tile_shading 1\n"
499500
"#define GL_QCOM_cooperative_matrix_conversion 1\n"
501+
"#define GL_QCOM_multiple_wait_queues 1\n"
500502
;
501503

502504
if (version >= 300) {
@@ -635,6 +637,7 @@ void TParseVersions::getPreamble(std::string& preamble)
635637
"#define GL_QCOM_image_processing2 1\n"
636638
"#define GL_QCOM_tile_shading 1\n"
637639
"#define GL_QCOM_cooperative_matrix_conversion 1\n"
640+
"#define GL_QCOM_multiple_wait_queues 1\n"
638641

639642
"#define GL_EXT_shader_explicit_arithmetic_types 1\n"
640643
"#define GL_EXT_shader_explicit_arithmetic_types_int8 1\n"

glslang/MachineIndependent/Versions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ const char* const E_GL_QCOM_image_processing = "GL_QCOM_image
320320
const char* const E_GL_QCOM_image_processing2 = "GL_QCOM_image_processing2";
321321
const char* const E_GL_QCOM_tile_shading = "GL_QCOM_tile_shading";
322322
const char* const E_GL_QCOM_cooperative_matrix_conversion = "GL_QCOM_cooperative_matrix_conversion";
323+
const char* const E_GL_QCOM_multiple_wait_queues = "GL_QCOM_multiple_wait_queues";
323324

324325
// AEP
325326
const char* const E_GL_ANDROID_extension_pack_es31a = "GL_ANDROID_extension_pack_es31a";

glslang/MachineIndependent/attribute.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ TAttributeType TParseContext::attributeFromName(const TString& name) const
127127
return EatExport;
128128
else if (name == "maximally_reconverges")
129129
return EatMaximallyReconverges;
130+
else if (name == "multiple_wait_queuesQCOM")
131+
return EatMultipleWaitQueuesQCOM;
130132
else
131133
return EatNone;
132134
}
@@ -338,6 +340,14 @@ void TParseContext::handleLoopAttributes(const TAttributes& attributes, TIntermN
338340
if (unsignedArgument("partial_count", uiValue))
339341
loop->setPartialCount(uiValue);
340342
break;
343+
case EatMultipleWaitQueuesQCOM:
344+
value = -1;
345+
if (it->size() == 0)
346+
loop->setMultipleWaitQueuesQCOM(0);
347+
else
348+
if (positiveSignedArgument("multiple_wait_queuesQCOM", value))
349+
loop->setMultipleWaitQueuesQCOM(value);
350+
break;
341351
default:
342352
warn(node->getLoc(), "attribute does not apply to a loop", "", "");
343353
break;

glslang/MachineIndependent/attribute.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ namespace glslang {
122122
EatSubgroupUniformControlFlow,
123123
EatExport,
124124
EatMaximallyReconverges,
125+
EatMultipleWaitQueuesQCOM,
125126
};
126127

127128
class TIntermAggregate;

0 commit comments

Comments
 (0)