Skip to content

Commit f363bb2

Browse files
authored
[SYCL][ABI Break] Add support for per-kernel auto GRF mode specification, and reimplement feature using kernel properties (#9258)
This change reimplements the GRF mode specification using native SYCL kernel properties, does an ABI break, and adds the `automatic` option. We add a new property named `sycl::detail::register_alloc_mode`, and it takes in an enum `sycl::detail::register_alloc_mode_enum` which currently has two values: `automatic` and `large`. This can be applied to kernels as below: ``` properties prop{register_alloc_mode<register_alloc_mode_enum::automatic>}; ... cgh.parallel_for<class Foo>( Size, prop, [=](id<1> i) { PA[i] += 2; }); ``` We do some `register_alloc_mode` specific work in `CompileTimePropertiesPass`, we add function metadata named `RegisterAllocMode` based on the function attribute `sycl-register-alloc-mode`. This is because llvm-spirv looks for the metadata. This metadata is how AOT works. We also do some `register_alloc_mode` specific work in `sycl-post-link`: 1) Split based on the value of the `sycl-register-alloc-mode` function attribute added in the front end 2) Add a binary property named `sycl-register-alloc-mode` used in the SYCL runtime. Note that ESIMD does not work at all yet for `automatic` yet, not for JIT nor AOT. This is because the VC backend does not support auto GRF. I have made a feature request for the VC team to add this. `large` continues to work for JIT only. --------- Signed-off-by: Sarnie, Nick <[email protected]>
1 parent eff4c76 commit f363bb2

File tree

21 files changed

+214
-408
lines changed

21 files changed

+214
-408
lines changed

llvm/include/llvm/SYCLLowerIR/LowerKernelProps.h

Lines changed: 0 additions & 27 deletions
This file was deleted.

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
#include "llvm/SYCLLowerIR/ESIMD/ESIMDVerifier.h"
8585
#include "llvm/SYCLLowerIR/ESIMD/LowerESIMD.h"
8686
#include "llvm/SYCLLowerIR/LowerInvokeSimd.h"
87-
#include "llvm/SYCLLowerIR/LowerKernelProps.h"
8887
#include "llvm/SYCLLowerIR/LowerWGLocalMemory.h"
8988
#include "llvm/SYCLLowerIR/LowerWGScope.h"
9089
#include "llvm/SYCLLowerIR/MutatePrintfAddrspace.h"

llvm/lib/Passes/PassRegistry.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ MODULE_PASS("memprof-module", ModuleMemProfilerPass())
129129
MODULE_PASS("poison-checking", PoisonCheckingPass())
130130
MODULE_PASS("pseudo-probe-update", PseudoProbeUpdatePass())
131131
MODULE_PASS("LowerESIMD", SYCLLowerESIMDPass())
132-
MODULE_PASS("lower-kernel-props", SYCLLowerKernelPropsPass())
133132
MODULE_PASS("ESIMDLowerVecArg", ESIMDLowerVecArgPass())
134133
MODULE_PASS("esimd-opt-call-conv", ESIMDOptimizeVecArgCallConvPass())
135134
MODULE_PASS("esimd-verifier", ESIMDVerifierPass())

