primal-barracuda 0.4.0

barraCuda — BARrier-free Rust Abstracted Cross-platform Unified Dimensional Algebra. Vendor-agnostic GPU compute via WGSL.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
// SPDX-License-Identifier: AGPL-3.0-or-later
//! Backend-agnostic GPU compute trait.
//!
//! `GpuBackend` defines the minimal surface a compute backend must implement:
//! buffer lifecycle, shader compilation, and compute dispatch.
//!
//! Two backends implement this trait:
//!
//! - **`SovereignDevice`** (sovereign, IPC-first) — compiles WGSL via the shader
//!   compiler primal's JSON-RPC (`shader.compile.wgsl`) and dispatches via the
//!   compute.dispatch primal's JSON-RPC (`compute.dispatch.submit`). No compile-time coupling to any primal crate.
//!   The dispatch primal routes to the best hardware path (VFIO/DRM) at runtime.
//!   Requires `sovereign-dispatch` feature.
//!
//! - **`WgpuDevice`** (fallback) — dispatches through wgpu → Vulkan/Metal/DX12.
//!   Used for development, CI, non-VFIO environments, and platforms without
//!   IOMMU support. No feature flag needed — this is the default backend.
//!
//! Ops that use `ComputeDispatch` work through this trait automatically.
//! Ops that use raw `wgpu::Device` calls can be migrated incrementally.

use crate::error::Result;
use std::sync::Arc;

/// GPU vendor identity.
///
/// Originally mirrored `coral_driver::hardware::Vendor` (now toadStool hardware
/// domain). Defined independently to maintain barraCuda's zero compile-time
/// coupling to any hardware primal.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Vendor {
    /// NVIDIA (nouveau, proprietary, VFIO, CUDA).
    Nvidia,
    /// AMD (amdgpu DRM).
    Amd,
    /// Intel (future).
    Intel,
    /// Unrecognized or software backend.
    Unknown,
}

/// GPU driver stack in use.
///
/// Distinguishes open-source from proprietary stacks without name-string
/// matching. Consumers use this for workarounds and transcendental safety
/// decisions instead of `backend.name().contains("NVK")`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum DriverKind {
    /// Mesa NVK / nouveau (open-source NVIDIA Vulkan).
    NvkMesa,
    /// NVIDIA proprietary Vulkan/CUDA driver.
    NvidiaProprietary,
    /// Mesa RADV (open-source AMD Vulkan).
    RadvMesa,
    /// AMD proprietary (AMDVLK or amdgpu-pro).
    AmdProprietary,
    /// Mesa Intel ANV.
    IntelMesa,
    /// Sovereign IPC backend (toadStool hardware dispatch).
    Sovereign,
    /// Software rasterizer (llvmpipe, lavapipe, `SwiftShader`).
    Software,
    /// Unknown / unrecognized driver.
    Unknown,
}

impl std::fmt::Display for Vendor {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Nvidia => f.write_str("NVIDIA"),
            Self::Amd => f.write_str("AMD"),
            Self::Intel => f.write_str("Intel"),
            Self::Unknown => f.write_str("Unknown"),
        }
    }
}

/// GPU memory technology.
///
/// Originally mirrored `coral_driver::hardware::MemoryType` (now toadStool
/// hardware domain). Standalone definition.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum MemoryKind {
    /// GDDR5 (Kepler, older AMD).
    Gddr5,
    /// HBM2 / `HBM2e` (datacenter).
    Hbm2,
    /// HBM3 / `HBM3e` (datacenter).
    Hbm3,
    /// GDDR6 (Turing, RDNA).
    Gddr6,
    /// GDDR6X (Ampere B, Ada).
    Gddr6x,
    /// GDDR7 (Blackwell consumer).
    Gddr7,
}

/// Vendor-agnostic hardware capabilities exposed by a GPU backend.
///
/// Built from vendor-specific profiles at device-open time. Springs and ops
/// use this to adapt behavior (precision routing, tier skipping, batch sizing)
/// without branching on vendor identity.
///
/// Parallel to toadStool's hardware capabilities (originally `coral_driver`)
/// but fully decoupled to maintain barraCuda's IPC-first architecture.
#[derive(Debug, Clone)]
pub struct BackendCapabilities {
    /// GPU vendor.
    pub vendor: Vendor,
    /// Driver stack in use (NVK, proprietary, RADV, etc.).
    pub driver_kind: DriverKind,
    /// Short device/chip name.
    pub device_name: String,
    /// Whether the ALU supports IEEE 754 binary64 natively.
    pub has_hardware_f64: bool,
    /// Whether hardware f64 reciprocal is reliable.
    pub has_hardware_f64_rcp: bool,
    /// Whether FP64 runs at full rate (1:2 ratio with FP32).
    pub has_full_rate_fp64: bool,
    /// Video memory technology.
    pub memory_kind: MemoryKind,
}

