From 0640c58fe0e02bb4eae3cd480115f70b11da2bfa Mon Sep 17 00:00:00 2001 From: Russel Arbore <rarbore2@illinois.edu> Date: Mon, 13 Jan 2025 21:30:53 -0600 Subject: [PATCH] tests pass built w/ cuda --- hercules_rt/build.rs | 4 ++- hercules_rt/src/rtdefs.cu | 66 ++++++++++++++++++++------------------- 2 files changed, 37 insertions(+), 33 deletions(-) diff --git a/hercules_rt/build.rs b/hercules_rt/build.rs index 00773d06..15b9f639 100644 --- a/hercules_rt/build.rs +++ b/hercules_rt/build.rs @@ -6,7 +6,7 @@ fn main() { if cfg!(feature = "cuda") { let out_dir = var("OUT_DIR").unwrap(); Command::new("nvcc") - .args(&["src/rtdefs.cu", "-c", "-fPIC", "-o"]) + .args(&["src/rtdefs.cu", "-c", "-o"]) .arg(&format!("{}/rtdefs.o", out_dir)) .status() .expect("PANIC: NVCC failed when building runtime. Is NVCC installed?"); @@ -17,7 +17,9 @@ fn main() { .unwrap(); println!("cargo::rustc-link-search=native={}", out_dir); + println!("cargo::rustc-link-search=native=/usr/lib/x86_64-linux-gnu/"); println!("cargo::rustc-link-lib=static=rtdefs"); + println!("cargo::rustc-link-lib=cudart"); println!("cargo::rerun-if-changed=src/rtdefs.cu"); } } diff --git a/hercules_rt/src/rtdefs.cu b/hercules_rt/src/rtdefs.cu index 890bf698..b7378d81 100644 --- a/hercules_rt/src/rtdefs.cu +++ b/hercules_rt/src/rtdefs.cu @@ -1,36 +1,38 @@ -void *cuda_alloc(size_t size) { - void *ptr = NULL; - cudaError_t res = cudaMalloc(&ptr, size); - if (res != cudaSuccess) { - ptr = NULL; +extern "C" { + void *cuda_alloc(size_t size) { + void *ptr = NULL; + cudaError_t res = cudaMalloc(&ptr, size); + if (res != cudaSuccess) { + ptr = NULL; + } + return ptr; } - return ptr; -} - -void *cuda_alloc_zeroed(size_t size) { - void *ptr = cuda_alloc(size); - if (!ptr) { - return NULL; + + void *cuda_alloc_zeroed(size_t size) { + void *ptr = cuda_alloc(size); + if (!ptr) { + return NULL; + } + cudaError_t res = cudaMemset(ptr, 0, size); + if (res != cudaSuccess) { + return NULL; + } + return ptr; } - cudaError_t res = cudaMemset(ptr, 0, size); - if (res != cudaSuccess) { - return NULL; + + void cuda_dealloc(void *ptr) { + cudaFree(ptr); + } + + void copy_cpu_to_cuda(void *dst, void *src, size_t size) { + cudaMemcpy(dst, src, size, cudaMemcpyHostToDevice); + } + + void copy_cuda_to_cpu(void *dst, void *src, size_t size) { + cudaMemcpy(dst, src, size, cudaMemcpyDeviceToHost); + } + + void copy_cuda_to_cuda(void *dst, void *src, size_t size) { + cudaMemcpy(dst, src, size, cudaMemcpyDeviceToDevice); } - return ptr; -} - -void cuda_dealloc(void *ptr) { - cudaFree(ptr); -} - -void copy_cpu_to_cuda(void *dst, void *src, size_t size) { - cudaMemcpy(dst, src, size, cudaMemcpyHostToDevice); -} - -void copy_cuda_to_cpu(void *dst, void *src, size_t size) { - cudaMemcpy(dst, src, size, cudaMemcpyDeviceToHost); -} - -void copy_cuda_to_cuda(void *dst, void *src, size_t size) { - cudaMemcpy(dst, src, size, cudaMemcpyDeviceToDevice); } -- GitLab