refactor(cuda): eliminate all CPU fallbacks — CUDA mandatory across ML stack
- Remove ALL #[cfg(feature = "cuda")] guards (~400+ occurrences) - Remove ALL #[cfg_attr(not(feature = "cuda"), ignore)] test annotations (~250) - Make cuda default feature in 9 ML crates (ml, ml-core, ml-dqn, ml-ppo, etc.) - Convert nvrtc JIT compilation to precompiled nvcc (searchsorted, prefix_sum) - Move compile_ptx_for_device() to ml-core for shared access - Delete dead CPU code: multi_step.rs, self_supervised_pretraining.rs, training_guard_gpu_tests.rs, CPU PER buffer paths, CPU Q-diagnostics - Replace unwrap_or(Device::Cpu) with hard errors everywhere - Remove dead is_cuda() else branches in DQN/PPO/hyperopt trainers - Change config defaults from "cpu" to "cuda" (rainbow, tlob, pipeline) - Port IQL value network to GPU kernel (5 CUDA entry points) - Port HER goal relabeling to GPU kernel (warp-per-sample) - Wire DSR GPU-to-CPU sync in training loop - cfg!(feature = "cuda") → true in inference_validator Zero warnings, zero errors across entire workspace. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -71,32 +71,29 @@ mod tests {
|
||||
|
||||
info!("📊 Testing CUDA device properties");
|
||||
|
||||
#[cfg(feature = "cuda")]
|
||||
{
|
||||
match cudarc::driver::CudaDevice::new(0) {
|
||||
Ok(device) => {
|
||||
info!("✅ CUDA device initialized successfully");
|
||||
|
||||
// Test device properties
|
||||
let device_name = device.name().unwrap_or("Unknown".to_string());
|
||||
let total_memory = device.total_memory().unwrap_or(0);
|
||||
|
||||
info!("Device name: {}", device_name);
|
||||
info!("Total memory: {} bytes ({:.2} GB)",
|
||||
total_memory, total_memory as f64 / (1024.0 * 1024.0 * 1024.0));
|
||||
|
||||
// Basic validation
|
||||
assert!(!device_name.is_empty(), "Device should have a name");
|
||||
assert!(total_memory > 0, "Device should have memory");
|
||||
|
||||
info!("✅ CUDA device properties validation passed");
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("⚠️ CUDA device initialization failed: {}", e);
|
||||
}
|
||||
match cudarc::driver::CudaDevice::new(0) {
|
||||
Ok(device) => {
|
||||
info!("✅ CUDA device initialized successfully");
|
||||
|
||||
// Test device properties
|
||||
let device_name = device.name().unwrap_or("Unknown".to_string());
|
||||
let total_memory = device.total_memory().unwrap_or(0);
|
||||
|
||||
info!("Device name: {}", device_name);
|
||||
info!("Total memory: {} bytes ({:.2} GB)",
|
||||
total_memory, total_memory as f64 / (1024.0 * 1024.0 * 1024.0));
|
||||
|
||||
// Basic validation
|
||||
assert!(!device_name.is_empty(), "Device should have a name");
|
||||
assert!(total_memory > 0, "Device should have memory");
|
||||
|
||||
info!("✅ CUDA device properties validation passed");
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("⚠️ CUDA device initialization failed: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -5,14 +5,12 @@
|
||||
use super::utils::*;
|
||||
use log::{info, warn};
|
||||
|
||||
#[cfg(feature = "cuda")]
|
||||
use cudarc::driver::{CudaDevice, DevicePtr, LaunchAsync, LaunchConfig};
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[cfg(feature = "cuda")]
|
||||
#[test]
|
||||
fn test_cuda_kernel_manager_creation() {
|
||||
init_gpu_test_env();
|
||||
@@ -49,7 +47,6 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "cuda")]
|
||||
#[test]
|
||||
fn test_cuda_memory_operations() {
|
||||
init_gpu_test_env();
|
||||
@@ -121,7 +118,6 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "cuda")]
|
||||
#[test]
|
||||
fn test_cuda_kernel_compilation() {
|
||||
init_gpu_test_env();
|
||||
@@ -270,7 +266,6 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "cuda")]
|
||||
#[test]
|
||||
fn test_cuda_stream_operations() {
|
||||
init_gpu_test_env();
|
||||
|
||||
@@ -219,7 +219,6 @@ mod tests {
|
||||
info!("✅ GPU memory pool behavior test completed");
|
||||
}
|
||||
|
||||
#[cfg(feature = "cuda")]
|
||||
#[test]
|
||||
fn test_cuda_memory_info() {
|
||||
init_gpu_test_env();
|
||||
|
||||
@@ -368,38 +368,35 @@ mod tests {
|
||||
let device = get_test_device();
|
||||
|
||||
// Test GPU monitoring
|
||||
#[cfg(feature = "cuda")]
|
||||
{
|
||||
match cudarc::driver::CudaDevice::new(0) {
|
||||
Ok(cuda_device) => {
|
||||
if let Ok(total_memory) = cuda_device.total_memory() {
|
||||
info!("GPU monitoring data:");
|
||||
info!(" Total GPU memory: {} bytes ({:.2} GB)",
|
||||
total_memory, total_memory as f64 / (1024.0 * 1024.0 * 1024.0));
|
||||
|
||||
// Test memory usage monitoring during allocation
|
||||
let start_time = Instant::now();
|
||||
let tensor_result = Tensor::zeros((2000, 2000), DType::F32, &device);
|
||||
let allocation_time = start_time.elapsed();
|
||||
|
||||
match tensor_result {
|
||||
Ok(_tensor) => {
|
||||
let estimated_usage = 2000 * 2000 * 4; // 4 bytes per f32
|
||||
|
||||
info!(" Allocation time: {:?}", allocation_time);
|
||||
info!(" Estimated memory usage: {} bytes ({:.2} MB)",
|
||||
estimated_usage, estimated_usage as f64 / (1024.0 * 1024.0));
|
||||
info!(" ✅ GPU monitoring data collected successfully");
|
||||
}
|
||||
Err(e) => {
|
||||
warn!(" ❌ GPU allocation failed during monitoring: {}", e);
|
||||
}
|
||||
match cudarc::driver::CudaDevice::new(0) {
|
||||
Ok(cuda_device) => {
|
||||
if let Ok(total_memory) = cuda_device.total_memory() {
|
||||
info!("GPU monitoring data:");
|
||||
info!(" Total GPU memory: {} bytes ({:.2} GB)",
|
||||
total_memory, total_memory as f64 / (1024.0 * 1024.0 * 1024.0));
|
||||
|
||||
// Test memory usage monitoring during allocation
|
||||
let start_time = Instant::now();
|
||||
let tensor_result = Tensor::zeros((2000, 2000), DType::F32, &device);
|
||||
let allocation_time = start_time.elapsed();
|
||||
|
||||
match tensor_result {
|
||||
Ok(_tensor) => {
|
||||
let estimated_usage = 2000 * 2000 * 4; // 4 bytes per f32
|
||||
|
||||
info!(" Allocation time: {:?}", allocation_time);
|
||||
info!(" Estimated memory usage: {} bytes ({:.2} MB)",
|
||||
estimated_usage, estimated_usage as f64 / (1024.0 * 1024.0));
|
||||
info!(" ✅ GPU monitoring data collected successfully");
|
||||
}
|
||||
Err(e) => {
|
||||
warn!(" ❌ GPU allocation failed during monitoring: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("❌ Failed to initialize CUDA device for monitoring: {}", e);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("❌ Failed to initialize CUDA device for monitoring: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user