1
1
use anyhow:: { bail, Result } ;
2
2
use std:: { fmt, str:: FromStr } ;
3
3
4
+ macro_rules! impl_otherwise {
5
+ ( $e: ident, $a: ident, $b: ident) => {
6
+ impl $e {
7
+ pub fn otherwise( & self ) -> Self {
8
+ match self {
9
+ $e:: $a => $e:: $b,
10
+ $e:: $b => $e:: $a,
11
+ }
12
+ }
13
+ }
14
+ } ;
15
+ }
16
+
4
17
pub const VALID_CONFIGS : & [ & str ] = & [
5
18
"mkl-dynamic-ilp64-iomp" ,
6
19
"mkl-dynamic-ilp64-seq" ,
@@ -18,6 +31,7 @@ pub enum LinkType {
18
31
Static ,
19
32
Dynamic ,
20
33
}
34
+ impl_otherwise ! ( LinkType , Static , Dynamic ) ;
21
35
22
36
impl fmt:: Display for LinkType {
23
37
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
@@ -56,6 +70,7 @@ pub enum DataModel {
56
70
/// `int`, `long` and pointer are 64bit, i.e. `sizeof(int) == 8`
57
71
ILP64 ,
58
72
}
73
+ impl_otherwise ! ( DataModel , LP64 , ILP64 ) ;
59
74
60
75
impl fmt:: Display for DataModel {
61
76
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
@@ -92,6 +107,8 @@ pub enum Threading {
92
107
Sequential ,
93
108
}
94
109
110
+ impl_otherwise ! ( Threading , OpenMP , Sequential ) ;
111
+
95
112
impl Default for Threading {
96
113
fn default ( ) -> Self {
97
114
Threading :: Sequential
@@ -159,59 +176,6 @@ impl Config {
159
176
. map ( |name| Self :: from_str ( name) . unwrap ( ) )
160
177
. collect ( )
161
178
}
162
-
163
- /// Common components
164
- ///
165
- /// The order must be following (or equivalent libs)
166
- ///
167
- /// mkl_intel_lp64 > mkl_intel_thread > mkl_core > iomp5
168
- ///
169
- pub fn libs ( & self ) -> Vec < String > {
170
- let mut libs = Vec :: new ( ) ;
171
- match self . index_size {
172
- DataModel :: LP64 => {
173
- libs. push ( "mkl_intel_lp64" . into ( ) ) ;
174
- }
175
- DataModel :: ILP64 => {
176
- libs. push ( "mkl_intel_ilp64" . into ( ) ) ;
177
- }
178
- } ;
179
- match self . parallel {
180
- Threading :: OpenMP => {
181
- libs. push ( "mkl_intel_thread" . into ( ) ) ;
182
- }
183
- Threading :: Sequential => {
184
- libs. push ( "mkl_sequential" . into ( ) ) ;
185
- }
186
- } ;
187
- libs. push ( "mkl_core" . into ( ) ) ;
188
- if matches ! ( self . parallel, Threading :: OpenMP ) {
189
- libs. push ( "iomp5" . into ( ) ) ;
190
- }
191
- libs
192
- }
193
-
194
- /// Dynamically loaded libraries, e.g. `libmkl_vml_avx2.so`
195
- ///
196
- /// - MKL seeks additional shared library **on runtime**.
197
- /// This function lists these files for packaging.
198
- pub fn additional_libs ( & self ) -> Vec < String > {
199
- match self . link {
200
- LinkType :: Static => Vec :: new ( ) ,
201
- LinkType :: Dynamic => {
202
- let mut libs = Vec :: new ( ) ;
203
- for prefix in & [ "mkl" , "mkl_vml" ] {
204
- for suffix in & [ "def" , "avx" , "avx2" , "avx512" , "avx512_mic" , "mc" , "mc3" ] {
205
- libs. push ( format ! ( "{}_{}" , prefix, suffix) ) ;
206
- }
207
- }
208
- libs. push ( "mkl_rt" . into ( ) ) ;
209
- libs. push ( "mkl_vml_mc2" . into ( ) ) ;
210
- libs. push ( "mkl_vml_cmpt" . into ( ) ) ;
211
- libs
212
- }
213
- }
214
- }
215
179
}
216
180
217
181
#[ cfg( test) ]
0 commit comments