-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
62 lines (55 loc) · 1.9 KB
/
Copy pathbuild.rs
File metadata and controls
62 lines (55 loc) · 1.9 KB
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
use std::env;
use std::path::PathBuf;
fn main() {
println!("cargo:rerun-if-changed=cuda/");
if cfg!(feature = "cuda") {
build_cuda();
} else {
build_cpu_stubs();
}
}
fn build_cpu_stubs() {
cc::Build::new()
.file("cuda/stubs.c")
.compile("fastnn_cuda_stubs");
}
fn build_cuda() {
// Find CUDA toolkit
let cuda_path = env::var("CUDA_PATH")
.or_else(|_| env::var("CUDA_HOME"))
.unwrap_or_else(|_| {
if cfg!(target_os = "windows") {
"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.0".to_string()
} else {
"/usr/local/cuda".to_string()
}
});
let cuda_include = PathBuf::from(&cuda_path).join("include");
let cuda_lib = if cfg!(target_os = "windows") {
PathBuf::from(&cuda_path).join("lib/x64")
} else {
PathBuf::from(&cuda_path).join("lib64")
};
// Compile CUDA kernels using cc with nvcc
cc::Build::new()
.cuda(true)
.cudart("shared")
.flag("-ccbin=g++-15") // GCC 16 is not yet supported by nvcc
.flag("-gencode=arch=compute_75,code=sm_75") // Turing
.flag("-gencode=arch=compute_80,code=sm_80") // Ampere
.flag("-gencode=arch=compute_86,code=sm_86") // Ampere (RTX 30xx)
.flag("-gencode=arch=compute_89,code=sm_89") // Ada Lovelace
.flag("-gencode=arch=compute_90,code=sm_90") // Hopper
.flag("--use_fast_math")
.flag("--extended-lambda")
.flag("-O3")
.include("cuda/include")
.include(&cuda_include)
.file("cuda/kernels.cu")
.compile("fastnn_cuda_kernels");
// Link CUDA runtime and libraries
println!("cargo:rustc-link-search=native={}", cuda_lib.display());
println!("cargo:rustc-link-lib=dylib=cudart");
println!("cargo:rustc-link-lib=dylib=cublas");
println!("cargo:rustc-link-lib=dylib=curand");
}