Skip to content
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

[SYCL2020] Update the multi_ptr class #1452

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/hipSYCL/sycl/access.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ enum class fence_space : char {
global_and_local
};

enum class decorated : char {
no,
yes,
legacy // [[deprecated]] TODO: This is deprecated but used as default value for multi_ptr template argument
};

inline std::ostream &operator<<(std::ostream &out,
const sycl::access::placeholder value)
{
Expand Down
37 changes: 31 additions & 6 deletions include/hipSYCL/sycl/libkernel/accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,21 @@ inline constexpr sycl::access_mode default_access_mode() {
return std::is_const_v<T> ? access_mode::read : access_mode::read_write;
}

template <target accessTarget, typename value_type>
struct multi_ptr_for_target {
using type = void*;
};

template <typename value_type>
struct multi_ptr_for_target<target::device, value_type> {
using type = global_ptr<value_type>;
};

template <typename value_type>
struct multi_ptr_for_target<target::local, value_type> {
using type = local_ptr<value_type>;
};

} // detail

namespace property {
Expand Down Expand Up @@ -772,7 +787,8 @@ class HIPSYCL_EMPTY_BASES accessor
typename detail::accessor::accessor_data_type<dataT, accessmode>::value;
using reference = value_type &;
using const_reference = const dataT &;
// TODO accessor_ptr
template <access::decorated IsDecorated>
using accessor_ptr = typename detail::multi_ptr_for_target<accessTarget, value_type>::type;
using iterator = detail::accessor_iterator<value_type, dimensions, accessor>;
using const_iterator = detail::accessor_iterator<const value_type, dimensions, accessor>;
using reverse_iterator = std::reverse_iterator<iterator>;
Expand Down Expand Up @@ -1178,8 +1194,11 @@ class HIPSYCL_EMPTY_BASES accessor
}

/* Available only when: accessTarget == access::target::host_buffer */
// TODO: T == host_buffer is deprecated in SYCL2020
template<access::target T = accessTarget,
typename = std::enable_if_t<T==access::target::host_buffer>>
typename = std::enable_if_t<
T == access::target::host_buffer ||
T == access::target::host_task>>
dataT *get_pointer() const noexcept
{
return const_cast<dataT*>(this->_ptr.get());
Expand All @@ -1203,6 +1222,16 @@ class HIPSYCL_EMPTY_BASES accessor
return constant_ptr<dataT>{const_cast<dataT*>(this->_ptr.get())};
}

/* Available only when: accessTarget == access::target::device */
template<access::decorated IsDecorated,
access::target T = accessTarget,
typename = std::enable_if_t<T == access::target::device>>
HIPSYCL_UNIVERSAL_TARGET
accessor_ptr<IsDecorated> get_multi_ptr() const noexcept
{
return accessor_ptr<IsDecorated>{this->_ptr.get()};
}

iterator begin() const noexcept {
return iterator::make_begin(this);
}
Expand Down Expand Up @@ -2126,10 +2155,6 @@ class accessor<
range<dimensions> _num_elements;
};

template <typename dataT, int dimensions = 1>
using local_accessor = accessor<dataT, dimensions, access::mode::read_write,
access::target::local>;

namespace detail::accessor {

template<class AccessorType>
Expand Down