mirror of
https://github.com/huggingface/candle.git
synced 2025-06-19 19:58:35 +00:00
Add some 'cuda-if-available' helper function. (#172)
This commit is contained in:
@ -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,
|
||||
|
@ -17,3 +17,10 @@ pub fn has_mkl() -> bool {
|
||||
#[cfg(not(feature = "mkl"))]
|
||||
return false;
|
||||
}
|
||||
|
||||
pub fn cuda_is_available() -> bool {
|
||||
#[cfg(feature = "cuda")]
|
||||
return true;
|
||||
#[cfg(not(feature = "cuda"))]
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user