Skip to content

[SYCL][ABI-Break] Support accessor property interface #6614

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sycl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ set(SYCL_MINOR_VERSION 7)
set(SYCL_PATCH_VERSION 0)
# Don't forget to re-enable sycl_symbols_windows.dump once we leave ABI-breaking
# window!
set(SYCL_DEV_ABI_VERSION 11)
set(SYCL_DEV_ABI_VERSION 12)
if (SYCL_ADD_DEV_VERSION_POSTFIX)
set(SYCL_VERSION_POSTFIX "-${SYCL_DEV_ABI_VERSION}")
endif()
Expand Down
68 changes: 56 additions & 12 deletions sycl/include/sycl/accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ class __SYCL_SPECIAL_CLASS accessor :
detail::convertToArrayOfN<3, 1>(BufferRef.get_range()),
getAdjustedMode(PropertyList),
detail::getSyclObjImpl(BufferRef).get(), AdjustedDim, sizeof(DataT),
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer) {
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer, PropertyList) {
preScreenAccessor(BufferRef.size(), PropertyList);
if (!IsPlaceH)
addHostAccessorAndWait(AccessorBaseHost::impl.get());
Expand Down Expand Up @@ -1042,7 +1042,7 @@ class __SYCL_SPECIAL_CLASS accessor :
detail::convertToArrayOfN<3, 1>(BufferRef.get_range()),
getAdjustedMode(PropertyList),
detail::getSyclObjImpl(BufferRef).get(), AdjustedDim, sizeof(DataT),
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer) {
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer, PropertyList) {
preScreenAccessor(BufferRef.size(), PropertyList);
if (!IsPlaceH)
addHostAccessorAndWait(AccessorBaseHost::impl.get());
Expand Down Expand Up @@ -1072,7 +1072,7 @@ class __SYCL_SPECIAL_CLASS accessor :
detail::convertToArrayOfN<3, 1>(BufferRef.get_range()),
getAdjustedMode(PropertyList),
detail::getSyclObjImpl(BufferRef).get(), Dimensions, sizeof(DataT),
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer) {
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer, PropertyList) {
preScreenAccessor(BufferRef.size(), PropertyList);
detail::associateWithHandler(CommandGroupHandler, this, AccessTarget);
detail::constructorNotification(detail::getSyclObjImpl(BufferRef).get(),
Expand Down Expand Up @@ -1103,7 +1103,7 @@ class __SYCL_SPECIAL_CLASS accessor :
detail::convertToArrayOfN<3, 1>(BufferRef.get_range()),
getAdjustedMode(PropertyList),
detail::getSyclObjImpl(BufferRef).get(), Dimensions, sizeof(DataT),
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer) {
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer, PropertyList) {
preScreenAccessor(BufferRef.size(), PropertyList);
detail::associateWithHandler(CommandGroupHandler, this, AccessTarget);
detail::constructorNotification(detail::getSyclObjImpl(BufferRef).get(),
Expand Down Expand Up @@ -1133,7 +1133,7 @@ class __SYCL_SPECIAL_CLASS accessor :
detail::convertToArrayOfN<3, 1>(BufferRef.get_range()),
getAdjustedMode(PropertyList),
detail::getSyclObjImpl(BufferRef).get(), Dimensions, sizeof(DataT),
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer) {
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer, PropertyList) {
preScreenAccessor(BufferRef.size(), PropertyList);
if (!IsPlaceH)
addHostAccessorAndWait(AccessorBaseHost::impl.get());
Expand Down Expand Up @@ -1166,7 +1166,7 @@ class __SYCL_SPECIAL_CLASS accessor :
detail::convertToArrayOfN<3, 1>(BufferRef.get_range()),
getAdjustedMode(PropertyList),
detail::getSyclObjImpl(BufferRef).get(), Dimensions, sizeof(DataT),
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer) {
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer, PropertyList) {
preScreenAccessor(BufferRef.size(), PropertyList);
if (!IsPlaceH)
addHostAccessorAndWait(AccessorBaseHost::impl.get());
Expand Down Expand Up @@ -1229,7 +1229,7 @@ class __SYCL_SPECIAL_CLASS accessor :
detail::convertToArrayOfN<3, 1>(BufferRef.get_range()),
getAdjustedMode(PropertyList),
detail::getSyclObjImpl(BufferRef).get(), Dimensions, sizeof(DataT),
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer) {
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer, PropertyList) {
preScreenAccessor(BufferRef.size(), PropertyList);
detail::associateWithHandler(CommandGroupHandler, this, AccessTarget);
detail::constructorNotification(detail::getSyclObjImpl(BufferRef).get(),
Expand Down Expand Up @@ -1261,7 +1261,7 @@ class __SYCL_SPECIAL_CLASS accessor :
detail::convertToArrayOfN<3, 1>(BufferRef.get_range()),
getAdjustedMode(PropertyList),
detail::getSyclObjImpl(BufferRef).get(), Dimensions, sizeof(DataT),
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer) {
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer, PropertyList) {
preScreenAccessor(BufferRef.size(), PropertyList);
detail::associateWithHandler(CommandGroupHandler, this, AccessTarget);
detail::constructorNotification(detail::getSyclObjImpl(BufferRef).get(),
Expand Down Expand Up @@ -1447,7 +1447,7 @@ class __SYCL_SPECIAL_CLASS accessor :
getAdjustedMode(PropertyList),
detail::getSyclObjImpl(BufferRef).get(), Dimensions,
sizeof(DataT), BufferRef.OffsetInBytes,
BufferRef.IsSubBuffer) {
BufferRef.IsSubBuffer, PropertyList) {
preScreenAccessor(BufferRef.size(), PropertyList);
if (BufferRef.isOutOfBounds(AccessOffset, AccessRange,
BufferRef.get_range()))
Expand Down Expand Up @@ -1488,7 +1488,7 @@ class __SYCL_SPECIAL_CLASS accessor :
getAdjustedMode(PropertyList),
detail::getSyclObjImpl(BufferRef).get(), Dimensions,
sizeof(DataT), BufferRef.OffsetInBytes,
BufferRef.IsSubBuffer) {
BufferRef.IsSubBuffer, PropertyList) {
preScreenAccessor(BufferRef.size(), PropertyList);
if (BufferRef.isOutOfBounds(AccessOffset, AccessRange,
BufferRef.get_range()))
Expand Down Expand Up @@ -1560,7 +1560,7 @@ class __SYCL_SPECIAL_CLASS accessor :
getAdjustedMode(PropertyList),
detail::getSyclObjImpl(BufferRef).get(), Dimensions,
sizeof(DataT), BufferRef.OffsetInBytes,
BufferRef.IsSubBuffer) {
BufferRef.IsSubBuffer, PropertyList) {
preScreenAccessor(BufferRef.size(), PropertyList);
if (BufferRef.isOutOfBounds(AccessOffset, AccessRange,
BufferRef.get_range()))
Expand Down Expand Up @@ -1600,7 +1600,7 @@ class __SYCL_SPECIAL_CLASS accessor :
getAdjustedMode(PropertyList),
detail::getSyclObjImpl(BufferRef).get(), Dimensions,
sizeof(DataT), BufferRef.OffsetInBytes,
BufferRef.IsSubBuffer) {
BufferRef.IsSubBuffer, PropertyList) {
preScreenAccessor(BufferRef.size(), PropertyList);
if (BufferRef.isOutOfBounds(AccessOffset, AccessRange,
BufferRef.get_range()))
Expand Down Expand Up @@ -1785,6 +1785,50 @@ class __SYCL_SPECIAL_CLASS accessor :
return constant_ptr<DataT>(getPointerAdjusted());
}

// accessor::has_property for runtime properties is only available in host
// code. This restriction is not listed in the core spec and will be added in
// future versions.
template <typename Property>
typename sycl::detail::enable_if_t<
!ext::oneapi::is_compile_time_property<Property>::value, bool>
has_property() const noexcept {
#ifndef __SYCL_DEVICE_ONLY__
return AccessorBaseHost::impl->MPropertyList.has_property<Property>();
#else
return false;
#endif
}

// accessor::get_property for runtime properties is only available in host
// code. This restriction is not listed in the core spec and will be added in
// future versions.
template <typename Property,
typename = typename sycl::detail::enable_if_t<
!ext::oneapi::is_compile_time_property<Property>::value>>
Property get_property() const {
#ifndef __SYCL_DEVICE_ONLY__
return AccessorBaseHost::impl->MPropertyList.get_property<Property>();
#else
return Property();
#endif
}

#if __cplusplus >= 201703L
template <typename Property>
static constexpr bool has_property(
typename std::enable_if_t<
ext::oneapi::is_compile_time_property<Property>::value> * = 0) {
return PropertyListT::template has_property<Property>();
}

template <typename Property>
static constexpr auto get_property(
typename std::enable_if_t<
ext::oneapi::is_compile_time_property<Property>::value> * = 0) {
return PropertyListT::template get_property<Property>();
}
#endif

bool operator==(const accessor &Rhs) const { return impl == Rhs.impl; }
bool operator!=(const accessor &Rhs) const { return !(*this == Rhs); }

Expand Down
18 changes: 14 additions & 4 deletions sycl/include/sycl/detail/accessor_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <sycl/access/access.hpp>
#include <sycl/detail/export.hpp>
#include <sycl/id.hpp>
#include <sycl/property_list.hpp>
#include <sycl/range.hpp>
#include <sycl/stl.hpp>

Expand Down Expand Up @@ -80,12 +81,14 @@ class __SYCL_EXPORT AccessorImplHost {
AccessorImplHost(id<3> Offset, range<3> AccessRange, range<3> MemoryRange,
access::mode AccessMode, void *SYCLMemObject, int Dims,
int ElemSize, int OffsetInBytes = 0,
bool IsSubBuffer = false, bool IsESIMDAcc = false)
bool IsSubBuffer = false, bool IsESIMDAcc = false,
const property_list &PropertyList = {})
: MOffset(Offset), MAccessRange(AccessRange), MMemoryRange(MemoryRange),
MAccessMode(AccessMode),
MSYCLMemObj((detail::SYCLMemObjI *)SYCLMemObject), MDims(Dims),
MElemSize(ElemSize), MOffsetInBytes(OffsetInBytes),
MIsSubBuffer(IsSubBuffer), MIsESIMDAcc(IsESIMDAcc) {}
MIsSubBuffer(IsSubBuffer), MIsESIMDAcc(IsESIMDAcc),
MPropertyList(PropertyList) {}

~AccessorImplHost();

Expand Down Expand Up @@ -130,20 +133,27 @@ class __SYCL_EXPORT AccessorImplHost {
// Outdated, leaving to preserve ABI.
// TODO: Remove during next major release.
bool MIsESIMDAcc;

// To preserve runtime properties
property_list MPropertyList;
};

using AccessorImplPtr = std::shared_ptr<AccessorImplHost>;

class AccessorBaseHost {
public:
template <typename PropertyListT = property_list>
AccessorBaseHost(id<3> Offset, range<3> AccessRange, range<3> MemoryRange,
access::mode AccessMode, void *SYCLMemObject, int Dims,
int ElemSize, int OffsetInBytes = 0,
bool IsSubBuffer = false) {
bool IsSubBuffer = false,
const PropertyListT &PropertyList = {}) {
impl = std::shared_ptr<AccessorImplHost>(
new AccessorImplHost(Offset, AccessRange, MemoryRange, AccessMode,
(detail::SYCLMemObjI *)SYCLMemObject, Dims,
ElemSize, OffsetInBytes, IsSubBuffer));
ElemSize, OffsetInBytes, IsSubBuffer,
/* IsESIMDAcc = */ false,
PropertyList));
}

protected:
Expand Down
4 changes: 4 additions & 0 deletions sycl/include/sycl/ext/oneapi/accessor_property_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ class accessor_property_list : protected sycl::detail::PropertyListBase {
}
#endif

operator sycl::property_list() const {
return property_list(MDataLessProps, MPropsWithData);
}

private:
template <typename, int, access::mode, access::target, access::placeholder,
typename PropertyListT>
Expand Down
5 changes: 5 additions & 0 deletions sycl/include/sycl/property_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ class property_list : protected detail::PropertyListBase {
template <typename... T> operator ext::oneapi::accessor_property_list<T...>();

private:
property_list(
std::bitset<detail::DataLessPropKind::DataLessPropKindSize> DataLessProps,
std::vector<std::shared_ptr<detail::PropertyWithDataBase>> PropsWithData)
: sycl::detail::PropertyListBase(DataLessProps, PropsWithData) {}

template <typename... PropsT>
friend class ext::oneapi::accessor_property_list;
};
Expand Down
18 changes: 16 additions & 2 deletions sycl/test/abi/layout_accessors_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,22 @@ using namespace sycl;
// CHECK-NEXT: 112 | Command * MBlockedCmd
// CHECK-NEXT: 120 | _Bool PerWI
// CHECK-NEXT: 121 | _Bool MIsESIMDAcc
// CHECK-NEXT: | [sizeof=128, dsize=122, align=8,
// CHECK-NEXT: | nvsize=122, nvalign=8]
// CHECK-NEXT: 128 | class sycl::property_list MPropertyList
// CHECK-NEXT: 128 | class sycl::detail::PropertyListBase (base)
// CHECK-NEXT: 128 | class std::bitset<32> MDataLessProps
// CHECK-NEXT: 128 | struct std::_Base_bitset<1> (base)
// CHECK-NEXT: 128 | _WordT _M_w
// CHECK-NEXT: 136 | class std::vector<class std::shared_ptr<class sycl::detail::PropertyWithDataBase> > MPropsWithData
// CHECK-NEXT: 136 | struct std::_Vector_base<class std::shared_ptr<class sycl::detail::PropertyWithDataBase>, class std::allocator<class std::shared_ptr<class sycl::detail::PropertyWithDataBase> > > (base)
// CHECK-NEXT: 136 | 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
// CHECK-NEXT: 136 | class std::allocator<class std::shared_ptr<class sycl::detail::PropertyWithDataBase> > (base) (empty)
// CHECK-NEXT: 136 | class __gnu_cxx::new_allocator<class std::shared_ptr<class sycl::detail::PropertyWithDataBase> > (base) (empty)
// CHECK-NEXT: 136 | 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)
// CHECK-NEXT: 136 | pointer _M_start
// CHECK-NEXT: 144 | pointer _M_finish
// CHECK-NEXT: 152 | pointer _M_end_of_storage
// CHECK-NEXT: | [sizeof=160, dsize=160, align=8,
// CHECK-NEXT: | nvsize=160, nvalign=8]

// CHECK: 0 | class sycl::detail::LocalAccessorImplHost
// CHECK-NEXT: 0 | class sycl::range<3> MSize
Expand Down
2 changes: 1 addition & 1 deletion sycl/test/abi/symbol_size_alignment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ int main() {
check<accessor_t, 32, 8>();
check<detail::AccessorImplDevice<1>, 24, 8>();
check<detail::LocalAccessorBaseDevice<1>, 24, 8>();
check<detail::AccessorImplHost, 128, 8>();
check<detail::AccessorImplHost, 160, 8>();
check<detail::AccessorBaseHost, 16, 8>();
check<detail::LocalAccessorImplHost, 56, 8>();
check<buffer<int>, 40, 8>();
Expand Down