From 0131b2904bc2b30de283dbc338893922d448583c Mon Sep 17 00:00:00 2001 From: jgrusewski Date: Fri, 10 Apr 2026 18:11:50 +0200 Subject: [PATCH] =?UTF-8?q?refactor:=20rename=20all=20bf16=20transfer=20fu?= =?UTF-8?q?nctions=20=E2=86=92=20f32=20across=2019=20files,=20delete=20leg?= =?UTF-8?q?acy=20aliases?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit htod_f32_to_bf16 → htod_f32, clone_htod_f32_to_bf16 → clone_htod_f32, dtoh_bf16_to_f32 → dtoh_f32. No wrappers — all 67 call sites renamed directly. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../src/cuda_pipeline/decision_transformer.rs | 8 ++--- .../src/cuda_pipeline/gpu_action_selector.rs | 12 +++---- crates/ml/src/cuda_pipeline/gpu_attention.rs | 2 +- .../cuda_pipeline/gpu_backtest_evaluator.rs | 2 +- .../ml/src/cuda_pipeline/gpu_dqn_trainer.rs | 14 ++++---- .../cuda_pipeline/gpu_experience_collector.rs | 16 ++++----- .../ml/src/cuda_pipeline/gpu_iql_trainer.rs | 6 ++-- crates/ml/src/cuda_pipeline/gpu_monitoring.rs | 2 +- crates/ml/src/cuda_pipeline/gpu_portfolio.rs | 4 +-- .../ml/src/cuda_pipeline/gpu_ppo_collector.rs | 14 ++++---- crates/ml/src/cuda_pipeline/gpu_statistics.rs | 2 +- .../ml/src/cuda_pipeline/gpu_walk_forward.rs | 6 ++-- crates/ml/src/cuda_pipeline/mod.rs | 36 ++++++------------- crates/ml/src/hyperopt/adapters/mamba2.rs | 2 +- crates/ml/src/hyperopt/adapters/ppo.rs | 4 +-- crates/ml/src/trainers/dqn/trainer/metrics.rs | 2 +- .../src/trainers/dqn/trainer/training_loop.rs | 8 ++--- crates/ml/src/trainers/ppo.rs | 4 +-- crates/ml/src/trainers/tlob.rs | 2 +- 19 files changed, 66 insertions(+), 80 deletions(-) diff --git a/crates/ml/src/cuda_pipeline/decision_transformer.rs b/crates/ml/src/cuda_pipeline/decision_transformer.rs index aefd87ad8..e06604b68 100644 --- a/crates/ml/src/cuda_pipeline/decision_transformer.rs +++ b/crates/ml/src/cuda_pipeline/decision_transformer.rs @@ -464,7 +464,7 @@ impl DecisionTransformer { let mut params = stream.alloc_zeros::(total_params) .map_err(|e| MLError::ModelError(format!("DT params alloc: {e}")))?; - super::htod_f32_to_bf16(&stream, &host_params, &mut params)?; + super::htod_f32(&stream, &host_params, &mut params)?; let context_buf = stream.alloc_zeros::(context_size) .map_err(|e| MLError::ModelError(format!("DT context alloc: {e}")))?; @@ -894,7 +894,7 @@ impl DecisionTransformer { // ── Read back loss ───────────────────────────────────────────── let mut loss_host = [0.0_f32]; - super::dtoh_bf16_to_f32(stream, &scratch.total_loss, &mut loss_host)?; + super::dtoh_f32(stream, &scratch.total_loss, &mut loss_host)?; stream.synchronize() .map_err(|e| MLError::ModelError(format!("DT sync: {e}")))?; @@ -1043,7 +1043,7 @@ impl DecisionTransformer { { let mut ep_rewards_host = vec![0.0_f32; ep_total]; let mut global_rewards = vec![0.0_f32; num_bars]; - super::dtoh_bf16_to_f32(stream, &rewards_gpu, &mut global_rewards)?; + super::dtoh_f32(stream, &rewards_gpu, &mut global_rewards)?; stream.synchronize() .map_err(|e| MLError::ModelError(format!("DT sync rewards: {e}")))?; @@ -1055,7 +1055,7 @@ impl DecisionTransformer { } } - super::htod_f32_to_bf16(stream, &ep_rewards_host, &mut ep_rewards_gpu)?; + super::htod_f32(stream, &ep_rewards_host, &mut ep_rewards_gpu)?; } // RTG reverse cumulative sum diff --git a/crates/ml/src/cuda_pipeline/gpu_action_selector.rs b/crates/ml/src/cuda_pipeline/gpu_action_selector.rs index 0224d1e28..e9490d7ff 100644 --- a/crates/ml/src/cuda_pipeline/gpu_action_selector.rs +++ b/crates/ml/src/cuda_pipeline/gpu_action_selector.rs @@ -80,16 +80,16 @@ impl GpuActionSelector { pub fn set_count_bonuses(&mut self, exposure: &[f32; 5], order: &[f32; 3], urgency: &[f32; 3]) -> Result<(), MLError> { // Allocate or reuse GPU buffers let be = match self.bonus_exposure_buf.take() { - Some(mut buf) => { super::htod_f32_to_bf16(&self.stream, exposure, &mut buf)?; buf } - None => super::clone_htod_f32_to_bf16(&self.stream, exposure)?, + Some(mut buf) => { super::htod_f32(&self.stream, exposure, &mut buf)?; buf } + None => super::clone_htod_f32(&self.stream, exposure)?, }; let bo = match self.bonus_order_buf.take() { - Some(mut buf) => { super::htod_f32_to_bf16(&self.stream, order, &mut buf)?; buf } - None => super::clone_htod_f32_to_bf16(&self.stream, order)?, + Some(mut buf) => { super::htod_f32(&self.stream, order, &mut buf)?; buf } + None => super::clone_htod_f32(&self.stream, order)?, }; let bu = match self.bonus_urgency_buf.take() { - Some(mut buf) => { super::htod_f32_to_bf16(&self.stream, urgency, &mut buf)?; buf } - None => super::clone_htod_f32_to_bf16(&self.stream, urgency)?, + Some(mut buf) => { super::htod_f32(&self.stream, urgency, &mut buf)?; buf } + None => super::clone_htod_f32(&self.stream, urgency)?, }; self.bonus_exposure_ptr = be.device_ptr(&self.stream).0; self.bonus_order_ptr = bo.device_ptr(&self.stream).0; diff --git a/crates/ml/src/cuda_pipeline/gpu_attention.rs b/crates/ml/src/cuda_pipeline/gpu_attention.rs index f1e1c7c78..d037cfcde 100644 --- a/crates/ml/src/cuda_pipeline/gpu_attention.rs +++ b/crates/ml/src/cuda_pipeline/gpu_attention.rs @@ -147,7 +147,7 @@ impl GpuAttention { let mut params = stream.alloc_zeros::(total_params) .map_err(|e| MLError::ModelError(format!("attention params alloc: {e}")))?; - super::htod_f32_to_bf16(&stream, &host_params, &mut params)?; + super::htod_f32(&stream, &host_params, &mut params)?; let output_buf = stream.alloc_zeros::(b * d) .map_err(|e| MLError::ModelError(format!("attention output alloc: {e}")))?; diff --git a/crates/ml/src/cuda_pipeline/gpu_backtest_evaluator.rs b/crates/ml/src/cuda_pipeline/gpu_backtest_evaluator.rs index 6ad61a9a3..21b9983fd 100644 --- a/crates/ml/src/cuda_pipeline/gpu_backtest_evaluator.rs +++ b/crates/ml/src/cuda_pipeline/gpu_backtest_evaluator.rs @@ -516,7 +516,7 @@ impl GpuBacktestEvaluator { // ── Upload read-only data ───────────────────────────────────────── let prices_buf = stream.clone_htod(&flat_prices) .map_err(|e| MLError::ModelError(format!("prices upload: {e}")))?; - let features_buf = super::clone_htod_f32_to_bf16(&stream, &flat_features)?; + let features_buf = super::clone_htod_f32(&stream, &flat_features)?; let window_lens_buf = stream .clone_htod(&window_lens) .map_err(|e| MLError::ModelError(format!("window_lens upload: {e}")))?; diff --git a/crates/ml/src/cuda_pipeline/gpu_dqn_trainer.rs b/crates/ml/src/cuda_pipeline/gpu_dqn_trainer.rs index 4dbe7a74b..322e0c975 100644 --- a/crates/ml/src/cuda_pipeline/gpu_dqn_trainer.rs +++ b/crates/ml/src/cuda_pipeline/gpu_dqn_trainer.rs @@ -2593,10 +2593,10 @@ impl GpuDqnTrainer { let mut spec_v_s1 = alloc_bf16(&stream, config.state_dim, "spec_v_s1")?; let mut spec_u_s2 = alloc_bf16(&stream, config.shared_h2, "spec_u_s2")?; let mut spec_v_s2 = alloc_bf16(&stream, config.shared_h1, "spec_v_s2")?; - super::htod_f32_to_bf16(&stream, &init_u_s1, &mut spec_u_s1)?; - super::htod_f32_to_bf16(&stream, &init_v_s1, &mut spec_v_s1)?; - super::htod_f32_to_bf16(&stream, &init_u_s2, &mut spec_u_s2)?; - super::htod_f32_to_bf16(&stream, &init_v_s2, &mut spec_v_s2)?; + super::htod_f32(&stream, &init_u_s1, &mut spec_u_s1)?; + super::htod_f32(&stream, &init_v_s1, &mut spec_v_s1)?; + super::htod_f32(&stream, &init_u_s2, &mut spec_u_s2)?; + super::htod_f32(&stream, &init_v_s2, &mut spec_v_s2)?; // Head spectral norm vectors: value head, adv/branch heads let vh = config.value_h; @@ -2613,8 +2613,8 @@ impl GpuDqnTrainer { let mut $v_name = alloc_bf16(&stream, $v_n, $lbl_v)?; let init_u = rand_unit($u_n, &mut rng_state); let init_v = rand_unit($v_n, &mut rng_state); - super::htod_f32_to_bf16(&stream, &init_u, &mut $u_name)?; - super::htod_f32_to_bf16(&stream, &init_v, &mut $v_name)?; + super::htod_f32(&stream, &init_u, &mut $u_name)?; + super::htod_f32(&stream, &init_v, &mut $v_name)?; }; } @@ -3474,7 +3474,7 @@ impl GpuDqnTrainer { dtod_copy(readback_base + (3 * f32_bytes) as u64, td_src, td_bytes, &self.stream, 3, "readback_gather")?; // ── Single DtoH transfer ────────────────────────────────────── - super::dtoh_bf16_to_f32(&self.stream, &self.readback_buf, &mut self.readback_host)?; + super::dtoh_f32(&self.stream, &self.readback_buf, &mut self.readback_host)?; // ── Unpack on CPU ───────────────────────────────────────────── let c51_loss = self.readback_host[0]; diff --git a/crates/ml/src/cuda_pipeline/gpu_experience_collector.rs b/crates/ml/src/cuda_pipeline/gpu_experience_collector.rs index a0d49c7ed..ebf97fe0e 100644 --- a/crates/ml/src/cuda_pipeline/gpu_experience_collector.rs +++ b/crates/ml/src/cuda_pipeline/gpu_experience_collector.rs @@ -853,7 +853,7 @@ impl GpuExperienceCollector { portfolio_init[off + 9] = initial_capital; // [9] prev_equity // [10] hold_time = 0.0, [11] realized_pnl = 0.0 (already zero) } - super::htod_f32_to_bf16(&stream, &portfolio_init, &mut portfolio_states)?; + super::htod_f32(&stream, &portfolio_init, &mut portfolio_states)?; let mut rng_states = stream .alloc_zeros::(alloc_episodes) @@ -882,7 +882,7 @@ impl GpuExperienceCollector { 1.0, // dsr_var 0.0, // step_count ]; - let epoch_state = super::clone_htod_f32_to_bf16(&stream, &epoch_state_init)?; + let epoch_state = super::clone_htod_f32(&stream, &epoch_state_init)?; // ── Step 7: Allocate output buffers (2x for #7 counterfactual) ─── let total_output = alloc_episodes * alloc_timesteps; @@ -1292,7 +1292,7 @@ impl GpuExperienceCollector { // Zero the output buffer before reduction let zeros = vec![0.0_f32; TRADE_STATS_FLOATS]; - super::htod_f32_to_bf16(&self.stream, &zeros, &mut self.trade_stats_buf)?; + super::htod_f32(&self.stream, &zeros, &mut self.trade_stats_buf)?; // Launch reduction kernel: 1 block, 256 threads let blocks = 1_u32; @@ -1317,7 +1317,7 @@ impl GpuExperienceCollector { // Download 6-float result (24 bytes) let mut host_stats = vec![0.0_f32; TRADE_STATS_FLOATS]; - super::dtoh_bf16_to_f32(&self.stream, &self.trade_stats_buf, &mut host_stats)?; + super::dtoh_f32(&self.stream, &self.trade_stats_buf, &mut host_stats)?; let win_count = host_stats[0]; let loss_count = host_stats[1]; @@ -1335,7 +1335,7 @@ impl GpuExperienceCollector { // raw_returns_out is NOT doubled by counterfactual (only states/actions/rewards/dones are) let base_output = self.alloc_episodes * self.alloc_timesteps; let mut host_raw_returns = vec![0.0_f32; base_output]; - super::dtoh_bf16_to_f32(&self.stream, &self.raw_returns_out, &mut host_raw_returns)?; + super::dtoh_f32(&self.stream, &self.raw_returns_out, &mut host_raw_returns)?; let step_returns: Vec = host_raw_returns.iter().map(|&r| r as f64).collect(); @@ -2193,7 +2193,7 @@ impl GpuExperienceCollector { portfolio_init[off + 9] = initial_capital; // [9] prev_equity // [10] hold_time = 0.0, [11] realized_pnl = 0.0 (already zero) } - super::htod_f32_to_bf16(&self.stream, &portfolio_init, &mut self.portfolio_states)?; + super::htod_f32(&self.stream, &portfolio_init, &mut self.portfolio_states)?; // Fresh RNG seeds let rng_seeds: Vec = (0..self.alloc_episodes) @@ -2230,7 +2230,7 @@ impl GpuExperienceCollector { /// Read DSR EMA state from GPU after experience collection. pub fn read_epoch_dsr_state(&self) -> Result<(f32, f32), MLError> { let mut host = vec![0.0_f32; 8]; - super::dtoh_bf16_to_f32(&self.stream, &self.epoch_state, &mut host)?; + super::dtoh_f32(&self.stream, &self.epoch_state, &mut host)?; Ok((host[5], host[6])) } @@ -2305,7 +2305,7 @@ impl GpuExperienceCollector { if ofi_flat.is_empty() { return Ok(()); } - let gpu_buf = super::clone_htod_f32_to_bf16(&self.stream, ofi_flat)?; + let gpu_buf = super::clone_htod_f32(&self.stream, ofi_flat)?; info!( "OFI features uploaded to GPU: {} bars x {} dims ({:.1} KB)", ofi_flat.len() / self.ofi_dim, diff --git a/crates/ml/src/cuda_pipeline/gpu_iql_trainer.rs b/crates/ml/src/cuda_pipeline/gpu_iql_trainer.rs index cf273dd59..c0a5d3ab0 100644 --- a/crates/ml/src/cuda_pipeline/gpu_iql_trainer.rs +++ b/crates/ml/src/cuda_pipeline/gpu_iql_trainer.rs @@ -244,8 +244,8 @@ impl GpuIqlTrainer { // Zero total_loss and grad_norm before kernel launches let zero_f32 = [0.0_f32]; - super::htod_f32_to_bf16(&self.stream, &zero_f32, &mut self.total_loss_buf)?; - super::htod_f32_to_bf16(&self.stream, &zero_f32, &mut self.grad_norm_buf)?; + super::htod_f32(&self.stream, &zero_f32, &mut self.total_loss_buf)?; + super::htod_f32(&self.stream, &zero_f32, &mut self.grad_norm_buf)?; let batch_size_i32 = b as i32; let total_params_i32 = self.total_params as i32; @@ -482,7 +482,7 @@ fn init_xavier_weights( // Upload to GPU let mut params_buf = alloc_f32(stream, total, "iql_params")?; - super::htod_f32_to_bf16(stream, &weights, &mut params_buf)?; + super::htod_f32(stream, &weights, &mut params_buf)?; Ok(params_buf) } diff --git a/crates/ml/src/cuda_pipeline/gpu_monitoring.rs b/crates/ml/src/cuda_pipeline/gpu_monitoring.rs index 6f9e996e5..7e52a2a6e 100644 --- a/crates/ml/src/cuda_pipeline/gpu_monitoring.rs +++ b/crates/ml/src/cuda_pipeline/gpu_monitoring.rs @@ -103,7 +103,7 @@ impl GpuMonitoringReducer { /// Download summary from GPU (single 48-byte transfer). pub fn download_summary(&self) -> Result { let mut raw = vec![0.0_f32; 24]; - super::dtoh_bf16_to_f32(&self.stream, &self.summary_buf, &mut raw)?; + super::dtoh_f32(&self.stream, &self.summary_buf, &mut raw)?; Ok(MonitoringSummary { mean_reward: raw[0], reward_std: raw[1], diff --git a/crates/ml/src/cuda_pipeline/gpu_portfolio.rs b/crates/ml/src/cuda_pipeline/gpu_portfolio.rs index ebfe0aa5e..7dfb8341f 100644 --- a/crates/ml/src/cuda_pipeline/gpu_portfolio.rs +++ b/crates/ml/src/cuda_pipeline/gpu_portfolio.rs @@ -119,7 +119,7 @@ impl GpuPortfolioSimulator { cash_reserve_pct, 0.0, ]; - super::htod_f32_to_bf16(&stream, &init_state, &mut portfolio_state_buf)?; + super::htod_f32(&stream, &init_state, &mut portfolio_state_buf)?; debug!( "GPU portfolio sim initialized: capital={}, spread={}, reserve={}%, max_pos={}, episode_len={}, total_bars={}", @@ -293,7 +293,7 @@ impl GpuPortfolioSimulator { /// Reset portfolio state to initial capital. pub fn reset(&mut self, initial_capital: f32, avg_spread: f32, cash_reserve_pct: f32) -> Result<(), MLError> { let init_state = [initial_capital, 0.0, 0.0, initial_capital, avg_spread, 0.0, cash_reserve_pct, 0.0_f32]; - super::htod_f32_to_bf16(&self.stream, &init_state, &mut self.portfolio_state_buf)?; + super::htod_f32(&self.stream, &init_state, &mut self.portfolio_state_buf)?; Ok(()) } diff --git a/crates/ml/src/cuda_pipeline/gpu_ppo_collector.rs b/crates/ml/src/cuda_pipeline/gpu_ppo_collector.rs index 044204eaa..7e5908982 100644 --- a/crates/ml/src/cuda_pipeline/gpu_ppo_collector.rs +++ b/crates/ml/src/cuda_pipeline/gpu_ppo_collector.rs @@ -149,7 +149,7 @@ impl PpoExperienceBatch { let count = self.total() * self.state_dim; let view = self.states.slice(..count); let mut host = vec![0.0_f32; count]; - super::dtoh_bf16_to_f32(&self.stream, &view, &mut host)?; + super::dtoh_f32(&self.stream, &view, &mut host)?; Ok(host) } @@ -169,7 +169,7 @@ impl PpoExperienceBatch { let count = self.total(); let view = self.log_probs.slice(..count); let mut host = vec![0.0_f32; count]; - super::dtoh_bf16_to_f32(&self.stream, &view, &mut host)?; + super::dtoh_f32(&self.stream, &view, &mut host)?; Ok(host) } @@ -178,7 +178,7 @@ impl PpoExperienceBatch { let count = self.total(); let view = self.advantages.slice(..count); let mut host = vec![0.0_f32; count]; - super::dtoh_bf16_to_f32(&self.stream, &view, &mut host)?; + super::dtoh_f32(&self.stream, &view, &mut host)?; Ok(host) } @@ -187,7 +187,7 @@ impl PpoExperienceBatch { let count = self.total(); let view = self.returns.slice(..count); let mut host = vec![0.0_f32; count]; - super::dtoh_bf16_to_f32(&self.stream, &view, &mut host)?; + super::dtoh_f32(&self.stream, &view, &mut host)?; Ok(host) } @@ -346,7 +346,7 @@ impl GpuPpoExperienceCollector { // portfolio_init[off + 7] = 0.0; // cum_costs } let mut portfolio_states = portfolio_states; - super::htod_f32_to_bf16(&stream, &portfolio_init, &mut portfolio_states)?; + super::htod_f32(&stream, &portfolio_init, &mut portfolio_states)?; // ---- Step 5: Initialize RNG seeds ---- let rng_seeds: Vec = (0..MAX_EPISODES) @@ -513,7 +513,7 @@ impl GpuPpoExperienceCollector { config.barrier_loss_mult, config.barrier_max_bars, ]; - super::htod_f32_to_bf16(&self.stream, &barrier_cfg, &mut self.barrier_config)?; + super::htod_f32(&self.stream, &barrier_cfg, &mut self.barrier_config)?; // ---- Step 4: Launch config ---- let n = n_episodes as u32; @@ -763,7 +763,7 @@ impl GpuPpoExperienceCollector { *slot = cash_reserve_pct; // reserve_pct } } - super::htod_f32_to_bf16(&self.stream, &self.portfolio_init_staging, &mut self.portfolio_states)?; + super::htod_f32(&self.stream, &self.portfolio_init_staging, &mut self.portfolio_states)?; // Zero barrier states via async GPU memset (no CPU allocation) self.stream diff --git a/crates/ml/src/cuda_pipeline/gpu_statistics.rs b/crates/ml/src/cuda_pipeline/gpu_statistics.rs index 78bb9f178..821a33902 100644 --- a/crates/ml/src/cuda_pipeline/gpu_statistics.rs +++ b/crates/ml/src/cuda_pipeline/gpu_statistics.rs @@ -112,7 +112,7 @@ impl GpuStatistics { // Single 40-byte readback let mut host = [0.0_f32; 10]; - super::dtoh_bf16_to_f32(stream, &self.output_buf, &mut host)?; + super::dtoh_f32(stream, &self.output_buf, &mut host)?; let reward_sum = host[0]; let reward_sq_sum = host[1]; diff --git a/crates/ml/src/cuda_pipeline/gpu_walk_forward.rs b/crates/ml/src/cuda_pipeline/gpu_walk_forward.rs index a174b674a..029c5a7e5 100644 --- a/crates/ml/src/cuda_pipeline/gpu_walk_forward.rs +++ b/crates/ml/src/cuda_pipeline/gpu_walk_forward.rs @@ -580,12 +580,12 @@ impl GpuWalkForwardData { } // Upload features - let features_gpu = super::clone_htod_f32_to_bf16(stream, &flat_features)?; + let features_gpu = super::clone_htod_f32(stream, &flat_features)?; let mut vram = total_bars * feature_dim * 4; // Upload targets - let targets_gpu = super::clone_htod_f32_to_bf16(stream, &flat_targets)?; + let targets_gpu = super::clone_htod_f32(stream, &flat_targets)?; vram += total_bars * target_dim * 4; @@ -602,7 +602,7 @@ impl GpuWalkForwardData { flat_ofi.extend_from_slice(&[0.0_f32; 8]); } } - let buf = super::clone_htod_f32_to_bf16(stream, &flat_ofi)?; + let buf = super::clone_htod_f32(stream, &flat_ofi)?; vram += total_bars * 8 * 4; Some(buf) } else { diff --git a/crates/ml/src/cuda_pipeline/mod.rs b/crates/ml/src/cuda_pipeline/mod.rs index 186be0786..23a520adf 100644 --- a/crates/ml/src/cuda_pipeline/mod.rs +++ b/crates/ml/src/cuda_pipeline/mod.rs @@ -105,20 +105,6 @@ pub fn dtoh_f32>( Ok(()) } -// Legacy aliases — delegate to the f32 functions above. -// Keeps the 188 existing call sites compiling during incremental migration. -#[inline] -pub fn htod_f32_to_bf16(stream: &Arc, src: &[f32], dst: &mut CudaSlice) -> Result<(), MLError> { - htod_f32(stream, src, dst) -} -#[inline] -pub fn clone_htod_f32_to_bf16(stream: &Arc, src: &[f32]) -> Result, MLError> { - clone_htod_f32(stream, src) -} -#[inline] -pub fn dtoh_bf16_to_f32>(stream: &Arc, src: &Src, dst: &mut [f32]) -> Result<(), MLError> { - dtoh_f32(stream, src, dst) -} /// Compute optimal (grid_dim, block_dim) for a 1-D kernel launch. /// @@ -289,8 +275,8 @@ impl DqnGpuData { } } - let features = clone_htod_f32_to_bf16(stream, &flat_features)?; - let targets = clone_htod_f32_to_bf16(stream, &flat_targets)?; + let features = clone_htod_f32(stream, &flat_features)?; + let targets = clone_htod_f32(stream, &flat_targets)?; Ok(Self { features, @@ -340,8 +326,8 @@ impl DqnGpuData { .flat_map(|t| t.iter().map(|&v| v as f32)) .collect(); - let features_gpu = clone_htod_f32_to_bf16(stream, &flat_features)?; - let targets_gpu = clone_htod_f32_to_bf16(stream, &flat_targets)?; + let features_gpu = clone_htod_f32(stream, &flat_features)?; + let targets_gpu = clone_htod_f32(stream, &flat_targets)?; let ofi_features = if !ofi.is_empty() && ofi.iter().any(|row| row.iter().any(|&v| v != 0.0)) { let mut flat_ofi = Vec::with_capacity(num_bars * 8); @@ -354,7 +340,7 @@ impl DqnGpuData { flat_ofi.extend_from_slice(&[0.0_f32; 8]); } } - Some(clone_htod_f32_to_bf16(stream, &flat_ofi)?) + Some(clone_htod_f32(stream, &flat_ofi)?) } else { None }; @@ -395,7 +381,7 @@ impl DqnGpuData { } } - let ofi_buf = clone_htod_f32_to_bf16(stream, &flat)?; + let ofi_buf = clone_htod_f32(stream, &flat)?; self.ofi_features = Some(ofi_buf); Ok(()) @@ -534,7 +520,7 @@ impl DqnGpuData { .map_err(|e| MLError::ModelError(format!("build_batch alloc: {e}")))?; // Upload portfolio features once (3 scalars) - let port_gpu = clone_htod_f32_to_bf16(stream, portfolio_features)?; + let port_gpu = clone_htod_f32(stream, portfolio_features)?; // Get contiguous market features [count * feature_dim] let market_gpu = self.batch_features(start, count, stream)?; @@ -626,7 +612,7 @@ impl DqnGpuData { dst_offset_elems: usize, stream: &Arc, ) -> Result<(), MLError> { - let tmp = clone_htod_f32_to_bf16(stream, src)?; + let tmp = clone_htod_f32(stream, src)?; Self::dtod_copy_into(&tmp, dst, dst_offset_elems, src.len(), stream) } } @@ -712,8 +698,8 @@ impl GpuBufferPool { } // Upload the used slice to GPU via clone_htod. - let features = clone_htod_f32_to_bf16(stream, &self.feature_buf[..feat_len])?; - let targets = clone_htod_f32_to_bf16(stream, &self.target_buf[..targ_len])?; + let features = clone_htod_f32(stream, &self.feature_buf[..feat_len])?; + let targets = clone_htod_f32(stream, &self.target_buf[..targ_len])?; Ok(DqnGpuData { features, @@ -783,7 +769,7 @@ impl PpoGpuData { flat_states.extend_from_slice(state); } - let states = clone_htod_f32_to_bf16(stream, &flat_states)?; + let states = clone_htod_f32(stream, &flat_states)?; Ok(Self { states, diff --git a/crates/ml/src/hyperopt/adapters/mamba2.rs b/crates/ml/src/hyperopt/adapters/mamba2.rs index 5c9b76c0f..f1171497d 100644 --- a/crates/ml/src/hyperopt/adapters/mamba2.rs +++ b/crates/ml/src/hyperopt/adapters/mamba2.rs @@ -745,7 +745,7 @@ fn gpu_to_stream( stream: &Arc, ) -> Result { let host = t.to_host(stream)?; - let data = crate::cuda_pipeline::clone_htod_f32_to_bf16(stream, &host)?; + let data = crate::cuda_pipeline::clone_htod_f32(stream, &host)?; Ok(StreamTensor { data, shape: t.shape().to_vec(), // cpu-side shape clone diff --git a/crates/ml/src/hyperopt/adapters/ppo.rs b/crates/ml/src/hyperopt/adapters/ppo.rs index 1848108a0..c2c0d69ea 100644 --- a/crates/ml/src/hyperopt/adapters/ppo.rs +++ b/crates/ml/src/hyperopt/adapters/ppo.rs @@ -577,7 +577,7 @@ impl PPOTrainer { for (features, _) in training_data { flat_features.extend_from_slice(features); } - match crate::cuda_pipeline::clone_htod_f32_to_bf16(&stream, &flat_features) { + match crate::cuda_pipeline::clone_htod_f32(&stream, &flat_features) { Ok(buf) => { info!("PPO CUDA features uploaded: {} bars × 42 ({:.1} MB)", num_bars, (num_bars * 42 * 4) as f64 / 1_048_576.0); @@ -601,7 +601,7 @@ impl PPOTrainer { flat_targets.push(close); flat_targets.push(next_close); } - match crate::cuda_pipeline::clone_htod_f32_to_bf16(&stream, &flat_targets) { + match crate::cuda_pipeline::clone_htod_f32(&stream, &flat_targets) { Ok(buf) => { info!("PPO CUDA targets uploaded: {} bars × 4 ({:.1} MB)", num_bars, (num_bars * 4 * 4) as f64 / 1_048_576.0); diff --git a/crates/ml/src/trainers/dqn/trainer/metrics.rs b/crates/ml/src/trainers/dqn/trainer/metrics.rs index 3e550e55a..77d788853 100644 --- a/crates/ml/src/trainers/dqn/trainer/metrics.rs +++ b/crates/ml/src/trainers/dqn/trainer/metrics.rs @@ -272,7 +272,7 @@ impl DQNTrainer { // Allocate host buffer to match GPU buffer size, then truncate. let stream = self.cuda_stream.as_ref()?; let mut host_q = vec![0.0_f32; q_out.len()]; - crate::cuda_pipeline::dtoh_bf16_to_f32(stream, q_out, &mut host_q).ok()?; + crate::cuda_pipeline::dtoh_f32(stream, q_out, &mut host_q).ok()?; host_q.truncate(sample_size * total_actions); // Compute gap (best - second_best) WITHIN DIRECTION BRANCH ONLY diff --git a/crates/ml/src/trainers/dqn/trainer/training_loop.rs b/crates/ml/src/trainers/dqn/trainer/training_loop.rs index c1c1a4ddb..996dde83c 100644 --- a/crates/ml/src/trainers/dqn/trainer/training_loop.rs +++ b/crates/ml/src/trainers/dqn/trainer/training_loop.rs @@ -642,11 +642,11 @@ impl DQNTrainer { .collect(); self.targets_raw_cuda = Some( - crate::cuda_pipeline::clone_htod_f32_to_bf16(&stream, &flat_targets) + crate::cuda_pipeline::clone_htod_f32(&stream, &flat_targets) .map_err(|e| anyhow::anyhow!("targets_raw upload: {e}"))? ); self.features_raw_cuda = Some( - crate::cuda_pipeline::clone_htod_f32_to_bf16(&stream, &flat_features) + crate::cuda_pipeline::clone_htod_f32(&stream, &flat_features) .map_err(|e| anyhow::anyhow!("features_raw upload: {e}"))? ); @@ -1594,7 +1594,7 @@ impl DQNTrainer { if let Ok(q_out) = q_result { // Download Q-values (q_out may be larger than needed — match GPU buffer size) let mut host_q = vec![0.0_f32; q_out.len()]; - if crate::cuda_pipeline::dtoh_bf16_to_f32(refresh_stream, q_out, &mut host_q).is_ok() { + if crate::cuda_pipeline::dtoh_f32(refresh_stream, q_out, &mut host_q).is_ok() { host_q.truncate(batch_size_refresh * total_actions); let mut max_vals = Vec::with_capacity(batch_size_refresh); for row in 0..batch_size_refresh { @@ -1608,7 +1608,7 @@ impl DQNTrainer { } // Upload TD errors and indices as raw CudaSlice (zero GpuTensor) - if let Ok(td_slice) = crate::cuda_pipeline::clone_htod_f32_to_bf16(refresh_stream, &max_vals) { + if let Ok(td_slice) = crate::cuda_pipeline::clone_htod_f32(refresh_stream, &max_vals) { let idx_u32: Vec = valid_indices.iter() .take(batch_size_refresh) .map(|&i| i as u32) diff --git a/crates/ml/src/trainers/ppo.rs b/crates/ml/src/trainers/ppo.rs index 6932a2433..1dae52763 100644 --- a/crates/ml/src/trainers/ppo.rs +++ b/crates/ml/src/trainers/ppo.rs @@ -395,7 +395,7 @@ impl PpoTrainer { flat_features.push(v as f32); } } - let features_buf = crate::cuda_pipeline::clone_htod_f32_to_bf16(&stream, &flat_features)?; + let features_buf = crate::cuda_pipeline::clone_htod_f32(&stream, &flat_features)?; self.features_raw_cuda = Some(features_buf); // Upload targets [num_bars * 4] @@ -405,7 +405,7 @@ impl PpoTrainer { flat_targets.push(targets.get(i).copied().unwrap_or(0.0) as f32); } } - let targets_buf = crate::cuda_pipeline::clone_htod_f32_to_bf16(&stream, &flat_targets)?; + let targets_buf = crate::cuda_pipeline::clone_htod_f32(&stream, &flat_targets)?; self.targets_raw_cuda = Some(targets_buf); self.raw_data_num_bars = num_bars; diff --git a/crates/ml/src/trainers/tlob.rs b/crates/ml/src/trainers/tlob.rs index d96c5e755..c88a6287a 100644 --- a/crates/ml/src/trainers/tlob.rs +++ b/crates/ml/src/trainers/tlob.rs @@ -516,7 +516,7 @@ impl TLOBTrainer { let mut total_sq = 0.0_f64; for (name, param) in self.var_store.iter() { let mut host = vec![0.0_f32; param.data.len()]; - crate::cuda_pipeline::dtoh_bf16_to_f32(&stream, ¶m.data, &mut host) + crate::cuda_pipeline::dtoh_f32(&stream, ¶m.data, &mut host) .map_err(|e| anyhow::anyhow!("param {} DtoH: {e}", name))?; let sq: f64 = host.iter().map(|&v| (v as f64) * (v as f64)).sum(); total_sq += sq;