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

◆ segmented_argmax_stage() [1/2]

DependencyStage MayaFlux::Yantra::segmented_argmax_stage ( WordPairExecutionContext & context,
const GpuComputeConfig & config,
const SegmentGeometry & geometry )
inlinenodiscard

The stage that selects the largest value of every segment of values already on the device.

The values are whatever binding 0 resolves to: a shared buffer of the context, or one imported from another context with import_shared, for instance the result of a LaggedPair pass recorded earlier on the same recording. Nothing is staged from the host.

const auto spec = segmented_argmax_spec();
const auto config = config_from_spec(spec);
WordPairExecutionContext select(config, bindings_from_spec(spec), false, "SegmentedArgMax");
select.set_recording(recording);
select.import_shared(0, 0, correlation, 0, 1, GpuBufferBinding::ElementType::VEC2_U32);
select.record_stages({ segmented_argmax_stage(select, config, geometry) });
const auto best = read_argmax(select, geometry.count);
Shader context whose numeric input is staged as a uvec2 per double.
std::vector< ArgMaxResult > read_argmax(WordPairExecutionContext &context, size_t segments)
Read the selections of the segments of the last recorded stage.
DependencyStage segmented_argmax_stage(WordPairExecutionContext &context, const GpuComputeConfig &config, const SegmentGeometry &geometry)
The stage that selects the largest value of every segment of values already on the device.
GpuComputeConfig config_from_spec(const Portal::Graphics::ShaderSpec &spec)
Derive a GpuComputeConfig from a ShaderSpec.
std::vector< GpuBufferBinding > bindings_from_spec(const Portal::Graphics::ShaderSpec &spec)
Derive a GpuBufferBinding list from a ShaderSpec.
Portal::Graphics::ShaderSpec segmented_argmax_spec(uint32_t workgroup=256)
The spec of a SegmentedArgMax kernel.
Parameters
contextContext built with config.
configConfig of the spec the context was built from.
geometrySegment length, stride, first offset and count. Every segment must lie inside the values.

Definition at line 81 of file SegmentedArgMax.hpp.

83{
84 const std::array<uint32_t, 3> push { geometry.length, geometry.stride, geometry.offset };
85 const size_t result_bytes = static_cast<size_t>(geometry.count) * 2U * sizeof(uint64_t);
86
87 return DependencyStage {
88 .config = config,
89 .stage_fn = [&context, result_bytes, push](GpuDispatchCore&) {
90 if (!context.shared_buffer_info(0, 1)) {
91 context.set_output_size(1, result_bytes);
92 }
93 context.set_push_constants(push);
94 },
95 .explicit_groups = std::array<uint32_t, 3> { geometry.count, 1U, 1U },
96 };
97}
std::optional< SharedBufferInfo > shared_buffer_info(uint32_t set, size_t binding_index) const
What the shared buffer at (set, binding_index) declares, or nothing when absent.
void set_output_size(size_t index, size_t byte_size)
Declare the byte capacity of an output binding independently of input data.
void set_push_constants(const void *data, size_t bytes)
Set push constant data from a raw byte pointer.

References MayaFlux::Yantra::SegmentGeometry::count, MayaFlux::Yantra::SegmentGeometry::length, MayaFlux::Yantra::SegmentGeometry::offset, MayaFlux::Yantra::GpuDispatchCore::set_output_size(), MayaFlux::Yantra::GpuDispatchCore::set_push_constants(), MayaFlux::Yantra::GpuDispatchCore::shared_buffer_info(), and MayaFlux::Yantra::SegmentGeometry::stride.

Referenced by MayaFlux::Yantra::WaveformAnalyzer< std::vector< Kakshya::DataVariant >, Eigen::MatrixXd >::measure_chunk(), and segmented_argmax_stage().

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