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

partial fix for iterator traits and tags #1685

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions testing/regression/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
if ("thrust" IN_LIST THRUST_TARGETS)
thrust_add_test(test_target "regression.gh_902__iterator_category_to_system_returns_wrong_tag" "gh_902__iterator_category_to_system_returns_wrong_tag.cu" "thrust")
endif()

#
# Disabled as these test names are too long for CMAKE_OBJECT_PATH_MAX.
# We should integrate these with the other unit tests.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <thrust/iterator/detail/iterator_category_with_system_and_traversal.h>
#include <thrust/iterator/iterator_categories.h>
#include <thrust/iterator/iterator_traits.h>

template <class IteratorCategory>
using _category_to_system_t =
typename thrust::detail::iterator_category_to_system<IteratorCategory>::type;

static_assert(std::is_same<thrust::device_system_tag, _category_to_system_t<thrust::output_device_iterator_tag>>::value);
static_assert(std::is_same<thrust::device_system_tag, _category_to_system_t<thrust::input_device_iterator_tag>>::value);
// static_assert(std::is_same<thrust::device_system_tag, _category_to_system_t<thrust::forward_device_iterator_tag>>::value);
// static_assert(std::is_same<thrust::device_system_tag, _category_to_system_t<thrust::bidirectional_device_iterator_tag>>::value);
// static_assert(std::is_same<thrust::device_system_tag, _category_to_system_t<thrust::random_access_device_iterator_tag>>::value);

static_assert(std::is_same<thrust::host_system_tag, _category_to_system_t<thrust::output_host_iterator_tag>>::value);
static_assert(std::is_same<thrust::host_system_tag, _category_to_system_t<thrust::input_host_iterator_tag>>::value);
static_assert(std::is_same<thrust::host_system_tag, _category_to_system_t<thrust::forward_host_iterator_tag>>::value);
static_assert(std::is_same<thrust::host_system_tag, _category_to_system_t<thrust::bidirectional_host_iterator_tag>>::value);
static_assert(std::is_same<thrust::host_system_tag, _category_to_system_t<thrust::random_access_host_iterator_tag>>::value);

// static_assert(!std::is_convertible<thrust::input_device_iterator_tag, thrust::input_host_iterator_tag>::value);
static_assert(!std::is_convertible<thrust::input_host_iterator_tag, thrust::input_device_iterator_tag>::value);
20 changes: 10 additions & 10 deletions thrust/iterator/detail/iterator_category_to_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,24 @@ template <typename> struct device_iterator_category_to_backend_system;
// we should just specialize this metafunction for iterator_category_with_system_and_traversal
template<typename Category>
struct iterator_category_to_system
// convertible to host iterator?
// convertible to device iterator?
: eval_if<
or_<
is_convertible<Category, thrust::input_host_iterator_tag>,
is_convertible<Category, thrust::output_host_iterator_tag>
is_convertible<Category, thrust::input_device_iterator_tag>,
is_convertible<Category, thrust::output_device_iterator_tag>
>::value,

detail::identity_<thrust::host_system_tag>,
// convertible to device iterator?
detail::identity_<thrust::device_system_tag>,

// convertible to host iterator?
eval_if<
or_<
is_convertible<Category, thrust::input_device_iterator_tag>,
is_convertible<Category, thrust::output_device_iterator_tag>
is_convertible<Category, thrust::input_host_iterator_tag>,
is_convertible<Category, thrust::output_host_iterator_tag>
>::value,

detail::identity_<thrust::device_system_tag>,

detail::identity_<thrust::host_system_tag>,
// unknown system
detail::identity_<void>
> // if device
Expand Down
16 changes: 8 additions & 8 deletions thrust/iterator/detail/iterator_category_to_traversal.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,23 @@ template <typename Category>

template<typename Category>
struct category_to_traversal
// check for host system
// check for device system
: eval_if<
or_<
is_convertible<Category, thrust::input_host_iterator_tag>,
is_convertible<Category, thrust::output_host_iterator_tag>
is_convertible<Category, thrust::input_device_iterator_tag>,
is_convertible<Category, thrust::output_device_iterator_tag>
>::value,

host_system_category_to_traversal<Category>,
device_system_category_to_traversal<Category>,

// check for device system
// check for host system
eval_if<
or_<
is_convertible<Category, thrust::input_device_iterator_tag>,
is_convertible<Category, thrust::output_device_iterator_tag>
is_convertible<Category, thrust::input_host_iterator_tag>,
is_convertible<Category, thrust::output_host_iterator_tag>
>::value,

device_system_category_to_traversal<Category>,
host_system_category_to_traversal<Category>,

// unknown category
detail::identity_<void>
Expand Down