ashvardanian / SimSIMD

Up to 200x Faster Dot Products & Similarity Metrics — for Python, Rust, C, JS, and Swift, supporting f64, f32, f16 real & complex, i8, and bit vectors using SIMD for both AVX2, AVX-512, NEON, SVE, & SVE2 📐
https://ashvardanian.com/posts/simsimd-faster-scipy/
Apache License 2.0
989 stars 59 forks source link

Rust has an f16 and bf16 type #124

Closed MarkReedZ closed 2 months ago

MarkReedZ commented 5 months 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 5 months ago

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

MarkReedZ commented 5 months ago

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

Wyctus commented 5 months 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 5 months 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 5 months 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 5 months ago

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

ashvardanian commented 2 months ago

Hey @Wyctus! As you may have seen, the bf16 is now implemented. Have you tried using it? Do you still have any questions?

Wyctus commented 2 months ago

Hey @Wyctus! As you may have seen, the bf16 is now implemented. Have you tried using it? Do you still have any questions?

Awesome! I haven't seen it yet, but I'm gonna try it tomorrow! 🚀 Thanks!

Wyctus commented 2 months ago

I tried to test bf16 in Rust, but I couldn't find a struct bf16(u16) new type and the traits SpatialSimilarity, ProbabilitySimilarity and ComplexProducts implemented for it.

Am I missing something?

ashvardanian commented 2 months ago

Oh, wow, we forgot to expose it to Rust 🙈 Any chance you could contribute, @Wyctus? Should be identical to f16.

Wyctus commented 2 months ago

Sure, I'll send a PR, hopefully I'll have time today!

ashvardanian commented 2 months ago

Hey, @Wyctus! How is it going? Would be great to merge those extensions into #154 - gonna be an epic release, and even better with your contributions 🤗

Wyctus commented 2 months ago

Hey, I'm going to send the PR later today! 🙂

ashvardanian commented 2 months ago

Epic! The next release is going to be the coolest in the history of this library!