Add some 'cuda-if-available' helper function. (#172)

This commit is contained in:
Laurent Mazare
2023-07-15 08:25:15 +01:00
committed by GitHub
parent 2ddda706bd
commit 66750f9827
8 changed files with 33 additions and 72 deletions

View File

@ -109,6 +109,14 @@ impl Device {
}
}
pub fn cuda_if_available(ordinal: usize) -> Result<Self> {
if crate::utils::cuda_is_available() {
Self::new_cuda(ordinal)
} else {
Ok(Self::Cpu)
}
}
pub(crate) fn rand_uniform(
&self,
shape: &Shape,