Files
rustytorch/crates/specialized/rtx-cfd/tests/gpu_kernels.rs
T
2026-03-04 00:08:42 +00:00

60 lines
1.7 KiB
Rust

//! Tests for GPU kernel functionality
#[cfg(feature = "cuda")]
mod cuda_tests {
use rtx_cfd::{CfdConfig, kernels::CudaKernelManager};
#[test]
fn test_cuda_kernel_manager_creation() {
let config = CfdConfig::default();
let result = CudaKernelManager::new(&config);
// If CUDA is available, it should work, otherwise it should fail gracefully
match result {
Ok(_manager) => {
println!("CUDA kernel manager created successfully");
}
Err(e) => {
println!("CUDA not available or failed to initialize: {}", e);
// This is expected on systems without CUDA
}
}
}
#[test]
fn test_cuda_memory_allocation() {
let config = CfdConfig::default();
if let Ok(manager) = CudaKernelManager::new(&config) {
let result = manager.allocate_f32(1024);
match result {
Ok(_slice) => {
println!("GPU memory allocation successful");
}
Err(e) => {
println!("GPU memory allocation failed: {}", e);
}
}
}
}
}
#[cfg(not(feature = "cuda"))]
mod cpu_fallback_tests {
use rtx_cfd::{CfdConfig, kernels::CudaKernelManager};
#[test]
fn test_cuda_not_available() {
let config = CfdConfig::default();
let result = CudaKernelManager::new(&config);
assert!(
result.is_err(),
"CUDA should not be available without cuda feature"
);
if let Err(e) = result {
println!("Expected error: {}", e);
}
}
}