Use num-cpus to enable parallelism.

This commit is contained in:
laurent
2023-06-27 14:42:26 +01:00
parent 8371890996
commit ca6aa8ff12
4 changed files with 17 additions and 4 deletions

12
candle-core/src/utils.rs Normal file
View File

@ -0,0 +1,12 @@
use std::str::FromStr;
pub(crate) 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(),
}
}