[HIP] Device buffer pool + right-sized GEMV blocks (decode perf)
DeviceBuf::alloc/Drop now reuse freed buffers via a thread-local size-bucketed free list instead of hipMalloc/hipFree per intermediate (~1200 alloc/free per token). Safe: all launches share the default stream and host copies are blocking, so a recycled buffer's prior use is ordered before its next launch. Escape hatch VETTA_NO_BUF_POOL=1. nvfp4_gemv 256->128 threads (K/16=144 groups: half the waves were idle), mxfp8_gemv 256->64 (K/32<=72 groups); cheaper block reduction. MEASURED (gfx1150 release, GEN 64): decode 269ms/tok -> 234ms/tok (3.72->4.27 tok/s, ~15%). Parity unchanged: 18 ld GPU + 17 hip GPU green. Profiling shows the remaining hotspot is the scalar-dequant expert GEMV (~87ms/tok) — the fdot2 hardware-dot + device-resident blocks + hipGraph path is the next big lever.
This commit is contained in:
1 parent
0a46c4dd7b
commit
4bc268f69c
2 files changed
+31
-3
No files matched your search
@@ -130,9 +130,33 @@ pub struct DeviceBuf {
|
||||
pub bytes: usize,
|
||||
}
|
||||
|
||||
/// Size-bucketed free list of device buffers. The layer forward allocates and
|
||||
/// frees ~25 short-lived intermediates per visit (~1200 hipMalloc/hipFree per
|
||||
/// token); hipMalloc/hipFree each synchronize the device, dominating decode
|
||||
/// latency. Reusing freed buffers by exact size removes that churn. Safe because
|
||||
/// all launches share the default stream and every host copy (hipMemcpy) is
|
||||
/// blocking: a buffer is only recycled after its last use is ordered before the
|
||||
/// next launch that reuses it. Thread-local (cargo test runs tests in parallel).
|
||||
/// Escape hatch: VETTA_NO_BUF_POOL=1 forces raw hipMalloc/hipFree.
|
||||
#[cfg(feature = "hip")]
|
||||
thread_local! {
|
||||
static BUF_POOL: std::cell::RefCell<std::collections::HashMap<usize, Vec<*mut std::os::raw::c_void>>> =
|
||||
std::cell::RefCell::new(std::collections::HashMap::new());
|
||||
}
|
||||
|
||||
#[cfg(feature = "hip")]
|
||||
fn pool_enabled() -> bool {
|
||||
std::env::var("VETTA_NO_BUF_POOL").is_err()
|
||||
}
|
||||
|
||||
#[cfg(feature = "hip")]
|
||||
impl DeviceBuf {
|
||||
pub fn alloc(bytes: usize) -> Result<Self, String> {
|
||||
if pool_enabled() {
|
||||
if let Some(ptr) = BUF_POOL.with(|p| p.borrow_mut().get_mut(&bytes).and_then(|v| v.pop())) {
|
||||
return Ok(Self { ptr, bytes });
|
||||
}
|
||||
}
|
||||
let mut ptr: *mut std::os::raw::c_void = std::ptr::null_mut();
|
||||
let rc = unsafe { ffi::vetta_buf_alloc(&mut ptr, bytes) };
|
||||
if rc != 0 || ptr.is_null() { return Err(format!("hipMalloc({bytes}) failed")); }
|
||||
@@ -169,7 +193,11 @@ impl DeviceBuf {
|
||||
#[cfg(feature = "hip")]
|
||||
impl Drop for DeviceBuf {
|
||||
fn drop(&mut self) {
|
||||
unsafe { ffi::vetta_buf_free(self.ptr); }
|
||||
if pool_enabled() && !self.ptr.is_null() {
|
||||
BUF_POOL.with(|p| p.borrow_mut().entry(self.bytes).or_default().push(self.ptr));
|
||||
} else {
|
||||
unsafe { ffi::vetta_buf_free(self.ptr); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user