Skip to content

Commit b40ea1c

Browse files
svenvhjsji
authored andcommitted
SPIRVReader: Support LocalSizeHintId (#2907)
If there is no `OpExecutionMode .. LocalSizeHint` in the input, see if there is an `OpExecutionModeId .. LocalSizeHintId` and take the value for the `work_group_size_hint` metadata from the referenced constants instead. Once `LocalSizeHintId` has been translated to LLVM IR, it is indistinguishable from a (non-ID) `LocalSizeHint` execution mode. Original commit: KhronosGroup/SPIRV-LLVM-Translator@420f5dd41a21d5a
1 parent 3de3ce1 commit b40ea1c

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

llvm-spirv/lib/SPIRV/SPIRVReader.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4606,6 +4606,16 @@ bool SPIRVToLLVM::transMetadata() {
46064606
if (auto *EM = BF->getExecutionMode(ExecutionModeLocalSizeHint)) {
46074607
F->setMetadata(kSPIR2MD::WGSizeHint,
46084608
getMDNodeStringIntVec(Context, EM->getLiterals()));
4609+
} else if (auto *EM =
4610+
BF->getExecutionModeId(ExecutionModeLocalSizeHintId)) {
4611+
std::vector<SPIRVWord> Values;
4612+
for (const auto Id : EM->getLiterals()) {
4613+
if (auto Val = transIdAsConstant(Id)) {
4614+
Values.emplace_back(static_cast<SPIRVWord>(*Val));
4615+
}
4616+
}
4617+
F->setMetadata(kSPIR2MD::WGSizeHint,
4618+
getMDNodeStringIntVec(Context, Values));
46094619
}
46104620
// Generate metadata for vec_type_hint
46114621
if (auto *EM = BF->getExecutionMode(ExecutionModeVecTypeHint)) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ void SPIRVExecutionMode::decode(std::istream &I) {
658658
case ExecutionModeLocalSize:
659659
case ExecutionModeLocalSizeId:
660660
case ExecutionModeLocalSizeHint:
661+
case ExecutionModeLocalSizeHintId:
661662
case ExecutionModeMaxWorkgroupSizeINTEL:
662663
WordLiterals.resize(3);
663664
break;
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+
OpMemoryModel Physical64 OpenCL
12+
OpEntryPoint Kernel %fn "testLocalSizeHintId"
13+
OpExecutionModeId %fn LocalSizeHintId %uint_64 %uint_1 %uint_1sco
14+
%void = OpTypeVoid
15+
%uint = OpTypeInt 32 0
16+
%uint_1 = OpConstant %uint 1
17+
%uint_64 = OpConstant %uint 64
18+
%uint_1sco = OpSpecConstantOp %uint UDiv %uint_64 %uint_64
19+
%fnTy = OpTypeFunction %void
20+
21+
; CHECK: define spir_kernel void @testLocalSizeHintId() {{.*}} !work_group_size_hint ![[MD:[0-9]+]]
22+
; CHECK: ![[MD]] = !{i32 64, i32 1, i32 1}
23+
24+
%fn = OpFunction %void None %fnTy
25+
%entry = OpLabel
26+
OpReturn
27+
OpFunctionEnd

0 commit comments

Comments
 (0)