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
988 stars 59 forks source link

Bug: Linker errors on Android #235

Open zhongzc opened 2 days ago

zhongzc commented 2 days ago

Describe the bug

See https://github.com/GreptimeTeam/greptimedb/issues/5016

I encountered linker errors when trying to build greptime for Android (aarch64-linux-android) using cargo ndk. The errors indicate undefined symbols for SIMD functions (e.g., simsimd_cos_f32, simsimd_dot_f32, simsimd_l2sq_f32) from the simsimd crate.

cargo ndk --platform 23 -t aarch64-linux-android build --locked --profile release --bin greptime --bin greptime --no-default-features
    Building arm64-v8a (aarch64-linux-android)
...
...
...
Compiling cmd v0.9.5 (/greptimedb/src/cmd)error: linking with /root/.cargo/bin/cargo-ndk failed: exit status: 1

  = note: ld: error: undefined symbol: simsimd_cos_f32
          >>> referenced by lib.rs:447 (rust/lib.rs:447)
          >>>               simsimd-9910860383191831.simsimd.a55a236d9e83b92-cgu.0.rcgu.o:(_$LT$f32$u20$as$u20$simsimd..SpatialSimilarity$GT$::cos::hffc7059aa27c91f8) in archive /greptimedb/target/aarch64-linux-android/release/deps/libsimsimd-9910860383191831.rlib

          ld: error: undefined symbol: simsimd_dot_f32
          >>> referenced by lib.rs:457 (rust/lib.rs:457)
          >>>               simsimd-9910860383191831.simsimd.a55a236d9e83b92-cgu.0.rcgu.o:(_$LT$f32$u20$as$u20$simsimd..SpatialSimilarity$GT$::dot::h02288694ae51f515) in archive /greptimedb/target/aarch64-linux-android/release/deps/libsimsimd-9910860383191831.rlib

          ld: error: undefined symbol: simsimd_l2sq_f32
          >>> referenced by lib.rs:467 (rust/lib.rs:467)
          >>>               simsimd-9910860383191831.simsimd.a55a236d9e83b92-cgu.0.rcgu.o:(_$LT$f32$u20$as$u20$simsimd..SpatialSimilarity$GT$::l2sq::h646b02bc768ea724) in archive /greptimedb/target/aarch64-linux-android/release/deps/libsimsimd-9910860383191831.rlib
          clang-14: error: linker command failed with exit code 1 (use -v to see invocation)

error: could not compile cmd (bin "greptime") due to 1 previous error
note: If the build failed due to a missing target, you can run this command:
note: 
note:     rustup target install aarch64-linux-android
make: *** [Makefile:75: build] Error 101
make: *** [Makefile:93: build-android-bin] Error 2

I'm not familiar with Android. Your guidance will be greatly appreciated if the problem is too simple or troublesome.

Steps to reproduce

git clone https://github.com/GreptimeTeam/greptimedb.git  
cd greptimedb
make build-android-bin

Expected behavior

Pass the build.

SimSIMD version

v6.0.5

Operating System

Android

Hardware architecture

Arm

Which interface are you using?

Rust bindings

Contact Details

No response

Are you open to being tagged as a contributor?

Is there an existing issue for this?

Code of Conduct

zhongzc commented 2 days ago

simsimd = "4" can be compiled, but "=5.0.0" fails

ashvardanian commented 2 days ago

Does it only fail on Android and passes everywhere else?

zhongzc commented 2 days ago

Does it only fail on Android and passes everywhere else?

Yes

ashvardanian commented 2 days ago

@zhongzc, any chance you could reproduce its build pipeline in an isolated GitHub CI job and add it to prerelease.yml? In that case I can research the issue and probably fix it 🤗

discord9 commented 1 day ago

@zhongzc, any chance you could reproduce its build pipeline in an isolated GitHub CI job and add it to prerelease.yml? In that case I can research the issue and probably fix it 🤗

I can reproduce using cargo ndk, and here is a minimal available case(it need docker to run), more instructions on how to reproduce is in the readme.md reproduce.zip Note the docker image it is using is not yet minimal, still working on reduce the docker image to minimal dependency, but hopefully that could be useful enough for now edited: I found a mininal reproduce case! very strange, I think, it might be a misconfigure in cargo ndk after all, see more in new README.MD. Basically build with instrumentisto/cargo-ndk works, but build with saschpe/android-ndk then install cargo ndk would cause same error, anyway see the new README.md in reproduce_min.zip! reproduce_min.zip

discord9 commented 1 day ago

More tests show that this is introduced in 5.0.0, it can compile (in the dockerfile image from reproduce_min.zip) using simsimd="=4.4.0" but failed with the same error ld: error: undefined symbol: simsimd_l2sq_f64 on simsimd="=5.0.0"

ashvardanian commented 1 day ago

Yes, that part is clear. The older versions didn't use dynamic dispatch in Rust. The new ones seem to work fine with Rust on most platforms, but we may need to find a different approach on Android.