-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
110 lines (91 loc) · 5.54 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
extern crate bindgen;
extern crate dirs;
use std::{env, process::Command, path::Path};
use bindgen::callbacks::{MacroParsingBehavior, ParseCallbacks};
#[derive(Debug)]
struct MacroCallback { }
impl ParseCallbacks for MacroCallback {
fn will_parse_macro(&self, name: &str) -> MacroParsingBehavior {
if ["FP_SUBNORMAL", "FP_NORMAL", "FP_ZERO", "FP_INFINITE", "FP_NAN"].contains(&name) {
return MacroParsingBehavior::Ignore
}
MacroParsingBehavior::Default
}
}
fn main() -> () {
let out_dir = env::var("OUT_DIR").unwrap();
if cfg!(feature="blis") {
//Link with BLIS assuming it is installed to the default location:
println!("cargo:rustc-link-search=native={}/blis/lib", dirs::home_dir().unwrap().to_str().unwrap() );
println!("cargo:rustc-link-search=native=/usr/local/lib");
println!("cargo:rustc-link-lib=static=blis");
//Needed when BLIS is compiled with GCC and OpenMP:
// println!("cargo:rustc-link-search=native=/usr/lib/gcc/x86_64-linux-gnu/5");
// println!("cargo:rustc-link-lib=dylib=gomp");
//Use bindgen to create bindings to BLIS's typedefs
//This allows us to interface with the BLIS micro-kernel
let bindings = bindgen::Builder::default()
.header("blis_types_wrapper.h")
.clang_arg("-include")
.clang_arg("stddef.h")
.clang_arg(format!("-I/{}/blis/include/blis", dirs::home_dir().unwrap().to_str().unwrap()))
.parse_callbacks(Box::new(MacroCallback{ }))
.whitelist_type("pack_t*")
.whitelist_type("auxinfo_t")
.generate()
.expect("Unable to generate bindings");
// Write the bindings to the $OUT_DIR/bindings.rs file.
let out_path = std::path::PathBuf::from(&out_dir);
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
//
// Compile knm "micro-kernel" standalone
// via: icc -I${HOME}/blis/include/blis -march=knm -O3 -std=c11 -c sgemm_knm_int_24x16.c -o sgemm_knm_int_24x16.o
//
if cfg!(feature="knm"){
Command::new("icc").arg(&format!("-I{}/blis/include/blis", dirs::home_dir().unwrap().to_str().unwrap()))
.args(&["-march=knm", "-O3", "-std=c11", "-fPIC", "-c", "ukernels/sgemm_knm_int_24x16.c", "-o"])
.arg(&format!("{}/sgemm_knm_int_24x16.o", &out_dir))
.status().unwrap();
Command::new("icc").arg(&format!("-I{}/blis/include/blis", dirs::home_dir().unwrap().to_str().unwrap()))
.args(&["-march=knm", "-O3", "-std=c11", "-fPIC", "-c", "ukernels/sgemm_knm_asm_24x16.c", "-o"])
.arg(&format!("{}/sgemm_knm_asm_24x16.o", &out_dir))
.status().unwrap();
Command::new("ar").args(&["crus", "libukernel.a", "sgemm_knm_int_24x16.o", "sgemm_knm_asm_24x16.o"])
.current_dir(&Path::new(&out_dir))
.status().unwrap();
println!("cargo:rustc-link-search=native={}", &out_dir);
println!("cargo:rustc-link-lib=static=ukernel");
}
if cfg!(feature="hsw"){
Command::new("icc").arg(&format!("-I{}/blis/include/blis", dirs::home_dir().unwrap().to_str().unwrap()))
.args(&["-march=hsw", "-O3", "-std=c11", "-fPIC", "-c", "ukernels/bli_gemm_haswell_asm_d12x4.c", "-o"])
.arg(&format!("{}/bli_gemm_haswell_asm_d12x4.o", &out_dir))
.status().unwrap();
Command::new("icc").arg(&format!("-I{}/blis/include/blis", dirs::home_dir().unwrap().to_str().unwrap()))
.args(&["-march=hsw", "-O3", "-std=c11", "-fPIC", "-c", "ukernels/bli_gemm_haswell_asm_d4x12.c", "-o"])
.arg(&format!("{}/bli_gemm_haswell_asm_d4x12.o", &out_dir))
.status().unwrap();
Command::new("icc").arg(&format!("-I{}/blis/include/blis", dirs::home_dir().unwrap().to_str().unwrap()))
.args(&["-march=hsw", "-O3", "-std=c11", "-fPIC", "-c", "ukernels/bli_gemm_haswell_asm_d8x6.c", "-o"])
.arg(&format!("{}/bli_gemm_haswell_asm_d8x6.o", &out_dir))
.status().unwrap();
Command::new("icc").arg(&format!("-I{}/blis/include/blis", dirs::home_dir().unwrap().to_str().unwrap()))
.args(&["-march=hsw", "-O3", "-std=c11", "-fPIC", "-c", "ukernels/bli_gemm_haswell_asm_d6x8.c", "-o"])
.arg(&format!("{}/bli_gemm_haswell_asm_d6x8.o", &out_dir))
.status().unwrap();
Command::new("ar").args(&["crus", "libukernel.a", "bli_gemm_haswell_asm_d12x4.o", "bli_gemm_haswell_asm_d4x12.o", "bli_gemm_haswell_asm_d6x8.o", "bli_gemm_haswell_asm_d8x6.o"])
.current_dir(&Path::new(&out_dir))
.status().unwrap();
println!("cargo:rustc-link-search=native={}", &out_dir);
println!("cargo:rustc-link-lib=static=ukernel");
}
//Needed for linking with BLIS when it was compiled with icc
// println!("cargo:rustc-link-lib=static=irc");
}
if cfg!(feature="libxsmm"){
println!("cargo:rustc-link-search=native={}/libxsmm/lib", dirs::home_dir().unwrap().to_str().unwrap() );
println!("cargo:rustc-link-lib=static=xsmm");
}
}