rfann 0.1.0

A pure Rust implementation of the Fast Artificial Neural Network (FANN) library
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
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
//! Core compute backend trait and implementations

use super::error::ComputeError;
use crate::ActivationFunction;
use num_traits::Float;
use std::collections::HashMap;

/// Abstract compute backend for neural network operations
pub trait ComputeBackend<T: Float>: Send + Sync + std::fmt::Debug {
    /// Backend initialization and capability detection
    fn initialize() -> Result<Self, ComputeError>
    where
        Self: Sized;
    fn is_available() -> bool
    where
        Self: Sized;
    fn capabilities(&self) -> BackendCapabilities;
    fn backend_type(&self) -> BackendType;

    /// Core neural network operations
    fn matrix_vector_multiply(
        &self,
        matrix: &[T],
        vector: &[T],
        rows: usize,
        cols: usize,
    ) -> Result<Vec<T>, ComputeError>;

    fn batch_matrix_vector_multiply(
        &self,
        matrix: &[T],
        vectors: &[Vec<T>],
        rows: usize,
        cols: usize,
    ) -> Result<Vec<Vec<T>>, ComputeError>;

    fn apply_activation_function(
        &self,
        inputs: &[T],
        function: ActivationFunction,
        steepness: T,
    ) -> Result<Vec<T>, ComputeError>;

    fn vector_operations(&self) -> &dyn VectorOps<T>;
    fn memory_manager(&self) -> &dyn MemoryManager<T>;
}

/// Vector operation primitives
pub trait VectorOps<T: Float> {
    fn dot_product(&self, a: &[T], b: &[T]) -> Result<T, ComputeError>;
    fn vector_add(&self, a: &[T], b: &[T]) -> Result<Vec<T>, ComputeError>;
    fn vector_scale(&self, vec: &[T], scalar: T) -> Result<Vec<T>, ComputeError>;
    fn vector_subtract(&self, a: &[T], b: &[T]) -> Result<Vec<T>, ComputeError>;
}

/// Memory management interface
pub trait MemoryManager<T: Float> {
    fn allocate_buffer(&self, size: usize) -> Result<super::memory::BufferHandle, ComputeError>;
    fn upload_data(
        &self,
        handle: super::memory::BufferHandle,
        data: &[T],
    ) -> Result<(), ComputeError>;
    fn download_data(&self, handle: super::memory::BufferHandle) -> Result<Vec<T>, ComputeError>;
    fn deallocate_buffer(&self, handle: super::memory::BufferHandle) -> Result<(), ComputeError>;
    fn memory_usage(&self) -> super::memory::MemoryStats;
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum BackendType {
    WebGPU,
    Simd,
    Cpu,
}

#[derive(Debug, Clone)]
pub struct BackendCapabilities {
    pub max_buffer_size: usize,
    pub supports_f64: bool,
    pub supports_f32: bool,
    pub supports_f16: bool,
    pub max_compute_units: usize,
    pub memory_bandwidth_gbps: f32,
    pub shader_model: Option<String>,
}

#[derive(Debug, Hash, PartialEq, Eq)]
pub struct ComputeProfile {
    pub matrix_size: MatrixSize,
    pub batch_size: usize,
    pub operation_type: OperationType,
}

#[derive(Debug, Hash, PartialEq, Eq)]
pub enum MatrixSize {
    Small,  // < 100x100
    Medium, // 100x100 - 1000x1000
    Large,  // > 1000x1000
}

#[derive(Debug, Hash, PartialEq, Eq)]
pub enum OperationType {
    ForwardPass,
    BackwardPass,
    Training,
    Inference,
}

/// Intelligent backend selection with performance-based switching
#[derive(Debug)]
pub struct BackendSelector<T: Float>
where
    T: Send + Sync,
{
    backends: Vec<Box<dyn ComputeBackend<T>>>,
    performance_cache: HashMap<ComputeProfile, BackendType>,
    fallback_chain: Vec<BackendType>,
}

impl<T: Float + std::fmt::Debug> Clone for BackendSelector<T>
where
    T: Send + Sync + 'static,
{
    fn clone(&self) -> Self {
        // Clone the backend selector by creating a new one
        // This is a simplified clone that recreates backends
        Self::new()
    }
}

impl<T: Float + std::fmt::Debug + Send + Sync + 'static> Default for BackendSelector<T> {
    fn default() -> Self {
        Self::new()
    }
}

