mirror of
https://github.com/huggingface/candle.git
synced 2025-06-19 03:54:56 +00:00
14 lines
344 B
Rust
14 lines
344 B
Rust
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)
|
|
}
|
|
}
|