From f98e5c04bffc23910214e73c13ba733c9000f319 Mon Sep 17 00:00:00 2001 From: bluss Date: Thu, 25 Mar 2021 19:43:46 +0100 Subject: [PATCH 1/2] API: Drop direct blas-src dependency, update docs for blas integration We can in theory unchain ourselves from the blas-src version and let the user be responsible for linking in blas in the final product. Update xtest-blas to test this configuration. Update instructions in readme for how to use it. --- Cargo.toml | 3 +-- README.rst | 29 +++++++++++++++++++++-------- src/lib.rs | 2 -- xtest-blas/src/lib.rs | 1 - xtest-blas/tests/oper.rs | 1 + 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ddd29c71a..374838b7e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,6 @@ approx = { version = "0.4", optional = true , default-features = false } # Use via the `blas` crate feature! cblas-sys = { version = "0.1.4", optional = true, default-features = false } -blas-src = { version = "0.7.0", optional = true, default-features = false } libc = { version = "0.2.82", optional = true } matrixmultiply = { version = "0.3.0", default-features = false} @@ -58,7 +57,7 @@ default = ["std"] # Enable blas usage # See README for more instructions -blas = ["cblas-sys", "blas-src", "libc"] +blas = ["cblas-sys", "libc"] # Old name for the serde feature serde-1 = ["serde"] diff --git a/README.rst b/README.rst index 36b98598f..1b57ccaa9 100644 --- a/README.rst +++ b/README.rst @@ -96,21 +96,34 @@ How to use with cargo :: [dependencies] - ndarray = "0.14.0" + ndarray = "0.15.0" -How to enable blas integration. Depend on ``blas-src`` directly to pick a blas -provider. Depend on the same ``blas-src`` version as ``ndarray`` does, for the -selection to work. An example configuration using system openblas is shown -below. Note that only end-user projects (not libraries) should select -provider:: +How to enable blas integration +----------------------------- +Blas integration is an optional add-on. + +Depend and link to ``blas-src`` directly to pick a blas provider. Ndarray +presently requires a blas provider that provides the ``cblas-sys`` interface. If +further feature selection is needed then you might need to depend directly on +the backend crate's source too (for example ``openblas-src``, to select +``cblas``). The backend version **must** be the one that ``blas-src`` also +depends on. + +An example configuration using system openblas is shown below. Note that only +end-user projects (not libraries) should select provider:: [dependencies] - ndarray = { version = "0.14.0", features = ["blas"] } + ndarray = { version = "0.15.0", features = ["blas"] } blas-src = { version = "0.7.0", default-features = false, features = ["openblas"] } openblas-src = { version = "0.9", default-features = false, features = ["cblas", "system"] } -For official releases of ``ndarray``, the versions are: +When this is done, your program must also link to ``blas_src`` by using it or +explicitly including it in your code:: + + extern crate blas_src; + +For official releases of ``ndarray``, versions that have been verified to work are: =========== ============ ================ ``ndarray`` ``blas-src`` ``openblas-src`` diff --git a/src/lib.rs b/src/lib.rs index 9ec666c14..56814d787 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -124,8 +124,6 @@ extern crate std; #[cfg(not(feature = "std"))] extern crate core as std; -#[cfg(feature = "blas")] -extern crate blas_src; #[cfg(feature = "blas")] extern crate cblas_sys; diff --git a/xtest-blas/src/lib.rs b/xtest-blas/src/lib.rs index 8b1378917..e69de29bb 100644 --- a/xtest-blas/src/lib.rs +++ b/xtest-blas/src/lib.rs @@ -1 +0,0 @@ - diff --git a/xtest-blas/tests/oper.rs b/xtest-blas/tests/oper.rs index d6230cced..da3b1ba63 100644 --- a/xtest-blas/tests/oper.rs +++ b/xtest-blas/tests/oper.rs @@ -2,6 +2,7 @@ extern crate approx; extern crate defmac; extern crate ndarray; extern crate num_traits; +extern crate blas_src; use ndarray::linalg::general_mat_mul; use ndarray::linalg::general_mat_vec_mul; From 5b96f1dd5a3c06277517af8b521c750a4e0d958e Mon Sep 17 00:00:00 2001 From: bluss Date: Thu, 25 Mar 2021 19:59:18 +0100 Subject: [PATCH 2/2] TEST: Remove ndarray build.rs and test-blas-openblas-sys feature flag This flag was not properly used anymore. Replace it with a proper blas test setup in xtest-numeric. --- Cargo.toml | 5 +---- build.rs | 10 ---------- scripts/all-tests.sh | 1 + xtest-numeric/Cargo.toml | 5 ++++- xtest-numeric/src/lib.rs | 3 +++ xtest-numeric/tests/accuracy.rs | 2 ++ 6 files changed, 11 insertions(+), 15 deletions(-) delete mode 100644 build.rs diff --git a/Cargo.toml b/Cargo.toml index 374838b7e..f48a371e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,8 +18,6 @@ description = "An n-dimensional array for general elements and for numerics. Lig keywords = ["array", "data-structure", "multidimensional", "matrix", "blas"] categories = ["data-structures", "science"] -build = "build.rs" - exclude = ["docgen/images/*"] [lib] @@ -63,8 +61,7 @@ blas = ["cblas-sys", "libc"] serde-1 = ["serde"] # These features are used for testing -test-blas-openblas-sys = ["blas"] -test = ["test-blas-openblas-sys"] +test = [] # This feature is used for docs docs = ["approx", "serde", "rayon"] diff --git a/build.rs b/build.rs deleted file mode 100644 index dd06c0b81..000000000 --- a/build.rs +++ /dev/null @@ -1,10 +0,0 @@ -/// -/// This build script emits the openblas linking directive if requested -/// - -fn main() { - println!("cargo:rerun-if-changed=build.rs"); - if cfg!(feature = "test-blas-openblas-sys") { - println!("cargo:rustc-link-lib=dylib=openblas"); - } -} diff --git a/scripts/all-tests.sh b/scripts/all-tests.sh index a9cd3e758..15fb3fe48 100755 --- a/scripts/all-tests.sh +++ b/scripts/all-tests.sh @@ -18,4 +18,5 @@ cargo test --manifest-path=xtest-serialization/Cargo.toml --verbose cargo test --manifest-path=xtest-blas/Cargo.toml --verbose cargo test --examples CARGO_TARGET_DIR=target/ cargo test --manifest-path=xtest-numeric/Cargo.toml --verbose +CARGO_TARGET_DIR=target/ cargo test --manifest-path=xtest-numeric/Cargo.toml --verbose --features test_blas ([ "$CHANNEL" != "nightly" ] || cargo bench --no-run --verbose --features "$FEATURES") diff --git a/xtest-numeric/Cargo.toml b/xtest-numeric/Cargo.toml index fd017bd39..8636fec41 100644 --- a/xtest-numeric/Cargo.toml +++ b/xtest-numeric/Cargo.toml @@ -10,6 +10,9 @@ ndarray = { path = "..", features = ["approx"] } ndarray-rand = { path = "../ndarray-rand/" } rand_distr = "0.4" +blas-src = { optional = true, version = "0.7.0", default-features = false, features = ["openblas"] } +openblas-src = { optional = true, version = "0.9", default-features = false, features = ["cblas", "system"] } + [dependencies.rand] version = "0.8.0" features = ["small_rng"] @@ -18,7 +21,7 @@ features = ["small_rng"] test = false [features] -test_blas = ["ndarray/blas", "ndarray/test-blas-openblas-sys"] +test_blas = ["ndarray/blas", "blas-src", "openblas-src"] [profile.dev] opt-level = 2 diff --git a/xtest-numeric/src/lib.rs b/xtest-numeric/src/lib.rs index e69de29bb..ba1c3b0d9 100644 --- a/xtest-numeric/src/lib.rs +++ b/xtest-numeric/src/lib.rs @@ -0,0 +1,3 @@ +#[cfg(feature = "test_blas")] +extern crate blas_src; + diff --git a/xtest-numeric/tests/accuracy.rs b/xtest-numeric/tests/accuracy.rs index 044ba17cc..4c454bac1 100644 --- a/xtest-numeric/tests/accuracy.rs +++ b/xtest-numeric/tests/accuracy.rs @@ -4,6 +4,8 @@ extern crate ndarray; extern crate ndarray_rand; extern crate rand; +extern crate numeric_tests; + use ndarray_rand::{RandomExt, F32}; use rand::{Rng, SeedableRng}; use rand::rngs::SmallRng;