Skip to content
Snippets Groups Projects
Commit ab75a1d6 authored by Praneet Rathi's avatar Praneet Rathi
Browse files

cuda

parent 6a2e59af
No related branches found
No related tags found
1 merge request!115GPU backend
Pipeline #201026 failed
...@@ -718,6 +718,7 @@ name = "juno_build" ...@@ -718,6 +718,7 @@ name = "juno_build"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"hercules_ir", "hercules_ir",
"hercules_rt",
"juno_frontend", "juno_frontend",
"with_builtin_macros", "with_builtin_macros",
] ]
......
...@@ -974,6 +974,9 @@ impl PassManager { ...@@ -974,6 +974,9 @@ impl PassManager {
println!("{}", cuda_ir); println!("{}", cuda_ir);
println!("{}", rust_rt); println!("{}", rust_rt);
let output_archive = format!("{}/lib{}.a", output_dir, module_name);
println!("{}", output_archive);
// Write the LLVM IR into a temporary file. // Write the LLVM IR into a temporary file.
let tmp_dir = TempDir::new().unwrap(); let tmp_dir = TempDir::new().unwrap();
let mut llvm_path = tmp_dir.path().to_path_buf(); let mut llvm_path = tmp_dir.path().to_path_buf();
...@@ -999,32 +1002,36 @@ impl PassManager { ...@@ -999,32 +1002,36 @@ impl PassManager {
.expect("Error running clang. Is it installed?"); .expect("Error running clang. Is it installed?");
assert!(clang_process.wait().unwrap().success()); assert!(clang_process.wait().unwrap().success());
// Write the CUDA IR into a temporary file. let mut ar_args = vec!["crus", &output_archive, &llvm_object];
let mut cuda_path = tmp_dir.path().to_path_buf();
cuda_path.push(format!("{}.cu", module_name));
let mut file = File::create(&cuda_path)
.expect("PANIC: Unable to open output CUDA IR file.");
file.write_all(cuda_ir.as_bytes())
.expect("PANIC: Unable to write output CUDA IR file contents.");
let cuda_object = format!("{}/{}_cuda.o", tmp_dir.path().to_str().unwrap(), module_name); let cuda_object = format!("{}/{}_cuda.o", tmp_dir.path().to_str().unwrap(), module_name);
let mut nvcc_process = Command::new("nvcc") if cfg!(feature = "cuda") {
.arg("-c") // Write the CUDA IR into a temporary file.
.arg("-O3") let mut cuda_path = tmp_dir.path().to_path_buf();
.arg("-o") cuda_path.push(format!("{}.cu", module_name));
.arg(&cuda_object) let mut file = File::create(&cuda_path)
.arg(&cuda_path) .expect("PANIC: Unable to open output CUDA IR file.");
.spawn() file.write_all(cuda_ir.as_bytes())
.expect("Error running nvcc. Is it installed?"); .expect("PANIC: Unable to write output CUDA IR file contents.");
assert!(nvcc_process.wait().unwrap().success());
let mut nvcc_process = Command::new("nvcc")
.arg("-c")
.arg("-O3")
.arg("-lcudart")
.arg("-L/usr/lib/x86_64-linux-gnu")
.arg("-L/usr/local/cuda/lib64")
.arg("-o")
.arg(&cuda_object)
.arg(&cuda_path)
.spawn()
.expect("Error running nvcc. Is it installed?");
assert!(nvcc_process.wait().unwrap().success());
ar_args.push(&cuda_object);
}
let output_archive = format!("{}/lib{}.a", output_dir, module_name);
println!("{}", output_archive);
let mut ar_process = Command::new("ar") let mut ar_process = Command::new("ar")
.arg("crus") .args(&ar_args)
.arg(&output_archive)
.arg(&llvm_object)
.arg(&cuda_object)
.spawn() .spawn()
.expect("Error running ar. Is it installed?"); .expect("Error running ar. Is it installed?");
assert!(ar_process.wait().unwrap().success()); assert!(ar_process.wait().unwrap().success());
......
...@@ -18,6 +18,7 @@ fn main() { ...@@ -18,6 +18,7 @@ fn main() {
println!("cargo::rustc-link-search=native={}", out_dir); println!("cargo::rustc-link-search=native={}", out_dir);
println!("cargo::rustc-link-search=native=/usr/lib/x86_64-linux-gnu/"); println!("cargo::rustc-link-search=native=/usr/lib/x86_64-linux-gnu/");
println!("cargo:rustc-link-search=native=/usr/local/cuda/lib64");
println!("cargo::rustc-link-lib=static=rtdefs"); println!("cargo::rustc-link-lib=static=rtdefs");
println!("cargo::rustc-link-lib=cudart"); println!("cargo::rustc-link-lib=cudart");
println!("cargo::rerun-if-changed=src/rtdefs.cu"); println!("cargo::rerun-if-changed=src/rtdefs.cu");
......
...@@ -5,9 +5,10 @@ authors = ["Aaron Councilman <aaronjc4@illinois.edu>"] ...@@ -5,9 +5,10 @@ authors = ["Aaron Councilman <aaronjc4@illinois.edu>"]
edition = "2021" edition = "2021"
[features] [features]
cuda = ["juno_frontend/cuda"] cuda = ["juno_frontend/cuda", "hercules_rt/cuda"]
[dependencies] [dependencies]
juno_frontend = { path = "../juno_frontend" } juno_frontend = { path = "../juno_frontend" }
hercules_rt = { path = "../hercules_rt", optional = true }
hercules_ir = { path = "../hercules_ir" } hercules_ir = { path = "../hercules_ir" }
with_builtin_macros = "0.1.0" with_builtin_macros = "0.1.0"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment