refactor: rename all bf16 transfer functions → f32 across 19 files, delete legacy aliases

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) <noreply@anthropic.com>
This commit is contained in:
jgrusewski
2026-04-10 18:11:50 +02:00
parent 95edfd024b
commit 0131b2904b
19 changed files with 66 additions and 80 deletions

View File

@@ -464,7 +464,7 @@ impl DecisionTransformer {
let mut params = stream.alloc_zeros::<half::bf16>(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::<half::bf16>(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

View File

@@ -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;

View File

@@ -147,7 +147,7 @@ impl GpuAttention {
let mut params = stream.alloc_zeros::<half::bf16>(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::<half::bf16>(b * d)
.map_err(|e| MLError::ModelError(format!("attention output alloc: {e}")))?;

View File

@@ -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}")))?;

View File

@@ -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];

View File

@@ -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::<u32>(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<f64> = 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<u32> = (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,

View File

@@ -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)
}

View File

@@ -103,7 +103,7 @@ impl GpuMonitoringReducer {
/// Download summary from GPU (single 48-byte transfer).
pub fn download_summary(&self) -> Result<MonitoringSummary, MLError> {
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],

View File

@@ -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(())
}

View File

@@ -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<u32> = (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

View File

@@ -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];

View File

@@ -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 {

View File

@@ -105,20 +105,6 @@ pub fn dtoh_f32<Src: cudarc::driver::DevicePtr<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<CudaStream>, src: &[f32], dst: &mut CudaSlice<f32>) -> Result<(), MLError> {
htod_f32(stream, src, dst)
}
#[inline]
pub fn clone_htod_f32_to_bf16(stream: &Arc<CudaStream>, src: &[f32]) -> Result<CudaSlice<f32>, MLError> {
clone_htod_f32(stream, src)
}
#[inline]
pub fn dtoh_bf16_to_f32<Src: cudarc::driver::DevicePtr<f32>>(stream: &Arc<CudaStream>, 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<CudaStream>,
) -> 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,

View File

@@ -745,7 +745,7 @@ fn gpu_to_stream(
stream: &Arc<cudarc::driver::CudaStream>,
) -> Result<StreamTensor, MLError> {
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

View File

@@ -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);

View File

@@ -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

View File

@@ -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<u32> = valid_indices.iter()
.take(batch_size_refresh)
.map(|&i| i as u32)

View File

@@ -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;

View File

@@ -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, &param.data, &mut host)
crate::cuda_pipeline::dtoh_f32(&stream, &param.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;