pub enum DeviceSpec {
Cpu,
Cuda {
device_id: usize,
},
Metal {
device_id: usize,
},
WebGpu,
}Expand description
Device specification parsed from a device string.
This enum represents different compute devices that can execute kernels. It’s used throughout the compilation pipeline for device selection and kernel caching.
Variants§
Cpu
CPU device (single-threaded or multi-threaded execution)
Cuda
CUDA GPU device with specific device ID
Metal
Metal GPU device (Apple Silicon) with specific device ID
WebGpu
WebGPU device (browser or native WebGPU)
Implementations§
Source§impl DeviceSpec
impl DeviceSpec
Sourcepub fn canonicalize(&self) -> String
pub fn canonicalize(&self) -> String
Canonicalize the device spec to a standard string representation.
§Examples
use morok_dtype::DeviceSpec;
assert_eq!(DeviceSpec::Cpu.canonicalize(), "CPU");
assert_eq!(DeviceSpec::Cuda { device_id: 0 }.canonicalize(), "CUDA:0");
assert_eq!(DeviceSpec::Cuda { device_id: 1 }.canonicalize(), "CUDA:1");Sourcepub fn max_buffers(&self) -> Option<usize>
pub fn max_buffers(&self) -> Option<usize>
Get maximum buffer count for this device.
Returns None if the device has no buffer limit (effectively unlimited).
Known limits:
- Metal: 31 buffers (Apple Silicon hardware limit)
- WebGPU: 8 buffers (WebGPU specification limit)
- CPU/CUDA: None (no practical limit)
Sourcepub fn base_type(&self) -> &'static str
pub fn base_type(&self) -> &'static str
Get the base device type string (strips device ID).
Used for device factory lookup and cache key construction.
Unlike canonicalize(), this returns a static string without device ID.
§Examples
use morok_dtype::DeviceSpec;
assert_eq!(DeviceSpec::Cpu.base_type(), "CPU");
assert_eq!(DeviceSpec::Cuda { device_id: 0 }.base_type(), "CUDA");
assert_eq!(DeviceSpec::Cuda { device_id: 1 }.base_type(), "CUDA");Trait Implementations§
Source§impl Clone for DeviceSpec
impl Clone for DeviceSpec
Source§fn clone(&self) -> DeviceSpec
fn clone(&self) -> DeviceSpec
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DeviceSpec
impl Debug for DeviceSpec
Source§impl<'de> Deserialize<'de> for DeviceSpec
impl<'de> Deserialize<'de> for DeviceSpec
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<DeviceSpec, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<DeviceSpec, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl DeviceSpecExt for DeviceSpec
impl DeviceSpecExt for DeviceSpec
Source§impl Hash for DeviceSpec
impl Hash for DeviceSpec
Source§impl PartialEq for DeviceSpec
impl PartialEq for DeviceSpec
Source§impl Serialize for DeviceSpec
impl Serialize for DeviceSpec
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Eq for DeviceSpec
impl StructuralPartialEq for DeviceSpec
Auto Trait Implementations§
impl Freeze for DeviceSpec
impl RefUnwindSafe for DeviceSpec
impl Send for DeviceSpec
impl Sync for DeviceSpec
impl Unpin for DeviceSpec
impl UnsafeUnpin for DeviceSpec
impl UnwindSafe for DeviceSpec
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more