Skip to content

Commit 420f5dd

Browse files
authored
[SPIR-V 1.2] 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.
1 parent 8ef84d2 commit 420f5dd

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

lib/SPIRV/SPIRVReader.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4573,6 +4573,16 @@ bool SPIRVToLLVM::transMetadata() {
45734573
if (auto *EM = BF->getExecutionMode(ExecutionModeLocalSizeHint)) {
45744574
F->setMetadata(kSPIR2MD::WGSizeHint,
45754575
getMDNodeStringIntVec(Context, EM->getLiterals()));
4576+
} else if (auto *EM =
4577+
BF->getExecutionModeId(ExecutionModeLocalSizeHintId)) {
4578+
std::vector<SPIRVWord> Values;
4579+
for (const auto Id : EM->getLiterals()) {
4580+
if (auto Val = transIdAsConstant(Id)) {
4581+
Values.emplace_back(static_cast<SPIRVWord>(*Val));
4582+
}
4583+
}
4584+
F->setMetadata(kSPIR2MD::WGSizeHint,
4585+
getMDNodeStringIntVec(Context, Values));
45764586
}
45774587
// Generate metadata for vec_type_hint
45784588
if (auto *EM = BF->getExecutionMode(ExecutionModeVecTypeHint)) {

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;

test/LocalSizeHintId.spvasm

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)