Skip to content

Commit

Permalink
[SYCL] Get pointer should not be called on host for local accessors (…
Browse files Browse the repository at this point in the history
…#13747)

Local accessors only have their memory allocated on device when a kernel
starts executing. Any pointer that refers to local memory on host before
kernel execution has begun is therefore invalid.

> This function may only be called from within a [SYCL kernel
function](https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#sycl-kernel-function).

Table 78 in

https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#_interface_for_local_accessors
  • Loading branch information
hdelan authored May 14, 2024
1 parent af65855 commit 7698ff8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
10 changes: 10 additions & 0 deletions sycl/include/sycl/accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2589,11 +2589,21 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(local_accessor) local_accessor
__SYCL2020_DEPRECATED(
"local_accessor::get_pointer() is deprecated, please use get_multi_ptr()")
local_ptr<DataT> get_pointer() const noexcept {
#ifndef __SYCL_DEVICE_ONLY__
throw sycl::exception(
make_error_code(errc::invalid),
"get_pointer must not be called on the host for a local accessor");
#endif
return local_ptr<DataT>(local_acc::getQualifiedPtr());
}

template <access::decorated IsDecorated>
accessor_ptr<IsDecorated> get_multi_ptr() const noexcept {
#ifndef __SYCL_DEVICE_ONLY__
throw sycl::exception(
make_error_code(errc::invalid),
"get_multi_ptr must not be called on the host for a local accessor");
#endif
return accessor_ptr<IsDecorated>(local_acc::getQualifiedPtr());
}

Expand Down
15 changes: 0 additions & 15 deletions sycl/unittests/accessor/LocalAccessorDefaultCtor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,3 @@ TEST(LocalAccessorDefaultCtorTest, LocalAcessorDefaultCtorSizeQueries) {
EXPECT_TRUE(size == 0);
EXPECT_TRUE(max_size == 0);
}

TEST(LocalAccessorDefaultCtorTest, LocalAcessorDefaultCtorPtrQueries) {
AccT acc;

// The return values of get_pointer() and get_multi_ptr() are
// unspecified. Just check they can run without any issue.
auto ptr = acc.get_pointer();
(void)ptr;
auto multi_ptr = acc.get_multi_ptr<access::decorated::yes>();
(void)multi_ptr;
auto multi_ptr_no_decorated = acc.get_multi_ptr<access::decorated::no>();
(void)multi_ptr_no_decorated;
auto multi_ptr_legacy = acc.get_multi_ptr<access::decorated::legacy>();
(void)multi_ptr_legacy;
}

0 comments on commit 7698ff8

Please sign in to comment.