Skip to content

Commit f4185c7

Browse files
authored
[SYCL] Implement get_multi_ptr for accessor and local_accessor (#8249)
- Implement get_multi_ptr for accessor and local_accessor - Add test for get_multi_ptr - Update the affected default ctor test
1 parent a5f3aca commit f4185c7

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

sycl/include/sycl/accessor.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,6 +2090,11 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
20902090
return constant_ptr<DataT>(getPointerAdjusted());
20912091
}
20922092

2093+
template <access::decorated IsDecorated>
2094+
accessor_ptr<IsDecorated> get_multi_ptr() const noexcept {
2095+
return accessor_ptr<IsDecorated>(getPointerAdjusted());
2096+
}
2097+
20932098
// accessor::has_property for runtime properties is only available in host
20942099
// code. This restriction is not listed in the core spec and will be added in
20952100
// future versions.
@@ -2773,6 +2778,11 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(local_accessor) local_accessor
27732778
return const_reverse_iterator(begin());
27742779
}
27752780

2781+
template <access::decorated IsDecorated>
2782+
accessor_ptr<IsDecorated> get_multi_ptr() const noexcept {
2783+
return accessor_ptr<IsDecorated>(local_acc::getQualifiedPtr());
2784+
}
2785+
27762786
template <typename Property> bool has_property() const noexcept {
27772787
#ifndef __SYCL_DEVICE_ONLY__
27782788
return this->getPropList().template has_property<Property>();

sycl/test/basic_tests/accessor/accessor_default_ctor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ int main() {
1111
assert(B.byte_size() == 0);
1212
// The return values of get_pointer() and get_multi_ptr() are unspecified.
1313
assert(B.get_pointer() == nullptr);
14-
// TODO: uncomment check with get_multi_ptr() when SYCL 2020 mupti_ptr feature
15-
// will be merged
16-
// assert(B.get_multi_ptr() == nullptr);
14+
assert(B.get_multi_ptr<sycl::access::decorated::yes>() == nullptr);
15+
assert(B.get_multi_ptr<sycl::access::decorated::no>() == nullptr);
16+
assert(B.get_multi_ptr<sycl::access::decorated::legacy>() == nullptr);
1717

1818
return 0;
1919
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -fsyntax-only
2+
3+
#include <cassert>
4+
#include <sycl/sycl.hpp>
5+
#include <type_traits>
6+
7+
using namespace sycl;
8+
9+
constexpr static int size = 1;
10+
11+
void test_get_multi_ptr(handler &cgh, buffer<int, size> &buffer) {
12+
using accessor_t =
13+
accessor<int, size, access::mode::read_write, access::target::device,
14+
access::placeholder::true_t>;
15+
using local_accessor_t = local_accessor<int, size>;
16+
17+
auto ptr = buffer.get_access<access_mode::read_write, target::device>(cgh);
18+
auto local_ptr = local_accessor<int, size>({size}, cgh);
19+
auto acc_multi_ptr = ptr.get_multi_ptr<access::decorated::yes>();
20+
auto local_acc_multi_ptr = local_ptr.get_multi_ptr<access::decorated::yes>();
21+
static_assert(
22+
std::is_same_v<
23+
decltype(acc_multi_ptr),
24+
typename accessor_t::template accessor_ptr<access::decorated::yes>>);
25+
static_assert(std::is_same_v<decltype(local_acc_multi_ptr),
26+
typename local_accessor_t::template accessor_ptr<
27+
access::decorated::yes>>);
28+
}

sycl/unittests/accessor/LocalAccessorDefaultCtor.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ TEST(LocalAccessorDefaultCtorTest, LocalAcessorDefaultCtorPtrQueries) {
3737
// unspecified. Just check they can run without any issue.
3838
auto ptr = acc.get_pointer();
3939
(void)ptr;
40-
// TODO: uncomment check with get_multi_ptr() when SYCL 2020 multi_ptr feature
41-
// will be merged
42-
// auto multi_ptr = acc.get_multi_ptr();
43-
// (void)multi_ptr;
40+
auto multi_ptr = acc.get_multi_ptr<access::decorated::yes>();
41+
(void)multi_ptr;
42+
auto multi_ptr_no_decorated = acc.get_multi_ptr<access::decorated::no>();
43+
(void)multi_ptr_no_decorated;
44+
auto multi_ptr_legacy = acc.get_multi_ptr<access::decorated::legacy>();
45+
(void)multi_ptr_legacy;
4446
}

0 commit comments

Comments
 (0)