ashvardanian / SimSIMD

Up to 200x Faster Inner Products and Vector Similarity — for Python, JavaScript, Rust, C, and Swift, supporting f64, f32, f16 real & complex, i8, and binary vectors using SIMD for both x86 AVX2 & AVX-512 and Arm NEON & SVE 📐
https://ashvardanian.com/posts/simsimd-faster-scipy/
Apache License 2.0
794 stars 42 forks source link

Rust has an f16 and bf16 type #124

Open MarkReedZ opened 1 month ago

MarkReedZ commented 1 month ago

Rust has a crate half that has an f16 and bf16 we could be using. Users would probably be using this?

Rust will be adding f16 into the core language.

The addition of bf16 into the core is tracked here

ashvardanian commented 1 month ago

Once they add, we can integrate the native type. Until then, I'd avoid dependencies.

MarkReedZ commented 1 month ago

Great. I added a link for bf16 above and will add these when available.

Wyctus commented 2 weeks ago

But f16 is already supported, there is even an example!

And this implementation also does not rely on the half crate. Doesn't this mean that it is also possible to introduce bf16 without a new dependency?

Or is this also blocked by the C implementation of bf16 not being ready yet?

ashvardanian commented 2 weeks ago

We don't need a C-level or Rust-level support for f16 and bf16 to implement those. Just cast an arbitrary 16-bit scalar to a similarly named type defined in SimSIMD and you ready to go 🤗

Wyctus commented 2 weeks ago

Thank you for the quick answer, but I'm a little bit lost. 🙃

So I looked into the Rust code and for example in the case of cos and f16, the simsimd_cos_f16 C function is called. But this function based on the platform uses f16 specific intrinsics (e.g. svmla_f16_x).

So I would expect that the bf16-based metrics also have some corresponding C-functions (e.g. simsimd_cos_bf16), which would rely on bf16 specific intrinsics. But I haven't found anything specific.

Do such bf16 intrinsics actually exist? I saw some bf16 related stuff for ARM NEON, and some for AVX512 but, I'm not sure what to do.

ashvardanian commented 2 weeks ago

bf16 isn't implemented yet, you can track the progress here: https://github.com/ashvardanian/SimSIMD/issues/80