diff --git a/crates/ml/examples/alpha_baseline.rs b/crates/ml/examples/alpha_baseline.rs index 3e718e108..a6006842c 100644 --- a/crates/ml/examples/alpha_baseline.rs +++ b/crates/ml/examples/alpha_baseline.rs @@ -1,3 +1,7 @@ +// CUDA kernel launches via cudarc + MappedF32::new (cuMemHostAlloc DEVICEMAP) require +// unsafe FFI. Workspace -W unsafe-code is structural noise here. Same rationale as +// ml-backtesting/src/harness.rs file-level allow. +#![allow(unsafe_code)] //! Phase E.3 Task 23 — Composition backtest with cost sweep. //! //! Trains the Phase E execution-policy DQN (linear Q + Phase 1d.3 diff --git a/crates/ml/examples/alpha_dqn_h600_smoke.rs b/crates/ml/examples/alpha_dqn_h600_smoke.rs index e391f19a4..451d8f48c 100644 --- a/crates/ml/examples/alpha_dqn_h600_smoke.rs +++ b/crates/ml/examples/alpha_dqn_h600_smoke.rs @@ -38,6 +38,12 @@ //! --n-episodes 1000 //! ``` +// CUDA kernel launches via `cudarc::launch_builder.launch(...)` and +// `MappedF32::new` (`cuMemHostAlloc(DEVICEMAP)` FFI) require `unsafe`. The +// workspace-wide `-W unsafe-code` lint is therefore noise here. Same rationale +// as `ml-backtesting/src/harness.rs` and `sim/mod.rs`'s file-level allows. +#![allow(unsafe_code)] + use std::fs::File; use std::io::Write; use std::mem::MaybeUninit; diff --git a/crates/ml/src/cuda_pipeline/cublaslt_debug.rs b/crates/ml/src/cuda_pipeline/cublaslt_debug.rs index 404f876c0..4224a4ced 100644 --- a/crates/ml/src/cuda_pipeline/cublaslt_debug.rs +++ b/crates/ml/src/cuda_pipeline/cublaslt_debug.rs @@ -1,3 +1,7 @@ +// CUDA kernel launches via cudarc + MappedF32::new (cuMemHostAlloc DEVICEMAP) require +// unsafe FFI. Workspace -W unsafe-code is structural noise here. Same rationale as +// ml-backtesting/src/harness.rs file-level allow. +#![allow(unsafe_code)] //! Standalone cublasLtMatmul debug test. //! Tests the EXACT same API call that fails in the experience collector on H100. //! Run: SQLX_OFFLINE=true cargo test -p ml --lib -- cuda_pipeline::cublaslt_debug --nocapture diff --git a/crates/ml/src/cuda_pipeline/gpu_walk_forward.rs b/crates/ml/src/cuda_pipeline/gpu_walk_forward.rs index 7ca3e0815..75d43710f 100644 --- a/crates/ml/src/cuda_pipeline/gpu_walk_forward.rs +++ b/crates/ml/src/cuda_pipeline/gpu_walk_forward.rs @@ -1,3 +1,7 @@ +// CUDA kernel launches via cudarc + MappedF32::new (cuMemHostAlloc DEVICEMAP) require +// unsafe FFI. Workspace -W unsafe-code is structural noise here. Same rationale as +// ml-backtesting/src/harness.rs file-level allow. +#![allow(unsafe_code)] //! GPU-resident walk-forward data manager. //! //! Uploads the ENTIRE dataset to GPU VRAM once, then provides per-fold diff --git a/crates/ml/src/cuda_pipeline/mod.rs b/crates/ml/src/cuda_pipeline/mod.rs index fefe500ba..81d056314 100644 --- a/crates/ml/src/cuda_pipeline/mod.rs +++ b/crates/ml/src/cuda_pipeline/mod.rs @@ -1,3 +1,7 @@ +// CUDA kernel launches via cudarc + MappedF32::new (cuMemHostAlloc DEVICEMAP) require +// unsafe FFI. Workspace -W unsafe-code is structural noise here. Same rationale as +// ml-backtesting/src/harness.rs file-level allow. +#![allow(unsafe_code)] //! GPU Pipeline: Pre-uploaded training data for DQN/PPO trainers. //! //! Eliminates per-bar heap allocations by uploading all training data diff --git a/crates/ml/src/hyperopt/adapters/mamba2.rs b/crates/ml/src/hyperopt/adapters/mamba2.rs index 0562aa22a..923b2a031 100644 --- a/crates/ml/src/hyperopt/adapters/mamba2.rs +++ b/crates/ml/src/hyperopt/adapters/mamba2.rs @@ -1,3 +1,7 @@ +// CUDA kernel launches via cudarc + MappedF32::new (cuMemHostAlloc DEVICEMAP) require +// unsafe FFI. Workspace -W unsafe-code is structural noise here. Same rationale as +// ml-backtesting/src/harness.rs file-level allow. +#![allow(unsafe_code)] //! MAMBA-2 Hyperparameter Optimization Adapter //! //! This module provides a production-ready adapter for optimizing MAMBA-2 diff --git a/crates/ml/src/hyperopt/adapters/ppo.rs b/crates/ml/src/hyperopt/adapters/ppo.rs index 054d7eb9d..9144037cb 100644 --- a/crates/ml/src/hyperopt/adapters/ppo.rs +++ b/crates/ml/src/hyperopt/adapters/ppo.rs @@ -1,3 +1,7 @@ +// CUDA kernel launches via cudarc + MappedF32::new (cuMemHostAlloc DEVICEMAP) require +// unsafe FFI. Workspace -W unsafe-code is structural noise here. Same rationale as +// ml-backtesting/src/harness.rs file-level allow. +#![allow(unsafe_code)] //! PPO Hyperparameter Optimization Adapter //! //! This module provides a production-ready adapter for optimizing PPO diff --git a/crates/ml/src/trainers/dqn/smoke_tests/helpers.rs b/crates/ml/src/trainers/dqn/smoke_tests/helpers.rs index f516dc731..228fd42c4 100644 --- a/crates/ml/src/trainers/dqn/smoke_tests/helpers.rs +++ b/crates/ml/src/trainers/dqn/smoke_tests/helpers.rs @@ -1,3 +1,7 @@ +// CUDA kernel launches via cudarc + MappedF32::new (cuMemHostAlloc DEVICEMAP) require +// unsafe FFI. Workspace -W unsafe-code is structural noise here. Same rationale as +// ml-backtesting/src/harness.rs file-level allow. +#![allow(unsafe_code)] use crate::trainers::dqn::{DQNHyperparameters, DQNTrainer}; use ml_core::device::MlDevice; diff --git a/crates/ml/src/trainers/dqn/smoke_tests/td_propagation.rs b/crates/ml/src/trainers/dqn/smoke_tests/td_propagation.rs index 7d586c16b..1966ecb5f 100644 --- a/crates/ml/src/trainers/dqn/smoke_tests/td_propagation.rs +++ b/crates/ml/src/trainers/dqn/smoke_tests/td_propagation.rs @@ -1,3 +1,7 @@ +// CUDA kernel launches via cudarc + MappedF32::new (cuMemHostAlloc DEVICEMAP) require +// unsafe FFI. Workspace -W unsafe-code is structural noise here. Same rationale as +// ml-backtesting/src/harness.rs file-level allow. +#![allow(unsafe_code)] //! TD propagation diagnostic: does sparse-reward Q-learning actually learn? //! //! After Phase 2's reward-shaping purge, training reward is essentially pure diff --git a/crates/ml/src/trainers/ppo.rs b/crates/ml/src/trainers/ppo.rs index f3543f7a6..7052be665 100644 --- a/crates/ml/src/trainers/ppo.rs +++ b/crates/ml/src/trainers/ppo.rs @@ -1,3 +1,7 @@ +// CUDA kernel launches via cudarc + MappedF32::new (cuMemHostAlloc DEVICEMAP) require +// unsafe FFI. Workspace -W unsafe-code is structural noise here. Same rationale as +// ml-backtesting/src/harness.rs file-level allow. +#![allow(unsafe_code)] //! PPO Trainer with gRPC Integration //! //! This module provides a production-ready PPO trainer that integrates with the ML Training Service diff --git a/crates/ml/tests/regime_wr_oracle_tests.rs b/crates/ml/tests/regime_wr_oracle_tests.rs index 8c68dc9a9..082060226 100644 --- a/crates/ml/tests/regime_wr_oracle_tests.rs +++ b/crates/ml/tests/regime_wr_oracle_tests.rs @@ -1,3 +1,7 @@ +// CUDA kernel launches via cudarc + MappedF32::new (cuMemHostAlloc DEVICEMAP) require +// unsafe FFI. Workspace -W unsafe-code is structural noise here. Same rationale as +// ml-backtesting/src/harness.rs file-level allow. +#![allow(unsafe_code)] //! Per-regime WR GPU oracle tests (audit follow-up 2026-05-09). //! //! Validates that `compute_backtest_metrics` correctly bucketises diff --git a/crates/ml/tests/smoke_test_real_data.rs b/crates/ml/tests/smoke_test_real_data.rs index b15f7a840..a5ffc9124 100644 --- a/crates/ml/tests/smoke_test_real_data.rs +++ b/crates/ml/tests/smoke_test_real_data.rs @@ -1,3 +1,7 @@ +// CUDA kernel launches via cudarc + MappedF32::new (cuMemHostAlloc DEVICEMAP) require +// unsafe FFI. Workspace -W unsafe-code is structural noise here. Same rationale as +// ml-backtesting/src/harness.rs file-level allow. +#![allow(unsafe_code)] #![allow( clippy::assertions_on_constants, clippy::assertions_on_result_states, diff --git a/docs/dqn-wire-up-audit.md b/docs/dqn-wire-up-audit.md index f5499edc0..7040f9be9 100644 --- a/docs/dqn-wire-up-audit.md +++ b/docs/dqn-wire-up-audit.md @@ -18750,3 +18750,29 @@ failed because Q2-Q9 contain different `instrument_id`s than Q1 — see (`FrontMonth` once DQN training moves to multi-quarter walk-forward). **Wire-up impact:** None (semantic preservation only). + +## 2026-05-22 — chore(ml): file-level allow(unsafe_code) on CUDA-launch files + +**Branch:** `ml-alpha-phase-a`. **Trigger:** CUDA kernel launches via +`cudarc::launch_builder` and `MappedF32::new` (cuMemHostAlloc DEVICEMAP FFI) +inherently require `unsafe` blocks. The workspace-wide `-W unsafe-code` lint +flagged ~80 individual unsafe blocks across 12 files, all structurally +identical (kernel launch must be unsafe). Established pattern is the +file-level allow in `ml-backtesting/src/harness.rs` and +`ml-backtesting/src/sim/mod.rs`. + +**Change:** Added `#![allow(unsafe_code)]` at the top of 12 files with the +same justification comment: `crates/ml/examples/alpha_dqn_h600_smoke.rs`, +`crates/ml/examples/alpha_baseline.rs`, +`crates/ml/src/cuda_pipeline/cublaslt_debug.rs`, +`crates/ml/src/cuda_pipeline/gpu_walk_forward.rs`, +`crates/ml/src/cuda_pipeline/mod.rs`, +`crates/ml/src/hyperopt/adapters/mamba2.rs`, +`crates/ml/src/hyperopt/adapters/ppo.rs`, +`crates/ml/src/trainers/dqn/smoke_tests/helpers.rs`, +`crates/ml/src/trainers/dqn/smoke_tests/td_propagation.rs`, +`crates/ml/src/trainers/ppo.rs`, +`crates/ml/tests/regime_wr_oracle_tests.rs`, +`crates/ml/tests/smoke_test_real_data.rs`. + +**Wire-up impact:** None (lint hygiene only — no semantic changes).