-
Notifications
You must be signed in to change notification settings - Fork 409
/
build.rs
47 lines (42 loc) · 1.79 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
fn main() {
let cores = num_cpus::get();
let tpcl2 = (cores as f64).log2().floor() as u32;
println!("cargo:rerun-if-changed=src/run.c");
println!("cargo:rerun-if-changed=src/hvm.c");
println!("cargo:rerun-if-changed=src/run.cu");
println!("cargo:rerun-if-changed=src/hvm.cu");
println!("cargo:rustc-link-arg=-rdynamic");
match cc::Build::new()
.file("src/run.c")
.opt_level(3)
.warnings(false)
.define("TPC_L2", &*tpcl2.to_string())
.define("IO", None)
.try_compile("hvm-c") {
Ok(_) => println!("cargo:rustc-cfg=feature=\"c\""),
Err(e) => {
println!("cargo:warning=\x1b[1m\x1b[31mWARNING: Failed to compile/run.c:\x1b[0m {}", e);
println!("cargo:warning=Ignoring/run.c and proceeding with build. \x1b[1mThe C runtime will not be available.\x1b[0m");
}
}
// Builds hvm.cu
if std::process::Command::new("nvcc").arg("--version").stdout(std::process::Stdio::null()).stderr(std::process::Stdio::null()).status().is_ok() {
if let Ok(cuda_path) = std::env::var("CUDA_HOME") {
println!("cargo:rustc-link-search=native={}/lib64", cuda_path);
} else {
println!("cargo:rustc-link-search=native=/usr/local/cuda/lib64");
}
cc::Build::new()
.cuda(true)
.file("src/run.cu")
.define("IO", None)
.flag("-diag-suppress=177") // variable was declared but never referenced
.flag("-diag-suppress=550") // variable was set but never used
.flag("-diag-suppress=20039") // a __host__ function redeclared with __device__, hence treated as a __host__ __device__ function
.compile("hvm-cu");
println!("cargo:rustc-cfg=feature=\"cuda\"");
}
else {
println!("cargo:warning=\x1b[1m\x1b[31mWARNING: CUDA compiler not found.\x1b[0m \x1b[1mHVM will not be able to run on GPU.\x1b[0m");
}
}