ndarray-linalg icon indicating copy to clipboard operation
ndarray-linalg copied to clipboard

Support Veclib of MacOS

Open jianshu93 opened this issue 3 years ago • 5 comments
trafficstars

Hello Team,

It seems openblas on MacOS can be replaced by the system default blas implementation called veclib, R language support it as the backend instead of default openblas et.al on MacOS systems. I am wondering whether this is possible because for new apple processors like M1 series, Intel-mkl is not supported and openblas is slower compare to default veclib (at lease in R experience it is). I cannot find so many info about veclib online so it may requires some additional investigation.

Thanks,

Jianshu

jianshu93 avatar Oct 31 '22 22:10 jianshu93

the built in apple framework for BLAS/LAPACK is Accelerate, ndarray and ndarray-linalg are both capable of using it (you may have to add a simple build.rs file but it's not too bad once you know the magic words). here is the blas_src page which is a good starting point, it links to the apple accelerate page.

source: not a maintainer, I use this library and have apple M1 laptop.

matthagan15 avatar Jan 25 '23 21:01 matthagan15

Hello,

Can you provide an example how to prepare a build.rs only for MacOS? I saw that both ndarray and ndarray-linalg rely directly on openblas-src, intel-mkl-src et.al.

Thanks,

Jianshu

jianshu93 avatar Jan 25 '23 22:01 jianshu93

sure, here's a simple binary crate I used to test the expm routine I'm trying to get pulled in: basic M1 setup. Look at blas-src in Cargo.toml and build.rs, that should be enough to get going on M1 mac.

matthagan15 avatar Jan 26 '23 00:01 matthagan15

that was a personal helper binary, I figured it'd be easier to point you to it so you could pull out the Cargo.toml and the build.rs files instead of putting them in a github comment

matthagan15 avatar Jan 26 '23 01:01 matthagan15

Hello all,

Please help if you can, this crate: https://github.com/jean-pierreBoth/annembed

I tried your suggestion and use blas-src, accelerate as the backend, but it does not work, the 3 features, openblas-system is the only one that works on M1 (aarch63) platform. Can you please try at your end. The problem is with ndarray-linalg, ndarray can use accelerate as back end easily but I always have this error:

error: linking with cc failed: exit status: 1 | = note: LC_ALL="C" PATH="/Users/jianshuzhao/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin:/opt/homebrew/opt/llvm/bin:/Users/jianshuzhao/bin:/Users/jianshuzhao/.cargo/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin" VSLANG="1033" ZERO_AR_DATE="1" "cc" "-arch" "arm64" "/var/folders/r_/nxv9frrj1jqgpn0_k63qgcf00000gn/T/rustc8vx1ts/symbols.o" "/Users/jianshuzhao/annembed/target/release/deps/annembed-e1a28c0193cd19a4.annembed.d4b81043660c57ba-cgu.15.rcgu.o" "-L" "/Users/jianshuzhao/annembed/target/release/deps" "-L" "/Users/jianshuzhao/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib" "/Users/jianshuzhao/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcompiler_builtins-d1be01496bebb995.rlib" "-liconv" "-lSystem" "-lc" "-lm" "-L" "/Users/jianshuzhao/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib" "-o" "/Users/jianshuzhao/annembed/target/release/deps/annembed-e1a28c0193cd19a4" "-Wl,-dead_strip" "-nodefaultlibs" = note: Undefined symbols for architecture arm64: "cblas_sdot", referenced from: ndarray::linalg::impl_linalg::$LT$impl$u20$ndarray..ArrayBase$LT$S$C$ndarray..dimension..dim..Dim$LT$$u5b$usize$u3b$$u20$1$u5d$$GT$$GT$$GT$::dot_impl::hc9d82004e6b67209 in annembed-e1a28c0193cd19a4.annembed.d4b81043660c57ba-cgu.15.rcgu.o annembed::tools::svdapprox::orthogonalize_with_q::h6f5c603b187435d8 in annembed-e1a28c0193cd19a4.annembed.d4b81043660c57ba-cgu.15.rcgu.o "_cblas_sgemm", referenced from: ndarray::linalg::impl_linalg::mat_mul_impl::hc582838647e30f97 in annembed-e1a28c0193cd19a4.annembed.d4b81043660c57ba-cgu.15.rcgu.o "_cblas_sgemv", referenced from: annembed::tools::svdapprox::MatRepr$LT$F$GT$::mat_dot_vector::h9aa49b98bb2b9a83 in annembed-e1a28c0193cd19a4.annembed.d4b81043660c57ba-cgu.15.rcgu.o "sgelqf", referenced from: annembed::tools::svdapprox::do_qr::hd984509065202632 in annembed-e1a28c0193cd19a4.annembed.d4b81043660c57ba-cgu.15.rcgu.o "sgesdd", referenced from: _$LT$f32$u20$as$u20$lax..Lapack$GT$::svddc::h796bc8ee227c7814 in annembed-e1a28c0193cd19a4.annembed.d4b81043660c57ba-cgu.15.rcgu.o "sorglq", referenced from: annembed::tools::svdapprox::do_qr::hd984509065202632 in annembed-e1a28c0193cd19a4.annembed.d4b81043660c57ba-cgu.15.rcgu.o ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

here I have CC using both the default clang, or gcc installed via brew, none of them work.

Thanks,

Jianshu

jianshu93 avatar Jul 04 '23 02:07 jianshu93