impl BackendCapabilities {
    /// Conservative defaults for unknown hardware.
    #[must_use]
    pub fn unknown() -> Self {
        Self {
            vendor: Vendor::Unknown,
            driver_kind: DriverKind::Unknown,
            device_name: String::from("unknown"),
            has_hardware_f64: false,
            has_hardware_f64_rcp: false,
            has_full_rate_fp64: false,
            memory_kind: MemoryKind::Gddr6,
        }
    }

    /// Whether this is an open-source Mesa driver (NVK, RADV, ANV).
    #[must_use]
    pub fn is_mesa(&self) -> bool {
        matches!(
            self.driver_kind,
            DriverKind::NvkMesa | DriverKind::RadvMesa | DriverKind::IntelMesa
        )
    }

    /// Whether this is the NVK/nouveau open-source NVIDIA Vulkan stack.
    #[must_use]
    pub fn is_nvk(&self) -> bool {
        matches!(self.driver_kind, DriverKind::NvkMesa)
    }

    /// Whether this is the NVIDIA proprietary driver.
    #[must_use]
    pub fn is_nvidia_proprietary(&self) -> bool {
        matches!(self.driver_kind, DriverKind::NvidiaProprietary)
    }
}

/// Hardware unit hint for fixed-function science dispatch (Level 3 portability).
///
/// Springs express abstract math ops; the dispatch pipeline maps them to
/// the best hardware unit. This hint travels through the IPC chain:
/// barraCuda → shader.compile primal (pipeline state) → compute.dispatch primal (hardware routing).
///
/// Reference: `wateringHole/GPU_FIXED_FUNCTION_SCIENCE_REPURPOSING.md`
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum HardwareHint {
    /// Standard compute shader path (ALU/FP32/FP64 cores).
    #[default]
    Compute,
    /// Tensor core MMA path — dense matmul, Gram matrices, convolutions.
    /// Requires FP16/BF16/TF32 input precision; the shader compiler primal emits MMA instructions.
    TensorCore,
    /// RT core BVH traversal — neighbor finding, SPH, acoustic ray tracing.
    /// The shader compiler primal emits `TraceRay`; the compute.dispatch primal binds acceleration structure.
    RtCore,
    /// Z-buffer hardware — distance fields, Voronoi diagrams.
    /// The shader compiler primal emits rasterization pipeline state; the compute.dispatch primal routes to ROPs.
    ZBuffer,
    /// Texture unit hardware interpolation — lookup tables, PDF evaluation.
    /// The shader compiler primal binds texture with interpolation mode; the compute.dispatch primal routes to TMUs.
    TextureUnit,
    /// ROP blend/scatter — force accumulation, scatter-add without atomics.
    /// The shader compiler primal emits blend state; the compute.dispatch primal routes to ROPs.
    RopBlend,
}

/// Descriptor for a single buffer binding in a compute dispatch.
pub struct BufferBinding<'a, B: GpuBackend + ?Sized> {
    /// Bind group index (0, 1, 2, ...).
    pub index: u32,
    /// Reference to the backend-specific buffer.
    pub buffer: &'a B::Buffer,
    /// Whether the shader only reads this buffer.
    pub read_only: bool,
    /// Whether this is a uniform buffer (vs storage).
    pub is_uniform: bool,
}

/// Complete description of a compute dispatch operation.
///
/// Backends receive this from `ComputeDispatch::submit()` and execute the
/// entire compile → bind → dispatch → submit → sync lifecycle.
pub struct DispatchDescriptor<'a, B: GpuBackend + ?Sized> {
    /// Human-readable label for debug/profiling.
    pub label: &'a str,
    /// WGSL shader source code.
    pub shader_source: &'a str,
    /// Shader entry point name.
    pub entry_point: &'a str,
    /// Buffer bindings for the dispatch.
    pub bindings: Vec<BufferBinding<'a, B>>,
    /// Workgroup counts (x, y, z).
    pub workgroups: (u32, u32, u32),
    /// Use f64 shader compilation path.
    pub f64_shader: bool,
    /// Use DF64 (double-float f32-pair) compilation path.
    pub df64_shader: bool,
    /// Hardware unit hint for fixed-function dispatch (Level 3 portability).
    /// Defaults to `Compute` (standard ALU path). The shader compiler primal uses this to
    /// emit the correct pipeline state; the compute.dispatch primal routes to the hardware unit.
    pub hardware_hint: HardwareHint,
}

