MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ order()

template<ComputeData OutputType = std::vector<Kakshya::DataVariant>>
std::vector< size_t > MayaFlux::Yantra::BitonicSorter< OutputType >::order ( std::span< const double > values)
inlinenodiscard

The indices that order one channel, computed on the GPU in the configured direction.

Returns
result[i] is the index in values of the i-th value in order. For the bidirectional order, result[i] is the value placed at position i.

Definition at line 93 of file BitonicSorter.hpp.

94 {
95 const auto direction = this->template config<StandardSorterConfig>().direction;
97 const size_t count = values.size();
99 std::iota(result.begin(), result.end(), size_t { 0 });
100 if (count < 2) {
101 return result;
102 }
103
104 auto& executor = this->context();
105 const size_t padded = std::bit_ceil(count);
107
109 std::iota(indices.begin(), indices.end(), uint32_t { 0 });
110 executor.set_binding_data(k_indices_binding, indices);
111
112 const auto stages = static_cast<uint32_t>(std::countr_zero(padded));
113 executor.set_multipass(stages * (stages + 1U) / 2U,
114 [padded](uint32_t pass_index, void* push) {
115 uint32_t level = 0;
117 while (remaining > level) {
118 remaining -= level + 1U;
119 ++level;
120 }
121 const SortPush pc {
122 .stage = level + 1U,
123 .pass = level - remaining,
124 .count = static_cast<uint32_t>(padded),
125 .descending = 0U,
126 };
127 std::memcpy(push, &pc, sizeof(SortPush));
128 });
129
131
132 const auto sorted = executor.primary_words();
133 if (sorted.size() < count) {
135 std::source_location::current(), "BitonicSorter: the sort returned {} of {} indices",
136 sorted.size(), count);
137 }
138 std::copy_n(sorted.begin(), count, result.begin());
139
143 for (size_t rank = 0; rank < count; ++rank) {
145 }
146 return placed;
147 }
148 return result;
149 }
WordPairExecutionContext & context()
The context, built on first use so a sorter can be created before any device.
static constexpr uint32_t k_indices_binding
static constexpr uint32_t k_keys_binding
Sorts each numeric channel on the GPU, exactly, without fp64.
const Config & config() const
The stored config struct of type Config, or its defaults when none was set.
output_type execute(const input_type &input)
OpUnit interface - operations can act as units in dependency graphs.
std::vector< size_t > mountain_positions(size_t count)
Target position of each rank in a mountain arrangement of count values.
Definition Sort.cpp:22

References MayaFlux::Journal::BufferProcessing, MayaFlux::Yantra::ComputeOperation< InputType, OutputType >::config(), context(), k_indices_binding, k_keys_binding, MayaFlux::Kinesis::Discrete::mountain_positions(), and MayaFlux::Journal::Yantra.

Referenced by arrange(), and MayaFlux::Yantra::RegionKeySorter::gpu_order().

Here is the call graph for this function:
Here is the caller graph for this function: