Skip to content

Commit 2b1d320

Browse files
authored
[SYCL] Ignore placeholder template parameter for accessor (#8071)
According to SYCL 2020 spec, placeholder template parameter has no bearing in whether the accessor is a placeholder or not, it is now solely determined by the constructor. --------- Signed-off-by: Maronas, Marcos <[email protected]>
1 parent 50e798f commit 2b1d320

File tree

7 files changed

+251
-56
lines changed

7 files changed

+251
-56
lines changed

sycl/include/sycl/accessor.hpp

Lines changed: 72 additions & 52 deletions
Large diffs are not rendered by default.

sycl/source/accessor.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,19 @@ AccessorBaseHost::AccessorBaseHost(id<3> Offset, range<3> AccessRange,
2525
impl = std::shared_ptr<AccessorImplHost>(
2626
new AccessorImplHost(Offset, AccessRange, MemoryRange, AccessMode,
2727
(detail::SYCLMemObjI *)SYCLMemObject, Dims, ElemSize,
28-
OffsetInBytes, IsSubBuffer, PropertyList));
28+
false, OffsetInBytes, IsSubBuffer, PropertyList));
29+
}
30+
31+
AccessorBaseHost::AccessorBaseHost(id<3> Offset, range<3> AccessRange,
32+
range<3> MemoryRange,
33+
access::mode AccessMode, void *SYCLMemObject,
34+
int Dims, int ElemSize, bool IsPlaceH,
35+
int OffsetInBytes, bool IsSubBuffer,
36+
const property_list &PropertyList) {
37+
impl = std::shared_ptr<AccessorImplHost>(
38+
new AccessorImplHost(Offset, AccessRange, MemoryRange, AccessMode,
39+
(detail::SYCLMemObjI *)SYCLMemObject, Dims, ElemSize,
40+
IsPlaceH, OffsetInBytes, IsSubBuffer, PropertyList));
2941
}
3042

