Add some 'cuda-if-available' helper function. (#172)

This commit is contained in:
Laurent Mazare
2023-07-15 08:25:15 +01:00
committed by GitHub
parent 2ddda706bd
commit 66750f9827
8 changed files with 33 additions and 72 deletions

View File

@ -1 +1,13 @@
use candle::{Device, Result};
pub fn device(cpu: bool) -> Result<Device> {
if cpu {
Ok(Device::Cpu)
} else {
let device = Device::cuda_if_available(0)?;
if !device.is_cuda() {
println!("Running on CPU, to run on GPU, build this example with `--features cuda`");
}
Ok(device)
}
}