Skip to content

Commit a7473fd

Browse files
[SYCL] Change signature of host_accessor::get_pointer for SYCL 2020 (#8109)
SYCL 2020 specifies that the `get_pointer` member should now return a raw pointer for based on `value_type` and should be `noexcept`. This commit changes the signature of `get_pointer` for host accessors. Note that `AccessorBaseHost::getPtr` cannot be made `noexcept` currently as it would be an ABI break. This does not limit the functionality of these changes, but should be changed during next ABI break. Signed-off-by: Larsen, Steffen <[email protected]>
1 parent 6464785 commit a7473fd

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

sycl/include/sycl/accessor.hpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
10981098
// range and offset are not supported.
10991099
void __init_esimd(ConcreteASPtrType Ptr) { MData = Ptr; }
11001100

1101-
ConcreteASPtrType getQualifiedPtr() const { return MData; }
1101+
ConcreteASPtrType getQualifiedPtr() const noexcept { return MData; }
11021102

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

1179-
PtrType getQualifiedPtr() const {
1179+
PtrType getQualifiedPtr() const noexcept {
11801180
if constexpr (IsHostBuf)
11811181
return reinterpret_cast<PtrType>(MAccData->MData);
11821182
else
@@ -2026,7 +2026,12 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
20262026
template <access::target AccessTarget_ = AccessTarget,
20272027
typename = detail::enable_if_t<AccessTarget_ ==
20282028
access::target::host_buffer>>
2029-
DataT *get_pointer() const {
2029+
#if SYCL_LANGUAGE_VERSION >= 202001
2030+
std::add_pointer_t<value_type> get_pointer() const noexcept
2031+
#else
2032+
DataT *get_pointer() const
2033+
#endif
2034+
{
20302035
return getPointerAdjusted();
20312036
}
20322037

@@ -2129,7 +2134,7 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
21292134

21302135
private:
21312136
#ifdef __SYCL_DEVICE_ONLY__
2132-
size_t getTotalOffset() const {
2137+
size_t getTotalOffset() const noexcept {
21332138
size_t TotalOffset = 0;
21342139
detail::dim_loop<Dimensions>([&, this](size_t I) {
21352140
TotalOffset = TotalOffset * impl.MemRange[I];
@@ -2148,7 +2153,7 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
21482153
// but for get_pointer() we must return the original pointer.
21492154
// On device, getQualifiedPtr() returns MData, so we need to backjust it.
21502155
// On host, getQualifiedPtr() does not return MData, no need to adjust.
2151-
auto getPointerAdjusted() const {
2156+
auto getPointerAdjusted() const noexcept {
21522157
#ifdef __SYCL_DEVICE_ONLY__
21532158
return getQualifiedPtr() - getTotalOffset();
21542159
#else
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: %clangxx -fsycl -fsyntax-only -sycl-std=2020 %s
2+
3+
// Tests the type of the get_pointer method of host_accessor.
4+
5+
#include <sycl/sycl.hpp>
6+
7+
#include <type_traits>
8+
9+
template <typename DataT, int Dims, sycl::access::mode Mode>
10+
void CheckHostAccessor() {
11+
using HostAccessorT = sycl::host_accessor<DataT, Dims, Mode>;
12+
using HostAccessorGetPointerT =
13+
decltype(std::declval<HostAccessorT>().get_pointer());
14+
static_assert(
15+
std::is_same_v<HostAccessorGetPointerT,
16+
std::add_pointer_t<typename HostAccessorT::value_type>>);
17+
}
18+
19+
template <typename DataT, int Dims> void CheckHostAccessorForModes() {
20+
CheckHostAccessor<DataT, Dims, sycl::access::mode::read>();
21+
CheckHostAccessor<DataT, Dims, sycl::access::mode::read_write>();
22+
CheckHostAccessor<DataT, Dims, sycl::access::mode::write>();
23+
}
24+
25+
template <typename DataT> void CheckHostAccessorForAllDimsAndModes() {
26+
CheckHostAccessorForModes<DataT, 1>();
27+
CheckHostAccessorForModes<DataT, 2>();
28+
CheckHostAccessorForModes<DataT, 3>();
29+
}
30+
31+
int main() {
32+
CheckHostAccessorForAllDimsAndModes<int>();
33+
CheckHostAccessorForAllDimsAndModes<const int>();
34+
return 0;
35+
}

0 commit comments

Comments
 (0)