3143
id<3> &AccessorBaseHost::getOffset() { return impl->MOffset; }
@@ -54,6 +66,8 @@ void *AccessorBaseHost::getPtr() const {
5466

5567
void *AccessorBaseHost::getMemoryObject() const { return impl->MSYCLMemObj; }
5668

69+
bool AccessorBaseHost::isPlaceholder() const { return impl->MIsPlaceH; }
70+
5771
LocalAccessorBaseHost::LocalAccessorBaseHost(
5872
sycl::range<3> Size, int Dims, int ElemSize,
5973
const property_list &PropertyList) {

sycl/source/detail/accessor_impl.hpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class Command;
4141

4242
class __SYCL_EXPORT AccessorImplHost {
4343
public:
44+
// TODO: Remove when ABI break is allowed.
4445
AccessorImplHost(id<3> Offset, range<3> AccessRange, range<3> MemoryRange,
4546
access::mode AccessMode, void *SYCLMemObject, int Dims,
4647
int ElemSize, int OffsetInBytes = 0,
@@ -49,15 +50,28 @@ class __SYCL_EXPORT AccessorImplHost {
4950
: MAccData(Offset, AccessRange, MemoryRange), MAccessMode(AccessMode),
5051
MSYCLMemObj((detail::SYCLMemObjI *)SYCLMemObject), MDims(Dims),
5152
MElemSize(ElemSize), MOffsetInBytes(OffsetInBytes),
52-
MIsSubBuffer(IsSubBuffer), MPropertyList(PropertyList) {}
53+
MIsSubBuffer(IsSubBuffer), MPropertyList(PropertyList),
54+
MIsPlaceH(false) {}
55+
56+
AccessorImplHost(id<3> Offset, range<3> AccessRange, range<3> MemoryRange,
57+
access::mode AccessMode, void *SYCLMemObject, int Dims,
58+
int ElemSize, bool IsPlaceH, int OffsetInBytes = 0,
59+
bool IsSubBuffer = false,
60+
const property_list &PropertyList = {})
61+
: MAccData(Offset, AccessRange, MemoryRange), MAccessMode(AccessMode),
62+
MSYCLMemObj((detail::SYCLMemObjI *)SYCLMemObject), MDims(Dims),
63+
MElemSize(ElemSize), MOffsetInBytes(OffsetInBytes),
64+
MIsSubBuffer(IsSubBuffer), MPropertyList(PropertyList),
65+
MIsPlaceH(IsPlaceH) {}
5366

5467
~AccessorImplHost();
5568

5669
AccessorImplHost(const AccessorImplHost &Other)
5770
: MAccData(Other.MAccData), MAccessMode(Other.MAccessMode),
5871
MSYCLMemObj(Other.MSYCLMemObj), MDims(Other.MDims),
5972
MElemSize(Other.MElemSize), MOffsetInBytes(Other.MOffsetInBytes),
60-
MIsSubBuffer(Other.MIsSubBuffer), MPropertyList(Other.MPropertyList) {}
73+
MIsSubBuffer(Other.MIsSubBuffer), MPropertyList(Other.MPropertyList),
74+
MIsPlaceH(Other.MIsPlaceH) {}
6175

6276
AccessorImplHost &operator=(const AccessorImplHost &Other) {
6377
MAccData = Other.MAccData;
@@ -68,6 +82,7 @@ class __SYCL_EXPORT AccessorImplHost {
6882
MOffsetInBytes = Other.MOffsetInBytes;
6983
MIsSubBuffer = Other.MIsSubBuffer;
7084
MPropertyList = Other.MPropertyList;
85+
MIsPlaceH = Other.MIsPlaceH;
7186
return *this;
7287
}
7388

@@ -106,6 +121,9 @@ class __SYCL_EXPORT AccessorImplHost {
106121

107122
// To preserve runtime properties
108123
property_list MPropertyList;
124+
125+
// Placeholder flag
126+
bool MIsPlaceH;
109127
};
110128

111129
using AccessorImplPtr = std::shared_ptr<AccessorImplHost>;

sycl/test/abi/sycl_symbols_linux.dump

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3836,7 +3836,9 @@ _ZN4sycl3_V16detail16AccessorBaseHost14getAccessRangeEv
38363836
_ZN4sycl3_V16detail16AccessorBaseHost14getMemoryRangeEv
38373837
_ZN4sycl3_V16detail16AccessorBaseHost6getPtrEv
38383838
_ZN4sycl3_V16detail16AccessorBaseHost9getOffsetEv
3839+
_ZN4sycl3_V16detail16AccessorBaseHostC1ENS0_2idILi3EEENS0_5rangeILi3EEES6_NS0_6access4modeEPviibibRKNS0_13property_listE
38393840
_ZN4sycl3_V16detail16AccessorBaseHostC1ENS0_2idILi3EEENS0_5rangeILi3EEES6_NS0_6access4modeEPviiibRKNS0_13property_listE
3841+
_ZN4sycl3_V16detail16AccessorBaseHostC2ENS0_2idILi3EEENS0_5rangeILi3EEES6_NS0_6access4modeEPviibibRKNS0_13property_listE
38403842
_ZN4sycl3_V16detail16AccessorBaseHostC2ENS0_2idILi3EEENS0_5rangeILi3EEES6_NS0_6access4modeEPviiibRKNS0_13property_listE
38413843
_ZN4sycl3_V16detail16AccessorImplHost6resizeEm
38423844
_ZN4sycl3_V16detail16AccessorImplHostD1Ev
@@ -4174,6 +4176,7 @@ _ZNK4sycl3_V16detail12sampler_impl19get_addressing_modeEv
41744176
_ZNK4sycl3_V16detail12sampler_impl33get_coordinate_normalization_modeEv
41754177
_ZNK4sycl3_V16detail16AccessorBaseHost11getElemSizeEv
41764178
_ZNK4sycl3_V16detail16AccessorBaseHost11getPropListEv
4179+
_ZNK4sycl3_V16detail16AccessorBaseHost13isPlaceholderEv
41774180
_ZNK4sycl3_V16detail16AccessorBaseHost14getAccessRangeEv
41784181
_ZNK4sycl3_V16detail16AccessorBaseHost14getMemoryRangeEv
41794182
_ZNK4sycl3_V16detail16AccessorBaseHost15getMemoryObjectEv

sycl/test/abi/sycl_symbols_windows.dump

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# DO NOT EDIT IT MANUALLY. Refer to sycl/doc/developer/ABIPolicyGuide.md for more info.
44
################################################################################
55

6-
# RUN: env LLVM_BIN_PATH=%llvm_build_bin_dir python %sycl_tools_src_dir/abi_check.py --mode check_symbols --reference %s %llvm_build_bin_dir/sycl6.dll
6+
# RUN: env LLVM_BIN_PATH=%llvm_build_bin_dir %python %sycl_tools_src_dir/abi_check.py --mode check_symbols --reference %s %llvm_build_bin_dir/sycl6.dll
77
# REQUIRES: windows
88
# UNSUPPORTED: libcxx
99

@@ -359,8 +359,10 @@
359359
??0AccessorBaseHost@detail@_V1@sycl@@QEAA@$$QEAV0123@@Z
360360
??0AccessorBaseHost@detail@_V1@sycl@@QEAA@AEBV0123@@Z
361361
??0AccessorBaseHost@detail@_V1@sycl@@QEAA@V?$id@$02@23@V?$range@$02@23@1W4mode@access@23@PEAXHHH_NAEBVproperty_list@23@@Z
362+
??0AccessorBaseHost@detail@_V1@sycl@@QEAA@V?$id@$02@23@V?$range@$02@23@1W4mode@access@23@PEAXHH_NH4AEBVproperty_list@23@@Z
362363
??0AccessorImplHost@detail@_V1@sycl@@QEAA@AEBV0123@@Z
363364
??0AccessorImplHost@detail@_V1@sycl@@QEAA@V?$id@$02@23@V?$range@$02@23@1W4mode@access@23@PEAXHHH_NAEBVproperty_list@23@@Z
365+
??0AccessorImplHost@detail@_V1@sycl@@QEAA@V?$id@$02@23@V?$range@$02@23@1W4mode@access@23@PEAXHH_NH4AEBVproperty_list@23@@Z
364366
??0HostProfilingInfo@detail@_V1@sycl@@QEAA@XZ
365367
??0LocalAccessorBaseHost@detail@_V1@sycl@@IEAA@AEBV?$shared_ptr@VLocalAccessorImplHost@detail@_V1@sycl@@@std@@@Z
366368
??0LocalAccessorBaseHost@detail@_V1@sycl@@QEAA@$$QEAV0123@@Z
@@ -1038,6 +1040,7 @@
10381040
?isInterop@SYCLMemObjT@detail@_V1@sycl@@QEBA_NXZ
10391041
?isOutOfRange@detail@_V1@sycl@@YA_NV?$vec@H$03@23@W4addressing_mode@23@V?$range@$02@23@@Z
10401042
?isPathPresent@OSUtil@detail@_V1@sycl@@SA_NAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z
1043+
?isPlaceholder@AccessorBaseHost@detail@_V1@sycl@@QEBA_NXZ
10411044
?isStateExplicitKernelBundle@handler@_V1@sycl@@AEBA_NXZ
10421045
?isValidModeForDestinationAccessor@handler@_V1@sycl@@CA_NW4mode@access@23@@Z
10431046
?isValidModeForSourceAccessor@handler@_V1@sycl@@CA_NW4mode@access@23@@Z
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
#include <gtest/gtest.h>
2+
3+
#include <helpers/PiImage.hpp>
4+
#include <helpers/PiMock.hpp>
5+
#include <numeric>
6+
#include <sycl/sycl.hpp>
7+
8+
TEST(AccessorPlaceholderTest, NoCommandGroupPlaceholderNoneTargetDevice) {
9+
static constexpr sycl::access_mode acmode = sycl::access_mode::read;
10+
static constexpr sycl::access::target actarget = sycl::access::target::device;
11+
using AccT = sycl::accessor<int, 1, acmode, actarget>;
12+
int data(14);
13+
sycl::range<1> r(1);
14+
sycl::buffer<int, 1> data_buf(&data, r);
15+
AccT acc(data_buf);
16+
EXPECT_TRUE(acc.is_placeholder());
17+
}
18+
19+
TEST(AccessorPlaceholderTest, NoCommandGroupPlaceholderTrueTargetDevice) {
20+
static constexpr sycl::access_mode acmode = sycl::access_mode::read;
21+
static constexpr sycl::access::target actarget = sycl::access::target::device;
22+
static constexpr sycl::access::placeholder acplaceholder =
23+
sycl::access::placeholder::true_t;
24+
using AccT = sycl::accessor<int, 1, acmode, actarget, acplaceholder>;
25+
int data(14);
26+
sycl::range<1> r(1);
27+
sycl::buffer<int, 1> data_buf(&data, r);
28+
AccT acc(data_buf);
29+
EXPECT_TRUE(acc.is_placeholder());
30+
}
31+
32+
TEST(AccessorPlaceholderTest, NoCommandGroupPlaceholderFalseTargetDevice) {
33+
static constexpr sycl::access_mode acmode = sycl::access_mode::read;
34+
static constexpr sycl::access::target actarget = sycl::access::target::device;
35+
static constexpr sycl::access::placeholder acplaceholder =
36+
sycl::access::placeholder::false_t;
37+
using AccT = sycl::accessor<int, 1, acmode, actarget, acplaceholder>;
38+
int data(14);
39+
sycl::range<1> r(1);
40+
sycl::buffer<int, 1> data_buf(&data, r);
41+
AccT acc(data_buf);
42+
EXPECT_TRUE(acc.is_placeholder());
43+
}
44+
45+
TEST(AccessorPlaceholderTest, PlaceholderNoneTargetDevice) {
46+
static constexpr sycl::access_mode acmode = sycl::access_mode::read;
47+
static constexpr sycl::access::target actarget = sycl::access::target::device;
48+
using AccT = sycl::accessor<int, 1, acmode, actarget>;
49+
int data(14);
50+
sycl::range<1> r(1);
51+
sycl::buffer<int, 1> data_buf(&data, r);
52+
sycl::unittest::PiMock Mock;
53+
sycl::platform Plt = Mock.getPlatform();
54+
sycl::queue q{Plt.get_devices()[0]};
55+
q.submit([&](sycl::handler &cgh) {
56+
AccT acc(data_buf, cgh);
57+
EXPECT_FALSE(acc.is_placeholder());
58+
});
59+
}
60+
61+
TEST(AccessorPlaceholderTest, PlaceholderTrueTargetDevice) {
62+
static constexpr sycl::access_mode acmode = sycl::access_mode::read;
63+
static constexpr sycl::access::target actarget = sycl::access::target::device;
64+
static constexpr sycl::access::placeholder acplaceholder =
65+
sycl::access::placeholder::true_t;
66+
using AccT = sycl::accessor<int, 1, acmode, actarget, acplaceholder>;
67+
int data(14);
68+
sycl::range<1> r(1);
69+
sycl::buffer<int, 1> data_buf(&data, r);
70+
sycl::unittest::PiMock Mock;
71+
sycl::platform Plt = Mock.getPlatform();
72+
sycl::queue q{Plt.get_devices()[0]};
73+
q.submit([&](sycl::handler &cgh) {
74+
AccT acc(data_buf, cgh);
75+
EXPECT_FALSE(acc.is_placeholder());
76+
});
77+
}
78+
79+
TEST(AccessorPlaceholderTest, PlaceholderFalseTargetDevice) {
80+
static constexpr sycl::access_mode acmode = sycl::access_mode::read;
81+
static constexpr sycl::access::target actarget = sycl::access::target::device;
82+
static constexpr sycl::access::placeholder acplaceholder =
83+
sycl::access::placeholder::false_t;
84+
using AccT = sycl::accessor<int, 1, acmode, actarget, acplaceholder>;
85+
int data(14);
86+
sycl::range<1> r(1);
87+
sycl::buffer<int, 1> data_buf(&data, r);
88+
sycl::unittest::PiMock Mock;
89+
sycl::platform Plt = Mock.getPlatform();
90+
sycl::queue q{Plt.get_devices()[0]};
91+
q.submit([&](sycl::handler &cgh) {
92+
AccT acc(data_buf, cgh);
93+
EXPECT_FALSE(acc.is_placeholder());
94+
});
95+
}
96+
97+
TEST(AccessorPlaceholderTest, PlaceholderNoneTargetHost) {
98+
static constexpr sycl::access_mode acmode = sycl::access_mode::read;
99+
static constexpr sycl::access::target actarget =
100+
sycl::access::target::host_buffer;
101+
using AccT = sycl::accessor<int, 1, acmode, actarget>;
102+
int data(14);
103+
sycl::range<1> r(1);
104+
sycl::buffer<int, 1> data_buf(&data, r);
105+
AccT acc(data_buf);
106+
EXPECT_FALSE(acc.is_placeholder());
107+
EXPECT_EQ(acc[0], data);
108+
}
109+
110+
TEST(AccessorPlaceholderTest, PlaceholderTrueTargetHost) {
111+
static constexpr sycl::access_mode acmode = sycl::access_mode::read;
112+
static constexpr sycl::access::target actarget =
113+
sycl::access::target::host_buffer;
114+
static constexpr sycl::access::placeholder acplaceholder =
115+
sycl::access::placeholder::true_t;
116+
using AccT = sycl::accessor<int, 1, acmode, actarget, acplaceholder>;
117+
int data(14);
118+
sycl::range<1> r(1);
119+
sycl::buffer<int, 1> data_buf(&data, r);
120+
AccT acc(data_buf);
121+
EXPECT_FALSE(acc.is_placeholder());
122+
}
123+
124+
TEST(AccessorPlaceholderTest, PlaceholderFalseTargetHost) {
125+
static constexpr sycl::access_mode acmode = sycl::access_mode::read;
126+
static constexpr sycl::access::target actarget =
127+
sycl::access::target::host_buffer;
128+
static constexpr sycl::access::placeholder acplaceholder =
129+
sycl::access::placeholder::false_t;
130+
using AccT = sycl::accessor<int, 1, acmode, actarget, acplaceholder>;
131+
int data(14);
132+
sycl::range<1> r(1);
133+
sycl::buffer<int, 1> data_buf(&data, r);
134+
AccT acc(data_buf);
135+
EXPECT_FALSE(acc.is_placeholder());
136+
}

sycl/unittests/accessor/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
add_sycl_unittest(AccessorTests OBJECT
22
AccessorIterator.cpp
3+
AccessorPlaceholder.cpp
34
AccessorReverseIterator.cpp
45
HostAccessorIterator.cpp
56
HostAccessorReverseIterator.cpp

0 commit comments

Comments
 (0)