Skip to content

Commit 8007eea

Browse files
authored
Merge pull request #93 from rust-math/seek-ubuntu
Test case for seeking MKL installed by apt
2 parents 8862ae5 + f7db8ed commit 8007eea

File tree

4 files changed

+116
-71
lines changed

4 files changed

+116
-71
lines changed

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,42 @@ jobs:
4444
--manifest-path=intel-mkl-tool/Cargo.toml
4545
--release
4646
--example seek
47+
48+
seek-apt:
49+
runs-on: ubuntu-22.04
50+
strategy:
51+
fail-fast: false
52+
matrix:
53+
image:
54+
- ubuntu:22.04
55+
- ubuntu:20.04
56+
- debian:10
57+
container:
58+
image: ${{ matrix.image }}
59+
steps:
60+
- uses: actions/checkout@v1
61+
62+
- name: Add non-free registry
63+
if: ${{ startsWith(matrix.image, 'debian') }}
64+
run: sed -i "s/main$/main contrib non-free/" /etc/apt/sources.list
65+
66+
- name: Install MKL using apt
67+
run: |
68+
export DEBIAN_FRONTEND=noninteractive
69+
apt update
70+
apt install -y intel-mkl curl gcc
71+
72+
- uses: actions-rs/toolchain@v1
73+
with:
74+
toolchain: 1.61.0
75+
profile: minimal
76+
default: true
77+
override: true
78+
- name: Run seek example
79+
uses: actions-rs/cargo@v1
80+
with:
81+
command: run
82+
args: >
83+
--manifest-path=intel-mkl-tool/Cargo.toml
84+
--release
85+
--example seek

intel-mkl-tool/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ repository = "https://github.com/rust-math/intel-mkl-src"
1010
keywords = []
1111
license = "MIT"
1212

13+
[features]
14+
# Do not allow linking dynamic library for mkl-static-*-iomp
15+
openmp-strict-link-type = []
16+
1317
[dependencies]
1418
anyhow = "1.0.58"
19+
log = "0.4.17"
1520
walkdir = "2.3.2"
21+
22+
[dev-dependencies]
23+
env_logger = "0.9.0"

intel-mkl-tool/examples/seek.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,16 @@ use intel_mkl_tool::*;
22
use std::process::ExitCode;
33

