Skip to content

[SYCL] Change signature of host_accessor::get_pointer for SYCL 2020 #8109

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
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
15 changes: 10 additions & 5 deletions sycl/include/sycl/accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
// range and offset are not supported.
void __init_esimd(ConcreteASPtrType Ptr) { MData = Ptr; }

ConcreteASPtrType getQualifiedPtr() const { return MData; }
ConcreteASPtrType getQualifiedPtr() const noexcept { return MData; }

template <typename DataT_, int Dimensions_, access::mode AccessMode_,
access::target AccessTarget_, access::placeholder IsPlaceholder_,
Expand Down Expand Up @@ -1176,7 +1176,7 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
sizeof(PtrType) - sizeof(detail::AccessorBaseHost) -
sizeof(MAccData)];

PtrType getQualifiedPtr() const {
PtrType getQualifiedPtr() const noexcept {
if constexpr (IsHostBuf)
return reinterpret_cast<PtrType>(MAccData->MData);
else
Expand Down Expand Up @@ -2021,7 +2021,12 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
template <access::target AccessTarget_ = AccessTarget,
typename = detail::enable_if_t<AccessTarget_ ==
access::target::host_buffer>>
DataT *get_pointer() const {
#if SYCL_LANGUAGE_VERSION >= 202001
std::add_pointer_t<value_type> get_pointer() const noexcept
#else
DataT *get_pointer() const
#endif
{
return getPointerAdjusted();
}

Expand Down Expand Up @@ -2124,7 +2129,7 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :

private:
#ifdef __SYCL_DEVICE_ONLY__
size_t getTotalOffset() const {
size_t getTotalOffset() const noexcept {
size_t TotalOffset = 0;
detail::dim_loop<Dimensions>([&, this](size_t I) {
TotalOffset = TotalOffset * impl.MemRange[I];
Expand All @@ -2143,7 +2148,7 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
// but for get_pointer() we must return the original pointer.
// On device, getQualifiedPtr() returns MData, so we need to backjust it.
// On host, getQualifiedPtr() does not return MData, no need to adjust.
auto getPointerAdjusted() const {
auto getPointerAdjusted() const noexcept {
#ifdef __SYCL_DEVICE_ONLY__
return getQualifiedPtr() - getTotalOffset();
#else
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// RUN: %clangxx -fsycl -fsyntax-only -sycl-std=2020 %s

// Tests the type of the get_pointer method of host_accessor.

#include <sycl/sycl.hpp>

#include <type_traits>

template <typename DataT, int Dims, sycl::access::mode Mode>
void CheckHostAccessor() {
using HostAccessorT = sycl::host_accessor<DataT, Dims, Mode>;
using HostAccessorGetPointerT =
decltype(std::declval<HostAccessorT>().get_pointer());
static_assert(
std::is_same_v<HostAccessorGetPointerT,
std::add_pointer_t<typename HostAccessorT::value_type>>);
}

template <typename DataT, int Dims> void CheckHostAccessorForModes() {
CheckHostAccessor<DataT, Dims, sycl::access::mode::read>();
CheckHostAccessor<DataT, Dims, sycl::access::mode::read_write>();
CheckHostAccessor<DataT, Dims, sycl::access::mode::write>();
}

template <typename DataT> void CheckHostAccessorForAllDimsAndModes() {
CheckHostAccessorForModes<DataT, 1>();
CheckHostAccessorForModes<DataT, 2>();
CheckHostAccessorForModes<DataT, 3>();
}

int main() {
CheckHostAccessorForAllDimsAndModes<int>();
CheckHostAccessorForAllDimsAndModes<const int>();
return 0;
}