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

Adding std::vector<T, usm_allocator>::iterator to is_passed_directly types #1438

Merged
merged 27 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e9c0488
adding std::vector<T, usm_allocator>::iterator to is_passed_directly …
danhoeflinger Mar 7, 2024
4c52a5f
adding host usm allocator support
danhoeflinger Mar 8, 2024
5d5ae9a
bugfix
danhoeflinger Mar 8, 2024
897f562
resolving ambiguity when these iterator types would match
danhoeflinger Mar 11, 2024
b3306a4
reverting formatting only change
danhoeflinger Mar 11, 2024
00b8764
only mark usm_allocator vector iterator as passed directly if we can …
danhoeflinger Mar 11, 2024
ba00bdc
name change for helper struct
danhoeflinger Mar 15, 2024
8d30b1b
make more readable, add check between different types of usm alloc
danhoeflinger Apr 2, 2024
2dabe9c
cleanup comments, debugging output, and formatting only changes
danhoeflinger Apr 2, 2024
8d43c85
returning original spacing
danhoeflinger Apr 2, 2024
5cc5eb4
::std:: -> std::
danhoeflinger Apr 3, 2024
a7fcff1
reorganize code and make public utilities
danhoeflinger Apr 3, 2024
c7c9e31
Add to the documentation
danhoeflinger Apr 3, 2024
23ed312
fixes for public utility
danhoeflinger Apr 3, 2024
3d63726
fixes for documentation
danhoeflinger Apr 3, 2024
3bb00d2
formatting
danhoeflinger Apr 3, 2024
f8b310f
Adding value type to public utility
danhoeflinger Apr 3, 2024
6082cd5
Removing public utility (for now)
danhoeflinger Apr 4, 2024
83e1a9a
doc improvements
danhoeflinger Apr 4, 2024
6e82fa3
formatting of note
danhoeflinger Apr 4, 2024
6ef2579
improve clarity of example intro
danhoeflinger Apr 4, 2024
1dc5634
removing extra spaces
danhoeflinger Apr 4, 2024
55b0f8d
formatting (against clang-format suggestion)
danhoeflinger Apr 4, 2024
22eaf87
doc suggestion to use usm pointer
danhoeflinger Apr 4, 2024
ae0dac8
removing doc changes (to separate into another PR)
danhoeflinger Apr 4, 2024
843fa58
adding line break
danhoeflinger Apr 4, 2024
3e4b385
Update utils_ranges_sycl.h
MikeDvorskiy Apr 4, 2024
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
28 changes: 28 additions & 0 deletions include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,34 @@ struct _ModeConverter<access_mode::write>
static constexpr access_mode __value = access_mode::discard_write;
};

template <typename Iter, typename ValueType = typename std::iterator_traits<Iter>::value_type>
using __default_alloc_vec_iter = typename std::vector<ValueType>::iterator;

template <typename Iter, typename ValueType = typename std::iterator_traits<Iter>::value_type>
using __usm_shared_alloc_vec_iter =
typename std::vector<ValueType, typename sycl::usm_allocator<ValueType, sycl::usm::alloc::shared>>::iterator;

template <typename Iter, typename ValueType = typename std::iterator_traits<Iter>::value_type>
using __usm_host_alloc_vec_iter =
typename std::vector<ValueType, typename sycl::usm_allocator<ValueType, sycl::usm::alloc::host>>::iterator;

// Evaluates to true if the provided type is an iterator with a value_type and if the implementation of a
// std::vector<value_type, Alloc>::iterator can be distinguished between three different allocators, the
// default, usm_shared, and usm_host. If all are distinct, it is very unlikely any non-usm based allocator
// could be confused with a usm allocator.
template <typename Iter, typename Void = void>
struct __vector_iter_distinguishes_by_allocator : std::false_type
{
};
template <typename Iter>
struct __vector_iter_distinguishes_by_allocator<
Iter, std::enable_if_t<!std::is_same_v<__default_alloc_vec_iter<Iter>, __usm_shared_alloc_vec_iter<Iter>> &&
!std::is_same_v<__default_alloc_vec_iter<Iter>, __usm_host_alloc_vec_iter<Iter>> &&
!std::is_same_v<__usm_host_alloc_vec_iter<Iter>, __usm_shared_alloc_vec_iter<Iter>>>>
: std::true_type
{
};

} // namespace __internal

template <typename T, typename Allocator>
Expand Down
11 changes: 11 additions & 0 deletions include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "../../utils_ranges.h"
#include "../../iterator_impl.h"
#include "../../glue_numeric_defs.h"
#include "sycl_iterator.h"
#include "sycl_defs.h"

namespace oneapi
Expand Down Expand Up @@ -206,6 +207,16 @@ struct is_passed_directly<Iter, ::std::enable_if_t<Iter::is_passed_directly::val
{
};

//support std::vector::iterator with usm host / shared allocator as passed directly
template <typename Iter>
struct is_passed_directly<
MikeDvorskiy marked this conversation as resolved.
Show resolved Hide resolved
Iter, std::enable_if_t<(std::is_same_v<Iter, oneapi::dpl::__internal::__usm_shared_alloc_vec_iter<Iter>> ||
std::is_same_v<Iter, oneapi::dpl::__internal::__usm_host_alloc_vec_iter<Iter>>) &&
oneapi::dpl::__internal::__vector_iter_distinguishes_by_allocator<Iter>::value>> :
std::true_type
{
};

template <typename Ip>
struct is_passed_directly<oneapi::dpl::counting_iterator<Ip>> : ::std::true_type
{
Expand Down
Loading