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

Allow python to build with non-scipy blas and lapack #151

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ sdp-r = ["sdp", "blas-src/r", "lapack-src/r"]
julia = ["sdp", "dep:libc", "dep:num-derive", "serde", "faer-sparse"]

# build as the python interface via maturin.
# NB: python builds use scipy shared libraries
# for blas/lapack, and should *not* explicitly
# enable a blas/lapack source package
# python builds will default to use scipy shared libraries
# for blas/lapack if none of the options above are specified.
# This is the behaviour used when building the python wheels
# for distribution on pypi

python = ["sdp", "dep:libc", "dep:pyo3", "dep:num-derive", "serde", "faer-sparse"]

#compile with faer supernodal solver option
Expand Down
33 changes: 33 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
macro_rules! printinfo {
($($tokens: tt)*) => {
println!("cargo:warning=\r\x1b[36;1m {}", format!($($tokens)*))
}
}

fn main() {
config_python_blas();
}

fn config_python_blas() {
// cfg(sdp_pyblas) is used to indicate that BLAS/LAPACK functions
// should be taken from Python's scipy. It will only be defined
// for python builds that do not link to one of the blas/lapack
// libraries provided by blas-src and lapack-src.
println!("cargo:rustc-check-cfg=cfg(sdp_pyblas)");

if cfg!(not(feature = "python")) {
return;
}

if !cfg!(any(
feature = "sdp-accelerate",
feature = "sdp-netlib",
feature = "sdp-openblas",
feature = "sdp-mkl",
feature = "sdp-r"
)) {
printinfo!("Python: compiling with python blas from scipy");
} else {
printinfo!("Python: compiling with local blas/lapack libraries");
}
}
2 changes: 1 addition & 1 deletion src/algebra/dense/blas/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![allow(clippy::too_many_arguments)]

cfg_if::cfg_if! {
if #[cfg(feature="python")] {
if #[cfg(sdp_pyblas)] {
// imports via scipy
use crate::python::pyblas::*;
}
Expand Down
5 changes: 5 additions & 0 deletions src/python/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ mod cscmatrix_py;
mod impl_default_py;
pub(crate) mod io;
mod module_py;

// compile this module if no local blas/lapack library
// has been specified, and we want to use the python/scipy
// version instead. sdp_pyblas is defined in build.rs
#[cfg(sdp_pyblas)]
pub(crate) mod pyblas;

// NB : Nothing is actually public here, but the python module itself
Expand Down
2 changes: 2 additions & 0 deletions src/python/module_py.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use pyo3::prelude::*;
#[pyfunction(name = "force_load_blas_lapack")]
fn force_load_blas_lapack_py() {
//force BLAS/LAPACK fcn pointer load
//when using scipy lapack/blas
#[cfg(sdp_pyblas)]
crate::python::pyblas::force_load();
}

Expand Down