Skip to content

Commit 2e4bfc9

Browse files
committed
[SYCL][ABI-Break] Implement property interface for local_accessor &
usm_allocator
1 parent 436f0d8 commit 2e4bfc9

File tree

5 files changed

+54
-11
lines changed

5 files changed

+54
-11
lines changed

sycl/include/sycl/accessor.hpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,8 +2167,8 @@ class __SYCL_SPECIAL_CLASS local_accessor_base :
21672167
(void)propList;
21682168
}
21692169
#else
2170-
: LocalAccessorBaseHost(range<3>{1, 1, 1}, AdjustedDim, sizeof(DataT)) {
2171-
(void)propList;
2170+
: LocalAccessorBaseHost(range<3>{1, 1, 1}, AdjustedDim, sizeof(DataT),
2171+
propList) {
21722172
detail::constructorNotification(nullptr, LocalAccessorBaseHost::impl.get(),
21732173
access::target::local, AccessMode, CodeLoc);
21742174
}
@@ -2200,8 +2200,7 @@ class __SYCL_SPECIAL_CLASS local_accessor_base :
22002200
}
22012201
#else
22022202
: LocalAccessorBaseHost(detail::convertToArrayOfN<3, 1>(AllocationSize),
2203-
AdjustedDim, sizeof(DataT)) {
2204-
(void)propList;
2203+
AdjustedDim, sizeof(DataT), propList) {
22052204
detail::constructorNotification(nullptr, LocalAccessorBaseHost::impl.get(),
22062205
access::target::local, AccessMode, CodeLoc);
22072206
}
@@ -2345,6 +2344,23 @@ class __SYCL_SPECIAL_CLASS __SYCL_TYPE(local_accessor) local_accessor
23452344
}
23462345

23472346
#endif
2347+
2348+
public:
2349+
template <typename Property> bool has_property() const noexcept {
2350+
#ifndef __SYCL_DEVICE_ONLY__
2351+
return this->getPropList().template has_property<Property>();
2352+
#else
2353+
return false;
2354+
#endif
2355+
}
2356+
2357+
template <typename Property> Property get_property() const {
2358+
#ifndef __SYCL_DEVICE_ONLY__
2359+
return this->getPropList().template get_property<Property>();
2360+
#else
2361+
return Property();
2362+
#endif
2363+
}
23482364
};
23492365

23502366
/// Image accessors.

sycl/include/sycl/detail/accessor_impl.hpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,23 +180,27 @@ class __SYCL_EXPORT LocalAccessorImplHost {
180180
public:
181181
// Allocate ElemSize more data to have sufficient padding to enforce
182182
// alignment.
183-
LocalAccessorImplHost(sycl::range<3> Size, int Dims, int ElemSize)
183+
LocalAccessorImplHost(sycl::range<3> Size, int Dims, int ElemSize,
184+
const property_list &PropertyList)
184185
: MSize(Size), MDims(Dims), MElemSize(ElemSize),
185-
MMem(Size[0] * Size[1] * Size[2] * ElemSize + ElemSize) {}
186+
MMem(Size[0] * Size[1] * Size[2] * ElemSize + ElemSize),
187+
MPropertyList(PropertyList) {}
186188

187189
sycl::range<3> MSize;
188190
int MDims;
189191
int MElemSize;
190192
std::vector<char> MMem;
193+
property_list MPropertyList;
191194
};
192195

193196
using LocalAccessorImplPtr = std::shared_ptr<LocalAccessorImplHost>;
194197

