fix(ml): migrate test uploads from clone_htod to mapped-pinned

Per feedback_no_htod_htoh_only_mapped_pinned: mapped-pinned only for
CPU↔GPU; tests not exempt. Previous commit ab64c0412 was a shallow
deprecated-API swap (memcpy_stod -> clone_htod) — both still HTOD
copies. This commit replaces all 5 uploads and the 1 readback in
test_eval_action_select_thompson_picks_proportionally with the
production mapped-pinned + memcpy_dtod_async pattern (mirrors lines
433-448 of the same file).

Closure 'upload_pinned' DRYs the 5 upload sites; readback uses
MappedI32Buffer + DtoD into staging.host_slice_mut().to_vec().
Zero HTOD/HTOH copies remain in this file. Documented in
dqn-wire-up-audit.md.
This commit is contained in:
jgrusewski
2026-05-22 20:39:32 +02:00
parent ab64c0412b
commit 8d72c14a8b
2 changed files with 77 additions and 6 deletions

View File

@@ -18792,3 +18792,26 @@ names. Per `feedback_no_legacy_aliases`: rename call sites directly, no
deprecated wrappers retained.
**Wire-up impact:** None (API surface unchanged; FFI semantics identical).
## 2026-05-22 — fix(ml): migrate test uploads from clone_htod to mapped-pinned
**Branch:** `ml-alpha-phase-a`. **Trigger:** prior commit (`ab64c0412`) had
swapped deprecated `memcpy_stod`/`memcpy_dtov` for `clone_htod`/`clone_dtoh`
— but both are HTOD/HTOH copies. Per `feedback_no_htod_htoh_only_mapped_pinned`
(memory pearl), mapped-pinned is the only permitted CPU↔GPU path, with
tests not exempt.
**Change:** `crates/ml/src/cuda_pipeline/mod.rs`
`test_eval_action_select_thompson_picks_proportionally`:
- Introduced `upload_pinned` closure that allocates a `MappedF32Buffer`,
`write_from_slice`s host data into the pinned page, allocates a device
destination via `stream.alloc_zeros`, and `memcpy_dtod_async` copies
staging.dev_ptr → dst with a stream sync. This is the same pattern used
at lines 433-448 (the production data-loader path).
- Replaced 5 `clone_htod` calls with `upload_pinned(&host)`.
- Replaced the 1 `clone_dtoh` readback with a `MappedI32Buffer` + DtoD
copy from `actions_buf` to `staging.dev_ptr`, then
`staging.host_slice_mut().to_vec()`.
**Wire-up impact:** None (test still produces the same direction histogram
assertions; only the FFI path changed).