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

[DO NOT MERGE] [Draft] Experimenting with fixing MatX build failures for #3308 #3356

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
84 changes: 68 additions & 16 deletions cub/cub/device/device_segmented_sort.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#pragma once

#include <cub/config.cuh>
#include <type_traits>
#include "thrust/iterator/constant_iterator.h"

#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
Expand All @@ -47,6 +49,47 @@

CUB_NAMESPACE_BEGIN


template<typename RefT, typename WrappedItT, typename VanillaItT>
void debug_fail(WrappedItT wrapped, VanillaItT vanilla)
{
static_assert(std::is_same<WrappedItT, void>::value, "Debug...");
}

template <typename Iterator, typename OffsetItT>
class OffsetIteratorT : public THRUST_NS_QUALIFIER::iterator_adaptor<OffsetIteratorT<Iterator, OffsetItT>, Iterator>
{
public:
using super_t = THRUST_NS_QUALIFIER::iterator_adaptor<OffsetIteratorT<Iterator, OffsetItT>, Iterator>;

OffsetIteratorT() = default;

_CCCL_HOST_DEVICE OffsetIteratorT(const Iterator& it, OffsetItT offset_it)
: super_t(it)
, offset_it(offset_it)
, it(it)
{}

// befriend thrust::iterator_core_access to allow it access to the private interface below
friend class THRUST_NS_QUALIFIER::iterator_core_access;

private:
OffsetItT offset_it;
Iterator it;

_CCCL_HOST_DEVICE typename super_t::reference dereference() const
{
debug_fail<typename super_t::reference>(*(this->base() + (*offset_it)), *it);
return *(this->base() + (*offset_it));
}
};

template <typename Iterator, typename OffsetItT>
_CCCL_HOST_DEVICE OffsetIteratorT<Iterator, OffsetItT> make_offset_iterator(const Iterator& it, OffsetItT offset_it)
{
return OffsetIteratorT<Iterator, OffsetItT>{it, offset_it};
}

