Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

Use CUB's ScanByKey implementation #1555

Merged
merged 5 commits into from
May 5, 2022
Merged
Changes from 4 commits
Commits
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
86 changes: 86 additions & 0 deletions testing/is_contiguous_iterator.cu
Original file line number Diff line number Diff line change
@@ -134,3 +134,89 @@ void test_is_contiguous_iterator_vectors()
}
DECLARE_VECTOR_UNITTEST(test_is_contiguous_iterator_vectors);

template <typename IteratorT, typename PointerT, bool ExpectPointer>
struct check_unwrapped_iterator
{
using unwrapped_t = typename std::remove_reference<
decltype(thrust::detail::try_unwrap_contiguous_iterator(
std::declval<IteratorT>()))>::type;

using result =
typename std::conditional<ExpectPointer,
std::is_same<unwrapped_t, PointerT>,
std::is_same<unwrapped_t, IteratorT>>::type;

static constexpr bool value = result::value;
};

template <typename T>
void test_try_unwrap_contiguous_iterator()
{
THRUST_STATIC_ASSERT((check_unwrapped_iterator<T *,
T *,
true>::value));
THRUST_STATIC_ASSERT((check_unwrapped_iterator<T *,
T *,
false>::value));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to test for check_unwrapped_iterator<T, T, true> + check_unwrapped_iterator<T, T, false> that I'm missing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the unwrapped raw pointer is the same type as the pass-through, both the true and false cases should pass here. Testing both just ensures that everything is working as expected.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the unwrapped raw pointer is the same type as the pass-through, both the true and false cases should pass here. Testing both just ensures that everything is working as expected.

THRUST_STATIC_ASSERT((check_unwrapped_iterator<T const *,
T const *,
true>::value));
THRUST_STATIC_ASSERT((check_unwrapped_iterator<T const *,
T const *,
false>::value));
THRUST_STATIC_ASSERT((check_unwrapped_iterator<thrust::device_ptr<T>,
T *,
true>::value));
THRUST_STATIC_ASSERT((check_unwrapped_iterator<thrust::device_ptr<T const>,
T const *,
true>::value));
THRUST_STATIC_ASSERT((check_unwrapped_iterator<typename std::vector<T>::iterator,
T *,
true>::value));
THRUST_STATIC_ASSERT((check_unwrapped_iterator<typename std::vector<T>::reverse_iterator,
T *,
false>::value));
THRUST_STATIC_ASSERT((check_unwrapped_iterator<typename std::array<T, 1>::iterator,
T *,
true>::value));
THRUST_STATIC_ASSERT((check_unwrapped_iterator<typename std::array<T const, 1>::iterator,
T const *,
true>::value));
THRUST_STATIC_ASSERT((check_unwrapped_iterator<typename std::list<T>::iterator,
T *,
false>::value));
THRUST_STATIC_ASSERT((check_unwrapped_iterator<typename std::deque<T>::iterator,
T *,
false>::value));
THRUST_STATIC_ASSERT((check_unwrapped_iterator<typename std::set<T>::iterator,
T *,
false>::value));
THRUST_STATIC_ASSERT((check_unwrapped_iterator<typename std::multiset<T>::iterator,
T *,
false>::value));
THRUST_STATIC_ASSERT((check_unwrapped_iterator<typename std::map<T, T>::iterator,
std::pair<T const, T> *,
false>::value));
THRUST_STATIC_ASSERT((check_unwrapped_iterator<typename std::multimap<T, T>::iterator,
std::pair<T const, T> *,
false>::value));
THRUST_STATIC_ASSERT((check_unwrapped_iterator<typename std::unordered_set<T>::iterator,
T *,
false>::value));
THRUST_STATIC_ASSERT((check_unwrapped_iterator<typename std::unordered_multiset<T>::iterator,
T *,
false>::value));
THRUST_STATIC_ASSERT((check_unwrapped_iterator<typename std::unordered_map<T, T>::iterator,
std::pair<T const, T> *,
false>::value));
THRUST_STATIC_ASSERT((check_unwrapped_iterator<typename std::unordered_multimap<T, T>::iterator,
std::pair<T const, T> *,
false>::value));
THRUST_STATIC_ASSERT((check_unwrapped_iterator<std::istream_iterator<T>,
T *,
false>::value));
THRUST_STATIC_ASSERT((check_unwrapped_iterator<std::ostream_iterator<T>,
void,
false>::value));
}
DECLARE_GENERIC_UNITTEST(test_try_unwrap_contiguous_iterator);
Loading