[HIP] copy_f32: device-side f32 copy for depth-block snapshot / bank rollback
k_copy_f32 (dst=src, n elements): enables device-side depth-block snapshot and core-loop bank rollback in the batched forward, eliminating the M=1 host D2H/H2D round-trips (layer.rs block snapshot + bank rollback). Exact (test copy_f32_exact). Additive — decode default unchanged. Foundation for the device-resident depth-block arena [n_blocks,B,h] that attn_res_mix reads directly (already M>1). Verified: hip GPU 32 green, workspace CPU -D warnings green, 6 Lean 0 sorryAx.
This commit is contained in:
1 parent
48de65d395
commit
3a2ad4da49
2 files changed
+39
No files matched your search
@@ -76,6 +76,7 @@ mod ffi {
|
||||
m: c_int, n_experts: c_int, k_top: c_int, route_scale: c_float, stream: *mut c_void,
|
||||
) -> c_int;
|
||||
pub fn vetta_vec_add(a: *const c_float, b: *const c_float, y: *mut c_float, n: usize, stream: *mut c_void) -> c_int;
|
||||
pub fn vetta_copy_f32(src: *const c_float, dst: *mut c_float, n: usize, stream: *mut c_void) -> c_int;
|
||||
pub fn vetta_cast_f32_bf16(x: *const c_float, y: *mut u16, n: usize, stream: *mut c_void) -> c_int;
|
||||
pub fn vetta_cast_f32_f16(x: *const c_float, y: *mut u16, n: usize, stream: *mut c_void) -> c_int;
|
||||
pub fn vetta_nvfp4_gemv(
|
||||
@@ -452,6 +453,14 @@ pub fn vec_add(a: &DeviceBuf, b: &DeviceBuf, y: &DeviceBuf, n: usize) -> Result<
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Device-side f32 copy (dst=src, n elements): depth-block snapshot / bank rollback.
|
||||
#[cfg(feature = "hip")]
|
||||
pub fn copy_f32(src: &DeviceBuf, dst: &DeviceBuf, n: usize) -> Result<(), String> {
|
||||
let rc = unsafe { ffi::vetta_copy_f32(src.ptr as *const f32, dst.ptr as *mut f32, n, std::ptr::null_mut()) };
|
||||
if rc != 0 { return Err("copy_f32 launch failed".into()); }
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Launch k_cast_f32_bf16: f32 activation -> BF16 (round-to-nearest-even).
|
||||
#[cfg(feature = "hip")]
|
||||
pub fn cast_f32_bf16(x: &DeviceBuf, y: &DeviceBuf, n: usize) -> Result<(), String> {
|
||||
@@ -1682,6 +1691,19 @@ mod gpu_tests {
|
||||
eprintln!("ctrl_pack_batched M={m} D={d}: byte-identical to sequential");
|
||||
}
|
||||
|
||||
/// copy_f32 device-side copy is exact (dst == src).
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn copy_f32_exact() {
|
||||
let n = 1024usize;
|
||||
let src: Vec<f32> = (0..n).map(|i| (i as f32 - 512.0) * 0.013).collect();
|
||||
let ds = DeviceBuf::alloc(n * 4).unwrap(); ds.h2d(&src).unwrap();
|
||||
let dd = DeviceBuf::alloc(n * 4).unwrap();
|
||||
copy_f32(&ds, &dd, n).unwrap();
|
||||
let mut got = vec![0f32; n]; dd.d2h(&mut got).unwrap();
|
||||
assert_eq!(got, src, "copy_f32 must be exact");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn shortconv4_multistep_parity() {
|
||||
|
||||
Reference in new issue
Block a user