/// Backend-agnostic GPU compute interface.
///
/// The trait is intentionally minimal: 9 required methods covering identity,
/// buffer lifecycle, and compute dispatch. Typed convenience methods (f32/f64/u32
/// buffers, reads, writes) are provided as defaults using bytemuck.
///
/// # Associated Types
///
/// - `Buffer`: The backend's buffer handle. For wgpu this is `wgpu::Buffer`;
///   for `SovereignDevice` it is `SovereignBuffer` (IPC-managed by the compute.dispatch primal).
///
/// # Design
///
/// The trait captures the **compute dispatch contract** — the part that
/// `ComputeDispatch` and most ops need. Backend-specific methods (raw
/// `wgpu::Device` access, pipeline caching, encoder guards) remain on
/// the concrete types for ops that need them during incremental migration.
pub trait GpuBackend: Send + Sync {
    /// Backend-specific buffer handle.
    type Buffer: Send + Sync;

    // ── Identity ──────────────────────────────────────────────────────

    /// Human-readable device name (e.g. "NVIDIA `GeForce` RTX 3080").
    fn name(&self) -> &str;

    /// Whether this device supports native f64 shaders.
    fn has_f64_shaders(&self) -> bool;

    /// Whether the device has been reported as lost by the driver.
    fn is_lost(&self) -> bool;

    /// Query the hardware capabilities of this device.
    ///
    /// Returns a vendor-agnostic description of the GPU's precision support,
    /// memory type, and vendor. Consumers use this to adapt behavior
    /// (e.g. precision routing, tier skipping) without knowing the vendor.
    ///
    /// The default returns conservative unknowns — backends should override.
    fn capabilities(&self) -> BackendCapabilities {
        BackendCapabilities::unknown()
    }

    // ── Buffer lifecycle ──────────────────────────────────────────────

    /// Allocate an empty storage buffer (read-write, copy src+dst).
    ///
    /// # Errors
    /// Returns [`Err`] if allocation fails (e.g. device lost, OOM).
    fn alloc_buffer(&self, label: &str, size: u64) -> Result<Self::Buffer>;

    /// Allocate a storage buffer initialized with `contents`.
    ///
    /// # Errors
    /// Returns [`Err`] if allocation fails.
    fn alloc_buffer_init(&self, label: &str, contents: &[u8]) -> Result<Self::Buffer>;

    /// Allocate a uniform buffer initialized with `contents`.
    ///
    /// # Errors
    /// Returns [`Err`] if allocation fails.
    fn alloc_uniform(&self, label: &str, contents: &[u8]) -> Result<Self::Buffer>;

    /// Write raw bytes to a buffer at `offset`.
    fn upload(&self, buffer: &Self::Buffer, offset: u64, data: &[u8]);

    /// Read `size` bytes from a buffer back to host memory.
    ///
    /// Returns [`bytes::Bytes`] for zero-copy downstream consumers.
    ///
    /// # Errors
    /// Returns [`Err`] if readback fails (e.g. device lost, mapping error).
    fn download(&self, buffer: &Self::Buffer, size: u64) -> Result<bytes::Bytes>;

    // ── Compute dispatch ──────────────────────────────────────────────

