[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:
adm committed 2026-12-01 19:06:33 +01:00
1 parent 59c41cb613
commit 25200e2e79
3 files changed
+25

No files matched your search

+3
View File
@@ -27,6 +27,9 @@ int vetta_hip_register_uma_pages(void* host_aligned_ptr, size_t bytes, void** ou
int vetta_hip_unregister_uma_pages(void* host_aligned_ptr);
// Minimal device buffer lifecycle (executor foundation).
// Set blocking host-wait schedule (no 100% CPU spin during GPU waits); call once
// before the first allocation creates the device context.
int vetta_hip_init_blocking_sync(void);
int vetta_buf_alloc(void** out, size_t bytes);
int vetta_buf_free(void* p);
int vetta_buf_h2d(void* dst, const void* src, size_t bytes);
+10
View File
@@ -43,6 +43,16 @@ extern "C" int vetta_hip_query_device(int dev_id, vetta_device_info_t* out) {
// ---- minimal device buffer lifecycle (UMA-aware) ---------------------------
// Host-wait schedule: BLOCKING so host synchronization (blocking hipMemcpy /
// hipStreamSynchronize) sleeps instead of spinning at 100% CPU while the GPU
// runs. Exact strata --hip-sync blocking (hipDeviceScheduleBlockingSync). Must
// run before the device context is created; tolerate hipErrorSetOnActiveProcess.
extern "C" int vetta_hip_init_blocking_sync(void) {
hipError_t e = hipSetDeviceFlags(hipDeviceScheduleBlockingSync);
if (e != hipSuccess && e != hipErrorSetOnActiveProcess) { (void)hipGetLastError(); return 1; }
return 0;
}
extern "C" int vetta_buf_alloc(void** out, size_t bytes) {
if (!out) return 1;
HIP_CHECK(hipMalloc(out, bytes));