Files
leleka/crates/cpu-sys/src/c_reference.rs
T
Pavlo Ratushnyi 95f768cfbf STRA-338 S12c: fns and impl blocks of 162 hot-path modules move into child modules (leleka-runtime, cuda-driver, deploy, cpu-sys)
The same lexer-based splitter as S12b, now with explicit re-exports: every moved free fn comes back to its module under its old name and old visibility (cfg attributes carried), so a name can never clash with another glob import. 162 module files of leleka-runtime (68), cuda-driver (84), deploy (10), cpu-sys, igpu and leleka-memory are split into groups of about 250 lines; types, constants, macros, nested modules and tests stay. Not touched: the files kar-off-ab edits, crate roots (lib.rs, main.rs, bin/*), and giant single impl blocks (next). This changes codegen-unit placement of engine code, so it is covered by the bitwise replay and the paired A/B on the 5090, not by a binary comparison.
2026-11-05 15:52:18 +01:00

176 lines
7.0 KiB
Rust

//! The C kernels in `csrc/` behind checked wrappers. Test-only (feature `c-reference`): the runtime
//! uses the Rust kernels in `simd`; this module is the independent C implementation they are
//! compared against, bit for bit, in `tests/rust_vs_c.rs`.
use crate::{
BLOCK_ELEMS, KernelError, MAX_DOT_LEN, MXFP4_BLOCK_BYTES, Q8_0_BLOCK_BYTES, avx2_available,
};
/// ABI version this module was written against; compared with the C library at run time.
pub const ABI_VERSION: u32 = 2;
mod ffi {
unsafe extern "C" {
pub fn leleka_cpu_abi_version() -> u32;
pub fn leleka_dot_mxfp4_q8_0_scalar(x: *const u8, y: *const u8, nb: usize) -> f32;
pub fn leleka_mxfp4_q8_0_isums_scalar(x: *const u8, y: *const u8, nb: usize, out: *mut i32);
pub fn leleka_dot_mxfp4_q8r_scalar(
x: *const u8,
ys: *const f32,
yq: *const i8,
nb: usize,
) -> f32;
#[cfg(all(target_arch = "x86_64", leleka_avxvnni))]
pub fn leleka_dot_mxfp4_q8r4_avxvnni(
x: *const u8,
ys: *const f32,
yq: *const i8,
nb: usize,
) -> f32;
#[cfg(target_arch = "x86_64")]
pub fn leleka_dot_mxfp4_q8_0_avx2(x: *const u8, y: *const u8, nb: usize) -> f32;
#[cfg(target_arch = "x86_64")]
pub fn leleka_mxfp4_q8_0_isums_avx2(x: *const u8, y: *const u8, nb: usize, out: *mut i32);
pub fn leleka_quantize_q8_0_scalar(x: *const f32, y: *mut u8, nb: usize);
pub fn leleka_dot_q8_0_q8_0_scalar(x: *const u8, y: *const u8, nb: usize) -> f32;
pub fn leleka_q8_0_q8_0_isums_scalar(x: *const u8, y: *const u8, nb: usize, out: *mut i32);
pub fn leleka_f32_to_f16_scalar(f: f32) -> u16;
#[cfg(target_arch = "x86_64")]
pub fn leleka_quantize_q8_0_avx2(x: *const f32, y: *mut u8, nb: usize);
#[cfg(target_arch = "x86_64")]
pub fn leleka_dot_q8_0_q8_0_avx2(x: *const u8, y: *const u8, nb: usize) -> f32;
#[cfg(target_arch = "x86_64")]
pub fn leleka_q8_0_q8_0_isums_avx2(x: *const u8, y: *const u8, nb: usize, out: *mut i32);
#[cfg(target_arch = "x86_64")]
pub fn leleka_f32_to_f16_f16c(f: f32) -> u16;
#[cfg(all(target_arch = "x86_64", leleka_avxvnni))]
pub fn leleka_dot_q8_0_q8_0_avxvnni(x: *const u8, y: *const u8, nb: usize) -> f32;
#[cfg(all(target_arch = "x86_64", leleka_avxvnni))]
pub fn leleka_q8_0_q8_0_isums_avxvnni(x: *const u8, y: *const u8, nb: usize, out: *mut i32);
#[cfg(target_arch = "x86_64")]
pub fn leleka_dot_mxfp4_q8r_avx2(
x: *const u8,
ys: *const f32,
yq: *const i8,
nb: usize,
) -> f32;
#[cfg(target_arch = "x86_64")]
pub fn leleka_dot_mxfp4_q8r4_avx2(
x: *const u8,
ys: *const f32,
yq: *const i8,
nb: usize,
) -> f32;
#[cfg(all(target_arch = "x86_64", leleka_avxvnni))]
pub fn leleka_dot_mxfp4_q8_0_avxvnni(x: *const u8, y: *const u8, nb: usize) -> f32;
#[cfg(all(target_arch = "x86_64", leleka_avxvnni))]
pub fn leleka_mxfp4_q8_0_isums_avxvnni(
x: *const u8,
y: *const u8,
nb: usize,
out: *mut i32,
);
pub fn leleka_dot_i8i8_scalar(w: *const i8, x: *const i8, n: usize) -> i32;
pub fn leleka_dot_i4i8_scalar(w4: *const u8, x: *const i8, n: usize) -> i32;
#[cfg(target_arch = "x86_64")]
pub fn leleka_dot_i8i8_avx2(w: *const i8, x: *const i8, n: usize) -> i32;
#[cfg(target_arch = "x86_64")]
pub fn leleka_dot_i4i8_avx2(w4: *const u8, x: *const i8, n: usize) -> i32;
#[cfg(all(target_arch = "x86_64", leleka_avxvnni))]
pub fn leleka_dot_i8i8_avxvnni(w: *const i8, x: *const i8, n: usize) -> i32;
#[cfg(all(target_arch = "x86_64", leleka_avxvnni))]
pub fn leleka_dot_i4i8_avxvnni(w4: *const u8, x: *const i8, n: usize) -> i32;
}
}
mod abi_version_fn;
#[allow(unused_imports)]
pub use abi_version_fn::abi_version;
#[allow(unused_imports)]
use abi_version_fn::check_i8;
#[allow(unused_imports)]
use abi_version_fn::check_i4;
#[allow(unused_imports)]
pub use abi_version_fn::dot_i8i8_scalar;
#[allow(unused_imports)]
pub use abi_version_fn::dot_i4i8_scalar;
#[cfg(target_arch = "x86_64")]
#[allow(unused_imports)]
pub use abi_version_fn::avxvnni_available;
#[allow(unused_imports)]
use abi_version_fn::check_mx;
#[allow(unused_imports)]
use abi_version_fn::check_mx_out;
#[allow(unused_imports)]
pub use abi_version_fn::dot_mxfp4_q8_0_scalar;
#[allow(unused_imports)]
pub use abi_version_fn::mxfp4_q8_0_isums_scalar;
#[cfg(target_arch = "x86_64")]
#[allow(unused_imports)]
pub use abi_version_fn::dot_mxfp4_q8_0_avx2;
#[cfg(target_arch = "x86_64")]
#[allow(unused_imports)]
pub use abi_version_fn::mxfp4_q8_0_isums_avx2;
#[allow(unused_imports)]
use abi_version_fn::check_q8r;
#[cfg(target_arch = "x86_64")]
#[allow(unused_imports)]
pub use abi_version_fn::dot_mxfp4_q8r_avx2;
#[cfg(target_arch = "x86_64")]
#[allow(unused_imports)]
pub use abi_version_fn::dot_mxfp4_q8r4_avx2;
#[allow(unused_imports)]
pub use abi_version_fn::dot_mxfp4_q8r_scalar;
#[cfg(target_arch = "x86_64")]
#[allow(unused_imports)]
pub use abi_version_fn::dot_mxfp4_q8r4_avxvnni;
#[cfg(target_arch = "x86_64")]
#[allow(unused_imports)]
pub use abi_version_fn::dot_mxfp4_q8_0_avxvnni;
#[cfg(target_arch = "x86_64")]
#[allow(unused_imports)]
pub use abi_version_fn::mxfp4_q8_0_isums_avxvnni;
#[allow(unused_imports)]
use abi_version_fn::check_q8;
#[allow(unused_imports)]
use abi_version_fn::check_quantize;
mod quantize_q8_0_scalar_fn;
#[allow(unused_imports)]
pub use quantize_q8_0_scalar_fn::quantize_q8_0_scalar;
#[cfg(target_arch = "x86_64")]
#[allow(unused_imports)]
pub use quantize_q8_0_scalar_fn::quantize_q8_0_avx2;
#[allow(unused_imports)]
pub use quantize_q8_0_scalar_fn::dot_q8_0_q8_0_scalar;
#[allow(unused_imports)]
pub use quantize_q8_0_scalar_fn::q8_0_q8_0_isums_scalar;
#[cfg(target_arch = "x86_64")]
#[allow(unused_imports)]
pub use quantize_q8_0_scalar_fn::dot_q8_0_q8_0_avx2;
#[cfg(target_arch = "x86_64")]
#[allow(unused_imports)]
pub use quantize_q8_0_scalar_fn::q8_0_q8_0_isums_avx2;
#[cfg(target_arch = "x86_64")]
#[allow(unused_imports)]
pub use quantize_q8_0_scalar_fn::dot_q8_0_q8_0_avxvnni;
#[cfg(target_arch = "x86_64")]
#[allow(unused_imports)]
pub use quantize_q8_0_scalar_fn::q8_0_q8_0_isums_avxvnni;
#[allow(unused_imports)]
pub use quantize_q8_0_scalar_fn::f32_to_f16_bits_scalar;
#[cfg(target_arch = "x86_64")]
#[allow(unused_imports)]
pub use quantize_q8_0_scalar_fn::f32_to_f16_bits_f16c;
#[cfg(target_arch = "x86_64")]
#[allow(unused_imports)]
pub use quantize_q8_0_scalar_fn::dot_i8i8_avx2;
#[cfg(target_arch = "x86_64")]
#[allow(unused_imports)]
pub use quantize_q8_0_scalar_fn::dot_i4i8_avx2;
#[cfg(target_arch = "x86_64")]
#[allow(unused_imports)]
pub use quantize_q8_0_scalar_fn::dot_i8i8_avxvnni;
#[cfg(target_arch = "x86_64")]
#[allow(unused_imports)]
pub use quantize_q8_0_scalar_fn::dot_i4i8_avxvnni;