Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cblas_dgemm returns incorrect results when the static feature of openblas-src is enabled on macOS #64

Closed
maoe opened this issue Mar 30, 2021 · 6 comments

Comments

@maoe
Copy link
Contributor

maoe commented Mar 30, 2021

https://github.com/maoe/ndarray-dot-repro is a reproducer. It was minimized from code which used argmin + ndarrayl feature.

This reproducer uses the patched version of openblas-src from #65 so that static build works both on Linux and macOS Big Sur.

The expected output of the main is [1.0, 1.0, 1.0, 1.0] but it returns the zero matrix on macOS when the static feature of openblas-src is enabled.

% cargo run
   Compiling ndarray-dot-repro v0.1.0 (/Users/maoe/src/github.com/maoe/ndarray-dot-repro)
    Finished dev [unoptimized + debuginfo] target(s) in 0.49s
     Running `target/debug/ndarray-dot-repro`
[
    1.0,
    1.0,
    1.0,
    1.0,
]
% cargo run --features openblas-src/static
   Compiling ndarray-dot-repro v0.1.0 (/Users/maoe/src/github.com/maoe/ndarray-dot-repro)
    Finished dev [unoptimized + debuginfo] target(s) in 0.52s
     Running `target/debug/ndarray-dot-repro`
[
    0.0,
    0.0,
    0.0,
    0.0,
]

FWIW, I haven't been able to reproduce the issue in C on macOS:

% git clone https://github.com/xianyi/OpenBLAS.git
% cd OpenBLAS
% git checkout v0.3.14 # This is the commit #65 uses
% make
% wget -q https://gist.githubusercontent.com/maoe/953c4e863703be915928b0f8997fcc46/raw/e827d61ae2944a72a37d0784c0aab0026e1b6cdb/repro.c # See https://gist.github.com/maoe/953c4e863703be915928b0f8997fcc46
% cc -o repro repro.c libopenblas.a
% ./repro
1.000000
1.000000
1.000000
1.000000
@maoe
Copy link
Contributor Author

maoe commented Mar 30, 2021

OpenMathLib/OpenBLAS#1088 looks similar but I'm not sure if it's the same issue as I haven't reproduced it in C yet.

@maoe
Copy link
Contributor Author

maoe commented Mar 30, 2021

Removed the dependency on blas-src on current master of the reproducer.

@maoe
Copy link
Contributor Author

maoe commented Mar 30, 2021

FWIW this issue remains even with #65.

@maoe
Copy link
Contributor Author

maoe commented Mar 31, 2021

Updated the reproducer with #65 and a simpler matrix input and updated the description accordingly.

maoe added a commit to maoe/ndarray-dot-repro that referenced this issue Mar 31, 2021
According to the Rust Reference, an extern block is used to link a
native library. I was thinking the extern crate declaration would do it
but apparently it doesn't. This patch seems to fix the issue reported in
blas-lapack-rs/openblas-src#64.
@maoe
Copy link
Contributor Author

maoe commented Mar 31, 2021

I managed to fix the issue with maoe/ndarray-dot-repro@4d94c73.

Apparently, at least on macOS, the static feature needs an empty extern block with #[link(name = "openblas")] attribute to work. I also tried putting the block in openblas-src's lib.rs but it didn't work. It seems that the block needs to be at the use site.

I guess the instructions on the wiki need updating.

@maoe
Copy link
Contributor Author

maoe commented Mar 31, 2021

Closing this because there's nothing to be done in this crate.

@maoe maoe closed this as completed Mar 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant