-
Notifications
You must be signed in to change notification settings - Fork 230
Expand file tree
/
Copy pathbuild.rs
More file actions
63 lines (50 loc) · 1.96 KB
/
build.rs
File metadata and controls
63 lines (50 loc) · 1.96 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
63
use std::env;
use std::path;
use std::process::{Command, Stdio};
use cuda_builder::CudaBuilder;
fn main() {
println!("cargo::rerun-if-changed=build.rs");
println!("cargo::rerun-if-changed=kernels");
let out_path = path::PathBuf::from(env::var("OUT_DIR").unwrap());
let kernels_path = path::PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("kernels");
CudaBuilder::new(kernels_path.as_path())
.copy_to(out_path.join("kernels.ptx"))
.build()
.unwrap();
// Generate PTX from native CUDA kernels
let cuda_kernel_path = kernels_path.join("cuda/sdot.cu");
println!("cargo::rerun-if-changed={}", cuda_kernel_path.display());
let cuda_ptx = out_path.join("kernels_cuda_mangles.ptx");
let mut nvcc = Command::new("nvcc");
nvcc.arg("--ptx")
.args(["--Werror", "all-warnings"])
.args(["--output-directory", out_path.as_os_str().to_str().unwrap()])
.args(["-o", cuda_ptx.as_os_str().to_str().unwrap()])
.arg(cuda_kernel_path.as_path());
let build = nvcc
.stderr(Stdio::inherit())
.output()
.expect("failed to execute nvcc kernel build");
assert!(build.status.success());
// Decodes (demangles) low-level identifiers
let cat_out = Command::new("cat")
.arg(cuda_ptx)
.stdout(Stdio::piped())
.stderr(Stdio::inherit())
.spawn()
.expect("Failed to start cat process")
.stdout
.expect("Failed to open cat stdout");
let outputs = std::fs::File::create(out_path.join("kernels_cuda.ptx"))
.expect("Can not open output ptc kernel file");
let filt_out = Command::new("cu++filt")
.arg("-p")
.stdin(Stdio::from(cat_out))
.stdout(Stdio::from(outputs))
.stderr(Stdio::inherit())
.spawn()
.expect("Failed to start cu++filt process")
.wait_with_output()
.expect("Failed to wait on cu++filt");
assert!(filt_out.status.success());
}