Skip to content

Commit

Permalink
[Backport to 15] [SPIR-V 1.2] SPIRVReader: Support LocalSizeHintId (K…
Browse files Browse the repository at this point in the history
…hronosGroup#2907) (KhronosGroup#2919)

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.

(cherry picked from commit 420f5dd)
  • Loading branch information
svenvh authored Dec 16, 2024
1 parent ce487b2 commit d3ba5f9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/SPIRV/SPIRVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4369,6 +4369,16 @@ bool SPIRVToLLVM::transMetadata() {
if (auto EM = BF->getExecutionMode(ExecutionModeLocalSizeHint)) {
F->setMetadata(kSPIR2MD::WGSizeHint,
getMDNodeStringIntVec(Context, EM->getLiterals()));
} else if (auto *EM =
BF->getExecutionModeId(ExecutionModeLocalSizeHintId)) {
std::vector<SPIRVWord> Values;
for (const auto Id : EM->getLiterals()) {
if (auto Val = transIdAsConstant(Id)) {
Values.emplace_back(static_cast<SPIRVWord>(*Val));
}
}
F->setMetadata(kSPIR2MD::WGSizeHint,
getMDNodeStringIntVec(Context, Values));
}
// Generate metadata for vec_type_hint
if (auto EM = BF->getExecutionMode(ExecutionModeVecTypeHint)) {
Expand Down
1 change: 1 addition & 0 deletions lib/SPIRV/libSPIRV/SPIRVEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ void SPIRVExecutionMode::decode(std::istream &I) {
case ExecutionModeLocalSize:
case ExecutionModeLocalSizeId:
case ExecutionModeLocalSizeHint:
case ExecutionModeLocalSizeHintId:
case ExecutionModeMaxWorkgroupSizeINTEL:
WordLiterals.resize(3);
break;
Expand Down
27 changes: 27 additions & 0 deletions test/LocalSizeHintId.spvasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
; REQUIRES: spirv-as

; RUN: spirv-as %s --target-env spv1.2 -o %t.spv
; RUN: spirv-val %t.spv
; RUN: llvm-spirv -r -o %t.rev.bc %t.spv
; RUN: llvm-dis %t.rev.bc -o - | FileCheck %s

OpCapability Addresses
OpCapability Linkage
OpCapability Kernel
OpMemoryModel Physical64 OpenCL
OpEntryPoint Kernel %fn "testLocalSizeHintId"
OpExecutionModeId %fn LocalSizeHintId %uint_64 %uint_1 %uint_1sco
%void = OpTypeVoid
%uint = OpTypeInt 32 0
%uint_1 = OpConstant %uint 1
%uint_64 = OpConstant %uint 64
%uint_1sco = OpSpecConstantOp %uint UDiv %uint_64 %uint_64
%fnTy = OpTypeFunction %void

; CHECK: define spir_kernel void @testLocalSizeHintId() {{.*}} !work_group_size_hint ![[MD:[0-9]+]]
; CHECK: ![[MD]] = !{i32 64, i32 1, i32 1}

%fn = OpFunction %void None %fnTy
%entry = OpLabel
OpReturn
OpFunctionEnd

0 comments on commit d3ba5f9

Please sign in to comment.