impl<T: Float + std::fmt::Debug + Send + Sync + 'static> BackendSelector<T> {
    pub fn new() -> Self {
        let mut backends = Vec::new();

        // Try to initialize backends in order of preference
        #[cfg(feature = "gpu")]
        {
            // WebGPU backend would be initialized here
            // Note: This requires async initialization, so we'll handle this differently
        }

        // Add SIMD backend if available
        if SimdBackend::<T>::is_available() {
            if let Ok(simd) = SimdBackend::initialize() {
                backends.push(Box::new(simd) as Box<dyn ComputeBackend<T>>);
            }
        }

        // CPU backend always available as final fallback
        if let Ok(cpu) = CpuBackend::initialize() {
            backends.push(Box::new(cpu) as Box<dyn ComputeBackend<T>>);
        }

        Self {
            backends,
            performance_cache: HashMap::new(),
            fallback_chain: vec![BackendType::WebGPU, BackendType::Simd, BackendType::Cpu],
        }
    }

    /// Get available backend types
    pub fn get_available_backends(&self) -> Vec<BackendType> {
        self.backends.iter().map(|b| b.backend_type()).collect()
    }

    /// Get current active backend type
    pub fn get_current_backend(&self) -> BackendType {
        // Return the first available backend (highest priority)
        if !self.backends.is_empty() {
            self.backends[0].backend_type()
        } else {
            BackendType::Cpu // Fallback
        }
    }

    /// Set the active backend
    pub fn set_backend(&mut self, backend_type: BackendType) {
        // Find the backend and move it to the front if available
        if let Some(pos) = self
            .backends
            .iter()
            .position(|b| b.backend_type() == backend_type)
        {
            // Move the selected backend to the front
            let backend = self.backends.remove(pos);
            self.backends.insert(0, backend);
        }
        // If backend not available, it will gracefully fall back to available ones
    }

    /// Select optimal backend for given problem size
    pub fn select_optimal_backend(&mut self, rows: usize, cols: usize) -> BackendType {
        let matrix_size = if rows > 1000 || cols > 1000 {
            MatrixSize::Large
        } else if rows > 100 || cols > 100 {
            MatrixSize::Medium
        } else {
            MatrixSize::Small
        };

        let profile = ComputeProfile {
            matrix_size,
            batch_size: 1,
            operation_type: OperationType::Inference,
        };

        // Use existing selection logic
        if let Some(backend) = self.select_backend(&profile) {
            backend.backend_type()
        } else {
            // Fallback to first available backend
            self.get_current_backend()
        }
    }

    pub fn select_backend(&self, profile: &ComputeProfile) -> Option<&dyn ComputeBackend<T>> {
        // Check performance cache first
        if let Some(backend_type) = self.performance_cache.get(profile) {
            if let Some(backend) = self.find_backend(*backend_type) {
                return Some(backend);
            }
        }

        // Default selection logic
        match profile.matrix_size {
            MatrixSize::Large => self
                .find_backend(BackendType::WebGPU)
                .or_else(|| self.find_backend(BackendType::Simd))
                .or_else(|| self.find_backend(BackendType::Cpu)),
            MatrixSize::Medium => {
                if profile.batch_size > 10 {
                    self.find_backend(BackendType::WebGPU)
                        .or_else(|| self.find_backend(BackendType::Simd))
                        .or_else(|| self.find_backend(BackendType::Cpu))
                } else {
                    self.find_backend(BackendType::Simd)
                        .or_else(|| self.find_backend(BackendType::Cpu))
                }
            }
            MatrixSize::Small => self
                .find_backend(BackendType::Simd)
                .or_else(|| self.find_backend(BackendType::Cpu)),
        }
    }

    fn find_backend(&self, backend_type: BackendType) -> Option<&dyn ComputeBackend<T>> {
        self.backends
            .iter()
            .find(|b| b.backend_type() == backend_type)
            .map(|b| b.as_ref())
    }

    pub fn capabilities(&self) -> Vec<BackendCapabilities> {
        self.backends.iter().map(|b| b.capabilities()).collect()
    }
}

/// SIMD backend using existing rfann SIMD operations
#[derive(Debug)]
pub struct SimdBackend<T: Float>
where
    T: Send + Sync,
{
    capabilities: BackendCapabilities,
    _phantom: std::marker::PhantomData<T>,
}

impl<T: Float + std::fmt::Debug + Send + Sync + 'static> Default for SimdBackend<T> {
    fn default() -> Self {
        Self::new()
    }
}

impl<T: Float + std::fmt::Debug + Send + Sync + 'static> SimdBackend<T> {
    pub fn new() -> Self {
        Self {
            capabilities: BackendCapabilities {
                max_buffer_size: usize::MAX,
                supports_f64: true,
                supports_f32: true,
                supports_f16: false, // CPU doesn't have native f16 support
                max_compute_units: {
                    #[cfg(feature = "parallel")]
                    {
                        num_cpus::get()
                    }
                    #[cfg(not(feature = "parallel"))]
                    {
                        4
                    } // Default fallback
                },
                memory_bandwidth_gbps: 50.0, // Typical DDR4 bandwidth
                shader_model: None,
            },
            _phantom: std::marker::PhantomData,
        }
    }
}

impl<T: Float + std::fmt::Debug> ComputeBackend<T> for SimdBackend<T>
where
    T: Send + Sync + 'static,
{
    fn initialize() -> Result<Self, ComputeError>
    where
        Self: Sized,
    {
        Ok(Self::new())
    }

    fn is_available() -> bool {
        true // SIMD operations are always available
    }

    fn capabilities(&self) -> BackendCapabilities {
        self.capabilities.clone()
    }

    fn backend_type(&self) -> BackendType {
        BackendType::Simd
    }

    fn matrix_vector_multiply(
        &self,
        matrix: &[T],
        vector: &[T],
        rows: usize,
        cols: usize,
    ) -> Result<Vec<T>, ComputeError> {
        if matrix.len() != rows * cols || vector.len() != cols {
            return Err(ComputeError::InvalidDimensions(format!(
                "Matrix {}x{} and vector {} dimensions don't match",
                rows,
                cols,
                vector.len()
            )));
        }

        let mut result = Vec::with_capacity(rows);

        for row in 0..rows {
            let mut sum = T::zero();
            for col in 0..cols {
                sum = sum + matrix[row * cols + col] * vector[col];
            }
            result.push(sum);
        }

        Ok(result)
    }

    fn batch_matrix_vector_multiply(
        &self,
        matrix: &[T],
        vectors: &[Vec<T>],
        rows: usize,
        cols: usize,
    ) -> Result<Vec<Vec<T>>, ComputeError> {
        let mut results = Vec::with_capacity(vectors.len());

        for vector in vectors {
            let result = self.matrix_vector_multiply(matrix, vector, rows, cols)?;
            results.push(result);
        }

        Ok(results)
    }

    fn apply_activation_function(
        &self,
        inputs: &[T],
        function: ActivationFunction,
        steepness: T,
    ) -> Result<Vec<T>, ComputeError> {
        Ok(inputs
            .iter()
            .map(|&x| self.apply_activation_cpu(x, function, steepness))
            .collect())
    }

    fn vector_operations(&self) -> &dyn VectorOps<T> {
        self
    }

    fn memory_manager(&self) -> &dyn MemoryManager<T> {
        self
    }
}

impl<T: Float + std::fmt::Debug + Send + Sync + 'static> SimdBackend<T> {
    fn apply_activation_cpu(&self, x: T, function: ActivationFunction, steepness: T) -> T {
        match function {
            ActivationFunction::Sigmoid => {
                let exp_val = (-steepness * x).exp();
                T::one() / (T::one() + exp_val)
            }
            ActivationFunction::ReLU => {
                if x > T::zero() {
                    x
                } else {
                    T::zero()
                }
            }
            ActivationFunction::ReLULeaky => {
                let alpha = T::from(0.01).unwrap_or(T::zero());
                if x > T::zero() {
                    x
                } else {
                    alpha * x
                }
            }
            ActivationFunction::Tanh => {
                let exp_2x = (steepness * x + steepness * x).exp();
                let exp_neg_2x = (-steepness * x - steepness * x).exp();
                (exp_2x - exp_neg_2x) / (exp_2x + exp_neg_2x)
            }
            ActivationFunction::Linear => x * steepness,
            _ => x, // Fallback for other functions
        }
    }
}

impl<T: Float + std::fmt::Debug + Send + Sync + 'static> VectorOps<T> for SimdBackend<T> {
    fn dot_product(&self, a: &[T], b: &[T]) -> Result<T, ComputeError> {
        if a.len() != b.len() {
            return Err(ComputeError::InvalidDimensions(
                "Vector length mismatch".to_string(),
            ));
        }

        let mut sum = T::zero();
        for (x, y) in a.iter().zip(b.iter()) {
            sum = sum + *x * *y;
        }
        Ok(sum)
    }

    fn vector_add(&self, a: &[T], b: &[T]) -> Result<Vec<T>, ComputeError> {
        if a.len() != b.len() {
            return Err(ComputeError::InvalidDimensions(
                "Vector length mismatch".to_string(),
            ));
        }

        Ok(a.iter().zip(b.iter()).map(|(x, y)| *x + *y).collect())
    }

    fn vector_scale(&self, vec: &[T], scalar: T) -> Result<Vec<T>, ComputeError> {
        Ok(vec.iter().map(|x| *x * scalar).collect())
    }

    fn vector_subtract(&self, a: &[T], b: &[T]) -> Result<Vec<T>, ComputeError> {
        if a.len() != b.len() {
            return Err(ComputeError::InvalidDimensions(
                "Vector length mismatch".to_string(),
            ));
        }

        Ok(a.iter().zip(b.iter()).map(|(x, y)| *x - *y).collect())
    }
}

impl<T: Float + std::fmt::Debug + Send + Sync + 'static> MemoryManager<T> for SimdBackend<T> {
    fn allocate_buffer(&self, _size: usize) -> Result<super::memory::BufferHandle, ComputeError> {
        // CPU memory management is handled by Vec<T> allocations
        // Return a placeholder handle since we don't need explicit buffer management
        use rand::Rng;
        let mut rng = rand::thread_rng();
        Ok(super::memory::BufferHandle::new(rng.gen()))
    }

    fn upload_data(
        &self,
        _handle: super::memory::BufferHandle,
        _data: &[T],
    ) -> Result<(), ComputeError> {
        // No-op for CPU backend
        Ok(())
    }

    fn download_data(&self, _handle: super::memory::BufferHandle) -> Result<Vec<T>, ComputeError> {
        // No-op for CPU backend - data is already in CPU memory
        Ok(Vec::new())
    }

    fn deallocate_buffer(&self, _handle: super::memory::BufferHandle) -> Result<(), ComputeError> {
        // No-op for CPU backend
        Ok(())
    }

    fn memory_usage(&self) -> super::memory::MemoryStats {
        super::memory::MemoryStats {
            total_allocated: 0, // Would need to track actual allocations
            available: usize::MAX,
            buffer_count: 0,
            fragmentation_ratio: 0.0,
        }
    }
}

/// CPU fallback backend
#[derive(Debug)]
pub struct CpuBackend<T: Float>
where
    T: Send + Sync,
{
    capabilities: BackendCapabilities,
    _phantom: std::marker::PhantomData<T>,
}

impl<T: Float + std::fmt::Debug + Send + Sync + 'static> Default for CpuBackend<T> {
    fn default() -> Self {
        Self::new()
    }
}

impl<T: Float + std::fmt::Debug + Send + Sync + 'static> CpuBackend<T> {
    pub fn new() -> Self {
        Self {
            capabilities: BackendCapabilities {
                max_buffer_size: usize::MAX,
                supports_f64: true,
                supports_f32: true,
                supports_f16: false, // CPU doesn't have native f16 support
                max_compute_units: 1,
                memory_bandwidth_gbps: 25.0, // Conservative estimate
                shader_model: None,
            },
            _phantom: std::marker::PhantomData,
        }
    }
}

impl<T: Float + std::fmt::Debug> ComputeBackend<T> for CpuBackend<T>
where
    T: Send + Sync + 'static,
{
    fn initialize() -> Result<Self, ComputeError>
    where
        Self: Sized,
    {
        Ok(Self::new())
    }

    fn is_available() -> bool {
        true // CPU is always available
    }

    fn capabilities(&self) -> BackendCapabilities {
        self.capabilities.clone()
    }

    fn backend_type(&self) -> BackendType {
        BackendType::Cpu
    }

    fn matrix_vector_multiply(
        &self,
        matrix: &[T],
        vector: &[T],
        rows: usize,
        cols: usize,
    ) -> Result<Vec<T>, ComputeError> {
        if matrix.len() != rows * cols || vector.len() != cols {
            return Err(ComputeError::InvalidDimensions(format!(
                "Matrix {}x{} and vector {} dimensions don't match",
                rows,
                cols,
                vector.len()
            )));
        }

        let mut result = Vec::with_capacity(rows);

        for row in 0..rows {
            let mut sum = T::zero();
            for col in 0..cols {
                sum = sum + matrix[row * cols + col] * vector[col];
            }
            result.push(sum);
        }

        Ok(result)
    }

    fn batch_matrix_vector_multiply(
        &self,
        matrix: &[T],
        vectors: &[Vec<T>],
        rows: usize,
        cols: usize,
    ) -> Result<Vec<Vec<T>>, ComputeError> {
        let mut results = Vec::with_capacity(vectors.len());

        for vector in vectors {
            let result = self.matrix_vector_multiply(matrix, vector, rows, cols)?;
            results.push(result);
        }

        Ok(results)
    }

    fn apply_activation_function(
        &self,
        inputs: &[T],
        function: ActivationFunction,
        steepness: T,
    ) -> Result<Vec<T>, ComputeError> {
        Ok(inputs
            .iter()
            .map(|&x| self.apply_activation_cpu(x, function, steepness))
            .collect())
    }

    fn vector_operations(&self) -> &dyn VectorOps<T> {
        self
    }

    fn memory_manager(&self) -> &dyn MemoryManager<T> {
        self
    }
}

