moe_gpu_dsp/lib.rs
1//! # moe-gpu-dsp
2//!
3//! MoE-routed GPU signal processing framework for Rust.
4//!
5//! Provides a zero-copy GPU pipeline for frequency-domain processing:
6//! upload signal once, run all processing on GPU, download result once.
7//!
8//! Built on [cudarc](https://docs.rs/cudarc) for CUDA bindings and cuFFT for
9//! batch FFT operations.
10//!
11//! ## Pipeline
12//!
13//! ```text
14//! Signal -> [GPU upload] -> Window -> Batch FFT R2C -> Magnitude
15//! -> Processing kernels (median filter, soft mask, custom)
16//! -> Batch FFT C2R -> Overlap-add -> [GPU download] -> Output
17//! ```
18//!
19//! ## Quick start
20//!
21//! ```ignore
22//! use moe_gpu_dsp::{GpuDsp, DspConfig};
23//!
24//! let dsp = GpuDsp::new(DspConfig::default()).unwrap();
25//! let (signal_dev, windowed, n_frames) = dsp.window_frames(&signal);
26//! let complex = dsp.batch_fft_r2c(&windowed, n_frames);
27//! // ... run processing kernels on GPU ...
28//! let output = dsp.batch_ifft_c2r_ola(&mut masked, n_frames, signal.len());
29//! ```
30
31#[cfg(feature = "cuda")]
32mod kernels;
33#[cfg(feature = "cuda")]
34mod pipeline;
35
36#[cfg(feature = "cuda")]
37pub use pipeline::{DspConfig, GpuDsp};
38
39#[cfg(feature = "cuda")]
40pub use kernels::{
41 KERNEL_MAGNITUDE, KERNEL_MEDIAN_FILTER, KERNEL_OVERLAP_ADD, KERNEL_SOFT_MASK,
42 KERNEL_WINDOW_FRAMES,
43};
44
45// Re-export cudarc types callers need
46#[cfg(feature = "cuda")]
47pub use cudarc::cufft::sys as cufft_sys;
48#[cfg(feature = "cuda")]
49pub use cudarc::driver::{CudaFunction, CudaSlice, CudaView, LaunchConfig, PushKernelArg};
50
51/// Stub when CUDA feature is not enabled.
52#[cfg(not(feature = "cuda"))]
53pub struct GpuDsp;
54
55#[cfg(not(feature = "cuda"))]
56impl GpuDsp {
57 pub fn new(_config: DspConfig) -> Option<Self> {
58 None
59 }
60}
61
62#[cfg(not(feature = "cuda"))]
63#[derive(Clone, Debug, Default)]
64pub struct DspConfig;