diff options
author | Ivar Flakstad <69173633+ivarflakstad@users.noreply.github.com> | 2024-01-08 06:48:33 +0100 |
---|---|---|
committer | Ivar Flakstad <69173633+ivarflakstad@users.noreply.github.com> | 2024-01-08 06:48:33 +0100 |
commit | ad075a5f7edb0114b820b3e99a19b17d0d25ec3b (patch) | |
tree | 71a37fc5ebc7a04a7a0c796725814b6649dcbe67 /candle-core/benches/utils.rs | |
parent | 3f04a79ada7ca974176a0c7c3c3306f394eae9a9 (diff) | |
download | candle-ad075a5f7edb0114b820b3e99a19b17d0d25ec3b.tar.gz candle-ad075a5f7edb0114b820b3e99a19b17d0d25ec3b.tar.bz2 candle-ad075a5f7edb0114b820b3e99a19b17d0d25ec3b.zip |
Remove allow pragma
Diffstat (limited to 'candle-core/benches/utils.rs')
-rw-r--r-- | candle-core/benches/utils.rs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/candle-core/benches/utils.rs b/candle-core/benches/utils.rs new file mode 100644 index 00000000..a93afc6e --- /dev/null +++ b/candle-core/benches/utils.rs @@ -0,0 +1,53 @@ +use candle_core::{Device, Result}; + +pub(crate) trait BenchDevice { + fn sync(&self) -> Result<()>; +} + +impl BenchDevice for Device { + fn sync(&self) -> Result<()> { + match self { + Device::Cpu => Ok(()), + Device::Cuda(device) => { + #[cfg(feature = "cuda")] + return Ok(device.synchronize()?); + #[cfg(not(feature = "cuda"))] + panic!("Cuda device without cuda feature enabled: {:?}", device) + } + Device::Metal(device) => { + #[cfg(feature = "metal")] + return Ok(device.wait_until_completed()?); + #[cfg(not(feature = "metal"))] + panic!("Metal device without metal feature enabled: {:?}", device) + } + } + } +} + +pub(crate) fn device() -> Result<Device> { + return if cfg!(feature = "metal") { + Device::new_metal(0) + } else if cfg!(feature = "cuda") { + Device::new_cuda(0) + } else { + Ok(Device::Cpu) + }; +} + +pub(crate) fn bench_name<S: Into<String>>(name: S) -> String { + format!("{}_{}", device_variant(), name.into()) +} + +const fn device_variant() -> &'static str { + return if cfg!(feature = "metal") { + "metal" + } else if cfg!(feature = "cuda") { + "cuda" + } else if cfg!(feature = "accelerate") { + "accelerate" + } else if cfg!(feature = "mkl") { + "mkl" + } else { + "cpu" + }; +} |