    /// Execute a complete compute dispatch: compile shader, create bindings,
    /// record compute pass, submit, and wait for completion.
    ///
    /// This is the core abstraction — each backend implements the full
    /// pipeline using its own API (wgpu, sovereign IPC, etc.).
    ///
    /// # Errors
    /// Returns [`Err`] if compilation, dispatch, or synchronization fails.
    fn dispatch_compute(&self, desc: DispatchDescriptor<'_, Self>) -> Result<()>;

    /// Execute multiple compute dispatches in a single GPU submission.
    ///
    /// On backends that support command batching (e.g. wgpu/Vulkan), all
    /// dispatches are recorded into one command encoder, amortizing the
    /// per-submission overhead (~1.6ms on Vulkan → ~0.1ms amortized).
    ///
    /// The default implementation calls [`dispatch_compute`] sequentially.
    /// Backends that support batching should override this.
    ///
    /// # Errors
    /// Returns [`Err`] if any dispatch fails.
    fn dispatch_compute_batch(&self, descs: Vec<DispatchDescriptor<'_, Self>>) -> Result<()> {
        for desc in descs {
            self.dispatch_compute(desc)?;
        }
        Ok(())
    }

    /// Dispatch a pre-compiled native binary (SASS, GFX) without shader
    /// compilation.
    ///
    /// Used by the sovereign dispatch path: the shader compiler primal compiles WGSL → native
    /// binary once, then dispatches the binary directly. This bypasses
    /// naga/SPIR-V entirely, avoiding the DF64 transcendental poisoning bug.
    ///
    /// The default implementation returns an error — only backends with
    /// native binary support (e.g. `SovereignDevice`) override this.
    ///
    /// # Errors
    /// Returns [`Err`] if the backend does not support binary dispatch, or
    /// if dispatch fails.
    fn dispatch_binary(
        &self,
        _binary: &[u8],
        _bindings: Vec<BufferBinding<'_, Self>>,
        _workgroups: (u32, u32, u32),
        _entry_point: &str,
    ) -> Result<()> {
        Err(crate::error::BarracudaError::Device(
            "dispatch_binary: not supported by this backend".into(),
        ))
    }

    // ── Typed convenience methods (defaults via bytemuck) ─────────────

    /// Allocate a storage buffer for `n` f32 values.
    /// # Errors
    /// Returns [`Err`] if allocation fails.
    fn create_backend_buffer_f32(&self, n: usize) -> Result<Self::Buffer> {
        self.alloc_buffer("f32_buffer", (n * std::mem::size_of::<f32>()) as u64)
    }

    /// Allocate a storage buffer for `n` f64 values.
    /// # Errors
    /// Returns [`Err`] if allocation fails.
    fn create_backend_buffer_f64(&self, n: usize) -> Result<Self::Buffer> {
        self.alloc_buffer("f64_buffer", (n * std::mem::size_of::<f64>()) as u64)
    }

    /// Allocate a storage buffer for `n` u32 values.
    /// # Errors
    /// Returns [`Err`] if allocation fails.
    fn create_backend_buffer_u32(&self, n: usize) -> Result<Self::Buffer> {
        self.alloc_buffer("u32_buffer", (n * std::mem::size_of::<u32>()) as u64)
    }

    /// Allocate a storage buffer initialized with f32 data.
    /// # Errors
    /// Returns [`Err`] if allocation fails.
    fn alloc_buffer_f32_init(&self, label: &str, data: &[f32]) -> Result<Self::Buffer> {
        self.alloc_buffer_init(label, bytemuck::cast_slice(data))
    }

    /// Allocate a storage buffer initialized with f64 data.
    /// # Errors
    /// Returns [`Err`] if allocation fails.
    fn alloc_buffer_f64_init(&self, label: &str, data: &[f64]) -> Result<Self::Buffer> {
        self.alloc_buffer_init(label, bytemuck::cast_slice(data))
    }

    /// Write f32 data to a buffer at offset 0.
    fn upload_f32(&self, buffer: &Self::Buffer, data: &[f32]) {
        self.upload(buffer, 0, bytemuck::cast_slice(data));
    }

    /// Write f64 data to a buffer at offset 0.
    fn upload_f64(&self, buffer: &Self::Buffer, data: &[f64]) {
        self.upload(buffer, 0, bytemuck::cast_slice(data));
    }

    /// Read `n` f32 values from a buffer.
    /// # Errors
    /// Returns [`Err`] if readback fails.
    fn download_f32(&self, buffer: &Self::Buffer, n: usize) -> Result<Vec<f32>> {
        let bytes = self.download(buffer, (n * std::mem::size_of::<f32>()) as u64)?;
        Ok(bytemuck::cast_slice(&bytes).to_vec())
    }

    /// Read `n` f64 values from a buffer.
    /// # Errors
    /// Returns [`Err`] if readback fails.
    fn download_f64(&self, buffer: &Self::Buffer, n: usize) -> Result<Vec<f64>> {
        let bytes = self.download(buffer, (n * std::mem::size_of::<f64>()) as u64)?;
        Ok(bytemuck::cast_slice(&bytes).to_vec())
    }

    /// Read `n` u32 values from a buffer.
    /// # Errors
    /// Returns [`Err`] if readback fails.
    fn download_u32(&self, buffer: &Self::Buffer, n: usize) -> Result<Vec<u32>> {
        let bytes = self.download(buffer, (n * std::mem::size_of::<u32>()) as u64)?;
        Ok(bytemuck::cast_slice(&bytes).to_vec())
    }

    /// Read raw bytes from a buffer without conversion.
    /// # Errors
    /// Returns [`Err`] if readback fails.
    fn download_bytes(&self, buffer: &Self::Buffer, size: u64) -> Result<bytes::Bytes> {
        self.download(buffer, size)
    }

    /// Allocate a uniform buffer from a `Pod` value.
    /// # Errors
    /// Returns [`Err`] if allocation fails.
    fn alloc_uniform_pod<T: bytemuck::NoUninit>(
        &self,
        label: &str,
        data: &T,
    ) -> Result<Self::Buffer> {
        self.alloc_uniform(label, bytemuck::bytes_of(data))
    }
}

/// Blanket implementation: `Arc<B>` delegates to the inner backend.
///
/// Most ops hold `Arc<WgpuDevice>` — this impl lets them pass `&self.device`
/// directly to `ComputeDispatch::new()` without explicit deref.
impl<B: GpuBackend> GpuBackend for Arc<B> {
    type Buffer = B::Buffer;

