[HIP] Blocking host-wait schedule: kill the 100% CPU spin during GPU inference
Federico observed vetta-infer at 100% CPU while the GPU runs — the same busy-wait the strata upstream had. Root cause: ROCm's default host-wait schedule spins on every blocking synchronization (the per-token logits hipMemcpy D2H waits for the whole 48-visit forward). The reference fixes it with --hip-sync blocking (hipDeviceScheduleBlockingSync, ink_hip_backend.hip.cpp:607). Apply the same: vetta_hip_init_blocking_sync() calls hipSetDeviceFlags(hipDeviceScheduleBlockingSync), invoked once via std::sync::Once at the top of DeviceBuf::alloc — before the first hipMalloc creates the device context (tolerates hipErrorSetOnActiveProcess). Escape hatch VETTA_NO_BLOCKING_SYNC=1 keeps the spin schedule for A/B measurement. Measured A/B (220-token prefill, instantaneous /proc CPU): spin (VETTA_NO_BLOCKING_SYNC=1): 101.2% blocking (default): 54.2% The ~47 pp of spin-wait is gone. The remaining ~54% is genuine kernel-launch overhead (~1300 launches/token, no HIP graph yet) — collapsing launches via graph capture is the deferred perf step that would bring host CPU near zero. Parity EXACT (16 tok) unchanged; 18 hip + 5 gw GPU green; workspace -D warnings green.
This commit is contained in:
1 parent
59c41cb613
commit
25200e2e79
3 files changed
+25
No files matched your search
@@ -24,6 +24,7 @@ mod ffi {
|
||||
|
||||
unsafe extern "C" {
|
||||
pub fn vetta_hip_query_device(dev_id: c_int, out: *mut DeviceInfoRaw) -> c_int;
|
||||
pub fn vetta_hip_init_blocking_sync() -> c_int;
|
||||
pub fn vetta_buf_alloc(out: *mut *mut c_void, bytes: usize) -> c_int;
|
||||
pub fn vetta_buf_free(p: *mut c_void) -> c_int;
|
||||
pub fn vetta_buf_h2d(dst: *mut c_void, src: *const c_void, bytes: usize) -> c_int;
|
||||
@@ -173,6 +174,17 @@ fn pool_enabled() -> bool {
|
||||
#[cfg(feature = "hip")]
|
||||
impl DeviceBuf {
|
||||
pub fn alloc(bytes: usize) -> Result<Self, String> {
|
||||
// Set the blocking host-wait schedule once, before the first hipMalloc
|
||||
// creates the device context, so GPU waits sleep instead of spinning at
|
||||
// 100% CPU (exact strata --hip-sync blocking).
|
||||
static SYNC_INIT: std::sync::Once = std::sync::Once::new();
|
||||
SYNC_INIT.call_once(|| unsafe {
|
||||
// Escape hatch VETTA_NO_BLOCKING_SYNC=1 keeps the ROCm default spin
|
||||
// schedule (for A/B CPU measurement).
|
||||
if std::env::var("VETTA_NO_BLOCKING_SYNC").is_err() {
|
||||
ffi::vetta_hip_init_blocking_sync();
|
||||
}
|
||||
});
|
||||
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 });
|
||||
|
||||
Reference in new issue
Block a user