195198
class LocalAccessorBaseHost {
196199
public:
197-
LocalAccessorBaseHost(sycl::range<3> Size, int Dims, int ElemSize) {
200+
LocalAccessorBaseHost(sycl::range<3> Size, int Dims, int ElemSize,
201+
const property_list &PropertyList = {}) {
198202
impl = std::shared_ptr<LocalAccessorImplHost>(
199-
new LocalAccessorImplHost(Size, Dims, ElemSize));
203+
new LocalAccessorImplHost(Size, Dims, ElemSize, PropertyList));
200204
}
201205
sycl::range<3> &getSize() { return impl->MSize; }
202206
const sycl::range<3> &getSize() const { return impl->MSize; }
@@ -218,6 +222,7 @@ class LocalAccessorBaseHost {
218222

219223
int getNumOfDims() { return impl->MDims; }
220224
int getElementSize() { return impl->MElemSize; }
225+
const property_list &getPropList() const { return impl->MPropertyList; }
221226

222227
protected:
223228
template <class Obj>

sycl/include/sycl/usm/usm_allocator.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ class usm_allocator {
106106
(One.MDevice == Two.MDevice));
107107
}
108108

109+
template <typename Property> bool has_property() const noexcept {
110+
return MPropList.has_property<Property>();
111+
}
112+
113+
template <typename Property> Property get_property() const {
114+
return MPropList.get_property<Property>();
115+
}
116+
109117
private:
110118
constexpr size_t getAlignment() const { return max(alignof(T), Alignment); }
111119

sycl/test/abi/layout_accessors_host.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,22 @@ using namespace sycl;
5858
// CHECK: 32 | pointer _M_start
5959
// CHECK-NEXT: 40 | pointer _M_finish
6060
// CHECK-NEXT: 48 | pointer _M_end_of_storage
61-
// CHECK-NEXT: | [sizeof=56, dsize=56, align=8,
62-
// CHECK-NEXT: | nvsize=56, nvalign=8]
61+
// CHECK-NEXT: 56 | class sycl::property_list MPropertyList
62+
// CHECK-NEXT: 56 | class sycl::detail::PropertyListBase (base)
63+
// CHECK-NEXT: 56 | class std::bitset<32> MDataLessProps
64+
// CHECK-NEXT: 56 | struct std::_Base_bitset<1> (base)
65+
// CHECK-NEXT: 56 | _WordT _M_w
66+
// CHECK-NEXT: 64 | class std::vector<class std::shared_ptr<class sycl::detail::PropertyWithDataBase> > MPropsWithData
67+
// CHECK-NEXT: 64 | struct std::_Vector_base<class std::shared_ptr<class sycl::detail::PropertyWithDataBase>, class std::allocator<class std::shared_ptr<class sycl::detail::PropertyWithDataBase> > > (base)
68+
// CHECK-NEXT: 64 | struct std::_Vector_base<class std::shared_ptr<class sycl::detail::PropertyWithDataBase>, class std::allocator<class std::shared_ptr<class sycl::detail::PropertyWithDataBase> > >::_Vector_impl _M_impl
69+
// CHECK-NEXT: 64 | class std::allocator<class std::shared_ptr<class sycl::detail::PropertyWithDataBase> > (base) (empty)
70+
// CHECK-NEXT: 64 | class __gnu_cxx::new_allocator<class std::shared_ptr<class sycl::detail::PropertyWithDataBase> > (base) (empty)
71+
// CHECK-NEXT: 64 | struct std::_Vector_base<class std::shared_ptr<class sycl::detail::PropertyWithDataBase>, class std::allocator<class std::shared_ptr<class sycl::detail::PropertyWithDataBase> > >::_Vector_impl_data (base)
72+
// CHECK-NEXT: 64 | pointer _M_start
73+
// CHECK-NEXT: 72 | pointer _M_finish
74+
// CHECK-NEXT: 80 | pointer _M_end_of_storage
75+
// CHECK-NEXT: | [sizeof=88, dsize=88, align=8,
76+
// CHECK-NEXT: | nvsize=88, nvalign=8]
6377

6478
//----------------------------------------------------------------------------//
6579
// Host buffer accessor.

sycl/test/abi/symbol_size_alignment.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ int main() {
4545
check<detail::LocalAccessorBaseDevice<1>, 24, 8>();
4646
check<detail::AccessorImplHost, 160, 8>();
4747
check<detail::AccessorBaseHost, 16, 8>();
48-
check<detail::LocalAccessorImplHost, 56, 8>();
48+
check<detail::LocalAccessorImplHost, 88, 8>();
4949
check<buffer<int>, 40, 8>();
5050
check<context, 16, 8>();
5151
check<cpu_selector, 8, 8>();

0 commit comments

Comments
 (0)