//! @rst
//! DeviceSegmentedSort provides device-wide, parallel operations for
//! computing a batched sort across multiple, non-overlapping sequences of
Expand Down Expand Up @@ -146,10 +189,12 @@ private:
EndOffsetIteratorT d_end_offsets,
cudaStream_t stream = 0)
{
using offset_it_t = OffsetIteratorT<EndOffsetIteratorT, thrust::constant_iterator<int>>;

constexpr bool is_descending = false;
constexpr bool is_overwrite_okay = false;
using DispatchT =
DispatchSegmentedSort<is_descending, KeyT, cub::NullType, int, BeginOffsetIteratorT, EndOffsetIteratorT>;
DispatchSegmentedSort<is_descending, KeyT, cub::NullType, int, BeginOffsetIteratorT, offset_it_t>;

DoubleBuffer<KeyT> d_keys(const_cast<KeyT*>(d_keys_in), d_keys_out);
DoubleBuffer<NullType> d_values;
Expand All @@ -162,7 +207,7 @@ private:
num_items,
num_segments,
d_begin_offsets,
d_end_offsets,
{d_end_offsets, thrust::make_constant_iterator(0)},
is_overwrite_okay,
stream);
}
Expand Down Expand Up @@ -321,8 +366,9 @@ private:
{
constexpr bool is_descending = true;
constexpr bool is_overwrite_okay = false;
using offset_it_t = OffsetIteratorT<EndOffsetIteratorT, thrust::constant_iterator<int>>;
using DispatchT =
DispatchSegmentedSort<is_descending, KeyT, cub::NullType, int, BeginOffsetIteratorT, EndOffsetIteratorT>;
DispatchSegmentedSort<is_descending, KeyT, cub::NullType, int, BeginOffsetIteratorT, offset_it_t>;

DoubleBuffer<KeyT> d_keys(const_cast<KeyT*>(d_keys_in), d_keys_out);
DoubleBuffer<NullType> d_values;
Expand All @@ -335,7 +381,7 @@ private:
num_items,
num_segments,
d_begin_offsets,
d_end_offsets,
{d_end_offsets, thrust::make_constant_iterator(0)},
is_overwrite_okay,
stream);
}
Expand Down Expand Up @@ -488,9 +534,10 @@ private:
{
constexpr bool is_descending = false;
constexpr bool is_overwrite_okay = true;
using offset_it_t = OffsetIteratorT<EndOffsetIteratorT, thrust::constant_iterator<int>>;

using DispatchT =
DispatchSegmentedSort<is_descending, KeyT, cub::NullType, int, BeginOffsetIteratorT, EndOffsetIteratorT>;
DispatchSegmentedSort<is_descending, KeyT, cub::NullType, int, BeginOffsetIteratorT, offset_it_t>;

DoubleBuffer<NullType> d_values;

Expand All @@ -502,7 +549,7 @@ private:
num_items,
num_segments,
d_begin_offsets,
d_end_offsets,
{d_end_offsets, thrust::make_constant_iterator(0)},
is_overwrite_okay,
stream);
}
Expand Down Expand Up @@ -658,9 +705,10 @@ private:
{
constexpr bool is_descending = true;
constexpr bool is_overwrite_okay = true;
using offset_it_t = OffsetIteratorT<EndOffsetIteratorT, thrust::constant_iterator<int>>;

using DispatchT =
DispatchSegmentedSort<is_descending, KeyT, cub::NullType, int, BeginOffsetIteratorT, EndOffsetIteratorT>;
DispatchSegmentedSort<is_descending, KeyT, cub::NullType, int, BeginOffsetIteratorT, offset_it_t>;

DoubleBuffer<NullType> d_values;

Expand All @@ -672,7 +720,7 @@ private:
num_items,
num_segments,
d_begin_offsets,
d_end_offsets,
{d_end_offsets, thrust::make_constant_iterator(0)},
is_overwrite_okay,
stream);
}
Expand Down Expand Up @@ -1379,7 +1427,8 @@ private:
{
constexpr bool is_descending = false;
constexpr bool is_overwrite_okay = false;
using DispatchT = DispatchSegmentedSort<is_descending, KeyT, ValueT, int, BeginOffsetIteratorT, EndOffsetIteratorT>;
using offset_it_t = OffsetIteratorT<EndOffsetIteratorT, thrust::constant_iterator<int>>;
using DispatchT = DispatchSegmentedSort<is_descending, KeyT, ValueT, int, BeginOffsetIteratorT, offset_it_t>;

DoubleBuffer<KeyT> d_keys(const_cast<KeyT*>(d_keys_in), d_keys_out);
DoubleBuffer<ValueT> d_values(const_cast<ValueT*>(d_values_in), d_values_out);
Expand All @@ -1392,7 +1441,7 @@ private:
num_items,
num_segments,
d_begin_offsets,
d_end_offsets,
{d_end_offsets, thrust::make_constant_iterator(0)},
is_overwrite_okay,
stream);
}
Expand Down Expand Up @@ -1578,7 +1627,8 @@ private:
{
constexpr bool is_descending = true;
constexpr bool is_overwrite_okay = false;
using DispatchT = DispatchSegmentedSort<is_descending, KeyT, ValueT, int, BeginOffsetIteratorT, EndOffsetIteratorT>;
using offset_it_t = OffsetIteratorT<EndOffsetIteratorT, thrust::constant_iterator<int>>;
using DispatchT = DispatchSegmentedSort<is_descending, KeyT, ValueT, int, BeginOffsetIteratorT, offset_it_t>;

DoubleBuffer<KeyT> d_keys(const_cast<KeyT*>(d_keys_in), d_keys_out);
DoubleBuffer<ValueT> d_values(const_cast<ValueT*>(d_values_in), d_values_out);
Expand All @@ -1591,7 +1641,7 @@ private:
num_items,
num_segments,
d_begin_offsets,
d_end_offsets,
{d_end_offsets, thrust::make_constant_iterator(0)},
is_overwrite_okay,
stream);
}
Expand Down Expand Up @@ -1771,7 +1821,8 @@ private:
{
constexpr bool is_descending = false;
constexpr bool is_overwrite_okay = true;
using DispatchT = DispatchSegmentedSort<is_descending, KeyT, ValueT, int, BeginOffsetIteratorT, EndOffsetIteratorT>;
using offset_it_t = OffsetIteratorT<EndOffsetIteratorT, thrust::constant_iterator<int>>;
using DispatchT = DispatchSegmentedSort<is_descending, KeyT, ValueT, int, BeginOffsetIteratorT, offset_it_t>;

return DispatchT::Dispatch(
d_temp_storage,
Expand All @@ -1781,7 +1832,7 @@ private:
num_items,
num_segments,
d_begin_offsets,
d_end_offsets,
{d_end_offsets, thrust::make_constant_iterator(0)},
is_overwrite_okay,
stream);
}
Expand Down Expand Up @@ -1966,7 +2017,8 @@ private:
{
constexpr bool is_descending = true;
constexpr bool is_overwrite_okay = true;
using DispatchT = DispatchSegmentedSort<is_descending, KeyT, ValueT, int, BeginOffsetIteratorT, EndOffsetIteratorT>;
using offset_it_t = OffsetIteratorT<EndOffsetIteratorT, thrust::constant_iterator<int>>;
using DispatchT = DispatchSegmentedSort<is_descending, KeyT, ValueT, int, BeginOffsetIteratorT, offset_it_t>;

return DispatchT::Dispatch(
d_temp_storage,
Expand All @@ -1976,7 +2028,7 @@ private:
num_items,
num_segments,
d_begin_offsets,
d_end_offsets,
{d_end_offsets, thrust::make_constant_iterator(0)},
is_overwrite_okay,
stream);
}
Expand Down
2 changes: 1 addition & 1 deletion thrust/thrust/iterator/iterator_adaptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class _CCCL_DECLSPEC_EMPTY_BASES iterator_adaptor

// counting_iterator will pick eg. diff_t=int64 when base=int32.
// Explicitly cast to avoid static conversion warnings.
m_iterator = static_cast<base_type>(m_iterator + n);
m_iterator = (m_iterator + n);
}

_CCCL_EXEC_CHECK_DISABLE
Expand Down
Loading