impl<T: Float + std::fmt::Debug + Send + Sync + 'static> CpuBackend<T> {
    fn apply_activation_cpu(&self, x: T, function: ActivationFunction, steepness: T) -> T {
        match function {
            ActivationFunction::Sigmoid => {
                let exp_val = (-steepness * x).exp();
                T::one() / (T::one() + exp_val)
            }
            ActivationFunction::ReLU => {
                if x > T::zero() {
                    x
                } else {
                    T::zero()
                }
            }
            ActivationFunction::ReLULeaky => {
                let alpha = T::from(0.01).unwrap_or(T::zero());
                if x > T::zero() {
                    x
                } else {
                    alpha * x
                }
            }
            ActivationFunction::Tanh => {
                let exp_2x = (steepness * x + steepness * x).exp();
                let exp_neg_2x = (-steepness * x - steepness * x).exp();
                (exp_2x - exp_neg_2x) / (exp_2x + exp_neg_2x)
            }
            ActivationFunction::Linear => x * steepness,
            _ => x, // Fallback for other functions
        }
    }
}

impl<T: Float + std::fmt::Debug + Send + Sync + 'static> VectorOps<T> for CpuBackend<T> {
    fn dot_product(&self, a: &[T], b: &[T]) -> Result<T, ComputeError> {
        if a.len() != b.len() {
            return Err(ComputeError::InvalidDimensions(
                "Vector length mismatch".to_string(),
            ));
        }

        let mut sum = T::zero();
        for (x, y) in a.iter().zip(b.iter()) {
            sum = sum + *x * *y;
        }
        Ok(sum)
    }

    fn vector_add(&self, a: &[T], b: &[T]) -> Result<Vec<T>, ComputeError> {
        if a.len() != b.len() {
            return Err(ComputeError::InvalidDimensions(
                "Vector length mismatch".to_string(),
            ));
        }

        Ok(a.iter().zip(b.iter()).map(|(x, y)| *x + *y).collect())
    }

    fn vector_scale(&self, vec: &[T], scalar: T) -> Result<Vec<T>, ComputeError> {
        Ok(vec.iter().map(|x| *x * scalar).collect())
    }

    fn vector_subtract(&self, a: &[T], b: &[T]) -> Result<Vec<T>, ComputeError> {
        if a.len() != b.len() {
            return Err(ComputeError::InvalidDimensions(
                "Vector length mismatch".to_string(),
            ));
        }

        Ok(a.iter().zip(b.iter()).map(|(x, y)| *x - *y).collect())
    }
}

impl<T: Float + std::fmt::Debug + Send + Sync + 'static> MemoryManager<T> for CpuBackend<T> {
    fn allocate_buffer(&self, _size: usize) -> Result<super::memory::BufferHandle, ComputeError> {
        use rand::Rng;
        let mut rng = rand::thread_rng();
        Ok(super::memory::BufferHandle::new(rng.gen()))
    }

    fn upload_data(
        &self,
        _handle: super::memory::BufferHandle,
        _data: &[T],
    ) -> Result<(), ComputeError> {
        Ok(())
    }

    fn download_data(&self, _handle: super::memory::BufferHandle) -> Result<Vec<T>, ComputeError> {
        Ok(Vec::new())
    }

    fn deallocate_buffer(&self, _handle: super::memory::BufferHandle) -> Result<(), ComputeError> {
        Ok(())
    }

    fn memory_usage(&self) -> super::memory::MemoryStats {
        super::memory::MemoryStats {
            total_allocated: 0,
            available: usize::MAX,
            buffer_count: 0,
            fragmentation_ratio: 0.0,
        }
    }
}