[HIP] GPU backend bring-up: feature-gated hipcc build + first verified kernel on gfx1150
- New crate vetta-infer-hip: HIP FFI/DMA backend (unsafe isolated here per AGENTS.md). Kernel build is feature-gated (`hip`, default OFF) so `cargo test --workspace` stays host-independent (97/97, no toolchain). build.rs invokes hipcc --offload-arch=gfx1150, archives libvetta_kernels.a, links amdhip64 from ROCM_PATH/lib. - kernels/hip/vetta_kernels.hip: device query, minimal device-buffer lifecycle (alloc/free/h2d/d2h, RAII DeviceBuf), and the first microkernel k_rms_norm_f32 (one block/row, shared-mem reduction). C ABI extended in vetta_kernels.h. - Safe wrappers: query_device, DeviceBuf, rms_norm_f32. Verified LIVE on Sogliola (cargo test -p vetta-infer-hip --features hip -- --ignored): device = AMD Radeon 890M Graphics gfx1150 CU=8 UMA=true; rms_norm parity vs CPU oracle max_rel_err ~1.3e-6 across rows 1/4/3/2 and d 2304/128/1024 (tolerance 1e-4). First GPU compute verified end-to-end: hipcc -> static lib -> FFI -> launch -> parity. This opens the GPU execution half (executor + remaining kernels toward the first served token).
This commit is contained in:
1 parent
f57060caa7
commit
bd0d4f2a63
7 files changed
+361
No files matched your search
@@ -0,0 +1,51 @@
|
||||
//! Build the HIP microkernels via hipcc when the `hip` feature is enabled.
|
||||
//! Default (no feature): no toolchain invocation — the workspace stays
|
||||
//! host-independent. With `--features hip`: compile kernels/hip/vetta_kernels.hip
|
||||
//! for gfx1150, archive it, and link the HIP runtime.
|
||||
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() {
|
||||
let manifest = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
|
||||
let kernels = manifest.join("../../kernels/hip");
|
||||
println!("cargo:rerun-if-changed={}", kernels.join("vetta_kernels.hip").display());
|
||||
println!("cargo:rerun-if-changed={}", kernels.join("vetta_kernels.h").display());
|
||||
println!("cargo:rerun-if-env-changed=HIPCC");
|
||||
|
||||
if env::var("CARGO_FEATURE_HIP").is_err() {
|
||||
return; // host-independent default: nothing to build
|
||||
}
|
||||
|
||||
let hipcc = env::var("HIPCC").unwrap_or_else(|_| "/opt/rocm/bin/hipcc".to_string());
|
||||
let out = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||
let src = kernels.join("vetta_kernels.hip");
|
||||
let obj = out.join("vetta_kernels.o");
|
||||
let lib = out.join("libvetta_kernels.a");
|
||||
|
||||
let arch = env::var("VETTA_OFFLOAD_ARCH").unwrap_or_else(|_| "gfx1150".to_string());
|
||||
let status = Command::new(&hipcc)
|
||||
.arg(format!("--offload-arch={arch}"))
|
||||
.args(["-O3", "-std=c++17", "-fPIC", "-c"])
|
||||
.arg(&src)
|
||||
.arg("-o")
|
||||
.arg(&obj)
|
||||
.status()
|
||||
.unwrap_or_else(|e| panic!("failed to spawn {hipcc}: {e}"));
|
||||
assert!(status.success(), "hipcc compile failed for {}", src.display());
|
||||
|
||||
let status = Command::new("ar")
|
||||
.arg("rcs")
|
||||
.arg(&lib)
|
||||
.arg(&obj)
|
||||
.status()
|
||||
.expect("failed to spawn ar");
|
||||
assert!(status.success(), "ar archive failed");
|
||||
|
||||
println!("cargo:rustc-link-search=native={}", out.display());
|
||||
let rocm = env::var("ROCM_PATH").unwrap_or_else(|_| "/opt/rocm".to_string());
|
||||
println!("cargo:rustc-link-search=native={rocm}/lib");
|
||||
println!("cargo:rustc-link-lib=static=vetta_kernels");
|
||||
println!("cargo:rustc-link-lib=amdhip64");
|
||||
}
|
||||
Reference in new issue
Block a user