Skip to content

wasm32 simd128 backend doesn't define CurrentCpuF16/CurrentCpuBF16, breaking any build with target-feature=+simd128 #4014

Open

Description

@willarrington

Issue

Building any crate that depends on candle-core for wasm32-wasip2 (or wasm32-unknown-unknown) with -C target-feature=+simd128 fails to compile, even though the crate only ever uses DType::F32 weights and never touches f16/bf16.

Cause
src/cpu/mod.rs gates vec_dot_f16/vec_dot_bf16's SIMD-accelerated path behind #[cfg(any(target_feature = "neon", target_feature = "avx2", target_feature = "simd128"))], which requires CurrentCpuF16/CurrentCpuBF16 to exist for whichever backend is active. src/cpu/avx.rs and src/cpu/neon.rs both define all three (CurrentCpu, CurrentCpuF16, CurrentCpuBF16); src/cpu/simd128.rs only defines CurrentCpu. mod.rs's own pub use simd128::CurrentCpu; (no F16/BF16) confirms this wasn't a re-export oversight — the types were simply never written for this backend, likely because WASM SIMD128 has no native f16/bf16 conversion instructions the way AVX has F16C or NEON has native fp16 support.

My fix
Same pattern avx.rs already uses for its own no-hardware-conversion case (#[cfg(not(target_feature = "f16c"))]) and unconditionally for bf16 without avx512bf16: convert scalar-at-a-time on load/store via half::f16/half::bf16's own to_f32/from_f32, and do the real accumulation math as real v128 f32x4 SIMD, reusing the same reduction shape simd128.rs's own CurrentCpu::vec_reduce already has.

Context

Found while enabling WASM SIMD for a Whisper-inference plugin (candle-core/candle-nn/candle-transformers 0.11.0) targeting wasm32-wasip2. Reproduced directly: the exact error[E0433]: cannot find type 'CurrentCpuBF16' at src/cpu/mod.rs:382 when building with the flag, confirmed by reading simd128.rs vs avx.rs/neon.rs side by side. Patched locally with the fix described above and confirmed it resolves the compile error.

Activity

  1. ragen1337 commented on Oct 2, 2026

    @ragen1337

    Reproduced this on the 0.11.0 tag (cannot find type 'CurrentCpuF16' in cpu/mod.rs), but it builds fine on current main with +simd128 for wasm32-wasip2. Looks like #3697 fixed it — the f16/bf16 add paths now dispatch to simd128:: functions instead of relying on CurrentCpuF16. So it should be gone in the next release; until then a git dependency on main works.

    #3776 was trying to fix the same thing but it's out of date now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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