    fn name(&self) -> &str {
        (**self).name()
    }
    fn has_f64_shaders(&self) -> bool {
        (**self).has_f64_shaders()
    }
    fn is_lost(&self) -> bool {
        (**self).is_lost()
    }
    fn capabilities(&self) -> BackendCapabilities {
        (**self).capabilities()
    }
    fn alloc_buffer(&self, label: &str, size: u64) -> Result<Self::Buffer> {
        (**self).alloc_buffer(label, size)
    }
    fn alloc_buffer_init(&self, label: &str, contents: &[u8]) -> Result<Self::Buffer> {
        (**self).alloc_buffer_init(label, contents)
    }
    fn alloc_uniform(&self, label: &str, contents: &[u8]) -> Result<Self::Buffer> {
        (**self).alloc_uniform(label, contents)
    }
    fn upload(&self, buffer: &Self::Buffer, offset: u64, data: &[u8]) {
        (**self).upload(buffer, offset, data);
    }
    fn download(&self, buffer: &Self::Buffer, size: u64) -> Result<bytes::Bytes> {
        (**self).download(buffer, size)
    }
    fn dispatch_compute(&self, desc: DispatchDescriptor<'_, Self>) -> Result<()> {
        (**self).dispatch_compute(reborrow_descriptor(desc))
    }

    fn dispatch_compute_batch(&self, descs: Vec<DispatchDescriptor<'_, Self>>) -> Result<()> {
        let reborrowed = descs.into_iter().map(reborrow_descriptor).collect();
        (**self).dispatch_compute_batch(reborrowed)
    }

    fn dispatch_binary(
        &self,
        binary: &[u8],
        bindings: Vec<BufferBinding<'_, Self>>,
        workgroups: (u32, u32, u32),
        entry_point: &str,
    ) -> Result<()> {
        let reborrowed = bindings
            .iter()
            .map(|b| BufferBinding {
                index: b.index,
                buffer: b.buffer,
                read_only: b.read_only,
                is_uniform: b.is_uniform,
            })
            .collect();
        (**self).dispatch_binary(binary, reborrowed, workgroups, entry_point)
    }
}

fn reborrow_descriptor<B: GpuBackend>(
    desc: DispatchDescriptor<'_, Arc<B>>,
) -> DispatchDescriptor<'_, B> {
    let bindings = desc
        .bindings
        .iter()
        .map(|b| BufferBinding {
            index: b.index,
            buffer: b.buffer,
            read_only: b.read_only,
            is_uniform: b.is_uniform,
        })
        .collect();
    DispatchDescriptor {
        label: desc.label,
        shader_source: desc.shader_source,
        entry_point: desc.entry_point,
        bindings,
        workgroups: desc.workgroups,
        f64_shader: desc.f64_shader,
        df64_shader: desc.df64_shader,
        hardware_hint: desc.hardware_hint,
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn hardware_hint_default_is_compute() {
        assert_eq!(HardwareHint::default(), HardwareHint::Compute);
    }

    #[test]
    fn hardware_hint_equality() {
        assert_eq!(HardwareHint::Compute, HardwareHint::Compute);
        assert_eq!(HardwareHint::TensorCore, HardwareHint::TensorCore);
        assert_ne!(HardwareHint::Compute, HardwareHint::TensorCore);
        assert_ne!(HardwareHint::RtCore, HardwareHint::ZBuffer);
    }

    #[test]
    fn hardware_hint_debug_formatting() {
        let s = format!("{:?}", HardwareHint::Compute);
        assert!(s.contains("Compute"));
        let s = format!("{:?}", HardwareHint::TensorCore);
        assert!(s.contains("TensorCore"));
    }
}