pub struct Avx2Math;Expand description
Concrete implementation of the SimdMath trait for processors with AVX2 and FMA support.
This is where we “connect the wires”: we connect the abstract mathematical operations of the system to the ultra-fast functions documented above. This struct ensures that NAM-rs takes full advantage of modern hardware to process audio in real time.
Trait Implementations§
Source§impl SimdMath for Avx2Math
impl SimdMath for Avx2Math
Source§unsafe fn fused_add_gemm_batch(
in_frames: &[f32],
weights: &[f32],
bias: &[f32],
out_frames: &mut [f32],
num_frames: usize,
do_bias: bool,
)
unsafe fn fused_add_gemm_batch( in_frames: &[f32], weights: &[f32], bias: &[f32], out_frames: &mut [f32], num_frames: usize, do_bias: bool, )
Performs matrix multiplication on a batch of vectors via AVX2. Useful when processing multiple audio frames concurrently to reduce overheads.
Source§unsafe fn fused_gemm_residual_batch(
in_frames: &[f32],
weights: &[f32],
bias: &[f32],
residual: &[f32],
out_frames: &mut [f32],
num_frames: usize,
do_bias: bool,
)
unsafe fn fused_gemm_residual_batch( in_frames: &[f32], weights: &[f32], bias: &[f32], residual: &[f32], out_frames: &mut [f32], num_frames: usize, do_bias: bool, )
Performs matrix-vector multiplication also adding the residual connection (skip connection) from the previous layer. Widely used in the WaveNet residual block architecture.
Source§unsafe fn gemv_overwrite(
in_frame: &[f32],
weights: &[f32],
bias: &[f32],
out_frame: &mut [f32],
do_bias: bool,
)
unsafe fn gemv_overwrite( in_frame: &[f32], weights: &[f32], bias: &[f32], out_frame: &mut [f32], do_bias: bool, )
Version that overwrites the output buffer directly with the matrix-vector multiplication result, without accumulating with pre-existing values in the buffer.
Source§unsafe fn gemv_overwrite_bf16(
_in_frame: &[u16],
_weights: &[u16],
_bias: &[f32],
_out_frame: &mut [f32],
_do_bias: bool,
)
unsafe fn gemv_overwrite_bf16( _in_frame: &[u16], _weights: &[u16], _bias: &[f32], _out_frame: &mut [f32], _do_bias: bool, )
Version that overwrites the output buffer accepting input data represented in BF16 (16-bit) and BF16 weights, performing accumulation in f32 to preserve fidelity.
Source§unsafe fn gemv_overwrite_bf16_4gate(
_in_frame: &[u16],
_weights: &[u16],
_bias: &[f32],
_out_gates: &mut [f32],
_hidden_size: usize,
_do_bias: bool,
)
unsafe fn gemv_overwrite_bf16_4gate( _in_frame: &[u16], _weights: &[u16], _bias: &[f32], _out_gates: &mut [f32], _hidden_size: usize, _do_bias: bool, )
Equivalent to gemv_overwrite_4gate but processing input data represented
in the BF16 reduced precision format.
Source§unsafe fn store_bf16(ptr: *mut u16, v: Self::V)
unsafe fn store_bf16(ptr: *mut u16, v: Self::V)
Converts a register containing 8 32-bit floats (Self::V) to the compact BF16 (16-bit) format and stores the results in memory.
§Bitwise SIMD Magic Details:
To convert f32 to BF16 without spending many CPU cycles on slow mathematical conversions, the technique leverages the structural similarity between IEEE 754 single-precision float and BF16: Both share the same dynamic range (8 exponent bits), but BF16 discards the 16 least significant mantissa bits (truncation/rounding).
Source§const ISA: InstructionSet = InstructionSet::Avx2
const ISA: InstructionSet = InstructionSet::Avx2
Source§unsafe fn dot_product(a: &[f32], b: &[f32]) -> f32
unsafe fn dot_product(a: &[f32], b: &[f32]) -> f32
Source§unsafe fn dot_product_4x_interleaved(
weights: &[[u16; 4]],
state: &[f32],
) -> [f32; 4]
unsafe fn dot_product_4x_interleaved( weights: &[[u16; 4]], state: &[f32], ) -> [f32; 4]
Source§unsafe fn dot_product_4x_interleaved_dual_frame(
weights: &[[u16; 4]],
state_f0: &[f32],
state_f1: &[f32],
) -> ([f32; 4], [f32; 4])
unsafe fn dot_product_4x_interleaved_dual_frame( weights: &[[u16; 4]], state_f0: &[f32], state_f1: &[f32], ) -> ([f32; 4], [f32; 4])
(results_f0, results_f1). Read moreSource§unsafe fn dot_product_4x_f32(weights: &[[f32; 4]], state: &[f32]) -> [f32; 4]
unsafe fn dot_product_4x_f32(weights: &[[f32; 4]], state: &[f32]) -> [f32; 4]
Source§unsafe fn dot_product_4x_f32_dual(
weights: &[[f32; 4]],
state_f0: &[f32],
state_f1: &[f32],
) -> ([f32; 4], [f32; 4])
unsafe fn dot_product_4x_f32_dual( weights: &[[f32; 4]], state_f0: &[f32], state_f1: &[f32], ) -> ([f32; 4], [f32; 4])
(results_f0, results_f1). Read moreSource§unsafe fn dot_product_8x_f32(weights: &[[f32; 8]], state: &[f32]) -> [f32; 8]
unsafe fn dot_product_8x_f32(weights: &[[f32; 8]], state: &[f32]) -> [f32; 8]
Source§unsafe fn dot_product_8x_f32_dual(
weights: &[[f32; 8]],
state_f0: &[f32],
state_f1: &[f32],
) -> ([f32; 8], [f32; 8])
unsafe fn dot_product_8x_f32_dual( weights: &[[f32; 8]], state_f0: &[f32], state_f1: &[f32], ) -> ([f32; 8], [f32; 8])
(results_f0, results_f1). Read moreSource§unsafe fn dot_product_16x_f32(weights: &[[f32; 16]], state: &[f32]) -> [f32; 16]
unsafe fn dot_product_16x_f32(weights: &[[f32; 16]], state: &[f32]) -> [f32; 16]
Source§unsafe fn dot_product_16x_f32_dual(
weights: &[[f32; 16]],
state_f0: &[f32],
state_f1: &[f32],
) -> ([f32; 16], [f32; 16])
unsafe fn dot_product_16x_f32_dual( weights: &[[f32; 16]], state_f0: &[f32], state_f1: &[f32], ) -> ([f32; 16], [f32; 16])
(results_f0, results_f1). Read moreSource§unsafe fn dot_product_4x_f32_accumulate(
weights: &[[f32; 4]],
state: &[f32],
init: &[f32; 4],
) -> [f32; 4]
unsafe fn dot_product_4x_f32_accumulate( weights: &[[f32; 4]], state: &[f32], init: &[f32; 4], ) -> [f32; 4]
init accumulator (bias + mixin). Read moreSource§unsafe fn dot_product_4x_f32_dual_accumulate(
weights: &[[f32; 4]],
state_f0: &[f32],
state_f1: &[f32],
init_f0: &[f32; 4],
init_f1: &[f32; 4],
) -> ([f32; 4], [f32; 4])
unsafe fn dot_product_4x_f32_dual_accumulate( weights: &[[f32; 4]], state_f0: &[f32], state_f1: &[f32], init_f0: &[f32; 4], init_f1: &[f32; 4], ) -> ([f32; 4], [f32; 4])
init_f0 / init_f1 accumulators.
Returns (results_f0, results_f1). Read moreSource§unsafe fn dot_product_8x_f32_accumulate(
weights: &[[f32; 8]],
state: &[f32],
init: &[f32; 8],
) -> [f32; 8]
unsafe fn dot_product_8x_f32_accumulate( weights: &[[f32; 8]], state: &[f32], init: &[f32; 8], ) -> [f32; 8]
init accumulator. Read moreSource§unsafe fn dot_product_8x_f32_dual_accumulate(
weights: &[[f32; 8]],
state_f0: &[f32],
state_f1: &[f32],
init_f0: &[f32; 8],
init_f1: &[f32; 8],
) -> ([f32; 8], [f32; 8])
unsafe fn dot_product_8x_f32_dual_accumulate( weights: &[[f32; 8]], state_f0: &[f32], state_f1: &[f32], init_f0: &[f32; 8], init_f1: &[f32; 8], ) -> ([f32; 8], [f32; 8])
init_f0 / init_f1 accumulators.
Returns (results_f0, results_f1). Read moreSource§unsafe fn dot_product_16x_f32_accumulate(
weights: &[[f32; 16]],
state: &[f32],
init: &[f32; 16],
) -> [f32; 16]
unsafe fn dot_product_16x_f32_accumulate( weights: &[[f32; 16]], state: &[f32], init: &[f32; 16], ) -> [f32; 16]
init accumulator. Read moreSource§unsafe fn dot_product_16x_f32_dual_accumulate(
weights: &[[f32; 16]],
state_f0: &[f32],
state_f1: &[f32],
init_f0: &[f32; 16],
init_f1: &[f32; 16],
) -> ([f32; 16], [f32; 16])
unsafe fn dot_product_16x_f32_dual_accumulate( weights: &[[f32; 16]], state_f0: &[f32], state_f1: &[f32], init_f0: &[f32; 16], init_f1: &[f32; 16], ) -> ([f32; 16], [f32; 16])
init_f0 / init_f1 accumulators.
Returns (results_f0, results_f1). Read moreSource§unsafe fn fused_add_gemv(
in_frame: &[f32],
weights: &[f32],
bias: &[f32],
out_frame: &mut [f32],
do_bias: bool,
)
unsafe fn fused_add_gemv( in_frame: &[f32], weights: &[f32], bias: &[f32], out_frame: &mut [f32], do_bias: bool, )
Source§unsafe fn fused_gemm_residual_batch_f32(
in_frames: &[f32],
weights: &[f32],
bias: &[f32],
residual: &[f32],
out_frames: &mut [f32],
num_frames: usize,
do_bias: bool,
)
unsafe fn fused_gemm_residual_batch_f32( in_frames: &[f32], weights: &[f32], bias: &[f32], residual: &[f32], out_frames: &mut [f32], num_frames: usize, do_bias: bool, )
Source§unsafe fn gemv_overwrite_4gate(
_in_frame: &[f32],
_weights: &[u16],
_bias: &[f32],
_out_gates: &mut [f32],
_hidden_size: usize,
_do_bias: bool,
)
unsafe fn gemv_overwrite_4gate( _in_frame: &[f32], _weights: &[u16], _bias: &[f32], _out_gates: &mut [f32], _hidden_size: usize, _do_bias: bool, )
Source§unsafe fn gemv_overwrite_batch(
in_frames: &[f32],
weights: &[f32],
bias: &[f32],
out_frames: &mut [f32],
num_frames: usize,
do_bias: bool,
)
unsafe fn gemv_overwrite_batch( in_frames: &[f32], weights: &[f32], bias: &[f32], out_frames: &mut [f32], num_frames: usize, do_bias: bool, )
Source§unsafe fn gemv_with_bias_f32(
in_frames: &[f32],
weights: &[f32],
bias: &[f32],
out_frames: &mut [f32],
num_frames: usize,
)
unsafe fn gemv_with_bias_f32( in_frames: &[f32], weights: &[f32], bias: &[f32], out_frames: &mut [f32], num_frames: usize, )
Source§unsafe fn gemv_no_bias_f32(
in_frames: &[f32],
weights: &[f32],
out_frames: &mut [f32],
num_frames: usize,
)
unsafe fn gemv_no_bias_f32( in_frames: &[f32], weights: &[f32], out_frames: &mut [f32], num_frames: usize, )
Source§unsafe fn batch_norm_process(
data: &mut [f32],
scale: &[f32],
offset: &[f32],
n_ch: usize,
num_frames: usize,
)
unsafe fn batch_norm_process( data: &mut [f32], scale: &[f32], offset: &[f32], n_ch: usize, num_frames: usize, )
Source§unsafe fn accumulate_head(dest: &mut [f32], src: &[f32])
unsafe fn accumulate_head(dest: &mut [f32], src: &[f32])
Source§unsafe fn tanh_and_accumulate_block(head_input: &mut [f32], block: &mut [f32])
unsafe fn tanh_and_accumulate_block(head_input: &mut [f32], block: &mut [f32])
Source§unsafe fn gated_activation_and_accumulate_block(
head_input: &mut [f32],
block: &mut [f32],
ch: usize,
)
unsafe fn gated_activation_and_accumulate_block( head_input: &mut [f32], block: &mut [f32], ch: usize, )
Source§unsafe fn tanh_and_overwrite_block(head_input: &mut [f32], block: &mut [f32])
unsafe fn tanh_and_overwrite_block(head_input: &mut [f32], block: &mut [f32])
Source§unsafe fn tanh_and_accumulate_with_seed(
head_input: &mut [f32],
block: &mut [f32],
seed: &[f32],
)
unsafe fn tanh_and_accumulate_with_seed( head_input: &mut [f32], block: &mut [f32], seed: &[f32], )
Source§unsafe fn gated_activation_and_overwrite_block(
head_input: &mut [f32],
block: &mut [f32],
ch: usize,
)
unsafe fn gated_activation_and_overwrite_block( head_input: &mut [f32], block: &mut [f32], ch: usize, )
Source§unsafe fn tanh_slice(slice: &mut [f32])
unsafe fn tanh_slice(slice: &mut [f32])
slice. Read moreSource§unsafe fn sigmoid_slice(slice: &mut [f32])
unsafe fn sigmoid_slice(slice: &mut [f32])
slice. Read moreSource§unsafe fn tanh_slice_hf(slice: &mut [f32])
unsafe fn tanh_slice_hf(slice: &mut [f32])
slice. Read moreSource§unsafe fn sigmoid_slice_hf(slice: &mut [f32])
unsafe fn sigmoid_slice_hf(slice: &mut [f32])
slice. Read moreSource§unsafe fn relu_slice(slice: &mut [f32])
unsafe fn relu_slice(slice: &mut [f32])
slice. Read moreSource§unsafe fn prelu_slice(slice: &mut [f32], slopes: &[f32])
unsafe fn prelu_slice(slice: &mut [f32], slopes: &[f32])
slice[i] = max(0, slice[i]) + slopes[i] * min(0, slice[i]). Read moreSource§unsafe fn softsign_slice(slice: &mut [f32])
unsafe fn softsign_slice(slice: &mut [f32])
slice. Read moreSource§unsafe fn silu_slice(slice: &mut [f32])
unsafe fn silu_slice(slice: &mut [f32])
slice. Read moreSource§unsafe fn hard_tanh_slice(slice: &mut [f32])
unsafe fn hard_tanh_slice(slice: &mut [f32])
slice. Read moreSource§unsafe fn hard_swish_slice(slice: &mut [f32])
unsafe fn hard_swish_slice(slice: &mut [f32])
slice. Read moreSource§unsafe fn fast_tanh_slice(slice: &mut [f32])
unsafe fn fast_tanh_slice(slice: &mut [f32])
slice. Read moreSource§unsafe fn leaky_hard_tanh_slice(
slice: &mut [f32],
min_val: f32,
max_val: f32,
min_slope: f32,
max_slope: f32,
)
unsafe fn leaky_hard_tanh_slice( slice: &mut [f32], min_val: f32, max_val: f32, min_slope: f32, max_slope: f32, )
Source§unsafe fn activation_tanh_block(buf: &mut [f32])
unsafe fn activation_tanh_block(buf: &mut [f32])
tanh_slice). Read moreSource§unsafe fn fused_lstm_gates_dyn(
gates: &mut [f32],
cell_state: &mut [f32],
cell_error: &mut [f32],
hidden_state: &mut [f32],
hidden_size: usize,
)
unsafe fn fused_lstm_gates_dyn( gates: &mut [f32], cell_state: &mut [f32], cell_error: &mut [f32], hidden_state: &mut [f32], hidden_size: usize, )
Source§unsafe fn convolve_stereo(
coeffs: *const f32,
input_l: *const f32,
input_r: *const f32,
taps: usize,
) -> (f32, f32)
unsafe fn convolve_stereo( coeffs: *const f32, input_l: *const f32, input_r: *const f32, taps: usize, ) -> (f32, f32)
Source§unsafe fn convolve_stereo_dual(
coeffs0: *const f32,
coeffs1: *const f32,
input_l: *const f32,
input_r: *const f32,
taps: usize,
) -> ((f32, f32), (f32, f32))
unsafe fn convolve_stereo_dual( coeffs0: *const f32, coeffs1: *const f32, input_l: *const f32, input_r: *const f32, taps: usize, ) -> ((f32, f32), (f32, f32))
Source§unsafe fn convolve_mono(
coeffs: *const f32,
input: *const f32,
taps: usize,
) -> f32
unsafe fn convolve_mono( coeffs: *const f32, input: *const f32, taps: usize, ) -> f32
Source§unsafe fn convolve_mono_dual(
coeffs0: *const f32,
coeffs1: *const f32,
input: *const f32,
taps: usize,
) -> (f32, f32)
unsafe fn convolve_mono_dual( coeffs0: *const f32, coeffs1: *const f32, input: *const f32, taps: usize, ) -> (f32, f32)
Source§unsafe fn apply_gain_and_detect_clipping_mono(
data: &mut [f32],
gain: f32,
) -> bool
unsafe fn apply_gain_and_detect_clipping_mono( data: &mut [f32], gain: f32, ) -> bool
Source§unsafe fn apply_gain_and_detect_clipping_stereo(
left: &mut [f32],
right: &mut [f32],
gain: f32,
) -> bool
unsafe fn apply_gain_and_detect_clipping_stereo( left: &mut [f32], right: &mut [f32], gain: f32, ) -> bool
Source§unsafe fn apply_gain_stereo(left: &mut [f32], right: &mut [f32], gain: f32)
unsafe fn apply_gain_stereo(left: &mut [f32], right: &mut [f32], gain: f32)
Source§unsafe fn apply_gain(data: &mut [f32], gain: f32)
unsafe fn apply_gain(data: &mut [f32], gain: f32)
Source§unsafe fn apply_ramp(data: &mut [f32], start: f32, step: f32)
unsafe fn apply_ramp(data: &mut [f32], start: f32, step: f32)
Source§unsafe fn apply_ramp_stereo(
left: &mut [f32],
right: &mut [f32],
start: f32,
step: f32,
)
unsafe fn apply_ramp_stereo( left: &mut [f32], right: &mut [f32], start: f32, step: f32, )
Source§unsafe fn apply_gain_then_dither(data: &mut [f32], gain: f32, offset: f32)
unsafe fn apply_gain_then_dither(data: &mut [f32], gain: f32, offset: f32)
data[i] = data[i] * gain + offset in a single pass. Read moreSource§unsafe fn apply_dither_add(data: &mut [f32], offset: f32)
unsafe fn apply_dither_add(data: &mut [f32], offset: f32)
Source§unsafe fn crossfade_blend_mono(out: &mut [f32], pending: &[f32], t: f32)
unsafe fn crossfade_blend_mono(out: &mut [f32], pending: &[f32], t: f32)
out[i] = out[i] * (1 - t) + pending[i] * t. Read moreSource§unsafe fn dot_product_bf16(_a: &[u16], _b: &[u16]) -> f32
unsafe fn dot_product_bf16(_a: &[u16], _b: &[u16]) -> f32
Source§unsafe fn dot_product_bf16_4x(
_w0: &[u16],
_w1: &[u16],
_w2: &[u16],
_w3: &[u16],
_in_frame: &[u16],
) -> [f32; 4]
unsafe fn dot_product_bf16_4x( _w0: &[u16], _w1: &[u16], _w2: &[u16], _w3: &[u16], _in_frame: &[u16], ) -> [f32; 4]
Source§unsafe fn f32_to_bf16(_src: &[f32], _dest: &mut [u16])
unsafe fn f32_to_bf16(_src: &[f32], _dest: &mut [u16])
dest[i] = bf16(src[i]). Read moreSource§unsafe fn compute_energy_stereo(l: &[f32], r: &[f32]) -> f32
unsafe fn compute_energy_stereo(l: &[f32], r: &[f32]) -> f32
max(energy(l), energy(r)) as max mean-square energy. Read moreSource§unsafe fn compute_energy(data: &[f32]) -> f32
unsafe fn compute_energy(data: &[f32]) -> f32
(1/N) * Σ x_i². Read moreSource§unsafe fn compute_max_diff(a: &[f32], b: &[f32]) -> f32
unsafe fn compute_max_diff(a: &[f32], b: &[f32]) -> f32
max(|a[i] - b[i]|). Read moreSource§unsafe fn compute_peak_abs_stereo(left: &[f32], right: &[f32]) -> (f32, f32)
unsafe fn compute_peak_abs_stereo(left: &[f32], right: &[f32]) -> (f32, f32)
(max(|left|), max(|right|)). Read moreSource§unsafe fn compute_peak_abs_mono(data: &[f32]) -> f32
unsafe fn compute_peak_abs_mono(data: &[f32]) -> f32
max(|x[i]|) for a single channel. Read moreSource§unsafe fn complex_mac_overwrite(
h_re: &[f32],
h_im: &[f32],
x_re: &[f32],
x_im: &[f32],
out_re: &mut [f32],
out_im: &mut [f32],
)
unsafe fn complex_mac_overwrite( h_re: &[f32], h_im: &[f32], x_re: &[f32], x_im: &[f32], out_re: &mut [f32], out_im: &mut [f32], )
Source§unsafe fn complex_mac_accumulate(
h_re: &[f32],
h_im: &[f32],
x_re: &[f32],
x_im: &[f32],
acc_re: &mut [f32],
acc_im: &mut [f32],
)
unsafe fn complex_mac_accumulate( h_re: &[f32], h_im: &[f32], x_re: &[f32], x_im: &[f32], acc_re: &mut [f32], acc_im: &mut [f32], )
Auto Trait Implementations§
impl Freeze for Avx2Math
impl RefUnwindSafe for Avx2Math
impl Send for Avx2Math
impl Sync for Avx2Math
impl Unpin for Avx2Math
impl UnsafeUnpin for Avx2Math
impl UnwindSafe for Avx2Math
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.