44
fn main() -> ExitCode {
5+
env_logger::Builder::new()
6+
.filter_level(log::LevelFilter::Info)
7+
.init();
58
let mut num_not_found = 0;
69
for cfg in Config::possibles() {
7-
let lib = Library::new(cfg);
8-
print!(
9-
"{:>7} {:>5} {:>4}",
10-
cfg.link.to_string(),
11-
cfg.index_size.to_string(),
12-
cfg.parallel.to_string()
13-
);
14-
if let Ok(lib) = lib {
15-
println!(" {}", lib.library_dir.display());
10+
log::info!("Seek {}", cfg);
11+
if let Ok(lib) = Library::new(cfg) {
12+
log::info!("{:?}", lib);
1613
} else {
1714
num_not_found += 1;
18-
println!(" Not found");
1915
}
2016
}
2117
return ExitCode::from(num_not_found);

intel-mkl-tool/src/entry.rs

Lines changed: 63 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{Config, LinkType, Threading};
2-
use anyhow::{bail, ensure, Context, Result};
2+
use anyhow::{bail, Context, Result};
33
use std::{
44
fs,
55
io::{self, BufRead},
@@ -67,13 +67,15 @@ impl Library {
6767
if out.status.success() {
6868
let path = String::from_utf8(out.stdout).context("Non-UTF8 MKL prefix")?;
6969
let prefix = Path::new(path.trim());
70+
let prefix = fs::canonicalize(prefix)?;
71+
log::info!("pkg-config found {} on {}", config, prefix.display());
7072
Self::seek_directory(config, prefix)
7173
} else {
72-
// pkg-config does not find MKL
74+
log::info!("pkg-config does not find {}", config);
7375
Ok(None)
7476
}
7577
} else {
76-
// pkg-config is not found
78+
log::info!("pkg-config itself is not found");
7779
Ok(None)
7880
}
7981
}
@@ -94,87 +96,87 @@ impl Library {
9496
let mut library_dir = None;
9597
let mut include_dir = None;
9698
let mut iomp5_dir = None;
97-
for entry in walkdir::WalkDir::new(root_dir).into_iter().flatten() {
98-
if entry.path_is_symlink() {
99-
continue;
100-
}
101-
let path = entry.into_path();
102-
if path.is_dir() {
103-
continue;
104-
}
99+
for path in walkdir::WalkDir::new(root_dir)
100+
.into_iter()
101+
.flatten() // skip unreadable directories
102+
.flat_map(|entry| {
103+
let path = entry.into_path();
104+
// Skip directory
105+
if path.is_dir() {
106+
return None;
107+
}
108+
// Skip files under directory for ia32
109+
if path.components().any(|c| {
110+
if let std::path::Component::Normal(c) = c {
111+
if let Some(c) = c.to_str() {
112+
if c.starts_with("ia32") {
113+
return true;
114+
}
115+
}
116+
}
117+
false
118+
}) {
119+
return None;
120+
}
121+
Some(path)
122+
})
123+
{
124+
let dir = path
125+
.parent()
126+
.expect("parent must exist here since this is under `root_dir`")
127+
.to_owned();
128+
105129
let (stem, ext) = match (path.file_stem(), path.extension()) {
106130
(Some(stem), Some(ext)) => (
107131
stem.to_str().context("Non UTF8 filename")?,
108132
ext.to_str().context("Non UTF8 filename")?,
109133
),
110134
_ => continue,
111135
};
112-
// Skip directory for ia32
113-
if path.components().any(|c| {
114-
if let std::path::Component::Normal(c) = c {
115-
if let Some(c) = c.to_str() {
116-
if c.starts_with("ia32") {
117-
return true;
118-
}
119-
}
120-
}
121-
false
122-
}) {
123-
continue;
124-
}
125136

126-
let dir = path
127-
.parent()
128-
.expect("parent must exist here since this is under `root_dir`")
129-
.to_owned();
130137
if stem == "mkl" && ext == "h" {
138+
log::info!("Found mkl.h: {}", path.display());
131139
include_dir = Some(dir);
132140
continue;
133141
}
142+
134143
let name = if let Some(name) = stem.strip_prefix(std::env::consts::DLL_PREFIX) {
135144
name
136145
} else {
137146
continue;
138147
};
139-
match (config.link, ext) {
140-
(LinkType::Static, STATIC_EXTENSION) => match name {
141-
"mkl_core" => {
142-
ensure!(
143-
library_dir.replace(dir).is_none(),
144-
"Two or more MKL found in {}",
145-
root_dir.display()
146-
)
147-
}
148-
"iomp5" => {
149-
ensure!(
150-
iomp5_dir.replace(dir).is_none(),
151-
"Two or more MKL found in {}",
152-
root_dir.display()
153-
)
154-
}
155-
_ => {}
156-
},
157-
(LinkType::Dynamic, std::env::consts::DLL_EXTENSION) => match name {
158-
"mkl_core" => {
159-
ensure!(
160-
library_dir.replace(dir).is_none(),
161-
"Two or more MKL found in {}",
162-
root_dir.display()
163-
)
148+
149+
match name {
150+
"mkl_core" => {
151+
match (config.link, ext) {
152+
(LinkType::Static, STATIC_EXTENSION)
153+
| (LinkType::Dynamic, std::env::consts::DLL_EXTENSION) => {}
154+
_ => continue,
164155
}
165-
"iomp5" => {
166-
ensure!(
167-
iomp5_dir.replace(dir).is_none(),
168-
"Two or more MKL found in {}",
169-
root_dir.display()
170-
)
156+
log::info!("Found: {}", path.display());
157+
library_dir = Some(dir);
158+
}
159+
"iomp5" => {
160+
// Allow both dynamic/static library by default
161+
//
162+
// This is due to some distribution does not provide libiomp5.a
163+
if cfg!(feature = "openmp-strict-link-type") {
164+
match (config.link, ext) {
165+
(LinkType::Static, STATIC_EXTENSION)
166+
| (LinkType::Dynamic, std::env::consts::DLL_EXTENSION) => {}
167+
_ => continue,
168+
}
171169
}
172-
_ => {}
173-
},
170+
log::info!("Found: {}", path.display());
171+
iomp5_dir = Some(dir);
172+
}
174173
_ => {}
175174
}
176175
}
177176
if config.parallel == Threading::OpenMP && iomp5_dir.is_none() {
177+
if let Some(ref lib) = library_dir {
178+
log::warn!("iomp5 not found while MKL found at {}", lib.display());
179+
}
178180
return Ok(None);
179181
}
180182
Ok(match (library_dir, include_dir) {

0 commit comments

Comments
 (0)