Skip to content

Commit c1c00f7

Browse files
svenvhjsji
authored andcommitted
SPIRVReader: Add SubgroupsPerWorkgroup(Id) (#2916)
Add support for consuming the SubgroupsPerWorkgroup (SPIR-V 1.1) and SubgroupsPerWorkgroupId (SPIR-V 1.2) execution modes. Map both of these to `spirv.ExecutionMode` named metadata. Original commit: KhronosGroup/SPIRV-LLVM-Translator@98cd3e46bd62bd0
1 parent 0b1bca1 commit c1c00f7

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

llvm-spirv/lib/SPIRV/SPIRVReader.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4649,6 +4649,25 @@ bool SPIRVToLLVM::transMetadata() {
46494649
auto *SizeMD = ConstantAsMetadata::get(getInt32(M, -1));
46504650
F->setMetadata(kSPIR2MD::SubgroupSize, MDNode::get(*Context, SizeMD));
46514651
}
4652+
// Generate metadata for SubgroupsPerWorkgroup/SubgroupsPerWorkgroupId.
4653+
auto EmitSubgroupsPerWorkgroupMD = [this, F](SPIRVExecutionModeKind EMK,
4654+
uint64_t Value) {
4655+
NamedMDNode *ExecModeMD =
4656+
M->getOrInsertNamedMetadata(kSPIRVMD::ExecutionMode);
4657+
SmallVector<Metadata *, 2> OperandVec;
4658+
OperandVec.push_back(ConstantAsMetadata::get(F));
4659+
OperandVec.push_back(ConstantAsMetadata::get(getUInt32(M, EMK)));
4660+
OperandVec.push_back(ConstantAsMetadata::get(getUInt32(M, Value)));
4661+
ExecModeMD->addOperand(MDNode::get(*Context, OperandVec));
4662+
};
4663+
if (auto *EM = BF->getExecutionMode(ExecutionModeSubgroupsPerWorkgroup)) {
4664+
EmitSubgroupsPerWorkgroupMD(EM->getExecutionMode(), EM->getLiterals()[0]);
4665+
} else if (auto *EM = BF->getExecutionModeId(
4666+
ExecutionModeSubgroupsPerWorkgroupId)) {
4667+
if (auto Val = transIdAsConstant(EM->getLiterals()[0])) {
4668+
EmitSubgroupsPerWorkgroupMD(EM->getExecutionMode(), *Val);
4669+
}
4670+
}
46524671
// Generate metadata for max_work_group_size
46534672
if (auto *EM = BF->getExecutionMode(ExecutionModeMaxWorkgroupSizeINTEL)) {
46544673
F->setMetadata(kSPIR2MD::MaxWGSize,

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVEntry.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,8 @@ void SPIRVExecutionMode::decode(std::istream &I) {
677677
case ExecutionModeSharedLocalMemorySizeINTEL:
678678
case ExecutionModeNamedBarrierCountINTEL:
679679
case ExecutionModeSubgroupSize:
680+
case ExecutionModeSubgroupsPerWorkgroup:
681+
case ExecutionModeSubgroupsPerWorkgroupId:
680682
case ExecutionModeMaxWorkDimINTEL:
681683
case ExecutionModeNumSIMDWorkitemsINTEL:
682684
case ExecutionModeSchedulerTargetFmaxMhzINTEL:
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
; REQUIRES: spirv-as
2+
3+
; RUN: spirv-as %s --target-env spv1.2 -o %t.spv
4+
; RUN: spirv-val %t.spv
5+
; RUN: llvm-spirv -r -o %t.rev.bc %t.spv
6+
; RUN: llvm-dis %t.rev.bc -o - | FileCheck %s
7+
8+
OpCapability Addresses
9+
OpCapability Linkage
10+
OpCapability Kernel
11+
OpCapability SubgroupDispatch
12+
OpMemoryModel Physical64 OpenCL
13+
OpEntryPoint Kernel %fn "testSubgroupsPerWorkgroup"
14+
OpExecutionMode %fn SubgroupsPerWorkgroup 8
15+
%void = OpTypeVoid
16+
%fnTy = OpTypeFunction %void
17+
18+
; CHECK: !spirv.ExecutionMode = !{![[MD:[0-9]+]]}
19+
; CHECK: ![[MD]] = !{ptr @testSubgroupsPerWorkgroup, i32 36, i32 8}
20+
21+
%fn = OpFunction %void None %fnTy
22+
%entry = OpLabel
23+
OpReturn
24+
OpFunctionEnd
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; REQUIRES: spirv-as
2+
3+
; RUN: spirv-as %s --target-env spv1.2 -o %t.spv
4+
; RUN: spirv-val %t.spv
5+
; RUN: llvm-spirv -r -o %t.rev.bc %t.spv
6+
; RUN: llvm-dis %t.rev.bc -o - | FileCheck %s
7+
8+
OpCapability Addresses
9+
OpCapability Linkage
10+
OpCapability Kernel
11+
OpCapability SubgroupDispatch
12+
OpMemoryModel Physical64 OpenCL
13+
OpEntryPoint Kernel %fn "testSubgroupsPerWorkgroupId"
14+
OpExecutionModeId %fn SubgroupsPerWorkgroupId %uint_8
15+
%void = OpTypeVoid
16+
%uint = OpTypeInt 32 0
17+
%uint_4 = OpConstant %uint 4
18+
%uint_8 = OpSpecConstantOp %uint IAdd %uint_4 %uint_4
19+
%fnTy = OpTypeFunction %void
20+
21+
; CHECK: !spirv.ExecutionMode = !{![[MD:[0-9]+]]}
22+
; CHECK: ![[MD]] = !{ptr @testSubgroupsPerWorkgroupId, i32 37, i32 8}
23+
24+
%fn = OpFunction %void None %fnTy
25+
%entry = OpLabel
26+
OpReturn
27+
OpFunctionEnd

0 commit comments

Comments
 (0)