Files
foxhunt/docs
jgrusewski 1e35324bf4 perf(htod): migrate gpu_experience_collector.rs to mapped-pinned (10 sites, hot path: bar_indices + feature_mask + per_sample_support)
HOT sites:
- L2992 hindsight bar_indices: was `alloc + memcpy_htod(total i32s)` on
  every collect_experiences_gpu when hindsight_fraction > 0. Added
  persistent `bar_indices_pinned: MappedI32Buffer` (capacity =
  alloc_episodes * alloc_timesteps * 2) allocated at constructor.
  Per-call host writes go through host_ptr; relabel kernel reads via
  dev_ptr u64.
- L3186 feature_mask: was alloc + memcpy_htod each epoch at t==0.
  Promoted `feature_mask_buf` to `Option<MappedF32Buffer>`. Reallocates
  only when mask size changes; CPU writes via host_ptr, state_gather
  reads via dev_ptr.
- L3816 update_per_sample_support: per_sample_support_buf is read-only
  by the kernel — promoted to MappedF32Buffer (kernel args now
  dev_ptr u64). per-epoch tile fill becomes a direct host_ptr write.

WARM sites:
- L3097 episode_starts upload: episode_starts_buf is GPU-mutated by
  domain_rand_episode_starts so must remain CudaSlice. Stage via
  MappedI32Buffer + memcpy_dtod_async through new helper
  `upload_host_to_cuda_i32_via_pinned`.
- L2009 upload_expert_actions: promoted expert_actions_gpu from
  Option<CudaSlice<i32>> to Option<MappedI32Buffer>. Direct host_ptr
  write replaces alloc + memcpy_htod.

COLD sites:
- L1076,3848 portfolio_states init/reset (GPU-mutated): use
  upload_host_to_cuda_f32_via_pinned (mapped-pinned staging + DtoD).
- L1093 epoch_state init (GPU-mutated): replace clone_htod_f32 with
  explicit alloc_zeros + upload_host_to_cuda_f32_via_pinned.
- L1341 saboteur_base init (GPU-mutated): use the same helper.
- L2784 trade_stats_buf pre-reduction zero: replaced htod_f32 of an
  all-zeros vec with stream.memset_zeros — fully GPU-side, no PCIe.

Imports: added DevicePtrMut for memcpy_dtod_async pointer extraction.

Per `feedback_no_partial_refactor.md`, every consumer of the migrated
buffers is updated in this commit:
- per_sample_support_buf kernel args at L3426 (compute_expected_q) and
  L3546 (quantile_q_select) now consume dev_ptr u64.
- feature_mask_buf accessor at L3195 reads via .dev_ptr.
- expert_actions_gpu field type change is contained (no external
  consumers in this crate).

cargo check -p ml --lib: 11 warnings (unchanged from prior commit on
this branch; 2 below 13-warning baseline because two unrelated trivial
warnings disappeared as a side-effect of the refactor).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 21:10:24 +02:00
..