Skip to content

Commit

Permalink
Support XPU device
Browse files Browse the repository at this point in the history
  • Loading branch information
jgong5 committed Dec 29, 2023
1 parent a2afb0a commit 3c6bedb
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions bindings/python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ enum Device {
Cuda(usize),
Mps,
Npu(usize),
Xpu(usize),
}

impl<'source> FromPyObject<'source> for Device {
Expand All @@ -231,6 +232,7 @@ impl<'source> FromPyObject<'source> for Device {
"cuda" => Ok(Device::Cuda(0)),
"mps" => Ok(Device::Mps),
"npu" => Ok(Device::Npu(0)),
"xpu" => Ok(Device::Xpu(0)),
name if name.starts_with("cuda:") => {
let tokens: Vec<_> = name.split(':').collect();
if tokens.len() == 2 {
Expand All @@ -253,6 +255,17 @@ impl<'source> FromPyObject<'source> for Device {
)))
}
}
name if name.starts_with("xpu:") => {
let tokens: Vec<_> = name.split(':').collect();
if tokens.len() == 2 {
let device: usize = tokens[1].parse()?;
Ok(Device::Xpu(device))
} else {
Err(SafetensorError::new_err(format!(
"device {name} is invalid"
)))
}
}
name => Err(SafetensorError::new_err(format!(
"device {name} is invalid"
))),
Expand All @@ -272,6 +285,7 @@ impl IntoPy<PyObject> for Device {
Device::Cuda(n) => format!("cuda:{n}").into_py(py),
Device::Mps => "mps".into_py(py),
Device::Npu(n) => format!("npu:{n}").into_py(py),
Device::Xpu(n) => format!("xpu:{n}").into_py(py),
}
}
}
Expand Down

0 comments on commit 3c6bedb

Please sign in to comment.