Skip to content

Commit 9d7a651

Browse files
authored
[SYCL][ESIMD] Disallow use of accessor::operator[] in ESIMD code (#5706)
This operator is not supported in ESIMD context. Signed-off-by: Sergey Dmitriev <[email protected]>
1 parent e1619fa commit 9d7a651

File tree

4 files changed

+27
-20
lines changed

4 files changed

+27
-20
lines changed

llvm/lib/SYCLLowerIR/ESIMD/ESIMDVerifier.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ using namespace llvm;
2828
// A list of unsupported functions in ESIMD context.
2929
static const char *IllegalFunctions[] = {
3030
"^cl::sycl::multi_ptr<.+> cl::sycl::accessor<.+>::get_pointer<.+>\\(\\) "
31-
"const"};
31+
"const",
32+
" cl::sycl::accessor<.+>::operator\\[\\]<.+>\\(.+\\) const"};
3233

3334
namespace {
3435

sycl/test/esimd/esimd_verify.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@
88
using namespace cl::sycl;
99
using namespace sycl::ext::intel::experimental::esimd;
1010

11-
// CHECK: error: function 'cl::sycl::multi_ptr<{{.+}}> cl::sycl::accessor<{{.+}}>::get_pointer<{{.+}}>() const' is not supported in ESIMD context
11+
// CHECK-DAG: error: function 'cl::sycl::multi_ptr<{{.+}}> cl::sycl::accessor<{{.+}}>::get_pointer<{{.+}}>() const' is not supported in ESIMD context
12+
// CHECK-DAG: error: function '{{.+}} cl::sycl::accessor<{{.+}}>::operator[]<{{.+}}>({{.+}}) const' is not supported in ESIMD context
1213

1314
SYCL_EXTERNAL auto
1415
test(accessor<int, 1, access::mode::read_write, access::target::device> &acc)
1516
SYCL_ESIMD_FUNCTION {
1617
return acc.get_pointer();
1718
}
19+
20+
SYCL_EXTERNAL void
21+
test1(accessor<int, 1, access::mode::read_write, access::target::device> &acc)
22+
SYCL_ESIMD_FUNCTION {
23+
acc[0] = 0;
24+
}

sycl/test/esimd/hw_compile.cpp

+14-10
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,20 @@ int main(void) {
2222
auto accB = bufB.get_access<cl::sycl::access::mode::read>(cgh);
2323
auto accC = bufC.get_access<cl::sycl::access::mode::write>(cgh);
2424

25-
cgh.parallel_for<class Test>(UnitRange * UnitRange,
26-
[=](sycl::id<1> i) SYCL_ESIMD_KERNEL {
27-
// those operations below would normally be
28-
// represented as a single vector operation
29-
// through ESIMD vector
30-
accC[i + 0] = accA[i + 0] + accB[i + 0];
31-
accC[i + 1] = accA[i + 1] + accB[i + 1];
32-
accC[i + 2] = accA[i + 2] + accB[i + 2];
33-
accC[i + 3] = accA[i + 3] + accB[i + 3];
34-
});
25+
cgh.parallel_for<class Test>(
26+
UnitRange * UnitRange, [=](sycl::id<1> i) SYCL_ESIMD_KERNEL {
27+
int off = i.get(0) * Size;
28+
// those operations below would normally be
29+
// represented as a single vector operation
30+
// through ESIMD vector
31+
cl::sycl::ext::intel::experimental::esimd::simd<int, Size> A(
32+
accA, off * sizeof(int));
33+
cl::sycl::ext::intel::experimental::esimd::simd<int, Size> B(
34+
accB, off * sizeof(int));
35+
cl::sycl::ext::intel::experimental::esimd::simd<int, Size> C =
36+
A + B;
37+
C.copy_to(accC, off * sizeof(int));
38+
});
3539
});
3640
}
3741

sycl/test/esimd/spirv_intrins_trans.cpp

+3-8
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,12 @@ __attribute__((sycl_kernel)) void kernel(Func kernelFunc) {
2121
size_t caller() {
2222

2323
size_t DoNotOpt[1];
24-
cl::sycl::buffer<size_t, 1> buf(&DoNotOpt[0], 1);
2524
uint32_t DoNotOpt32[1];
26-
cl::sycl::buffer<uint32_t, 1> buf32(&DoNotOpt32[0], 1);
27-
2825
size_t DoNotOptXYZ[3];
29-
cl::sycl::buffer<size_t, 1> bufXYZ(&DoNotOptXYZ[0], sycl::range<1>(3));
3026

3127
cl::sycl::queue().submit([&](cl::sycl::handler &cgh) {
32-
auto DoNotOptimize = buf.get_access<cl::sycl::access::mode::write>(cgh);
33-
auto DoNotOptimize32 = buf32.get_access<cl::sycl::access::mode::write>(cgh);
28+
auto DoNotOptimize = &DoNotOpt[0];
29+
auto DoNotOptimize32 = &DoNotOpt32[0];
3430

3531
kernel<class kernel_GlobalInvocationId_x>([=]() SYCL_ESIMD_KERNEL {
3632
DoNotOptimize[0] = __spirv_GlobalInvocationId_x();
@@ -193,8 +189,7 @@ size_t caller() {
193189
// x i64> %0, i64 1 %3 = extractelement <3 x i64> %0, i64 2
194190
// In this case we will generate 3 calls to the same GenX intrinsic,
195191
// But -early-cse will later remove this redundancy.
196-
auto DoNotOptimizeXYZ =
197-
bufXYZ.get_access<cl::sycl::access::mode::write>(cgh);
192+
auto DoNotOptimizeXYZ = &DoNotOptXYZ[0];
198193
kernel<class kernel_LocalInvocationId_xyz>([=]() SYCL_ESIMD_KERNEL {
199194
DoNotOptimizeXYZ[0] = __spirv_LocalInvocationId_x();
200195
DoNotOptimizeXYZ[1] = __spirv_LocalInvocationId_y();

0 commit comments

Comments
 (0)