Skip to content

Commit cc967fc

Browse files
authored
feat: add metal_if_available method for graceful Metal fallback (#3041)
1 parent 7b8f2b4 commit cc967fc

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

candle-core/src/device.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,14 @@ impl Device {
320320
}
321321
}
322322

323+
pub fn metal_if_available(ordinal: usize) -> Result<Self> {
324+
if crate::utils::metal_is_available() {
325+
Self::new_metal(ordinal)
326+
} else {
327+
Ok(Self::Cpu)
328+
}
329+
}
330+
323331
pub(crate) fn rand_uniform_f64(
324332
&self,
325333
lo: f64,

0 commit comments

Comments
 (0)