Skip to content

Commit fb52565

Browse files
authored
Merge pull request #47 from rust-math/alt-env
Detect system MKL without pkg-config
2 parents 71f81a0 + 5c3085b commit fb52565

File tree

10 files changed

+135
-33
lines changed

10 files changed

+135
-33
lines changed

.github/workflows/intel-mkl-tool.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ jobs:
2626
docker:
2727
runs-on: ubuntu-18.04
2828
strategy:
29+
fail-fast: false
2930
matrix:
30-
target: ["test", "seek", "package", "download"]
31+
target: ["test", "package", "seek", "seek-ubuntu", "seek-centos"]
3132
steps:
3233
- uses: actions/checkout@v1
3334
- name: Test with mkl-rust container

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Generated by Cargo
22
# will have compiled files and executables
33
target/
4-
.cargo/
4+
.cargo-*/
55

66
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
77
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock

README.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,25 @@ Please use `blas-sys`, `lapack-sys`, or `fftw-sys` to use BLAS, LAPACK, FFTW int
3434
fftw-sys = { version = "0.4", features = ["intel-mkl"] }
3535
```
3636

37-
## pkg-config
38-
39-
This crate does not download archive if `pkg-config` finds MKL shared library installed by other way.
40-
Be sure to set `PKG_CONFIG_PATH` and `LD_LIBRARY_PATH` correctly.
41-
For debian and ubuntu users, [ci/Dockerfile](ci/Dockerfile) may be helpful.
42-
Windows is not supported yet.
37+
## Find system MKL libraries
38+
39+
This crate will download archive from AWS S3 `rust-intel-mkl` bucket if no MKL library installed by other way, e.g. [apt]/[yum].
40+
`intel-mkl-src` seeks MKL in following manner:
41+
42+
- Check `${OUT_DIR}` where previous build has downloaded
43+
- Seek using [pkg-config] crate
44+
- `${PKG_CONFIG_PATH}` has to be set correctly. It may not be set by default in usual install.
45+
- You can confirm it by checking the following command returns error.
46+
```
47+
pkg-config --libs mkl-dynamic-lp64-iomp
48+
```
49+
- (experimental) Seek `${XDG_DATA_HOME}/intel-mkl-tool`
50+
- Seek a directory set by `${MKLROOT}` environment variable
51+
- Seek `/opt/intel/mkl`
52+
53+
[apt]: https://software.intel.com/content/www/us/en/develop/articles/installing-intel-free-libs-and-python-apt-repo.html
54+
[yum]: https://software.intel.com/content/www/us/en/develop/articles/installing-intel-free-libs-and-python-yum-repo.html
55+
[pkg-config]: https://github.com/rust-lang/pkg-config-rs
4356
4457
## License
4558
MKL is distributed under the Intel Simplified Software License for Intel(R) Math Kernel Library, See [License.txt](License.txt).

ci/Dockerfile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
ARG RUST_VERSION
22
FROM rust:${RUST_VERSION}
3-
ARG MKL_VERSION
43

54
WORKDIR /mkl
65

@@ -10,10 +9,10 @@ RUN apt update \
109
&& rm -rf /var/lib/apt/lists/*
1110

1211
COPY ./silent.cfg /mkl/
13-
RUN curl -sfLO http://registrationcenter-download.intel.com/akdlm/irc_nas/tec/16533/l_mkl_${MKL_VERSION}.tgz \
14-
&& tar xf l_mkl_${MKL_VERSION}.tgz \
15-
&& cd l_mkl_${MKL_VERSION} \
16-
&& ./install.sh -s ../silent.cfg \
12+
RUN curl -sfLO http://registrationcenter-download.intel.com/akdlm/irc_nas/tec/16533/l_mkl_2020.1.217.tgz \
13+
&& tar xf l_mkl_2020.1.217.tgz \
14+
&& cd l_mkl_2020.1.217 \
15+
&& ./install.sh -s ../silent.cfg \
1716
&& rm -rf /mkl
1817
ENV PKG_CONFIG_PATH /opt/intel/mkl/bin/pkgconfig
1918
RUN sed -i "s/MKLROOT/prefix/g" ${PKG_CONFIG_PATH}/*.pc

ci/Makefile

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
1-
REGISTRY := rustmath/mkl-rust
1+
REGISTRY := rustmath
22
RUST_VERSION := 1.43.0
3-
MKL_VERSION := 2020.1.217
4-
IMAGE := $(REGISTRY):$(RUST_VERSION)-$(MKL_VERSION)
53

6-
all: test
4+
all: test ubuntu centos
75

86
build:
97
docker build . \
108
--build-arg "RUST_VERSION=$(RUST_VERSION)" \
11-
--build-arg "MKL_VERSION=$(MKL_VERSION)" \
12-
-t $(IMAGE)
9+
-t $(REGISTRY)/mkl-rust:$(RUST_VERSION)
1310

14-
push: build
15-
docker push $(IMAGE)
11+
push: build ubuntu centos
12+
docker push $(REGISTRY)/mkl-rust:$(RUST_VERSION)
13+
docker push $(REGISTRY)/mkl-centos:$(RUST_VERSION)
14+
docker push $(REGISTRY)/mkl-ubuntu:$(RUST_VERSION)
1615

1716
test: build
18-
docker run -it --rm $(IMAGE) pkg-config --libs mkl-dynamic-lp64-iomp
17+
docker run -it --rm $(REGISTRY)/mkl-rust:$(RUST_VERSION) pkg-config --libs mkl-dynamic-lp64-iomp
18+
19+
ubuntu:
20+
docker build . -f $@.Dockerfile \
21+
--build-arg "RUST_VERSION=$(RUST_VERSION)" \
22+
-t $(REGISTRY)/mkl-ubuntu:$(RUST_VERSION)
23+
24+
centos:
25+
docker build . -f $@.Dockerfile \
26+
--build-arg "RUST_VERSION=$(RUST_VERSION)" \
27+
-t $(REGISTRY)/mkl-centos:$(RUST_VERSION)

ci/centos.Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# CentOS with official yum install procedure
2+
3+
FROM centos:7
4+
5+
# Setup Intel MKL
6+
RUN yum-config-manager --add-repo https://yum.repos.intel.com/mkl/setup/intel-mkl.repo \
7+
&& rpm --import https://yum.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB \
8+
&& yum install -y intel-mkl-2020.0-088 gcc pkg-config openssl-devel \
9+
&& rm -rf /var/cache/yum/* \
10+
&& yum clean all
11+
12+
# Setup Rust
13+
# From official setting in https://github.com/rust-lang/docker-rust
14+
ARG RUST_VERSION
15+
ENV RUSTUP_HOME=/usr/local/rustup
16+
ENV CARGO_HOME=/usr/local/cargo
17+
ENV PATH=/usr/local/cargo/bin:$PATH
18+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --default-toolchain ${RUST_VERSION}
19+
# this may concern security issue for production use, but this container is designed for development use.
20+
RUN chmod -R a+w $RUSTUP_HOME $CARGO_HOME
21+
22+
WORKDIR /src
23+
RUN chmod -R a+w /src

ci/ubuntu.Dockerfile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Ubuntu with official apt install procedure
2+
3+
FROM ubuntu:18.04
4+
5+
RUN apt update \
6+
&& apt install -y \
7+
apt-utils \
8+
curl \
9+
gnupg \
10+
libssl-dev \
11+
pkg-config \
12+
&& apt-get clean \
13+
&& rm -rf /var/lib/apt/lists/*
14+
15+
# Install MKL
16+
# https://software.intel.com/content/www/us/en/develop/articles/installing-intel-free-libs-and-python-apt-repo.html
17+
RUN curl -sfL https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB | apt-key add -
18+
RUN curl -sfL https://apt.repos.intel.com/setup/intelproducts.list -o /etc/apt/sources.list.d/intelproducts.list
19+
20+
RUN apt update \
21+
&& apt install -y intel-mkl-2020.0.088 \
22+
&& apt-get clean \
23+
&& rm -rf /var/lib/apt/lists/*
24+
25+
# Setup Rust
26+
# From official setting in https://github.com/rust-lang/docker-rust
27+
ARG RUST_VERSION
28+
ENV RUSTUP_HOME=/usr/local/rustup
29+
ENV CARGO_HOME=/usr/local/cargo
30+
ENV PATH=/usr/local/cargo/bin:$PATH
31+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --default-toolchain ${RUST_VERSION}
32+
# this may concern security issue for production use, but this container is designed for development use.
33+
RUN chmod -R a+w $RUSTUP_HOME $CARGO_HOME
34+
35+
WORKDIR /src
36+
RUN chmod -R a+w /src

intel-mkl-tool/Makefile

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
HERE := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
2-
IMAGE := rustmath/mkl-rust:1.43.0-2020.1.217
3-
4-
DOCKER_OPTION := --rm -u $(shell id -u):$(shell id -g) -v $(HERE):/src --env CARGO_HOME=/src/.cargo
1+
HERE := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
2+
RUST_VERSION := 1.43.0
3+
DOCKER_OPTION := --rm -u $(shell id -u):$(shell id -g) -v $(HERE):/src
54

65
test:
7-
docker run $(DOCKER_OPTION) $(IMAGE) cargo test with_mkl -- --ignored
6+
docker run $(DOCKER_OPTION) --env CARGO_HOME=/src/.cargo-cache rustmath/mkl-rust:$(RUST_VERSION) cargo test with_mkl -- --ignored
87

98
seek:
10-
docker run $(DOCKER_OPTION) $(IMAGE) cargo run --release -- seek
9+
docker run $(DOCKER_OPTION) --env CARGO_HOME=/src/.cargo-cache rustmath/mkl-rust:$(RUST_VERSION) cargo run --release -- seek
1110

1211
package:
13-
docker run $(DOCKER_OPTION) $(IMAGE) cargo run --release -- package
12+
docker run $(DOCKER_OPTION) --env CARGO_HOME=/src/.cargo-cache rustmath/mkl-rust:$(RUST_VERSION) cargo run --release -- package
13+
14+
seek-ubuntu:
15+
docker run $(DOCKER_OPTION) --env CARGO_HOME=/src/.cargo-ubuntu rustmath/mkl-ubuntu:$(RUST_VERSION) cargo run --release -- seek
1416

15-
download:
16-
docker run $(DOCKER_OPTION) $(IMAGE) cargo run --release -- download -o ./test_download
17+
seek-centos:
18+
docker run $(DOCKER_OPTION) --env CARGO_HOME=/src/.cargo-centos rustmath/mkl-centos:$(RUST_VERSION) cargo run --release -- seek

intel-mkl-tool/src/cli.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ fn main() -> Result<()> {
5858
}
5959

6060
Opt::Seek {} => {
61+
let available = Entry::available();
62+
if available.is_empty() {
63+
bail!("No MKL found");
64+
}
6165
for lib in Entry::available() {
6266
if let Ok(version) = lib.version() {
6367
println!("{:<22}: {}.{}", lib.name(), version.0, version.1);

intel-mkl-tool/src/entry.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ impl Targets {
3636
self.0.iter().any(|(_key, value)| value.is_some())
3737
}
3838

39-
fn seek(&mut self, dir: &Path) {
39+
fn seek<P: AsRef<Path>>(&mut self, dir: P) {
40+
let dir = dir.as_ref();
4041
for (key, value) in &mut self.0 {
4142
if dir.join(key).exists() {
4243
value.get_or_insert(dir.canonicalize().unwrap());
@@ -95,10 +96,24 @@ impl Entry {
9596
}
9697
}
9798

98-
// XDG_DATA_HOME
99+
// $XDG_DATA_HOME/intel-mkl-tool
99100
let path = xdg_home_path().join(config.name());
100101
targets.seek(&path);
101102

103+
// $MKLROOT
104+
let mkl_root = std::env::var("MKLROOT").map(|path| PathBuf::from(path));
105+
if let Ok(path) = mkl_root {
106+
if path.exists() {
107+
targets.seek(path.join("lib/intel64"));
108+
}
109+
}
110+
111+
// /opt/intel/mkl
112+
let opt_mkl = PathBuf::from("/opt/intel/mkl");
113+
if opt_mkl.exists() {
114+
targets.seek(opt_mkl.join("lib/intel64"));
115+
}
116+
102117
if targets.found_any() {
103118
return Ok(Self { config, targets });
104119
} else {

0 commit comments

Comments
 (0)