ci: wire up CI, fix no_std build, fix stale package names in scripts
CI / test (push) Failing after 15s

- Add .gitea/workflows/ci.yml running scripts/ci-test.sh (fmt, clippy,
  test, no_std check) on push/PR to main.
- Fix stale rustyhdf5-py/rustyhdf5-format package names in
  ci-test.sh/check-nostd.sh, which had been silently no-op'ing those
  checks (cargo warns but doesn't fail on an unknown --exclude/-p
  target).
- With those checks actually running, fix the real issues they surface:
  - clippy: useless_conversion in chunked_write.rs, byte_char_slices in
    global_heap.rs/object_header.rs.
  - cargo fmt: apply formatting across the workspace (whitespace only).
  - no_std (thumbv7em-none-eabihf) build errors in clawhdf5-format:
    core::sync::atomic::AtomicU64 doesn't exist on that target (no
    native 64-bit atomics) — switch profiling.rs's counters to
    portable-atomic, which falls back to a CAS-based emulation there
    and is a no-op wrapper elsewhere. Add missing alloc imports for
    Box (filters.rs), Vec (filters_szip.rs), and format! (dict_encoding.rs)
    on no_std paths. Replace f64::powi (std/libm-only) with a small
    local exponentiation-by-squaring helper in the scale-offset filter.
