[HIP][Core] Zero-VRAM PrefixCache in pinned host RAM (PinnedBuf) + DSpark SWA ring

Close Punto 3 of the flat-VRAM plan:
- Add PinnedBuf (hipHostMallocDefault / hipHostFree with stream 0 sync on drop) and pipelined async 1D/2D D2H/H2D copy helpers in vetta_kernels.{h,hip} and vetta-infer-hip.
- Migrate LayerSnapshot (KV + ShortConv hist) and DsparkSnapshot (drafter KV + frnn_last) from VRAM DeviceBuf to host PinnedBuf (0 bytes VRAM per checkpoint).
- Size DSpark SWA layers 0/2 in DsparkContext to DS_SWA_RING=1280 (-258 MiB VRAM at 32k context).
- Add GPU regression tests: pinned_buf_zero_vram_and_roundtrip_2d (+0.00 MiB VRAM on 64 MiB alloc) and serve_gen_pinned_prefix_cache_vram_flat (4 turns up to 2100 tok, 8/8 checkpoints full, VETTA_SPEC=1: 20674->20672->20676->20676 MiB, +2.00 MiB delta).
- Update README.md, docs/ORIENTATION.md, and review/2026-12-02-fix-drafter-e-ottimizzazioni.md.
This commit is contained in:
adm committed 2026-12-02 23:23:07 +01:00
1 parent c1c5221642
commit 1772050087
9 files changed
+370 -88

No files matched your search

+11 -1
View File
@@ -34,10 +34,20 @@ 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);
int vetta_buf_d2h(void* dst, const void* src, size_t bytes);
// Device-to-device copies (prefix-checkpoint snapshot/restore).
// Device-to-device copies (legacy/internal).
int vetta_buf_copy(void* dst, const void* src, size_t bytes);
int vetta_buf_copy2d(void* dst, size_t dpitch, const void* src, size_t spitch,
size_t width, size_t height);
// Pinned host RAM lifecycle + async D2H/H2D copies for zero-VRAM PrefixCache
// checkpoints (hipHostMallocDefault / hipHostFree with stream sync on free).
int vetta_host_alloc(void** out, size_t bytes);
int vetta_host_free(void* p);
int vetta_buf_d2h_async(void* dst_host, const void* src_dev, size_t bytes);
int vetta_buf_h2d_async(void* dst_dev, const void* src_host, size_t bytes);
int vetta_buf_copy2d_d2h_async(void* dst_host, size_t dpitch, const void* src_dev,
size_t spitch, size_t width, size_t height);
int vetta_buf_copy2d_h2d_async(void* dst_dev, size_t dpitch, const void* src_host,
size_t spitch, size_t width, size_t height);
// k_rms_norm (kernel #2): y[row] = x[row] * rsqrt(mean(x^2)+eps) * w.
int vetta_rms_norm_f32(const float* x, const float* w, float* y,
+39
View File
@@ -82,6 +82,45 @@ extern "C" int vetta_buf_copy2d(void* dst, size_t dpitch, const void* src,
HIP_CHECK(hipMemcpy2D(dst, dpitch, src, spitch, width, height, hipMemcpyDeviceToDevice));
return 0;
}
// Pinned host RAM buffers for zero-VRAM PrefixCache checkpoints (matches strata
// PromptCkpt): hipHostMallocDefault lives in host RAM (0 bytes VRAM) and transfers
// via SDMA on stream 0 with hipMemcpy[2D]Async. vetta_host_free syncs stream 0
// before hipHostFree so in-flight async copies never race with eviction/drop.
extern "C" int vetta_host_alloc(void** out, size_t bytes) {
if (!out) return 1;
HIP_CHECK(hipHostMalloc(out, bytes, hipHostMallocDefault));
return 0;
}
extern "C" int vetta_host_free(void* p) {
if (!p) return 0;
(void)hipStreamSynchronize((hipStream_t)0);
HIP_CHECK(hipHostFree(p));
return 0;
}
extern "C" int vetta_buf_d2h_async(void* dst_host, const void* src_dev, size_t bytes) {
if (bytes == 0) return 0;
HIP_CHECK(hipMemcpyAsync(dst_host, src_dev, bytes, hipMemcpyDeviceToHost, (hipStream_t)0));
return 0;
}
extern "C" int vetta_buf_h2d_async(void* dst_dev, const void* src_host, size_t bytes) {
if (bytes == 0) return 0;
HIP_CHECK(hipMemcpyAsync(dst_dev, src_host, bytes, hipMemcpyHostToDevice, (hipStream_t)0));
return 0;
}
extern "C" int vetta_buf_copy2d_d2h_async(void* dst_host, size_t dpitch, const void* src_dev,
size_t spitch, size_t width, size_t height) {
if (width == 0 || height == 0) return 0;
HIP_CHECK(hipMemcpy2DAsync(dst_host, dpitch, src_dev, spitch, width, height,
hipMemcpyDeviceToHost, (hipStream_t)0));
return 0;
}
extern "C" int vetta_buf_copy2d_h2d_async(void* dst_dev, size_t dpitch, const void* src_host,
size_t spitch, size_t width, size_t height) {
if (width == 0 || height == 0) return 0;
HIP_CHECK(hipMemcpy2DAsync(dst_dev, dpitch, src_host, spitch, width, height,
hipMemcpyHostToDevice, (hipStream_t)0));
return 0;
}
// Block until all queued GPU work completes (profiling phase boundaries; the
// batched forward is otherwise fully async with no host sync until final d2h).
extern "C" int vetta_synchronize(void) {