63 static constexpr uint32_t
no_channel { std::numeric_limits<uint32_t>::max() };
165 std::optional<std::pair<size_t, size_t>>
pending;
185 std::shared_ptr<Portal::Graphics::GpuBufferHandle>
runs;
186 std::shared_ptr<Portal::Graphics::GpuBufferHandle>
report;
210 const ChannelIntervals& intervals, uint32_t first_channel, uint32_t last_channel, std::string name =
"intervals")
213 for (
const auto& [start, end] : intervals.
intervals) {
243template <ComputeData InputType = Eigen::MatrixXd, ComputeData OutputType = std::vector<std::vector<
double>>>
261 this->set_config(std::move(config));
281 const auto*
record = result.facets.template get<IntervalExtraction>();
284 std::source_location::current(),
"Interval extraction produced no result");
315 }
catch (
const std::exception& e) {
340 std::source_location::current(),
"The recording can only be shared before the extractor starts");
389 }
catch (
const std::exception& e) {
404 std::source_location::current(),
"An earlier submit has not been collected");
411 record.channels.resize(counts.size());
412 for (
size_t channel = 0; channel < counts.size(); ++channel) {
438 [[nodiscard]] std::optional<IntervalExtraction>
collect()
446 for (
size_t channel = 0; channel <
m_outstanding->calls.size(); ++channel) {
459 [[nodiscard]] std::vector<IntervalBuffers>
buffers()
const
461 std::vector<IntervalBuffers> views(
m_last_calls.size());
462 for (
size_t channel = 0; channel <
m_last_calls.size(); ++channel) {
469 .runs_address =
m_context->shared_buffer_address(0, runs),
470 .report_address =
m_context->shared_buffer_address(0, report),
472 .runs = std::make_shared<Portal::Graphics::GpuBufferHandle>(
m_context->shared_buffer_handle(0, runs)),
473 .report = std::make_shared<Portal::Graphics::GpuBufferHandle>(
m_context->shared_buffer_handle(0, report)),
506 return "IntervalExtractor";
519 std::source_location::current(),
"An earlier submit has not been collected");
521 const auto calls =
record_all(numeric_data, cfg);
525 record.channels.resize(numeric_data.size());
527 std::vector<std::vector<double>> flat(numeric_data.size());
528 for (
size_t channel = 0; channel < numeric_data.size(); ++channel) {
530 for (
const auto& [start, end] :
record.channels[channel].intervals) {
531 flat[channel].push_back(
static_cast<double>(start));
532 flat[channel].push_back(
static_cast<double>(end));
541 }
catch (
const std::exception& e) {
578 mutable std::unique_ptr<ShaderExecutionContext<>>
m_context;
585 template <
typename Columns>
591 for (
size_t channel = 0; channel < columns.size(); ++channel) {
595 check_gate(settings.gate_channel, columns.size(), columns[channel].size());
596 if (columns[settings.gate_channel].size() != columns[channel].size()) {
598 std::source_location::current(),
"Gate column {} has {} scores and column {} has {}",
599 settings.gate_channel, columns[settings.gate_channel].size(), channel, columns[channel].size());
604 std::vector<ChannelCall> calls(columns.size());
605 for (
size_t channel = 0; channel < columns.size(); ++channel) {
606 const std::span<const double> scores { columns[channel].data(), columns[channel].size() };
619 for (
size_t channel = 0; channel < counts.size(); ++channel) {
622 std::source_location::current(),
"Channel {} has no device scores bound", channel);
627 check_gate(settings.gate_channel, counts.size(), counts[channel]);
628 if (counts[settings.gate_channel] != counts[channel]) {
630 std::source_location::current(),
"Gate column {} has {} scores and column {} has {}",
631 settings.gate_channel, counts[settings.gate_channel], channel, counts[channel]);
635 std::source_location::current(),
"Gate column {} has no device scores bound", settings.gate_channel);
640 std::vector<ChannelCall> calls(counts.size());
641 for (
size_t channel = 0; channel < counts.size(); ++channel) {
654 static void check_gate(uint32_t gate,
size_t columns,
size_t length)
656 if (gate >= columns) {
658 std::source_location::current(),
"Gate column {} is not a column of the {} given, for a column of {} scores",
659 gate, columns, length);
665 if (
m_seen.size() != channels) {
666 m_seen.assign(channels, 0);
675 std::source_location::current(),
"Thresholds must be finite");
679 std::source_location::current(),
"{}", reason);
686 for (
const auto& settings : cfg.
columns) {
697 m_recording = std::make_shared<GpuDispatchRecorder>(
true);
699 m_context = std::make_unique<ShaderExecutionContext<>>(
704 std::source_location::current(),
"IntervalExtractor needs a graphics device and none is available");
713 ChannelCall
prepare_channel(
size_t channel, std::span<const double> scores,
bool resident, uint32_t resident_count,
bool flush)
715 const auto n = resident ? resident_count :
static_cast<uint32_t
>(scores.size());
716 if (n == 0 && !flush) {
734 m_context->upload_shared_raw(0, state_binding,
reinterpret_cast<const uint8_t*
>(zeros.data()), zeros.size() *
sizeof(uint32_t));
737 if (!resident && n > 0) {
738 const std::vector<float> floats(scores.begin(), scores.end());
739 m_context->upload_shared_raw(0, scores_binding,
reinterpret_cast<const uint8_t*
>(floats.data()), floats.size() *
sizeof(
float));
741 const uint32_t none = 0;
742 m_context->upload_shared_raw(0, report_binding,
reinterpret_cast<const uint8_t*
>(&none),
sizeof(none));
744 const uint32_t first =
m_seen[channel];
749 m_seen[channel] = first + n;
751 return { .ran =
true, .capacity = n + 4, .first = first, .count = n };
760 std::vector<DependencyStage> stages;
761 for (
size_t channel = 0; channel < calls.size(); ++channel) {
762 if (!calls[channel].ran) {
775 calls[channel].first, calls[channel].count, cfg.
flush));
777 if (!stages.empty()) {
789 std::array<uint32_t, interval_scan_report_words> words {};
793 if (report.emitted > 0) {
794 std::vector<uint32_t> runs(
static_cast<size_t>(report.emitted) * 2);
796 result.
intervals.reserve(report.emitted);
797 for (uint32_t i = 0; i < report.emitted; ++i) {
798 result.
intervals.emplace_back(runs[2 * i], runs[2 * i + 1]);
802 result.
pending = report.pending;
#define MF_ERROR(comp, ctx,...)
#define MF_DESCRIBE(...)
Requests a generated member description for a struct at namespace scope.
The stage that runs the interval scan on device memory, its push layout and its buffer contract.
Runs of a score sequence that stay above a threshold, found in order as a stream, for MayaFlux::Kines...
void set(T value)
Stores a struct under its type identity.
bool is_initialized() const
Check if compiler is initialized.
const Config & config() const
output_type apply_operation(const input_type &input)
ConfigRefs stored_configs(Supports< Configs... >) const
output_type convert_result(std::vector< std::vector< double > > &result_data, DataStructureInfo &metadata)
Non-template base that owns all type-independent GPU dispatch logic.
static std::tuple< NumericChannels, DataStructureInfo > extract_structured_double(T &compute_data)
Extract structured double data from Datum container or direct ComputeData with automatic container ha...
@ ComputeMatrix
Compute operations (Yantra - algorithms, matrices, DSP).
@ Yantra
DSP algorithms, computational units, matrix operations, Grammar.
std::string diagnose_interval_scan(const IntervalScanConfig &config)
Why a config cannot be scanned.
constexpr FenceID INVALID_FENCE
MAYAFLUX_API ShaderFoundry & get_shader_foundry()
Get the global shader compiler instance.
BufferUsageHint
Semantic usage hint for buffer allocation and memory properties.
constexpr uint32_t interval_scan_state_words
Words of the state buffer.
ExtractionType
Categories of extraction operations for discovery and organization.
@ PATTERN_BASED
Extract based on pattern recognition.
IntervalExtractor< Eigen::MatrixXd, std::vector< std::vector< double > > > MatrixIntervalExtractor
Matrix interval extractor: the MatrixXd an analyzer returns, one score channel per column -> interval...
DependencyStage interval_scan_stage(const Kinesis::Discrete::IntervalScanConfig &config, uint64_t scores, uint64_t gate, uint64_t state, uint64_t runs, uint64_t report, uint32_t first_index, uint32_t n, bool flush)
One interval_scan dispatch: continue a stream with n scores from device memory.
IntervalScanReport decode_interval_scan_report(std::span< const uint32_t > words)
Decode the report buffer.
Kinesis::Discrete::IntervalScanConfig interval_scan_config(const IntervalScanSettings &settings, uint32_t length)
The host scan configuration of one column's settings over a stream of the given length.
constexpr uint32_t interval_scan_report_words
Words of the report buffer: the run count, then the open run and the pending interval.
constexpr size_t interval_scan_runs_words(size_t n) noexcept
Words the run list needs for n scores: a start and an end for each run that can close,...
IntervalExtractor< std::vector< Kakshya::DataVariant >, std::vector< std::vector< double > > > StandardIntervalExtractor
Standard interval extractor: DataVariant scores -> interval pairs per channel.
IntervalMethod
How the score sequence is turned into intervals.
@ HYSTERESIS_RUNS
Engage at or above the enter threshold, release below the leave threshold after a minimum gap.
std::vector< std::reference_wrapper< const OperationConfig > > ConfigRefs
Borrowed views of the configs an operation holds.
Kakshya::RegionGroup interval_regions(const ChannelIntervals &intervals, uint32_t first_channel, uint32_t last_channel, std::string name="intervals")
One region per interval, spanning the given channels.
constexpr const char * interval_scan_shader
std::pair< std::shared_ptr< Kriya::BufferPipeline >, std::shared_ptr< Buffers::AudioBuffer > > record(const std::shared_ptr< Kakshya::DynamicSoundStream > &stream, uint32_t input_channel, double seconds, std::optional< uint32_t > monitor, uint32_t channel)
Record a live input channel into a stream for a number of seconds.
void add_region(const Region ®ion)
Organizes related signal regions into a categorized collection.
static Region audio_span(uint64_t start_frame, uint64_t end_frame, uint32_t start_channel, uint32_t end_channel, const std::string &label="")
Create a Region representing a span in audio (frames and channels).
Settings of an IntervalScanner.
enum MayaFlux::Portal::Graphics::GpuBufferBinding::ElementType FLOAT32
Plain-data description of the compute shader to dispatch.
Stores a scoped enum in its underlying integer type.
std::optional< size_t > open_start
std::optional< std::pair< size_t, size_t > > pending
std::vector< std::pair< size_t, size_t > > intervals
Intervals of one channel, half open sample ranges in stream order.
Dimensions, modality, source type, and optional Composite field schema.
Facets facets
Typed results that travel with the data, read by type.
std::unordered_map< std::string, std::any > metadata
Associated metadata.
Input/Output container for computation pipeline data flow with structure preservation.
uint32_t capacity
Pairs the run list can hold.
std::shared_ptr< Portal::Graphics::GpuBufferHandle > report
std::shared_ptr< Portal::Graphics::GpuBufferHandle > runs
Device views of one channel's results from the latest call, for a consumer that reads them on the GPU...
IntervalExtractorConfig config
std::vector< ChannelCall > calls
Portal::Graphics::FenceID fence
Push constants of interval_scan.comp.
uint32_t first_sample
Sample position of score 0.
bool emit_on_close
Emit each interval as soon as it closes, with full padding on both sides.
double leave_margin
How far below the enter threshold a score must fall to count as a gap.
uint32_t padding
Samples added on each side of an interval.
static constexpr uint32_t no_channel
Value of gate_channel for no gate.
bool use_longest_gap
Cut a capped run at its longest gap instead of the last one.
uint32_t min_gap
Shortest gap that ends a run, in samples.
uint32_t samples_per_score
Samples between successive scores.
uint32_t gate_channel
Column that gates this one, or no_channel.
double gate_threshold
Gate score below which this column is silent.
uint32_t max_run
Longest interval in samples, 0 for no cap.
double enter_threshold
Score at or above which a run starts.
uint32_t gap_at_limit
Gaps longer than this are candidates for cutting a capped run, in samples.
double leave_floor
Lowest leave threshold.
uint32_t min_run
Shortest run kept, in samples.
How one score column is turned into intervals.
The config structs an operation class accepts, declared as using supports.
A set of (device, runtime) pairs.