tenferro_gpu/cubecl/identity.rs
1//! Provider-neutral GPU extension vocabulary (issue #1597).
2//!
3//! These types describe capabilities and stable device identity without
4//! forcing CUDA-, CubeCL-, or WebGPU-specific concepts into a shared surface.
5//! Backend-specific operations live in their provider namespaces
6//! (`cuda`, `webgpu`); the types here are shared vocabulary only.
7
8use std::fmt;
9
10/// Stable physical or MIG device identity as a 16-byte UUID.
11///
12/// This is the durable comparison identity for diagnostics and topology. It is
13/// distinct from the process-visible ordinal [`CudaDeviceId`](crate::cuda::CudaDeviceId);
14/// the two must never be conflated in equality semantics.
15///
16/// # Examples
17///
18/// ```
19/// use tenferro_gpu::cuda::CudaDeviceUuid;
20///
21/// let uuid = CudaDeviceUuid::from_bytes([7; 16]);
22/// assert_eq!(uuid.to_bytes(), [7; 16]);
23/// assert_eq!(uuid, CudaDeviceUuid::from_bytes([7; 16]));
24/// ```
25#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
26pub struct CudaDeviceUuid([u8; 16]);
27
28impl CudaDeviceUuid {
29 /// Construct a device UUID from its 16 raw bytes.
30 ///
31 /// # Examples
32 ///
33 /// ```
34 /// use tenferro_gpu::cuda::CudaDeviceUuid;
35 ///
36 /// const UUID: CudaDeviceUuid = CudaDeviceUuid::from_bytes([1; 16]);
37 /// assert_eq!(UUID.as_bytes(), &[1; 16]);
38 /// ```
39 pub const fn from_bytes(bytes: [u8; 16]) -> Self {
40 Self(bytes)
41 }
42
43 /// Borrow the 16 raw UUID bytes.
44 ///
45 /// # Examples
46 ///
47 /// ```
48 /// use tenferro_gpu::cuda::CudaDeviceUuid;
49 ///
50 /// let uuid = CudaDeviceUuid::from_bytes([2; 16]);
51 /// assert_eq!(uuid.as_bytes(), &[2; 16]);
52 /// ```
53 pub const fn as_bytes(&self) -> &[u8; 16] {
54 &self.0
55 }
56
57 /// Return the 16 raw UUID bytes.
58 ///
59 /// # Examples
60 ///
61 /// ```
62 /// use tenferro_gpu::cuda::CudaDeviceUuid;
63 ///
64 /// let uuid = CudaDeviceUuid::from_bytes([3; 16]);
65 /// assert_eq!(uuid.to_bytes(), [3; 16]);
66 /// ```
67 pub const fn to_bytes(self) -> [u8; 16] {
68 self.0
69 }
70}
71
72impl fmt::Debug for CudaDeviceUuid {
73 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
74 f.debug_tuple("CudaDeviceUuid").field(&self.0).finish()
75 }
76}
77
78/// CUDA compute capability `major.minor` (e.g. 9.0 for Hopper-class parts).
79///
80/// # Examples
81///
82/// ```
83/// use tenferro_gpu::cuda::CudaComputeCapability;
84///
85/// let cc = CudaComputeCapability { major: 9, minor: 0 };
86/// assert_eq!(cc.major, 9);
87/// assert_eq!(cc.minor, 0);
88/// ```
89#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
90pub struct CudaComputeCapability {
91 /// Major component of the compute capability.
92 pub major: u32,
93 /// Minor component of the compute capability.
94 pub minor: u32,
95}
96
97/// Capability a GPU extension may query before using a provider-specific path.
98///
99/// [`CudaExecSession::supports`](crate::cuda::CudaExecSession::supports) reports
100/// whether the capability is plausibly available on the current session. This is
101/// orthogonal to the primitive [`OperationCapability`](tenferro_tensor::OperationCapability)
102/// matrix: extension capabilities describe what the extension seam itself can
103/// do, not which tensor operations the backend implements.
104///
105/// # Examples
106///
107/// ```
108/// use tenferro_gpu::cuda::GpuExtensionCapability;
109///
110/// let capability = GpuExtensionCapability::RawStream;
111/// assert!(matches!(capability, GpuExtensionCapability::RawStream));
112/// ```
113#[non_exhaustive]
114#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
115pub enum GpuExtensionCapability {
116 /// Launch external kernels through the CubeCL client.
117 CubeClKernel,
118 /// Load native (PTX/CUBIN/SPIR-V) module artifacts.
119 NativeModule,
120 /// Compile kernel source at runtime (NVRTC / shader compiler).
121 RuntimeCompilation,
122 /// Borrow a raw provider stream for library interop.
123 RawStream,
124 /// Asynchronous same-device copy across runtime/domain boundaries.
125 SameDeviceAsyncCopy,
126 /// Directional peer-to-peer copy between devices.
127 PeerCopy,
128}