mirror of
https://github.com/huggingface/candle.git
synced 2025-06-17 02:58:50 +00:00
Add some 'cuda-if-available' helper function. (#172)
This commit is contained in:
@ -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)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user