This commit is contained in:
Omar Sobh
2026-08-05 10:50:13 -07:00
parent b70d594c4f
commit 55959b4920
34 changed files with 590 additions and 365 deletions
+89 -83
View File
@@ -13,42 +13,44 @@ use std::arch::x86_64::*;
/// Caller must verify is_x86_feature_detected!("avx512f").
// SAFETY: Caller must have verified avx512f via is_x86_feature_detected!.
#[target_feature(enable = "avx512f")]
pub unsafe fn dot_product(a: &[f32], b: &[f32]) -> f32 { unsafe {
assert_eq!(a.len(), b.len());
let len = a.len();
let mut i = 0;
let mut acc0 = _mm512_setzero_ps();
let mut acc1 = _mm512_setzero_ps();
pub unsafe fn dot_product(a: &[f32], b: &[f32]) -> f32 {
unsafe {
assert_eq!(a.len(), b.len());
let len = a.len();
let mut i = 0;
let mut acc0 = _mm512_setzero_ps();
let mut acc1 = _mm512_setzero_ps();
// Process 32 elements per iteration (2x16 unrolled)
while i + 32 <= len {
let va0 = _mm512_loadu_ps(a.as_ptr().add(i));
let vb0 = _mm512_loadu_ps(b.as_ptr().add(i));
acc0 = _mm512_fmadd_ps(va0, vb0, acc0);
// Process 32 elements per iteration (2x16 unrolled)
while i + 32 <= len {
let va0 = _mm512_loadu_ps(a.as_ptr().add(i));
let vb0 = _mm512_loadu_ps(b.as_ptr().add(i));
acc0 = _mm512_fmadd_ps(va0, vb0, acc0);
let va1 = _mm512_loadu_ps(a.as_ptr().add(i + 16));
let vb1 = _mm512_loadu_ps(b.as_ptr().add(i + 16));
acc1 = _mm512_fmadd_ps(va1, vb1, acc1);
let va1 = _mm512_loadu_ps(a.as_ptr().add(i + 16));
let vb1 = _mm512_loadu_ps(b.as_ptr().add(i + 16));
acc1 = _mm512_fmadd_ps(va1, vb1, acc1);
i += 32;
i += 32;
}
if i + 16 <= len {
let va = _mm512_loadu_ps(a.as_ptr().add(i));
let vb = _mm512_loadu_ps(b.as_ptr().add(i));
acc0 = _mm512_fmadd_ps(va, vb, acc0);
i += 16;
}
let mut sum = _mm512_reduce_add_ps(_mm512_add_ps(acc0, acc1));
while i < len {
sum += a[i] * b[i];
i += 1;
}
sum
}
if i + 16 <= len {
let va = _mm512_loadu_ps(a.as_ptr().add(i));
let vb = _mm512_loadu_ps(b.as_ptr().add(i));
acc0 = _mm512_fmadd_ps(va, vb, acc0);
i += 16;
}
let mut sum = _mm512_reduce_add_ps(_mm512_add_ps(acc0, acc1));
while i < len {
sum += a[i] * b[i];
i += 1;
}
sum
}}
}
/// AVX-512 cosine similarity — fused single pass.
///
@@ -56,38 +58,40 @@ pub unsafe fn dot_product(a: &[f32], b: &[f32]) -> f32 { unsafe {
/// Caller must verify is_x86_feature_detected!("avx512f").
// SAFETY: Caller must have verified avx512f via is_x86_feature_detected!.
#[target_feature(enable = "avx512f")]
pub unsafe fn cosine_similarity(a: &[f32], b: &[f32]) -> f32 { unsafe {
assert_eq!(a.len(), b.len());
let len = a.len();
let mut i = 0;
pub unsafe fn cosine_similarity(a: &[f32], b: &[f32]) -> f32 {
unsafe {
assert_eq!(a.len(), b.len());
let len = a.len();
let mut i = 0;
let mut dot_acc = _mm512_setzero_ps();
let mut norm_a_acc = _mm512_setzero_ps();
let mut norm_b_acc = _mm512_setzero_ps();
let mut dot_acc = _mm512_setzero_ps();
let mut norm_a_acc = _mm512_setzero_ps();
let mut norm_b_acc = _mm512_setzero_ps();
while i + 16 <= len {
let va = _mm512_loadu_ps(a.as_ptr().add(i));
let vb = _mm512_loadu_ps(b.as_ptr().add(i));
dot_acc = _mm512_fmadd_ps(va, vb, dot_acc);
norm_a_acc = _mm512_fmadd_ps(va, va, norm_a_acc);
norm_b_acc = _mm512_fmadd_ps(vb, vb, norm_b_acc);
i += 16;
while i + 16 <= len {
let va = _mm512_loadu_ps(a.as_ptr().add(i));
let vb = _mm512_loadu_ps(b.as_ptr().add(i));
dot_acc = _mm512_fmadd_ps(va, vb, dot_acc);
norm_a_acc = _mm512_fmadd_ps(va, va, norm_a_acc);
norm_b_acc = _mm512_fmadd_ps(vb, vb, norm_b_acc);
i += 16;
}
let mut dot = _mm512_reduce_add_ps(dot_acc);
let mut norm_a = _mm512_reduce_add_ps(norm_a_acc);
let mut norm_b = _mm512_reduce_add_ps(norm_b_acc);
while i < len {
dot += a[i] * b[i];
norm_a += a[i] * a[i];
norm_b += b[i] * b[i];
i += 1;
}
let denom = (norm_a * norm_b).sqrt();
if denom == 0.0 { 0.0 } else { dot / denom }
}
let mut dot = _mm512_reduce_add_ps(dot_acc);
let mut norm_a = _mm512_reduce_add_ps(norm_a_acc);
let mut norm_b = _mm512_reduce_add_ps(norm_b_acc);
while i < len {
dot += a[i] * b[i];
norm_a += a[i] * a[i];
norm_b += b[i] * b[i];
i += 1;
}
let denom = (norm_a * norm_b).sqrt();
if denom == 0.0 { 0.0 } else { dot / denom }
}}
}
/// AVX-512 L2 distance.
///
@@ -95,27 +99,29 @@ pub unsafe fn cosine_similarity(a: &[f32], b: &[f32]) -> f32 { unsafe {
/// Caller must verify is_x86_feature_detected!("avx512f").
// SAFETY: Caller must have verified avx512f via is_x86_feature_detected!.
#[target_feature(enable = "avx512f")]
pub unsafe fn l2_distance(a: &[f32], b: &[f32]) -> f32 { unsafe {
assert_eq!(a.len(), b.len());
let len = a.len();
let mut i = 0;
let mut acc = _mm512_setzero_ps();
pub unsafe fn l2_distance(a: &[f32], b: &[f32]) -> f32 {
unsafe {
assert_eq!(a.len(), b.len());
let len = a.len();
let mut i = 0;
let mut acc = _mm512_setzero_ps();
while i + 16 <= len {
let va = _mm512_loadu_ps(a.as_ptr().add(i));
let vb = _mm512_loadu_ps(b.as_ptr().add(i));
let diff = _mm512_sub_ps(va, vb);
acc = _mm512_fmadd_ps(diff, diff, acc);
i += 16;
while i + 16 <= len {
let va = _mm512_loadu_ps(a.as_ptr().add(i));
let vb = _mm512_loadu_ps(b.as_ptr().add(i));
let diff = _mm512_sub_ps(va, vb);
acc = _mm512_fmadd_ps(diff, diff, acc);
i += 16;
}
let mut sum = _mm512_reduce_add_ps(acc);
while i < len {
let d = a[i] - b[i];
sum += d * d;
i += 1;
}
sum.sqrt()
}
let mut sum = _mm512_reduce_add_ps(acc);
while i < len {
let d = a[i] - b[i];
sum += d * d;
i += 1;
}
sum.sqrt()
}}
}