Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
gpu_neural_realtime_node.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <memory>
5
10
11namespace pulp::gpu_audio {
12
16enum class NeuralFamily : std::uint8_t {
19 Tcn = 2,
20 Ssm = 3,
21 Lstm = 4,
22 Gru = 5,
23 Custom = 255,
24};
25
30class GpuNeuralModel;
31using GpuNeuralModelHandle = std::shared_ptr<GpuNeuralModel>;
32
34namespace detail {
35struct RealtimeGpuHealth;
36struct NeuralRealtimeTestAccess;
37struct SharedIoProviderIdentity;
38} // namespace detail
39
93 public:
95 enum class ShadowPolicy : std::uint8_t {
96 Auto = 0,
97 Inline = 1,
98 Worker = 2,
102 None = 3,
103 };
104
106 static constexpr float kAutoInlineMaxCostPct = 15.0f;
107
124
145
192
199
203 bool prepare() override;
206 bool release() noexcept;
207
209 bool cpu_fallback_prepared() const noexcept override;
212 void prime_fallback(const audio::BufferView<const float>& input,
213 std::uint32_t n) noexcept override;
215 void process_cpu_fallback(const audio::BufferView<const float>& input,
216 audio::BufferView<float>& output, std::uint32_t n) noexcept override;
218 void process_block(const audio::BufferView<const float>&, audio::BufferView<float>&,
219 std::uint32_t) final;
220
221 // Host/UI reads; see the threading note on the class.
222
228 std::uint64_t sanitized_input_samples() const noexcept;
233 std::uint64_t callback_contract_violations() const noexcept;
234 NeuralFamily family() const noexcept;
237 bool gpu_kernel_available() const noexcept;
240 std::uint64_t epoch() const noexcept;
243 bool fenced() const noexcept;
247 std::uint64_t recovery_sequence() const noexcept;
249 GpuAudioStatus status_snapshot() const noexcept override;
250 bool bind_realtime_path(detail::RealtimeGpuNodeBinding& binding) noexcept override;
256 ShadowStatus shadow_status() const noexcept;
257
258 private:
259 struct Impl;
260 std::unique_ptr<Impl> impl_;
262 bool ready() const noexcept;
263 bool authenticated_provider() const noexcept;
264 // Provider identity for the transport: Dawn when authenticated, Cpu when
265 // prepared without a GPU backend, otherwise Unknown.
266 GpuAudioProvider transport_provider() const noexcept;
267 detail::SharedIoProviderIdentity provider_identity_for_transport() const noexcept;
268 static std::uint8_t process(void*, const audio::BufferView<const float>&,
269 audio::BufferView<float>&, std::uint32_t, std::uint64_t, bool,
270 std::uint64_t) noexcept;
271 static std::uint32_t service(void*, std::uint64_t) noexcept;
272 static bool fence(void*) noexcept;
273 static void offline_render(void*, bool offline) noexcept;
274 static void delivered(void*, std::uint64_t, std::uint8_t, std::uint64_t,
275 std::uint64_t) noexcept;
276 static std::uint64_t next_sequence(void*) noexcept;
277 static bool health(const void*, detail::RealtimeGpuHealth&) noexcept;
278};
279
280} // namespace pulp::gpu_audio
A unit of audio work the transport schedules onto a non-real-time worker.
Definition gpu_audio_node.hpp:92
Architecture-neutral realtime neural node with a built-in CPU shadow.
Definition gpu_neural_realtime_node.hpp:92
std::uint64_t callback_contract_violations() const noexcept
Invalid or out-of-sequence callbacks observed on the CPU-only path.
void process_block(const audio::BufferView< const float > &, audio::BufferView< float > &, std::uint32_t) final
Not a legacy FIFO node. GpuAudioTransport rejects an unprepared instance.
ShadowStatus shadow_status() const noexcept
Allocation-free shadow diagnostics beyond the public shadow_* fields of status_snapshot(),...
bool prepare() override
Stop/join callback and worker first: prepare() begins with release().
bool release() noexcept
Stop/join callback and worker first.
GpuAudioRecoveryReason recovery_reason() const noexcept
First latched recovery cause.
bool gpu_kernel_available() const noexcept
True only while a GPU backend for this family is prepared and has not been quiesced by an offline fen...
GpuAudioStatus status_snapshot() const noexcept override
Allocation-free lifecycle projection.
void process_cpu_fallback(const audio::BufferView< const float > &input, audio::BufferView< float > &output, std::uint32_t n) noexcept override
RT-safe. Emits the latency-aligned block staged by prime_fallback().
GpuNeuralRealtimeNode(Config config)
Host thread only.
friend struct detail::NeuralRealtimeTestAccess
Definition gpu_neural_realtime_node.hpp:261
std::uint64_t recovery_sequence() const noexcept
Sequence associated with the first latched recovery cause, or UINT64_MAX.
PrepareError
Why the last prepare() returned false.
Definition gpu_neural_realtime_node.hpp:126
@ ReleaseFailed
Definition gpu_neural_realtime_node.hpp:139
@ ChannelMismatch
Definition gpu_neural_realtime_node.hpp:130
@ ShadowModelMismatch
The shadow model's channels, block size or sample rate differ.
Definition gpu_neural_realtime_node.hpp:143
@ InvalidConfig
Definition gpu_neural_realtime_node.hpp:128
@ BridgeFailed
Definition gpu_neural_realtime_node.hpp:138
@ ModelBound
The model is bound to another node.
Definition gpu_neural_realtime_node.hpp:134
@ BackendInflightExceeded
max_inflight exceeds the backend's own in-flight capacity.
Definition gpu_neural_realtime_node.hpp:132
@ ShadowRequired
ShadowPolicy::None for a family without a GPU kernel.
Definition gpu_neural_realtime_node.hpp:141
@ ShadowPrepareFailed
Definition gpu_neural_realtime_node.hpp:135
@ ShadowUnpublished
The shadow processors were prepared but not published.
Definition gpu_neural_realtime_node.hpp:137
@ FamilyMismatch
Definition gpu_neural_realtime_node.hpp:129
NeuralFamily family() const noexcept
GpuAudioNodeDescriptor descriptor() const override
PrepareError last_prepare_error() const noexcept
Reason for the most recent failed prepare(); None after a success.
std::uint64_t sanitized_input_samples() const noexcept
Non-finite input samples (NaN, +/-Inf) replaced with zero since prepare().
void prime_fallback(const audio::BufferView< const float > &input, std::uint32_t n) noexcept override
RT-safe.
~GpuNeuralRealtimeNode() override
Stop/join the callback and worker first; destruction releases.
GpuNeuralRealtimeNode(const GpuNeuralRealtimeNode &)=delete
bool bind_realtime_path(detail::RealtimeGpuNodeBinding &binding) noexcept override
Private transport hook, not for node authors: a node that the GPU audio transport drives through a st...
GpuAudioCapabilityReport capability_report() const noexcept
Allocation-free capability projection.
ShadowPolicy
Where the built-in CPU shadow runs.
Definition gpu_neural_realtime_node.hpp:95
@ Inline
Definition gpu_neural_realtime_node.hpp:97
@ Auto
Definition gpu_neural_realtime_node.hpp:96
@ Worker
Definition gpu_neural_realtime_node.hpp:98
@ None
A realtime GPU miss is silent.
Definition gpu_neural_realtime_node.hpp:102
GpuNeuralRealtimeNode & operator=(const GpuNeuralRealtimeNode &)=delete
std::uint64_t epoch() const noexcept
Current GPU delivery epoch, or zero when no GPU epoch is open.
bool cpu_fallback_prepared() const noexcept override
True once every channel's shadow processor is published.
static constexpr float kAutoInlineMaxCostPct
Auto selects Inline when the total inline cost (one channel's cost times the channel count) is at mos...
Definition gpu_neural_realtime_node.hpp:106
bool fenced() const noexcept
True before preparation, or once GPU delivery was fenced.
Definition analyzer_provider.hpp:12
Definition gpu_audio_node.hpp:78
Definition flow_pans.hpp:19
GpuAudioRecoveryReason
First latched reason that a node entered recovery.
Definition gpu_audio_status.hpp:40
MissPolicy
What the transport does for a block when the GPU result is not ready in time (the worker fell behind,...
Definition gpu_audio_node.hpp:12
@ CpuFallback
Run the node's CPU fallback for the missed block.
Definition gpu_audio_node.hpp:38
NeuralFamily
Architecture family of a neural model hosted by GpuNeuralRealtimeNode.
Definition gpu_neural_realtime_node.hpp:16
@ Lstm
Definition gpu_neural_realtime_node.hpp:21
@ Ssm
Definition gpu_neural_realtime_node.hpp:20
@ Unknown
Definition gpu_neural_realtime_node.hpp:17
@ Gru
Definition gpu_neural_realtime_node.hpp:22
@ WaveNet
Definition gpu_neural_realtime_node.hpp:18
@ Tcn
Definition gpu_neural_realtime_node.hpp:19
GpuAudioProvider
Provider identity when the selected path can establish it without exposing backend handles.
Definition gpu_audio_capability.hpp:21
@ Unknown
Definition gpu_audio_capability.hpp:22
@ Custom
Definition gpu_audio_program.hpp:20
std::shared_ptr< GpuNeuralModel > GpuNeuralModelHandle
Definition gpu_neural_realtime_node.hpp:31
STL namespace.
Backend-neutral, allocation-free capability snapshot for installed SDK consumers.
Definition gpu_audio_capability.hpp:46
Declared, fixed scheduling properties of a GPU audio node.
Definition gpu_audio_node.hpp:44
Versioned, allocation-free status shared by native hosts and UI adapters.
Definition gpu_audio_status.hpp:80
Definition gpu_neural_realtime_node.hpp:146
std::uint32_t prewarm_blocks
Silent blocks run through the GPU and the CPU shadow at prepare so both histories begin at the same s...
Definition gpu_neural_realtime_node.hpp:166
NeuralFamily family
Must match the family the model was built for.
Definition gpu_neural_realtime_node.hpp:148
GpuNeuralModelHandle shadow_model
Optional cheaper model for the shadow.
Definition gpu_neural_realtime_node.hpp:176
void * shadow_audio_workgroup
Borrowed os_workgroup_t of the host's audio thread.
Definition gpu_neural_realtime_node.hpp:181
std::uint32_t max_inflight
Maximum GPU blocks in flight; at most capacity - lead_blocks and at most the backend's own in-flight ...
Definition gpu_neural_realtime_node.hpp:163
std::uint64_t completion_service_wait_ns
Optional bounded completion-service budget for each non-RT worker pump.
Definition gpu_neural_realtime_node.hpp:169
std::uint32_t lead_blocks
Fixed output delay in blocks; the CPU shadow is delayed by the same amount, so host delay compensatio...
Definition gpu_neural_realtime_node.hpp:154
MissPolicy miss_policy
Only CpuFallback is accepted: the shadow is built in.
Definition gpu_neural_realtime_node.hpp:171
std::uint32_t watchdog_blocks
GPU watchdog budget in callback blocks: a provider that completes nothing for this many blocks while ...
Definition gpu_neural_realtime_node.hpp:190
ShadowPolicy shadow_policy
Definition gpu_neural_realtime_node.hpp:172
std::uint32_t shadow_queue_blocks
Worker queue depth in blocks, for both directions.
Definition gpu_neural_realtime_node.hpp:178
std::uint32_t channels
Must match the model's channel count.
Definition gpu_neural_realtime_node.hpp:151
GpuNeuralModelHandle model
Definition gpu_neural_realtime_node.hpp:149
std::uint32_t capacity
GPU ring depth. Must exceed lead_blocks.
Definition gpu_neural_realtime_node.hpp:156
Allocation-free shadow diagnostics.
Definition gpu_neural_realtime_node.hpp:109
float inline_cost_total_pct
The per-channel cost times the channel count: what Inline would spend on the audio thread.
Definition gpu_neural_realtime_node.hpp:117
float inline_cost_per_channel_pct
One block of the shadow model for one channel, as a percentage of the block period,...
Definition gpu_neural_realtime_node.hpp:114
ShadowPolicy requested
Definition gpu_neural_realtime_node.hpp:110
std::uint64_t shadow_resyncs
Times the Worker restarted the model's state after a dropped input.
Definition gpu_neural_realtime_node.hpp:121
std::uint64_t shadow_input_dropped
Worker inputs dropped because the shadow queue was full.
Definition gpu_neural_realtime_node.hpp:119
bool workgroup_joined
Definition gpu_neural_realtime_node.hpp:122