Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions vortex-cuda/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ pub mod cuda_kernel_generator;

fn main() {
let manifest_dir = env::var("CARGO_MANIFEST_DIR").expect("Failed to get manifest dir");
// https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts
let profile = env::var("PROFILE").unwrap();

// Source directory for kernels (hand-written and generated .cu/.cuh files)
let kernels_src = Path::new(&manifest_dir).join("kernels/src");
// Output directory for compiled .ptx files
let kernels_gen = Path::new(&manifest_dir).join("kernels/gen");
// Output directory for compiled .ptx files - separate by profile.
let kernels_gen = Path::new(&manifest_dir).join("kernels/gen").join(&profile);

std::fs::create_dir_all(&kernels_gen).expect("Failed to create kernels/gen directory");

Expand All @@ -37,6 +39,8 @@ fn main() {
kernels_gen.display()
);

println!("cargo:rerun-if-env-changed=PROFILE");

// Regenerate bit_unpack kernels only when the generator changes
for entry in std::fs::read_dir(Path::new(&manifest_dir).join("cuda_kernel_generator"))
.expect("Failed to read cuda_kernel_generator directory")
Expand Down Expand Up @@ -70,7 +74,7 @@ fn main() {
println!("cargo:rerun-if-changed={}", path.display());
}
// Compile all .cu files to PTX in gen directory
nvcc_compile_ptx(&kernels_src, &kernels_gen, &path)
nvcc_compile_ptx(&kernels_src, &kernels_gen, &path, &profile)
.map_err(|e| {
format!("Failed to compile CUDA kernel {}: {}", path.display(), e)
})
Expand All @@ -88,12 +92,14 @@ fn generate_unpack<T: FastLanes>(output_dir: &Path, thread_count: usize) -> io::
generate_cuda_unpack_for_width::<T, _>(&mut cu_writer, thread_count)
}

fn nvcc_compile_ptx(include_dir: &Path, output_dir: &Path, cu_path: &Path) -> io::Result<()> {
// https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts
let profile = env::var("PROFILE").unwrap();

fn nvcc_compile_ptx(
include_dir: &Path,
output_dir: &Path,
cu_path: &Path,
profile: &str,
) -> io::Result<()> {
let mut cmd = Command::new("nvcc");
if profile.as_str() == "debug" {
if profile == "debug" {
cmd.arg("-O0");

// NVCC debugging options:
Expand Down
Loading