PyO3 / rust-numpy

PyO3-based Rust bindings of the NumPy C-API
BSD 2-Clause "Simplified" License
1.15k stars 112 forks source link

Support blas #71

Closed kngwyu closed 2 years ago

rth commented 6 years ago

What did you have in mind for this issue?

Wouldn't using some wrapper around BLAS like https://github.com/kali/blis-rs or https://github.com/peterhj/libopenblas_ffi (but possibly more recently updated) be enough for rust-numpy users? ndarray also uses some BLAS from what I understood.

Or you mean accessing the BLAS used by numpy?

kngwyu commented 6 years ago

I just meant using ndarray's blas by adding a feature flag in Cargo.toml, like

[features]
default = []
blas = ["ndarray/blas"]
rth commented 4 years ago

So if one does build a package that depends say on ndarray/blas what is supposed to happen in the generated python extension? Is it expected to be dynamically linked with a BLAS library or are additional steps necessary?

For instance, in https://github.com/argmin-rs/pyargmin/pull/20#issuecomment-598943590 the dependency tree it pretty extensive and it looks like some of the dependencies use ndarray with BLAS (or BLAS directly). The build works fine, but at import I get

E   ImportError: /home/rth/src/pyargmin/argmin/_lib.cpython-38-x86_64-linux-gnu.so: 
       undefined symbol: cblas_ddot

and BLAS is not dynamically linked,

$ ldd  _lib.cpython-38-x86_64-linux-gnu.so
        linux-vdso.so.1 (0x00007ffddd583000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ffb90991000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007ffb90986000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ffb90965000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007ffb9094b000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ffb90760000)
        /lib64/ld-linux-x86-64.so.2 (0x00007ffb90aab000)

Any pointers in what direction to look would be very much appreciated.

rth commented 4 years ago

Is it expected to be dynamically linked with a BLAS library or are additional steps necessary?

Never mind. Explicitly adding the blas-src and openblas-src dependencies as indicated in the ndarray docs did fix linking. I'm just surprised compilation previously succeed without errors.

emmatyping commented 3 years ago

FWIW if anyone wants an example of what supporting linking to BLAS looks like, here is what I do: https://github.com/BQSKit/qsearch/blob/master/qsrs/Cargo.toml

I also allow people to edit pyproject.toml to specify which build they want depending on platform https://github.com/BQSKit/qsearch/blob/master/qsrs/pyproject.toml

It certainly isn't the most ergonomic, but it works decently well.