Skip to content

Commit

Permalink
Fix for iterators with const-qualified value type (#1527)
Browse files Browse the repository at this point in the history
const qualified type iterators were causing problems when checking for usm std::vector iterators because of the way that check must be, we were instantiating ill-formed std::vectors during the check, resulting in static assertions being triggered.  This avoids any types which result in ill-formed vectors, as they cannot be eligible anyway.

---------

Signed-off-by: Dan Hoeflinger <[email protected]>
  • Loading branch information
danhoeflinger authored Apr 25, 2024
1 parent 089fbb9 commit 141aa38
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
30 changes: 30 additions & 0 deletions include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,36 @@ struct __vector_iter_distinguishes_by_allocator<
{
};

template <typename Iter, typename Void = void>
struct __is_known_usm_vector_iter_impl : std::false_type
{
};

template <typename Iter>
struct __is_known_usm_vector_iter_impl<
Iter, std::enable_if_t<std::conjunction<
std::disjunction<std::is_same<Iter, oneapi::dpl::__internal::__usm_shared_alloc_vec_iter<Iter>>,
std::is_same<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 Iter, typename Void = void>
struct __is_known_usm_vector_iter : std::false_type
{
};

//We must avoid instantiating vector of const, reference, or function elements to avoid ill-formed vector instantiation
template <typename Iter>
struct __is_known_usm_vector_iter<
Iter, std::enable_if_t<std::conjunction<
std::negation<std::disjunction<std::is_const<typename std::iterator_traits<Iter>::value_type>,
std::is_reference<typename std::iterator_traits<Iter>::value_type>,
std::is_function<typename std::iterator_traits<Iter>::value_type>>>,
oneapi::dpl::__internal::__is_known_usm_vector_iter_impl<Iter>>::value>> : std::true_type
{
};

} // namespace __internal

template <typename T, typename Allocator>
Expand Down
7 changes: 2 additions & 5 deletions include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,8 @@ 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<
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
struct is_passed_directly<Iter, std::enable_if_t<oneapi::dpl::__internal::__is_known_usm_vector_iter<Iter>::value>>
: std::true_type
{
};

Expand Down

0 comments on commit 141aa38

Please sign in to comment.