Skip to content

Runtime SIMD dispatch can select an FMA kernel tier on a CPU without FMA #7732

Description

@tobocop2

Summary

The runtime SIMD dispatch in lance-core picks the SimdSupport::Avx2 tier when only AVX2 is detected:

// rust/lance-core/src/utils/cpu.rs (main)
} else if is_x86_feature_detected!("avx2") {
    SimdSupport::Avx2

but every kernel that tier dispatches to in lance-linalg::distance::{cosine, dot, l2, norm_l2} and simd::dist_table is annotated #[target_feature(enable = "avx,fma")]. AVX2 does not imply FMA in the x86 ISA, so a host that reports AVX2 without FMA takes this tier and executes an FMA instruction (vfmadd…) it cannot run — an illegal-instruction crash.

Impact

Latent, not live. Every AVX2-capable part Intel and AMD have shipped also has FMA, so no real CPU triggers this today. It is a hole in the feature-detection contract, not a crash anyone is currently hitting.

Fix

Found and fixed while working on #6630. The tier now requires both features:

} else if is_x86_feature_detected!("avx2") && is_x86_feature_detected!("fma") {
    SimdSupport::Avx2

The tier's contract is documented on the enum variant, and a test asserts that neither the Avx2 nor AvxFma tier can be selected on a host without FMA.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions