mirror of
https://github.com/huggingface/candle.git
synced 2025-06-16 18:48:51 +00:00
13 lines
313 B
Rust
13 lines
313 B
Rust
use std::str::FromStr;
|
|
|
|
pub fn get_num_threads() -> usize {
|
|
// Respond to the same environment variable as rayon.
|
|
match std::env::var("RAYON_NUM_THREADS")
|
|
.ok()
|
|
.and_then(|s| usize::from_str(&s).ok())
|
|
{
|
|
Some(x) if x > 0 => x,
|
|
Some(_) | None => num_cpus::get(),
|
|
}
|
|
}
|