use oxicuda_driver::Device;
fn main() {
if let Err(e) = oxicuda_driver::init() {
eprintln!("Failed to load CUDA driver: {e}");
eprintln!("Is an NVIDIA GPU driver installed?");
std::process::exit(1);
}
let count = match Device::count() {
Ok(n) => n,
Err(e) => {
eprintln!("cuDeviceGetCount failed: {e}");
std::process::exit(1);
}
};
if count == 0 {
println!("No CUDA-capable GPUs found.");
return;
}
println!(
"OxiCUDA device info ({count} device{} found)",
if count == 1 { "" } else { "s" }
);
println!("{}", "─".repeat(40));
for idx in 0..count {
let dev = match Device::get(idx) {
Ok(d) => d,
Err(e) => {
eprintln!("[{idx}] Failed to get device: {e}");
continue;
}
};
let name = dev.name().unwrap_or_else(|_| "<unknown>".into());
let (cc_major, cc_minor) = dev.compute_capability().unwrap_or((0, 0));
let sm_str = compute_capability_to_sm_str(cc_major, cc_minor);
let mp_count = dev.multiprocessor_count().unwrap_or(0);
let max_threads = dev.max_threads_per_block().unwrap_or(0);
let total_mem_mib = dev.total_memory().map(|b| b / (1024 * 1024)).unwrap_or(0);
let driver_ver = oxicuda_driver::driver_version().unwrap_or(0);
println!(
"[{idx}] {name}\n\
\x20 Compute capability : {cc_major}.{cc_minor} ({sm_str})\n\
\x20 Multiprocessors : {mp_count}\n\
\x20 Max threads/block : {max_threads}\n\
\x20 Global memory : {total_mem_mib} MiB\n\
\x20 Driver version : {driver_ver}",
);
}
}
fn compute_capability_to_sm_str(major: i32, minor: i32) -> String {
match (major, minor) {
(9, 0) => "sm_90".to_string(), _ => format!("sm_{major}{minor}"),
}
}