Skip to content

Commit 1d72965

Browse files
againullromanovvlad
authored andcommitted
[SYCL] Specify address space for pointer to data in accessor class
Accessor class contains pointer to data which is currently in the generic address space. This causes SPIR-V Environment specification violation for cases when accessor is wrapped to some object because structure that has a pointer in the generic address space is not allowed as a kernel argument. Fix specifies concrete address space for this pointer in accessor class. Signed-off-by: Artur Gainullin <[email protected]>
1 parent a24d3e0 commit 1d72965

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

sycl/include/CL/sycl/accessor.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ class accessor :
699699

700700
detail::AccessorImplDevice<AdjustedDim> impl;
701701

702-
PtrType MData;
702+
ConcreteASPtrType MData;
703703

704704
void __init(ConcreteASPtrType Ptr, range<AdjustedDim> AccessRange,
705705
range<AdjustedDim> MemRange, id<AdjustedDim> Offset) {
@@ -715,7 +715,7 @@ class accessor :
715715
MData += Offset[0];
716716
}
717717

718-
PtrType getQualifiedPtr() const { return MData; }
718+
ConcreteASPtrType getQualifiedPtr() const { return MData; }
719719

720720
public:
721721
// Default constructor for objects later initialized with __init member.
@@ -1030,9 +1030,9 @@ class accessor<DataT, Dimensions, AccessMode, access::target::local,
10301030
: impl(detail::InitializedVal<AdjustedDim, range>::template get<0>()) {}
10311031

10321032
private:
1033-
PtrType getQualifiedPtr() const { return MData; }
1033+
ConcreteASPtrType getQualifiedPtr() const { return MData; }
10341034

1035-
PtrType MData;
1035+
ConcreteASPtrType MData;
10361036

10371037
#else
10381038

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// RUN: %clangxx --sycl -Xclang -fsycl-is-device -emit-llvm %s -S -o %t.ll
2+
// RUN: FileCheck %s --input-file %t.ll
3+
//
4+
// Check the address space of the pointer in accessor class.
5+
//
6+
// CHECK: %struct{{.*}}AccWrapper = type { %"class{{.*}}cl::sycl::accessor" }
7+
// CHECK-NEXT: %"class{{.*}}cl::sycl::accessor" = type { %"class{{.*}}AccessorImplDevice", i32 addrspace(1)* }
8+
// CHECK: %struct{{.*}}AccWrapper = type { %"class{{.*}}cl::sycl::accessor" }
9+
// CHECK-NEXT: %"class{{.*}}cl::sycl::accessor" = type { %"class{{.*}}LocalAccessorBaseDevice", i32 addrspace(3)* }
10+
//
11+
// Check that kernel arguments doesn't have generic address space.
12+
//
13+
// CHECK-NOT: define weak_odr dso_local spir_kernel void @"{{.*}}check_adress_space"({{.*}}addrspace(4){{.*}})
14+
15+
#include <CL/sycl.hpp>
16+
17+
using namespace cl::sycl;
18+
19+
template <typename Acc> struct AccWrapper { Acc accessor; };
20+
21+
int main() {
22+
23+
cl::sycl::queue queue;
24+
int array[10] = {0};
25+
{
26+
cl::sycl::buffer<int, 1> buf((int *)array, cl::sycl::range<1>(10),
27+
{cl::sycl::property::buffer::use_host_ptr()});
28+
queue.submit([&](cl::sycl::handler &cgh) {
29+
auto acc = buf.get_access<cl::sycl::access::mode::read_write>(cgh);
30+
cl::sycl::accessor<int, 1, cl::sycl::access::mode::read_write,
31+
cl::sycl::access::target::local>
32+
local_acc(cl::sycl::range<1>(10), cgh);
33+
auto acc_wrapped = AccWrapper<decltype(acc)>{acc};
34+
auto local_acc_wrapped = AccWrapper<decltype(local_acc)>{local_acc};
35+
cgh.parallel_for<class check_adress_space>(
36+
cl::sycl::range<1>(buf.get_count()), [=](cl::sycl::item<1> it) {
37+
auto idx = it.get_linear_id();
38+
acc_wrapped.accessor[idx] = local_acc_wrapped.accessor[idx];
39+
});
40+
});
41+
queue.wait();
42+
}
43+
44+
return 0;
45+
}

0 commit comments

Comments
 (0)