Explicit imports in leleka-model-format, leleka-native-cpu-expert and leleka-cpu-sys; explicit_imports.py: own glob names, static mut, intrinsics

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Pavlo Ratushnyi
2026-11-14 14:35:23 +01:00
co-authored by Claude Sonnet 5.5
parent f59b00d027
commit fb428d3d9b
46 changed files with 234 additions and 85 deletions
@@ -1,7 +1,8 @@
//! Attention score and weighted-sum kernels, SwiGLU, f16 conversion and the softmax exponent sum.
#[allow(unused_imports)]
use super::*;
use super::{AttnShape, KernelError, ScoreSpec, check_scores, check_swiglu, check_weighted_sum, simd};
#[cfg(target_arch="x86_64")]
use super::avx2_available;
/// Attention scores for a group of `heads` query heads that share the keys:
/// `out[g * n + i] = scale * dot(q[g * hd ..][..hd], keys[i * stride ..][..hd])` with
+6 -2
View File
@@ -1,7 +1,11 @@
//! The AVX2 and AVX-VNNI dot, quantize and multi-activation kernels (x86-64 only).
#[allow(unused_imports)]
use super::*;
use super::{
KernelError, MXFP4_BLOCK_BYTES, Q8_0_BLOCK_BYTES, Q8rRef, check_i4, check_i8, check_multi, check_mx, check_mx_out,
check_q8, check_q8r, check_quantize, simd,
};
#[cfg(target_arch="x86_64")]
use super::{avx2_available, avxvnni_available};
/// AVX2 version of [`dot_i8i8_scalar`]. Activations must be in `[-127, 127]` to match it.
#[cfg(target_arch = "x86_64")]
@@ -1,8 +1,9 @@
//! Functions: `quantize_q8_0_scalar`, `quantize_q8_0_avx2`, `dot_q8_0_q8_0_scalar`, `q8_0_q8_0_isums_scalar` and 10 ...
//! Split out of `c_reference` to keep its files under the line limit.
#[allow(unused_imports)]
use super::*;
use super::{KernelError, avx2_available, check_i4, check_i8, check_mx_out, check_q8, check_quantize, ffi};
#[cfg(target_arch="x86_64")]
use super::avxvnni_available;
/// Quantize floats (a multiple of 32) to Q8_0 blocks; scale = amax / 127 as a half, quants rounded
/// to nearest even and clamped to `[-127, 127]`. Non-finite input gives unspecified (but memory safe)
+4 -2
View File
@@ -1,7 +1,9 @@
//! Operand length and shape checks shared by the scalar and SIMD kernels.
#[allow(unused_imports)]
use super::*;
use super::{
ActRef, AttnShape, BLOCK_ELEMS, KernelError, MAX_DOT_LEN, MULTI_MAX, MXFP4_BLOCK_BYTES, Q8_0_BLOCK_BYTES, Q8rRef,
TILE_MAX,
};
pub(super) fn check_i8(w: &[i8], x: &[i8]) -> Result<(), KernelError> {
if w.len() != x.len() {
+4 -2
View File
@@ -1,7 +1,9 @@
//! The portable scalar reference kernels.
#[allow(unused_imports)]
use super::*;
use super::{
KernelError, MXFP4_BLOCK_BYTES, Q8_0_BLOCK_BYTES, Q8rRef, check_i4, check_i8, check_multi, check_mx, check_mx_out,
check_q8, check_q8r, check_quantize, simd,
};
// ---------------------------------------------------------------------- portable level ----------
@@ -1,7 +1,12 @@
//! Attention score and weighted-sum kernels over f32 keys and values, and the vector exponential.
#[allow(unused_imports)]
use super::*;
use super::{
__m128i, __m256, _CMP_LT_OQ, _MM_FROUND_NO_EXC, _MM_FROUND_TO_NEAREST_INT, _mm_loadu_si128, _mm256_add_epi32,
_mm256_add_ps, _mm256_andnot_ps, _mm256_castsi256_ps, _mm256_cmp_ps, _mm256_cvtph_ps, _mm256_cvtps_epi32,
_mm256_fmadd_ps, _mm256_fnmadd_ps, _mm256_loadu_ps, _mm256_min_ps, _mm256_mul_ps, _mm256_round_ps,
_mm256_set1_epi32, _mm256_set1_ps, _mm256_setzero_ps, _mm256_slli_epi32, _mm256_storeu_ps, AttnShape, ScoreSpec,
hsum_ps,
};
// ---- attention ----
@@ -1,7 +1,11 @@
//! Attention over f16 caches, SwiGLU, f16 conversion and the softmax exponent sum.
#[allow(unused_imports)]
use super::*;
use super::{
__m128i, _MM_FROUND_TO_NEAREST_INT, _mm_loadu_si128, _mm_storeu_si128, _mm256_add_ps, _mm256_cvtph_ps,
_mm256_cvtps_ph, _mm256_div_ps, _mm256_fmadd_ps, _mm256_loadu_ps, _mm256_max_ps, _mm256_min_ps, _mm256_mul_ps,
_mm256_set1_ps, _mm256_setzero_ps, _mm256_storeu_ps, _mm256_sub_ps, AttnShape, ScoreSpec, WeightedSum,
attn_dot_f16, cvt_f32_f16, exp256, hsum_ps, load_f16x8,
};
#[target_feature(enable = "avx2,fma,f16c")]
pub unsafe fn attn_scores_f16_avx2(q: &[f32], keys: &[u16], spec: ScoreSpec, out: &mut [f32]) {
+5 -2
View File
@@ -1,7 +1,10 @@
//! MXFP4 times Q8_0 dot products and their per-block integer sums (AVX2 and AVX-VNNI).
#[allow(unused_imports)]
use super::*;
use super::{
__m256, __m256i, _mm_set1_epi8, _mm256_add_ps, _mm256_cvtepi32_ps, _mm256_dpbusd_avx_epi32, _mm256_fmadd_ps,
_mm256_loadu_si256, _mm256_set1_epi16, _mm256_set1_ps, _mm256_setzero_ps, _mm256_setzero_si256, _mm256_sign_epi8,
MXFP4_BYTES, Q8_0_BYTES, block_p32_avx2, e8m0_half, half_to_f32, hsum_epi32, hsum_ps, mx_table, mx_values,
};
#[inline]
#[target_feature(enable = "avx2,avxvnni")]
@@ -1,7 +1,12 @@
//! Q8_0 times Q8_0 dot products, the q8r4 MXFP4 dot and the AVX2 MXFP4 tile.
#[allow(unused_imports)]
use super::*;
use super::{
__m128i, __m256i, _mm_loadu_si128, _mm_set1_epi8, _mm_xor_si128, _mm256_add_ps, _mm256_cvtepi32_ps,
_mm256_dpbusd_avx_epi32, _mm256_fmadd_ps, _mm256_loadu_si256, _mm256_madd_epi16, _mm256_maddubs_epi16,
_mm256_set_m128i, _mm256_set1_epi16, _mm256_set1_ps, _mm256_setzero_ps, _mm256_setzero_si256, _mm256_sign_epi8,
ActRef, KVALUES_MXFP4, MXFP4_BYTES, Q8_0_BYTES, block_p32_vnni, e8m0_half, half_to_f32, hsum_epi32, hsum_ps,
mx_table, mx_values, mxfp4_scaled_fma,
};
#[target_feature(enable = "avx2,fma,avxvnni")]
pub unsafe fn dot_mxfp4_q8r4_avxvnni(x: &[u8], ys: &[f32], yq: &[i8]) -> f32 {
+7 -2
View File
@@ -1,7 +1,12 @@
//! Activation quantization to Q8_0 blocks (AVX2).
#[allow(unused_imports)]
use super::*;
use super::{
__m256, __m256i, _MM_FROUND_NO_EXC, _MM_FROUND_TO_NEAREST_INT, _mm_cvtss_f32, _mm_max_ps, _mm_max_ss,
_mm_movehdup_ps, _mm_movehl_ps, _mm256_andnot_ps, _mm256_castps256_ps128, _mm256_cvtps_epi32,
_mm256_extractf128_ps, _mm256_loadu_ps, _mm256_max_epi8, _mm256_max_ps, _mm256_mul_ps, _mm256_packs_epi16,
_mm256_packs_epi32, _mm256_permutevar8x32_epi32, _mm256_round_ps, _mm256_set1_epi8, _mm256_set1_ps,
_mm256_setr_epi32, _mm256_storeu_si256, Q8_0_BYTES, cvt_f32_f16,
};
/// The largest absolute value of the 32 floats in `v0..v3`, reduced in the fixed lane order of the portable code.
#[inline]
@@ -1,7 +1,15 @@
//! Horizontal sums, f16 loads, the int8 and int4 dot products and the MXFP4 lookup tables (AVX2 and AVX-VNNI).
#[allow(unused_imports)]
use super::*;
use super::{
__m128i, __m256, __m256i, _MM_FROUND_TO_NEAREST_INT, _mm_abs_epi8, _mm_add_epi32, _mm_add_ps, _mm_add_ss,
_mm_and_si128, _mm_cvtph_ps, _mm_cvtps_ph, _mm_cvtsi32_si128, _mm_cvtsi128_si32, _mm_cvtss_f32,
_mm_dpbusd_avx_epi32, _mm_extract_epi16, _mm_hadd_epi32, _mm_loadu_si128, _mm_movehl_ps, _mm_set_ss, _mm_set1_epi8,
_mm_setzero_si128, _mm_shuffle_ps, _mm_sign_epi8, _mm_srli_epi16, _mm_sub_epi8, _mm_unpackhi_epi8,
_mm_unpacklo_epi8, _mm256_add_epi32, _mm256_castps256_ps128, _mm256_castsi256_si128, _mm256_extractf128_ps,
_mm256_extracti128_si256, _mm256_loadu_si256, _mm256_madd_epi16, _mm256_maddubs_epi16, _mm256_set_m128i,
_mm256_set1_epi8, _mm256_set1_epi16, _mm256_setzero_si256, _mm256_shuffle_epi8, _mm256_sign_epi8, _mm256_sub_epi8,
KVALUES_MXFP4,
};
#[inline]
#[target_feature(enable = "avx2")]
+6 -2
View File
@@ -1,7 +1,11 @@
//! Tile kernels over several rows and activations at once, and the multi-activation reduction.
#[allow(unused_imports)]
use super::*;
use super::{
__m256, __m256i, _mm_set1_epi8, _mm256_add_ps, _mm256_cvtepi32_ps, _mm256_dpbusd_avx_epi32, _mm256_fmadd_ps,
_mm256_loadu_ps, _mm256_loadu_si256, _mm256_madd_epi16, _mm256_maddubs_epi16, _mm256_mul_ps, _mm256_set1_epi8,
_mm256_set1_epi16, _mm256_set1_ps, _mm256_setzero_ps, _mm256_setzero_si256, _mm256_sign_epi8, _mm256_xor_si256,
ActRef, MXFP4_BYTES, Q8_0_BYTES, e8m0_half, half_to_f32, hsum_ps, mx_table_biased, mx_values, mxfp4_tile_avx2,
};
/// MXFP4 rows against activations, AVX-VNNI with unsigned weights.
#[inline]
+3 -2
View File
@@ -1,7 +1,8 @@
//! Prepared activations and the tile kernels that take several rows and activations at once.
#[allow(unused_imports)]
use super::*;
use super::{ActRef, BLOCK_ELEMS, KernelError, MXFP4_BLOCK_BYTES, Q8_0_BLOCK_BYTES, check_tile, simd};
#[cfg(target_arch="x86_64")]
use super::{avx2_available, avxvnni_available};
/// Largest number of rows or activations in one tile.
pub const TILE_MAX: usize = 4;
@@ -1,8 +1,9 @@
//! Methods of `Strategy`: `as_str`. Methods of `Plan`: `from_env`, `with_overrides`. Implements `Default for Plan`.
//! Functions: `open_direct`, `open_direct`, `read_at`, `read_at` and 3 more.
#[allow(unused_imports)]
use super::*;
use super::{
ALIGN, Aligned, AtomicU64, Duration, File, Instant, Mutex, Ordering, Plan, Report, Shared, Strategy, io, strategy,
};
impl Strategy {
pub fn as_str(self) -> &'static str {
@@ -1,8 +1,11 @@
//! Functions: `stream_buffer_bytes`, `stream_buffer_bytes`, `with_test_stream_buffer`.
//! Split out of `gguf` to keep its files under the line limit.
#[allow(unused_imports)]
use super::*;
use super::{
BTreeMap, BufRead, BufReader, Digest, Error, File, HashSet, Path, Read, STREAM_BUFFER_BYTES, Seek, SeekFrom, Sha256,
};
#[cfg(test)]
use super::STREAM_BUFFER_TEST_OVERRIDE;
// Production always uses `STREAM_BUFFER_BYTES`. Tests may shrink the span
// stream buffer on their own thread to exercise multi-chunk behaviour with
@@ -1,5 +1,9 @@
//! Opt-in transport only. The original digest/index gates still own admission.
use super::*;
use super::{
BTreeMap, BufRead, BufReader, Cursor, Digest, Error, File, HashSet, IndexRules, Path, Read, ResidentTensor, Result,
Seek, SeekFrom, Sha256, TensorIndex, VerifiedGgufFile, cursor, ensure_size, open_regular_file,
parse_artifact_digest, parse_index, read_index_file, resident, stream_file_span,
};
use crate::qwen4exp::ProvisionalExpertSource;
pub(crate) fn open_expert_capture(
@@ -1,5 +1,8 @@
//! Retained actual admitted file, not a caller pointer or an immutable-file claim.
use super::*;
use super::{
BTreeMap, BufRead, BufReader, Digest, Error, File, HashSet, Path, Read, Result, Seek, SeekFrom, Sha256,
VerifiedGgufFile,
};
#[cfg(unix)]
use std::os::unix::fs::MetadataExt;
pub struct ExpertFileOwner {
+4 -1
View File
@@ -1,6 +1,9 @@
//! Actual immutable bytes loaded from one admitted retained source owner.
//! No finite, runtime row, activation or device certificate is minted here.
use super::*;
use super::{
BTreeMap, BufRead, BufReader, Digest, Error, File, GgufSourceFence, HashSet, Path, Read, Result, Seek, SeekFrom,
Sha256, VerifiedGgufFile, resident,
};
use std::sync::atomic::{AtomicU64, Ordering};
// Private source-owner identity, assigned only after actual admitted-file fill.
@@ -1,8 +1,10 @@
//! Methods of `ResidentTensor`: `charged_bytes`, `len`, `file_mapped`, `backing`.
//! Methods of `ResidentStorage`: `backing`, `as_slice`, `len`.
#[allow(unused_imports)]
use super::*;
use super::{
AtomicU64, BTreeMap, BufRead, BufReader, Digest, Error, File, FileSpan, HashSet, NEXT_SOURCE_ID, Ordering, Path,
Read, ResidentStorage, ResidentTensor, Result, Seek, SeekFrom, Sha256,
};
pub(super) fn next_source_id() -> Result<u64> {
let mut current = NEXT_SOURCE_ID.load(Ordering::Relaxed);
@@ -1,8 +1,11 @@
//! Methods of `VerifiedGgufFile`: `load_resident_tensor`, `resident_extent`, `load_huge`, `load_heap` and 7 more.
//! Methods of `GgufSourceFence`: `copy_resident_tensor`. Functions: `mapping_granularity`, `mapping_granularity`.
#[allow(unused_imports)]
use super::*;
use super::{
AtomicU64, BTreeMap, BufRead, BufReader, Digest, Error, File, FileSpan, GgufSourceFence, HashSet, Ordering, Path,
Read, ResidentLoadError, ResidentStorage, ResidentTensor, Result, Seek, SeekFrom, Sha256, VerifiedGgufFile,
next_source_id, resident,
};
type LoadResult<T> = std::result::Result<T, ResidentLoadError>;
@@ -1,8 +1,10 @@
//! Methods of `KarPleRowReader`: `read_rows`.
//! Functions: `independent_handles`, `reopen_independent`, `reopen_independent`, `read_rows_parallel` and 11 more.
#[allow(unused_imports)]
use super::*;
use super::{
COLD_SKIP, COLD_SKIP_CALLS, Digest, File, HashSet, KarError, KarPleRowPacket, KarPleRowReader, PLE_ROWS, Read,
Seek, SeekFrom, Sha256, VerifiedPart, WARM_ROW_NS,
};
/// `n` handles on `file` that can serve reads at the same time; the file itself when no more can be had.
pub(super) fn independent_handles(file: &File, n: usize) -> Vec<File> {
@@ -1,8 +1,10 @@
//! Methods of `KarPleProfile`: `new`, `with_total_rows`, `native_shard_sha256`.
//! Methods of `KarPleRowPacket`: `payload`, `partition`.
#[allow(unused_imports)]
use super::*;
use super::{
Digest, File, HashSet, KarError, KarPlePartProvenance, KarPleProfile, KarPleProfileSpec, KarPleRowPacket,
KarStartupRead, KarTrust, PLE_ROWS, Read, Seek, SeekFrom, Sha256,
};
impl KarPleProfile {
/// Bounds validation does not authenticate the manifest's origin. Only the
@@ -1,8 +1,11 @@
//! Methods of `Selection`: `window_error`, `resident_prefix_bytes`, `window`, `rows` and 1 more.
//! Methods of `GpuWindow`: `new`, `staged_source_bytes`, `scratch`.
#[allow(unused_imports)]
use super::*;
use super::{
ArchiveSlot, BTreeMap, EXPERT_ROLES, GpuRows, GpuWindow, KarError, KarInspection, KarLevelSelector, KarLevelsError,
KernelModelError, MAX_TOKENS, RangeSource, Result, RowPlan, RowShape, SCRATCH_ALIGN, STATUS_BYTES, ScratchBudget,
ScratchBytes, Selection, WindowPlan, model, selection,
};
impl Selection<'_> {
pub(super) fn window_error(&self, reason: KernelModelError) -> KarLevelsError {
@@ -1,8 +1,10 @@
//! Methods of `PleReaderConfig`: `new`. Methods of `ReaderStats`: `percentile`.
//! Implements `PageSource for File`, `Display for PleError` and 1 more.
#[allow(unused_imports)]
use super::*;
use super::{
AlignedBuf, Arc, Condvar, Duration, EMPTY, File, HashMap, Instant, JoinHandle, Mutex, MutexGuard, PAGE, PageSource,
PlannedRead, PleError, PleReaderConfig, ROW_BYTES, ReaderStats, RowCache, State, Use, VecDeque, WAYS, fmt, io,
};
impl PageSource for File {
fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result<usize> {
@@ -1,6 +1,15 @@
//! Provisional transport: deliberately no byte accessor, source certificate,
//! Clone, or model view. Only the genuine model's bank boundary consumes it.
use super::*;
use super::{
BANKS, BTreeMap, BTreeSet, Bank, BankDescriptor, BindingError, Cell, Error, FUTURE_HEADROOM, LayerRole,
PINNED_IDENTITIES, Qwen4ExpArtifact, Rc, ResidentExpertBank, ResidentExpertSourceError, ResidentExpertSourceReport,
ResolvedTensor, SOURCE_CAP, TensorIndex, TensorRole, VerifiedGgufFile, checked_descriptor, expert_roles, gguf,
retention_metadata_bytes, size_of, slot,
};
#[cfg(any(target_os="linux", windows, not(any(target_os="linux",windows))))]
use super::memory_available;
#[cfg(target_os="linux")]
use super::Read;
use std::{fs::File, path::Path};
const RETAINED_KAR_BYTES: u64 = 55_295_529_472;
@@ -1,5 +1,8 @@
//! Optional raw encoded source retention, distinct from finite/device admission.
use super::*;
use super::{
BTreeMap, BTreeSet, BindingError, Error, LayerRole, PINNED_IDENTITIES, Qwen4ExpArtifact, ResolvedTensor,
TensorIndex, TensorRole, VerifiedGgufFile, expert_roles, fmt, gguf, io, plan_stream_rows, topology,
};
use std::{cell::Cell, mem::size_of, rc::Rc};
#[cfg(target_os = "linux")]
use std::{fs::File, io::Read};
@@ -1,8 +1,16 @@
//! Methods of `Qwen4ExpArtifact`: `load_resident_expert_source`, `check_expert_layout`, `plan_banks`, `load_banks` a...
//! Methods of `ResidentExpertBankLease`: `bank_count`, `source_bytes`, `charged_source_bytes`, `file_mapped` and 1 m...
#[allow(unused_imports)]
use super::*;
use super::{
BANKS, BTreeMap, BTreeSet, Bank, BankDescriptor, BindingError, Cell, Error, FUTURE_HEADROOM, Qwen4ExpArtifact, Rc,
ResidentExpertBank, ResidentExpertBankLease, ResidentExpertBankMember, ResidentExpertSourceError,
ResidentExpertSourceReport, SOURCE_CAP, TensorRole, admit, checked_descriptor, expert_roles, gguf,
retention_metadata_bytes, size_of, slot, topology,
};
#[cfg(any(target_os="linux", windows, not(any(target_os="linux",windows))))]
use super::memory_available;
#[cfg(target_os="linux")]
use super::{File, Read};
/// The memory the admission saw: `MemAvailable` bytes observed and the headroom kept for the future.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -1,8 +1,13 @@
//! Methods of `ResidentExpertBank`: `note_copy`, `report`, `tensor`.
//! Implements `Display for ResidentExpertSourceError`, `Error for ResidentExpertSourceError`.
#[allow(unused_imports)]
use super::*;
use super::{
BANKS, BTreeMap, BTreeSet, Bank, BankDescriptor, BindingError, Cell, Error, FUTURE_HEADROOM, LayerRole, Rc,
ResidentExpertBank, ResidentExpertSourceError, ResidentExpertSourceReport, ResolvedTensor, SOURCE_CAP, TensorRole,
fmt, gguf, plan_stream_rows, size_of,
};
#[cfg(target_os="linux")]
use super::{File, Read};
// Rc headers plus the small owners, never a second encoded payload allocation.
pub(super) fn retention_metadata_bytes() -> Result<usize, ResidentExpertSourceError> {
@@ -1,6 +1,9 @@
//! Literal FileExpertSource GGUF role directory. No payload copy, finite or
//! pinning authority. The immutable directory retains the actual admitted FD.
use super::*;
use super::{
BTreeMap, BTreeSet, BindingError, Error, LayerRole, Qwen4ExpArtifact, ResolvedTensor, TensorRole, gguf,
plan_stream_rows,
};
use std::mem::size_of;
#[derive(Clone, Copy)]
pub struct FileExpertExtent {
@@ -1,8 +1,10 @@
//! Methods of `Case`: `new`, `gate_up`, `down`.
//! Functions: `quantize_acts`, `cpu_blob`, `iq_gate_up`, `time_ggml_gu` and 15 more. Defines `Fail`, `Case`, `KqCase`.
#[allow(unused_imports)]
use super::*;
use super::{
FF, H, Instant, Kind, NT, NativeActivation, NativeFormat, bench, bits, c_int, cpu, dot, elapsed, ggml_rows,
iq4nl_hq, name, numerical, outputs, printf, refs, rel, zeros,
};
use std::ffi::CStr;
type Fail<T> = std::result::Result<T, String>;
@@ -1,8 +1,10 @@
//! Functions: `float_reference`, `reference_shapes_ok`, `swiglu_hidden`, `project_down` and 21 more. Defines `Fail`.
//! Split out of `rust_bench_frontend` to keep its files under the line limit.
#[allow(unused_imports)]
use super::*;
use super::{
CString, Error, FF, H, Kind, NT, NativeFormat, ParityGpu, Q81Owner, Result, bench, bits, cpu, cpu_blob, name,
numerical, printf, rel, zeros,
};
type Fail<T> = std::result::Result<T, String>;
@@ -1,8 +1,7 @@
//! Functions: `numerical`, `zeros`, `refs`, `outputs` and 11 more.
//! Split out of `rust_bench_frontend` to keep its files under the line limit.
#[allow(unused_imports)]
use super::*;
use super::{CString, Error, FF, H, Instant, Kind, NAMES, NT, NativeActivation, NativeFormat, Result, bench, cpu};
pub(super) fn numerical<T>(r: Result<T>) -> std::result::Result<T, String> {
r.map_err(|e| format!("CPU benchmark: {e:?}"))
@@ -1,8 +1,10 @@
//! Running the parity bench: the synthetic and layer modes, the formats, `unbound_main` and `run`.
//! Apart from `numerical` and `float_reference`, which hold the references the run compares to.
#[allow(unused_imports)]
use super::*;
use super::{
CString, FF, H, NativeFormat, ParityGpu, USAGE, bench, c_int, check_bf16, check_blob, check_q5_one, gpu, model,
native_fmt, numerical, printf, setenv, setvbuf, stdout, type_of,
};
/// # Safety
/// Call ONLY at process entry before any thread or native CPU dispatch exists:
@@ -1,8 +1,7 @@
//! Methods of `Kind`: `from_original`, `original_id`, `block`, `row_bytes` and 3 more. Methods of `ActKind`: `bytes`.
//! Functions: `alloc`, `store_f16`, `bf16_bits`, `store_bf16` and 1 more.
#[allow(unused_imports)]
use super::*;
use super::{ActKind, Activation, Error, Kind, Result, Storage, to_half};
/// Every `Kind` in declaration order; `KIND_IDS` and `KIND_BLOCKS` are indexed by `kind as usize`.
const KINDS: [Kind; 28] = [
@@ -1,8 +1,13 @@
//! Methods of `NativeFormat`: `offsets`, `new`, `validate`.
//! Functions: `iq4nl_dot`, `dot_zero`, `dot_k`, `dot` and 8 more.
#[allow(unused_imports)]
use super::*;
use super::{
__m256, _mm_loadu_si128, _mm256_add_ps, _mm256_castsi256_ps, _mm256_cvtepi32_ps, _mm256_cvtepu16_epi32,
_mm256_cvtph_ps, _mm256_fmadd_ps, _mm256_loadu_ps, _mm256_loadu_si256, _mm256_madd_epi16, _mm256_maddubs_epi16,
_mm256_mul_ps, _mm256_set1_epi8, _mm256_set1_epi16, _mm256_set1_ps, _mm256_setzero_ps, _mm256_slli_epi32,
_mm256_sub_epi8, _mm256_xor_si256, Activation, Error, Kind, NativeFormat, Q8K, Q8Zero, Result, Storage, half,
hsum_ggml, hsum_original,
};
impl NativeFormat {
/// Byte offsets of the up matrix, the down matrix and the whole blob for the given row sizes.
@@ -1,8 +1,7 @@
//! Functions: `raw_align`, `quantize_half_raw`, `quantize_raw`, `dot_raw_zero` and 2 more.
//! Split out of `rust_ggml` to keep its files under the line limit.
#[allow(unused_imports)]
use super::*;
use super::{ActKind, Kind, Q8K, Q8One, Q8Zero, bf16_bits, float_dot, iq4nl_dot, q1_dot, q2_generic, to_half};
/// Alignment the encoded activation of `kind` is reinterpreted with (F32: bytes, K: `Q8K`, others: `u16`/`Q8*`).
fn raw_align(kind: Kind) -> usize {
@@ -2,8 +2,16 @@
//! generic dots.
//! Apart from `iq4nl_n` and `u16`, which hold other widths of the same kernels.
#[allow(unused_imports)]
use super::*;
use super::{
__m128i, __m256i, __m512i, _mm_and_si128, _mm_loadu_si128, _mm_set1_epi8, _mm_shuffle_epi8, _mm_srli_epi16,
_mm256_add_epi32, _mm256_castsi128_si256, _mm256_cvtepi32_ps, _mm256_fmadd_ps, _mm256_inserti128_si256,
_mm256_loadu_si256, _mm256_madd_epi16, _mm256_maddubs_epi16, _mm256_set1_epi16, _mm256_set1_ps, _mm256_setzero_ps,
_mm256_setzero_si256, _mm256_sign_epi8, _mm512_add_epi32, _mm512_castsi256_si512, _mm512_cvtepi32_ps,
_mm512_cvtepu8_epi32, _mm512_fmadd_ps, _mm512_i32gather_epi32, _mm512_inserti64x4, _mm512_loadu_si512,
_mm512_madd_epi16, _mm512_maddubs_epi16, _mm512_mask_add_epi32, _mm512_mask_sub_epi8, _mm512_reduce_add_ps,
_mm512_set1_epi32, _mm512_set1_ps, _mm512_setzero_ps, _mm512_setzero_si512, IQ3S_GRID, IQ3XXS_GRID, KVALUES_IQ4NL,
Q8K, Q8Zero, decode, decoded, factor, format_bytes, half, hsum_ggml, iq3_half, iq4nl_n, prefetch, signs32, u16,
};
/// IQ3 formats (`iq3_multi_fast`): both halves' grid words straight into the 512-bit register, lane order = `decode`'s
/// byte order. Returns the grid bytes, the 16-bit scales and the sign mask of sub-block `j`.
@@ -1,8 +1,12 @@
//! Functions: `iq4nl_values`, `iq4nl_block`, `iq4nl_alternating`, `iq4nl_n`.
//! Split out of `rust_iq` to keep its files under the line limit.
#[allow(unused_imports)]
use super::*;
use super::{
__m128i, __m256, __m256i, _mm_and_si128, _mm_loadu_si128, _mm_set1_epi8, _mm_shuffle_epi8, _mm_srli_epi16,
_mm256_add_ps, _mm256_castsi128_si256, _mm256_cvtepi32_ps, _mm256_fmadd_ps, _mm256_inserti128_si256,
_mm256_loadu_si256, _mm256_madd_epi16, _mm256_maddubs_epi16, _mm256_set1_epi16, _mm256_set1_ps, _mm256_setzero_ps,
_mm256_sign_epi8, KVALUES_IQ4NL, Q8Zero, half, hsum_ggml, hsum_original, prefetch, u16,
};
/// The 32 IQ4_NL values (signed bytes) of one 18-byte block.
#[target_feature(enable = "avx2,fma,f16c")]
+7 -2
View File
@@ -1,8 +1,13 @@
//! Functions: `u16`, `u32`, `format_bytes`, `factor` and 17 more.
//! Split out of `rust_iq` to keep its files under the line limit.
#[allow(unused_imports)]
use super::*;
use super::{
__m256i, _mm_loadl_epi64, _mm256_add_epi32, _mm256_and_si256, _mm256_cvtepi32_ps, _mm256_cvtepu8_epi32,
_mm256_fmadd_ps, _mm256_loadu_si256, _mm256_madd_epi16, _mm256_maddubs_epi16, _mm256_or_si256, _mm256_set1_epi32,
_mm256_set1_ps, _mm256_setr_epi32, _mm256_setzero_ps, _mm256_setzero_si256, _mm256_sign_epi8, _mm256_slli_epi32,
_mm256_srlv_epi32, _mm256_storeu_si256, IQ2S_GRID, IQ2XS_GRID, IQ2XXS_GRID, IQ3S_GRID, IQ3XXS_GRID, KSIGNS_IQ2XS,
KVALUES_IQ4NL, Q8K, dot_multi512_impl, half, hsum_original, prefetch, signs32,
};
// Bounds: `row` is walked with chunks_exact/checked slicing and every activation block is safe-indexed (`y[i]`), so
// a short operand panics instead of reading past it. The raw loads are 32/64 bytes at 64*j+32*h (j<4,h<2) of a
@@ -1,8 +1,10 @@
//! Functions: `admit`, `gate_up_rows`, `down_rows`, `admit_expert` and 9 more. Defines `RowSpace`.
//! Split out of `rust_legacy` to keep its files under the line limit.
#[allow(unused_imports)]
use super::*;
use super::{
ActQ, BLOB, D_CODES, D_SCALES, Error, FF, GU_SCALES, GateUpOut, H, MAX_ROWS, PlanarActivation, PlanarScratch,
Result, act_refs, down_row, gate_up_pair, half, legacy_supported, oracle_q8_zero_enabled, silu, whole_single,
};
/// The output width of a legacy row-range entry point and the chunk count its activations must have.
#[derive(Clone, Copy)]
@@ -1,8 +1,10 @@
//! Implements `Default for SingleScratch`. Functions: `gate_each`, `down_each`, `whole_single`.
//! Split out of `rust_legacy` to keep its files under the line limit.
#[allow(unused_imports)]
use super::*;
use super::{
ActQ, FF, GateUpOut, MAX_ROWS, PlanarActivation, SingleScratch, act_refs, down_row, gate_up_pair,
oracle_q8_zero_enabled, silu,
};
// Disjoint row cells are written by the pool callback; it never creates an
// overlapping mutable whole-row slice while another worker owns another range.
@@ -1,8 +1,7 @@
//! STRA-338 size4: the row-pair helpers shared by the legacy planar entry points (`gate_each`, `down_each`,
//! `whole_single`, `gate_up_rows`, `down_rows`, `expert_quantized`).
#[allow(unused_imports)]
use super::*;
use super::{ActQ, D_CODES, D_SCALES, GU_SCALES, MAX_ROWS, PlanarActivation, row};
/// The per-token `ActQ` references of `a` (unused slots point at `empty`).
pub(super) fn act_refs<'a>(a: &'a [&PlanarActivation], empty: &'a ActQ) -> [&'a ActQ; MAX_ROWS] {
@@ -1,8 +1,18 @@
//! Methods of `PlanarActivation`: `quantize`, `quantize_oracle`, `quantize_native`.
//! Implements `Default for PlanarActivation`, `Default for PlanarScratch`.
#[allow(unused_imports)]
use super::*;
use super::{
__cpuid, __cpuid_count, __m256, __m256i, __m512, _mm_add_epi32, _mm_cvtsi128_si32, _mm_hadd_epi32, _mm_loadl_epi64,
_mm_loadu_si128, _mm_maskz_loadu_epi16, _mm256_and_si256, _mm256_castsi256_si128, _mm256_cvtepi32_ps,
_mm256_cvtepu16_epi64, _mm256_cvtph_ps, _mm256_dpbusd_epi32, _mm256_extracti128_si256, _mm256_fmadd_ps,
_mm256_loadu_si256, _mm256_multishift_epi64_epi8, _mm256_set1_epi8, _mm256_set1_epi64x, _mm256_set1_ps,
_mm256_setzero_ps, _mm256_setzero_si256, _mm512_add_epi32, _mm512_and_si512, _mm512_castps256_ps512,
_mm512_cvtepi32_ps, _mm512_cvtepu16_epi64, _mm512_dpbusd_epi32, _mm512_fmadd_ps, _mm512_loadu_si512,
_mm512_maskz_loadu_ps, _mm512_maskz_mov_ps, _mm512_mul_ps, _mm512_multishift_epi64_epi8, _mm512_permutexvar_ps,
_mm512_reduce_add_ps, _mm512_set1_epi8, _mm512_set1_epi32, _mm512_set1_epi64, _mm512_setr_epi32, _mm512_setzero_ps,
_mm512_setzero_si512, _xgetbv, ActQ, Error, FF, H, MAX_ROWS, ORACLE, OnceLock, Ordering, PlanarActivation,
PlanarScratch, Result, SingleScratch, hsum_original,
};
pub fn set_oracle_q8_zero(enabled: bool) {
ORACLE.store(enabled, Ordering::Relaxed);
@@ -3,7 +3,7 @@
//! its first task, when it finished its last one, how long it computed and how many tasks it took; the host
//! snapshots the phase when all tasks are done. Times are nanoseconds from the publication of the phase.
use super::*;
use super::{AtomicU32, AtomicU64, Instant, Ordering};
/// Tasks of one phase never exceed 3 per thread of 16 threads; the table keeps a margin.
const TASK_TABLE: usize = 256;
+12 -2
View File
@@ -564,8 +564,18 @@ class Plan:
return {p for p, _ in mod.anon}
def _own_names(self, mod):
items, uses, _ = mod.parsed()
return set(items) | {n for n, _, _ in uses} | set(mod.children)
"""Names the module declares, imports by name, or takes from its own globs other than `use super::*`."""
items, uses, globs = mod.parsed()
names = set(items) | {n for n, _, _ in uses} | set(mod.children)
for path, _ in globs:
if path == ["super"]:
continue
target = self.crate.resolve_module(mod, path)
if target is not None:
inner = self.crate.names(target, self.crate.is_ancestor(target, mod))
if inner is not OPAQUE:
names |= set(inner)
return names
def apply(self, files, needs):
done = []
+2 -2
View File
@@ -159,7 +159,7 @@ def statements(stripped):
ITEM_RE = re.compile(
r"^(pub(?:\s*\([^)]*\))?\s+)?"
r"(?:(?:unsafe|async|const|default)\s+|extern\s*(?:\"\"\s*)?)*"
rf"(fn|struct|enum|trait|union|type|const|static|mod)\s+({IDENT})"
rf"(fn|struct|enum|trait|union|type|const|static|mod)\s+(?:mut\s+)?({IDENT})"
)
@@ -275,7 +275,7 @@ class Module:
continue
if re.match(r"(?:unsafe\s+)?extern\s*(?:\"\"\s*)?\{", head):
for vis, kind, name in re.findall(
rf"(pub(?:\s*\([^)]*\))?\s+)?(?:safe\s+|unsafe\s+)?(fn|static)\s+({IDENT})", head
rf"(pub(?:\s*\([^)]*\))?\s+)?(?:safe\s+|unsafe\s+)?(fn|static)\s+(?:mut\s+)?({IDENT})", head
):
items[name.removeprefix("r#")] = (bool(vis), kind)
mark(name.removeprefix("r#"), attrs)