Skip to content

Commit f24a0bb

Browse files
authored
[SYCL][ESIMD] Fix an issue with setting VCSLMSize attribute (#9155)
With the recent SLM handling changes we started assigning "VCSLMSize"="4294967295" attribute to the kernels using classic slm_init() with the size taken from the spec constant. Previous behavior is to set 0. VC backend takes the size from the intrinsic if [the provided size is greater than in metadata.](https://github.com/intel/intel-graphics-compiler/blob/2aa8d536f8823833a18fc5f84c9b4bce9c8060dd/IGC/VectorCompiler/lib/GenXCodeGen/GenXLowering.cpp#L5662) Kernel will not compile with max_int amount of requested SLM:
1 parent 1bcc9f0 commit f24a0bb

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

llvm/lib/SYCLLowerIR/ESIMD/LowerESIMDSlmReservation.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,12 @@ size_t lowerSLMReservationCalls(Module &M) {
635635
// - now set each kernel's SLMSize metadata to the pre-calculated value
636636
for (auto &E : Kernel2MaxSLM) {
637637
int MaxSLM = E.second;
638+
// Clamp negative values to 0. MaxSLM could have been not estimated, e.g.
639+
// due to having __esimd_slm_init with non-const operand (specialization
640+
// constant case). VC backend will use size provided in __esimd_slm_init
641+
// if it is greater than value provided in metadata.
642+
if (MaxSLM < 0)
643+
MaxSLM = 0;
638644
llvm::Value *MaxSLMv =
639645
llvm::ConstantInt::get(Type::getInt32Ty(M.getContext()), MaxSLM);
640646
const Function *Kernel = E.first;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: %clangxx -O2 -fsycl -fsycl-device-only -Xclang -emit-llvm %s -o %t
2+
// RUN: sycl-post-link -split-esimd -lower-esimd -O2 -S %t -o %t.table
3+
// RUN: FileCheck %s -input-file=%t_esimd_0.ll
4+
5+
// Checks that we set 0 as VCSLMSize when slm_init is used with
6+
// non-constant operand, like with specialization constant.
7+
8+
#include <sycl/detail/image_ocl_types.hpp>
9+
#include <sycl/ext/intel/esimd.hpp>
10+
#include <sycl/sycl.hpp>
11+
12+
using namespace sycl::ext::intel::esimd;
13+
using namespace sycl::ext::intel::experimental::esimd;
14+
15+
constexpr sycl::specialization_id<uint64_t> Size(1024);
16+
17+
int main() {
18+
sycl::queue queue;
19+
{
20+
queue.submit([&](sycl::handler &cgh) {
21+
cgh.single_task<class Kernel3Name>(
22+
[=](sycl::kernel_handler kh) SYCL_ESIMD_KERNEL {
23+
slm_init(kh.get_specialization_constant<Size>());
24+
});
25+
// CHECK: define weak_odr dso_local spir_kernel void @{{.*}}(i8 addrspace(1)* noundef align 1 "VCArgumentIOKind"="0" %{{.*}}) local_unnamed_addr #1
26+
});
27+
}
28+
29+
return 0;
30+
}
31+
32+
// CHECK: attributes #1 = { {{.*}} "VCSLMSize"="0"

0 commit comments

Comments
 (0)