diff --git a/include/ck_tile/core/container/sequence.hpp b/include/ck_tile/core/container/sequence.hpp index 763d860d68..1eb276e116 100644 --- a/include/ck_tile/core/container/sequence.hpp +++ b/include/ck_tile/core/container/sequence.hpp @@ -13,6 +13,9 @@ namespace ck_tile { +template +struct array; // declare for later use (array->seq utility) + template struct sequence; @@ -332,29 +335,45 @@ struct uniform_sequence_gen }; // reverse inclusive scan (with init) sequence -template -struct sequence_reverse_inclusive_scan; +namespace impl { +template +struct sequence_reverse_inclusive_scan_impl; -template -struct sequence_reverse_inclusive_scan, Reduce, Init> +template +struct sequence_reverse_inclusive_scan_impl, Reduce, Init> { - using old_scan = typename sequence_reverse_inclusive_scan, Reduce, Init>::type; + template + static constexpr auto compute(sequence) + { + constexpr index_t size = sizeof...(Is); + if constexpr(size == 0) + { + return sequence<>{}; + } + else + { + constexpr array arr = []() { + array values = {Is...}; + array result = {0}; + result[size - 1] = Reduce{}(values[size - 1], Init); + for(index_t i = size - 1; i > 0; --i) + { + result[i - 1] = Reduce{}(values[i - 1], result[i]); + } + return result; + }(); + return sequence{}; + } + } - static constexpr index_t new_reduce = Reduce{}(I, old_scan{}.front()); - - using type = typename sequence_merge, old_scan>::type; + using type = decltype(compute(make_index_sequence{})); }; +} // namespace impl -template -struct sequence_reverse_inclusive_scan, Reduce, Init> +template +struct sequence_reverse_inclusive_scan { - using type = sequence; -}; - -template -struct sequence_reverse_inclusive_scan, Reduce, Init> -{ - using type = sequence<>; + using type = typename impl::sequence_reverse_inclusive_scan_impl::type; }; // split sequence @@ -1105,9 +1124,6 @@ struct sorted_sequence_histogram, sequence> }; } // namespace detail -template -struct array; // declare for later use (array->seq utility) - // SeqSortedSamples: <0, 2, 3, 5, 7>, SeqRange: <0, 3, 6, 9> -> SeqHistogram : <2, 2, 1> template CK_TILE_HOST_DEVICE constexpr auto histogram_sorted_sequence(SeqSortedSamples, sequence)