Skip to content

Commit 495c515

Browse files
czoli1976kali
authored andcommitted
linalg/x86_64: build on the 1.91 MSRV and the cfg-off path
The AMX / AVX-VNNI detection reads CPUID via std::arch::x86_64::__cpuid_count. That intrinsic is `unsafe` on tract's MSRV (rustc 1.91) but was made safe in a later release, so the calls compiled locally yet broke every 1.91 CI job with E0133. Wrap each call in `unsafe { }` (required on 1.91) and add `#[allow(unused_unsafe)]` so newer toolchains, where the call is safe, don't trip `unused_unsafe` under `-D warnings`. Also gate the `PackedI8K4` and `super::amx` imports in mmm.rs on the cfgs that actually use them, so the old-assembler build (Debian stretch, all kernel cfgs off) has no unused-import warnings. Verified: tract-linalg compiles on rustc 1.91.0 and 1.94, clippy-clean. https://claude.ai/code/session_018Hes6yEvk2TSWB26SAJfqT
1 parent 51196c8 commit 495c515

4 files changed

Lines changed: 14 additions & 6 deletions

File tree

linalg/src/x86_64_fma/amx.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ pub fn cache_sizes() -> CacheSizes {
5252
*CACHE.get_or_init(|| {
5353
let mut out = CacheSizes::default();
5454
for sub in 0..16 {
55-
let r = std::arch::x86_64::__cpuid_count(4, sub);
55+
#[allow(unused_unsafe)]
56+
let r = unsafe { std::arch::x86_64::__cpuid_count(4, sub) };
5657
let cache_type = r.eax & 0x1F;
5758
if cache_type == 0 {
5859
break;
@@ -83,7 +84,8 @@ fn cpu_has_amx_int8() -> bool {
8384
if !std::is_x86_feature_detected!("avx512f") {
8485
return false;
8586
}
86-
let r = std::arch::x86_64::__cpuid_count(7, 0);
87+
#[allow(unused_unsafe)]
88+
let r = unsafe { std::arch::x86_64::__cpuid_count(7, 0) };
8789
// bit 24 = AMX-TILE, bit 25 = AMX-INT8 in EDX.
8890
const AMX_TILE: u32 = 1 << 24;
8991
const AMX_INT8: u32 = 1 << 25;

linalg/src/x86_64_fma/amx_bf16.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ fn cpu_has_amx_bf16() -> bool {
3030
if !std::is_x86_feature_detected!("avx512f") {
3131
return false;
3232
}
33-
let r = std::arch::x86_64::__cpuid_count(7, 0);
33+
#[allow(unused_unsafe)]
34+
let r = unsafe { std::arch::x86_64::__cpuid_count(7, 0) };
3435
const AMX_BF16: u32 = 1 << 22;
3536
const AMX_TILE: u32 = 1 << 24;
3637
(r.edx & AMX_BF16) != 0 && (r.edx & AMX_TILE) != 0

linalg/src/x86_64_fma/avxvnni.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ fn cpu_has_avxvnni() -> bool {
2626
if !std::is_x86_feature_detected!("avx2") {
2727
return false;
2828
}
29-
let max_sub = std::arch::x86_64::__cpuid_count(7, 0).eax;
29+
#[allow(unused_unsafe)]
30+
let max_sub = unsafe { std::arch::x86_64::__cpuid_count(7, 0) }.eax;
3031
if max_sub < 1 {
3132
return false;
3233
}
33-
let r = std::arch::x86_64::__cpuid_count(7, 1);
34+
#[allow(unused_unsafe)]
35+
let r = unsafe { std::arch::x86_64::__cpuid_count(7, 1) };
3436
(r.eax & (1 << 4)) != 0
3537
}
3638

linalg/src/x86_64_fma/mmm.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ use crate::Ops;
22
use crate::block_quant::*;
33
use crate::mmm::ImplementationQuality::ManuallyOptimized;
44
use crate::mmm::MatMatMul;
5-
use crate::pack::{PackedFormat, PackedI8K4};
5+
use crate::pack::PackedFormat;
6+
#[cfg(any(tract_avx512vnni, tract_avxvnni, tract_amx_int8))]
7+
use crate::pack::PackedI8K4;
68

9+
#[cfg(tract_amx_int8)]
710
use super::amx::{PackedAmxA, has_amx_int8};
811
#[cfg(tract_amx_bf16)]
912
use super::amx_bf16::{PackedAmxBf16A, PackedBf16K2, has_amx_bf16};

0 commit comments

Comments
 (0)