llvm/lib/SYCLLowerIR/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ add_llvm_component_library(LLVMSYCLLowerIR
5959
ESIMD/LowerESIMDSlmReservation.cpp
6060
HostPipes.cpp
6161
LowerInvokeSimd.cpp
62-
LowerKernelProps.cpp
6362
LowerWGLocalMemory.cpp
6463
LowerWGScope.cpp
6564
MutatePrintfAddrspace.cpp

llvm/lib/SYCLLowerIR/CompileTimePropertiesPass.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "llvm/SYCLLowerIR/CompileTimePropertiesPass.h"
1212
#include "llvm/SYCLLowerIR/DeviceGlobals.h"
13+
#include "llvm/SYCLLowerIR/ESIMD/ESIMDUtils.h"
1314
#include "llvm/SYCLLowerIR/HostPipes.h"
1415

1516
#include "llvm/ADT/APInt.h"
@@ -27,6 +28,7 @@ namespace {
2728

2829
constexpr StringRef SYCL_HOST_ACCESS_ATTR = "sycl-host-access";
2930
constexpr StringRef SYCL_PIPELINED_ATTR = "sycl-pipelined";
31+
constexpr StringRef SYCL_REGISTER_ALLOC_MODE_ATTR = "sycl-register-alloc-mode";
3032

3133
constexpr StringRef SPIRV_DECOR_MD_KIND = "spirv.Decorations";
3234
constexpr StringRef SPIRV_PARAM_DECOR_MD_KIND = "spirv.ParameterDecorations";
@@ -175,14 +177,15 @@ MDNode *attributeToDecorateMetadata(LLVMContext &Ctx, const Attribute &Attr) {
175177
/// Tries to generate a SPIR-V execution mode metadata node from an attribute.
176178
/// If the attribute is unknown \c None will be returned.
177179
///
178-
/// @param M [in] the LLVM module.
180+
/// @param F [in] the LLVM function.
179181
/// @param Attr [in] the LLVM attribute to generate metadata for.
180182
///
181183
/// @returns a pair with the name of the resulting metadata and a pointer to
182184
/// the metadata node with its values if the attribute has a
183185
/// corresponding SPIR-V execution mode. Otherwise \c None is returned.
184186
std::optional<std::pair<std::string, MDNode *>>
185-
attributeToExecModeMetadata(Module &M, const Attribute &Attr) {
187+
attributeToExecModeMetadata(Function &F, const Attribute &Attr) {
188+
Module &M = *F.getParent();
186189
LLVMContext &Ctx = M.getContext();
187190
const DataLayout &DLayout = M.getDataLayout();
188191

@@ -267,6 +270,15 @@ attributeToExecModeMetadata(Module &M, const Attribute &Attr) {
267270
return std::pair<std::string, MDNode *>("ip_interface",
268271
getIpInterface("csr", Ctx, Attr));
269272

273+
if (AttrKindStr == SYCL_REGISTER_ALLOC_MODE_ATTR &&
274+
!llvm::esimd::isESIMD(F)) {
275+
uint32_t RegAllocModeVal = getAttributeAsInteger<uint32_t>(Attr);
276+
Metadata *AttrMDArgs[] = {ConstantAsMetadata::get(Constant::getIntegerValue(
277+
Type::getInt32Ty(Ctx), APInt(32, RegAllocModeVal)))};
278+
return std::pair<std::string, MDNode *>("RegisterAllocMode",
279+
MDNode::get(Ctx, AttrMDArgs));
280+
}
281+
270282
return std::nullopt;
271283
}
272284

@@ -420,7 +432,7 @@ PreservedAnalyses CompileTimePropertiesPass::run(Module &M,
420432
} else if (MDNode *SPIRVMetadata =
421433
attributeToDecorateMetadata(Ctx, Attribute))
422434
MDOps.push_back(SPIRVMetadata);
423-
else if (auto NamedMetadata = attributeToExecModeMetadata(M, Attribute))
435+
else if (auto NamedMetadata = attributeToExecModeMetadata(F, Attribute))
424436
NamedMDOps.push_back(*NamedMetadata);
425437
}
426438

llvm/lib/SYCLLowerIR/ESIMD/ESIMDVerifier.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ static const char *LegalSYCLFunctions[] = {
5959
"^sycl::_V1::exp<.+>",
6060
"^sycl::_V1::bit_cast<.+>",
6161
"^sycl::_V1::operator.+<.+>",
62-
"^sycl::_V1::ext::intel::experimental::set_kernel_properties",
6362
"^sycl::_V1::ext::oneapi::sub_group::.+",
6463
"^sycl::_V1::ext::oneapi::experimental::spec_constant<.+>::.+",
6564
"^sycl::_V1::ext::oneapi::experimental::this_sub_group",

llvm/lib/SYCLLowerIR/ESIMD/LowerESIMD.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,8 +1969,6 @@ size_t SYCLLowerESIMDPass::runOnFunction(Function &F,
19691969
ToErase.push_back(CI);
19701970
continue;
19711971
}
1972-
assert(!Name.startswith("__sycl_set_kernel_properties") &&
1973-
"__sycl_set_kernel_properties must have been lowered");
19741972

19751973
if (Name.empty() ||
19761974
(!Name.startswith(ESIMD_INTRIN_PREF1) && !isDevicelibFunction(Name)))

llvm/lib/SYCLLowerIR/LowerKernelProps.cpp

Lines changed: 0 additions & 90 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
; Check we create RegisterAllocMode metadata if there is a non-ESIMD kernel with that property
2+
; RUN: opt -passes=compile-time-properties %s -S | FileCheck %s --check-prefix CHECK-IR
3+
4+
; Function Attrs: convergent norecurse
5+
define weak_odr dso_local spir_kernel void @sycl_regallocmode() #1 {
6+
; CHECK-IR-NOT: !RegisterAllocMode
7+
; CHECK-IR: sycl_regallocmode() #[[#Attr1:]]{{.*}}!RegisterAllocMode ![[#MDVal:]] {
8+
; CHECK-IR-NOT: !RegisterAllocMode
9+
; CHECK-IR: ![[#MDVal]] = !{i32 2}
10+
entry:
11+
ret void
12+
}
13+
14+
; Function Attrs: convergent norecurse
15+
define weak_odr dso_local spir_kernel void @sycl_noregallocmode() #0 {
16+
entry:
17+
ret void
18+
}
19+
20+
; Function Attrs: convergent norecurse
21+
define weak_odr dso_local spir_kernel void @esimd_regallocmode() #1 !sycl_explicit_simd !1 {
22+
entry:
23+
ret void
24+
}
25+
26+
; Function Attrs: convergent norecurse
27+
define weak_odr dso_local spir_kernel void @esimd_noregallocmode() #0 {
28+
entry:
29+
ret void
30+
}
31+
32+
attributes #0 = { convergent norecurse }
33+
attributes #1 = { convergent norecurse "sycl-register-alloc-mode"="2" }
34+
35+
!1 = !{}

llvm/test/SYCLLowerIR/lower_kernel_props.ll

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)