inferno-ai 0.10.3

Enterprise AI/ML model runner with automatic updates, real-time monitoring, and multi-interface support
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
#![allow(dead_code, unused_imports, unused_variables)]
// Hardware acceleration module for Inferno AI/ML platform
// Provides CUDA, ROCm, Metal, and CPU SIMD optimizations

use anyhow::Result;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::sync::Arc;
use tokio::sync::RwLock;

/// Hardware acceleration configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HardwareConfig {
    pub enabled: bool,
    pub gpu_acceleration: bool,
    pub cpu_simd_optimization: bool,
    pub mixed_precision: bool,
    pub multi_gpu_support: bool,
    pub gpu_memory_limit_mb: Option<usize>,
    pub preferred_gpu_vendor: GpuVendor,
    pub cpu_thread_count: Option<usize>,
    pub tensor_core_usage: bool,
    pub dynamic_optimization: bool,
}

impl Default for HardwareConfig {
    fn default() -> Self {
        Self {
            enabled: true,
            gpu_acceleration: true,
            cpu_simd_optimization: true,
            mixed_precision: true,
            multi_gpu_support: false,
            gpu_memory_limit_mb: None,
            preferred_gpu_vendor: GpuVendor::Auto,
            cpu_thread_count: None,
            tensor_core_usage: true,
            dynamic_optimization: true,
        }
    }
}

/// GPU vendor preferences
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum GpuVendor {
    Auto,
    Nvidia,
    Amd,
    Intel,
    Apple,
}

/// Hardware capabilities detection
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HardwareCapabilities {
    pub cpu_cores: usize,
    pub cpu_threads: usize,
    pub cpu_simd_support: Vec<SimdInstructionSet>,
    pub gpu_devices: Vec<GpuDevice>,
    pub total_memory_mb: usize,
    pub gpu_memory_mb: usize,
    pub supports_mixed_precision: bool,
    pub supports_tensor_cores: bool,
}

/// SIMD instruction set support
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum SimdInstructionSet {
    SSE2,
    SSE3,
    SSE4_1,
    SSE4_2,
    AVX,
    AVX2,
    AVX512,
    NEON, // ARM
}

/// GPU device information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GpuDevice {
    pub id: usize,
    pub name: String,
    pub vendor: GpuVendor,
    pub memory_mb: usize,
    pub compute_capability: Option<String>,
    pub supports_fp16: bool,
    pub supports_int8: bool,
    pub max_threads_per_block: usize,
    pub multiprocessor_count: usize,
}

/// Hardware optimization metrics
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct HardwareMetrics {
    pub gpu_utilization: f64,
    pub cpu_utilization: f64,
    pub memory_bandwidth_utilization: f64,
    pub tensor_throughput_gops: f64,
    pub mixed_precision_speedup: f64,
    pub simd_operations_per_second: f64,
    pub gpu_memory_usage_mb: f64,
}

/// CUDA-specific optimizations
pub struct CudaOptimizer {
    device_count: usize,
    devices: Vec<GpuDevice>,
    current_device: Option<usize>,
}

impl CudaOptimizer {
    pub fn new() -> Result<Self> {
        // Simulate CUDA initialization
        let devices = Self::detect_cuda_devices()?;
        let device_count = devices.len();

        Ok(Self {
            device_count,
            devices,
            current_device: if device_count > 0 { Some(0) } else { None },
        })
    }

    fn detect_cuda_devices() -> Result<Vec<GpuDevice>> {
        // Simulate CUDA device detection
        // In a real implementation, this would use CUDA runtime API
        let mut devices = Vec::new();

        // Mock device for testing
        if cfg!(feature = "cuda") || std::env::var("SIMULATE_CUDA").is_ok() {
            devices.push(GpuDevice {
                id: 0,
                name: "NVIDIA GeForce RTX 4090".to_string(),
                vendor: GpuVendor::Nvidia,
                memory_mb: 24576, // 24GB
                compute_capability: Some("8.9".to_string()),
                supports_fp16: true,
                supports_int8: true,
                max_threads_per_block: 1024,
                multiprocessor_count: 128,
            });
        }

        Ok(devices)
    }

    pub async fn optimize_for_cuda(&self, model_data: &[u8]) -> Result<Vec<u8>> {
        if self.current_device.is_none() {
            return Ok(model_data.to_vec());
        }

        tracing::info!("Applying CUDA optimizations");

        // Simulate CUDA-specific optimizations
        tokio::time::sleep(std::time::Duration::from_millis(50)).await;

        // In a real implementation, this would:
        // - Optimize kernel launches
        // - Configure memory coalescing
        // - Set up tensor core usage
        // - Apply mixed precision optimizations

        Ok(model_data.to_vec())
    }

    pub fn get_device_info(&self, device_id: usize) -> Option<&GpuDevice> {
        self.devices.get(device_id)
    }
}

/// ROCm (AMD GPU) optimizations
pub struct RocmOptimizer {
    devices: Vec<GpuDevice>,
}

impl RocmOptimizer {
    pub fn new() -> Result<Self> {
        let devices = Self::detect_rocm_devices()?;
        Ok(Self { devices })
    }

    fn detect_rocm_devices() -> Result<Vec<GpuDevice>> {
        let mut devices = Vec::new();

        // Mock ROCm device for testing
        if cfg!(feature = "rocm") || std::env::var("SIMULATE_ROCM").is_ok() {
            devices.push(GpuDevice {
                id: 0,
                name: "AMD Radeon RX 7900 XTX".to_string(),
                vendor: GpuVendor::Amd,
                memory_mb: 24576, // 24GB
                compute_capability: Some("gfx1100".to_string()),
                supports_fp16: true,
                supports_int8: true,
                max_threads_per_block: 1024,
                multiprocessor_count: 96,
            });
        }

        Ok(devices)
    }

    pub async fn optimize_for_rocm(&self, model_data: &[u8]) -> Result<Vec<u8>> {
        if self.devices.is_empty() {
            return Ok(model_data.to_vec());
        }

        tracing::info!("Applying ROCm optimizations");
        tokio::time::sleep(std::time::Duration::from_millis(50)).await;

        Ok(model_data.to_vec())
    }
}

/// Metal (Apple GPU) optimizations
pub struct MetalOptimizer {
    devices: Vec<GpuDevice>,
}

impl MetalOptimizer {
    pub fn new() -> Result<Self> {
        let devices = Self::detect_metal_devices()?;
        Ok(Self { devices })
    }

    fn detect_metal_devices() -> Result<Vec<GpuDevice>> {
        let mut devices = Vec::new();

        // Mock Metal device for testing on macOS
        if cfg!(target_os = "macos") || std::env::var("SIMULATE_METAL").is_ok() {
            devices.push(GpuDevice {
                id: 0,
                name: "Apple M2 Ultra".to_string(),
                vendor: GpuVendor::Apple,
                memory_mb: 196608, // 192GB unified memory
                compute_capability: Some("Metal 3.1".to_string()),
                supports_fp16: true,
                supports_int8: true,
                max_threads_per_block: 1024,
                multiprocessor_count: 76, // GPU cores
            });
        }

        Ok(devices)
    }

    pub async fn optimize_for_metal(&self, model_data: &[u8]) -> Result<Vec<u8>> {
        if self.devices.is_empty() {
            return Ok(model_data.to_vec());
        }

        tracing::info!("Applying Metal Performance Shaders optimizations");
        tokio::time::sleep(std::time::Duration::from_millis(30)).await;

        // In a real implementation, this would use Metal Performance Shaders
        // for optimized matrix operations and neural network layers

        Ok(model_data.to_vec())
    }
}

/// CPU SIMD optimizations
pub struct SimdOptimizer {
    supported_instruction_sets: Vec<SimdInstructionSet>,
    optimal_vector_size: usize,
}

impl Default for SimdOptimizer {
    fn default() -> Self {
        Self::new()
    }
}

impl SimdOptimizer {
    pub fn new() -> Self {
        let supported_instruction_sets = Self::detect_simd_support();
        let optimal_vector_size = Self::determine_optimal_vector_size(&supported_instruction_sets);

        Self {
            supported_instruction_sets,
            optimal_vector_size,
        }
    }

    fn detect_simd_support() -> Vec<SimdInstructionSet> {
        let mut supported = Vec::new();

        // Simulate SIMD detection - in practice, use cpuid or similar
        #[cfg(target_arch = "x86_64")]
        {
            supported.push(SimdInstructionSet::SSE2);
            supported.push(SimdInstructionSet::SSE3);
            supported.push(SimdInstructionSet::SSE4_1);
            supported.push(SimdInstructionSet::SSE4_2);
            supported.push(SimdInstructionSet::AVX);

            if std::env::var("ENABLE_AVX2").is_ok() {
                supported.push(SimdInstructionSet::AVX2);
            }

            if std::env::var("ENABLE_AVX512").is_ok() {
                supported.push(SimdInstructionSet::AVX512);
            }
        }

        #[cfg(target_arch = "aarch64")]
        {
            supported.push(SimdInstructionSet::NEON);
        }

        supported
    }

    fn determine_optimal_vector_size(instruction_sets: &[SimdInstructionSet]) -> usize {
        if let Some(instruction_set) = instruction_sets.iter().next_back() {
            match instruction_set {
                SimdInstructionSet::AVX512 => return 64, // 512 bits = 64 bytes
                SimdInstructionSet::AVX2 | SimdInstructionSet::AVX => return 32, // 256 bits = 32 bytes
                SimdInstructionSet::SSE4_2
                | SimdInstructionSet::SSE4_1
                | SimdInstructionSet::SSE3
                | SimdInstructionSet::SSE2 => return 16, // 128 bits = 16 bytes
                SimdInstructionSet::NEON => return 16, // 128 bits = 16 bytes
            }
        }
        8 // Fallback to 64-bit operations
    }

    pub async fn optimize_tensor_operations(&self, data: &[f32]) -> Result<Vec<f32>> {
        tracing::debug!(
            "Applying SIMD optimizations with vector size: {}",
            self.optimal_vector_size
        );

        // Simulate SIMD-optimized operations
        let mut optimized_data = Vec::with_capacity(data.len());

        // Vectorized operations (simplified simulation)
        for chunk in data.chunks(self.optimal_vector_size / 4) {
            // f32 = 4 bytes
            let processed_chunk: Vec<f32> = chunk
                .iter()
                .map(|&x| x * 1.1 + 0.01) // Simulate some computation
                .collect();
            optimized_data.extend(processed_chunk);
        }

        Ok(optimized_data)
    }

    pub fn get_performance_characteristics(&self) -> HashMap<String, f64> {
        let mut characteristics = HashMap::new();

        // Estimate performance based on supported instruction sets
        let mut base_performance = 1.0;

        for instruction_set in &self.supported_instruction_sets {
            match instruction_set {
                SimdInstructionSet::AVX512 => base_performance *= 4.0,
                SimdInstructionSet::AVX2 => base_performance *= 2.5,
                SimdInstructionSet::AVX => base_performance *= 2.0,
                SimdInstructionSet::SSE4_2 => base_performance *= 1.5,
                SimdInstructionSet::NEON => base_performance *= 2.0,
                _ => base_performance *= 1.2,
            }
        }

        characteristics.insert("simd_speedup".to_string(), base_performance);
        characteristics.insert("vector_size".to_string(), self.optimal_vector_size as f64);
        characteristics.insert(
            "instruction_sets".to_string(),
            self.supported_instruction_sets.len() as f64,
        );

        characteristics
    }
}

/// Main hardware optimizer
pub struct HardwareOptimizer {
    config: HardwareConfig,
    capabilities: HardwareCapabilities,
    metrics: Arc<RwLock<HardwareMetrics>>,
    cuda_optimizer: Option<CudaOptimizer>,
    rocm_optimizer: Option<RocmOptimizer>,
    metal_optimizer: Option<MetalOptimizer>,
    simd_optimizer: SimdOptimizer,
}

impl HardwareOptimizer {
    /// Create new hardware optimizer
    pub async fn new(config: HardwareConfig) -> Result<Self> {
        let capabilities = Self::detect_hardware_capabilities().await?;

        // Initialize GPU optimizers based on availability and preference
        let cuda_optimizer = if config.gpu_acceleration {
            CudaOptimizer::new().ok()
        } else {
            None
        };

        let rocm_optimizer = if config.gpu_acceleration {
            RocmOptimizer::new().ok()
        } else {
            None
        };

        let metal_optimizer = if config.gpu_acceleration {
            MetalOptimizer::new().ok()
        } else {
            None
        };

        let simd_optimizer = SimdOptimizer::new();

        Ok(Self {
            config,
            capabilities,
            metrics: Arc::new(RwLock::new(HardwareMetrics::default())),
            cuda_optimizer,
            rocm_optimizer,
            metal_optimizer,
            simd_optimizer,
        })
    }

    /// Detect hardware capabilities
    async fn detect_hardware_capabilities() -> Result<HardwareCapabilities> {
        let cpu_cores = num_cpus::get_physical();
        let cpu_threads = num_cpus::get();

        // Detect SIMD support
        let cpu_simd_support = SimdOptimizer::detect_simd_support();

        // Detect GPU devices
        let mut gpu_devices = Vec::new();
        let mut gpu_memory_mb = 0;

        // Try CUDA
        if let Ok(cuda) = CudaOptimizer::new() {
            for device in &cuda.devices {
                gpu_memory_mb += device.memory_mb;
                gpu_devices.push(device.clone());
            }
        }

        // Try ROCm
        if let Ok(rocm) = RocmOptimizer::new() {
            for device in &rocm.devices {
                gpu_memory_mb += device.memory_mb;
                gpu_devices.push(device.clone());
            }
        }

        // Try Metal
        if let Ok(metal) = MetalOptimizer::new() {
            for device in &metal.devices {
                gpu_memory_mb += device.memory_mb;
                gpu_devices.push(device.clone());
            }
        }

        // Get system memory (simplified)
        let total_memory_mb = 16384; // Mock 16GB - in practice, use sysinfo crate

        let supports_mixed_precision =
            !gpu_devices.is_empty() && gpu_devices.iter().any(|d| d.supports_fp16);

        let supports_tensor_cores = gpu_devices
            .iter()
            .any(|d| matches!(d.vendor, GpuVendor::Nvidia) && d.supports_fp16);

        Ok(HardwareCapabilities {
            cpu_cores,
            cpu_threads,
            cpu_simd_support,
            gpu_devices,
            total_memory_mb,
            gpu_memory_mb,
            supports_mixed_precision,
            supports_tensor_cores,
        })
    }

    /// Optimize model for current hardware
    pub async fn optimize_for_hardware(&self, model_path: &str) -> Result<String> {
        tracing::info!("Optimizing model for hardware: {}", model_path);

        // Read model data
        let model_data = tokio::fs::read(model_path).await?;

        // Apply hardware-specific optimizations
        let optimized_data = self.apply_hardware_optimizations(model_data).await?;

        // Save optimized model
        let optimized_path = format!("{}.hw_optimized", model_path);
        tokio::fs::write(&optimized_path, optimized_data).await?;

        // Update metrics
        self.update_metrics().await;

        tracing::info!("Hardware optimization completed: {}", optimized_path);
        Ok(optimized_path)
    }

    async fn apply_hardware_optimizations(&self, mut model_data: Vec<u8>) -> Result<Vec<u8>> {
        // Apply GPU optimizations based on preference and availability
        match self.config.preferred_gpu_vendor {
            GpuVendor::Nvidia | GpuVendor::Auto => {
                if let Some(ref cuda) = self.cuda_optimizer {
                    model_data = cuda.optimize_for_cuda(&model_data).await?;
                }
            }
            GpuVendor::Amd => {
                if let Some(ref rocm) = self.rocm_optimizer {
                    model_data = rocm.optimize_for_rocm(&model_data).await?;
                }
            }
            GpuVendor::Apple => {
                if let Some(ref metal) = self.metal_optimizer {
                    model_data = metal.optimize_for_metal(&model_data).await?;
                }
            }
            GpuVendor::Intel => {
                // Intel GPU optimizations would go here
                tracing::debug!("Intel GPU optimizations not yet implemented");
            }
        }

        // Apply CPU SIMD optimizations if no GPU or as fallback
        if self.config.cpu_simd_optimization {
            // For simplicity, assume model contains f32 data we can optimize
            // In practice, this would parse the actual model format
        }

        Ok(model_data)
    }

    /// Get optimal device for inference
    pub fn get_optimal_device(&self) -> Option<&GpuDevice> {
        if !self.config.gpu_acceleration || self.capabilities.gpu_devices.is_empty() {
            return None;
        }

        // Select best device based on memory and compute capability
        self.capabilities.gpu_devices.iter().max_by(|a, b| {
            // Primary: memory size
            let memory_cmp = a.memory_mb.cmp(&b.memory_mb);
            if memory_cmp != std::cmp::Ordering::Equal {
                return memory_cmp;
            }

            // Secondary: multiprocessor count
            a.multiprocessor_count.cmp(&b.multiprocessor_count)
        })
    }

    /// Configure mixed precision settings
    pub async fn configure_mixed_precision(&self) -> Result<()> {
        if !self.config.mixed_precision || !self.capabilities.supports_mixed_precision {
            return Ok(());
        }

        tracing::info!("Configuring mixed precision inference");

        // Configure automatic mixed precision
        // In practice, this would set up AMP for PyTorch or TensorRT

        Ok(())
    }

    /// Update hardware metrics
    async fn update_metrics(&self) {
        let mut metrics = self.metrics.write().await;

        // Simulate hardware metrics collection
        metrics.gpu_utilization = 85.0; // Mock 85% GPU utilization
        metrics.cpu_utilization = 45.0; // Mock 45% CPU utilization
        metrics.memory_bandwidth_utilization = 70.0;
        metrics.tensor_throughput_gops = 500.0; // Mock 500 GOPS
        metrics.mixed_precision_speedup = if self.config.mixed_precision {
            1.8
        } else {
            1.0
        };

        // Calculate SIMD performance
        let simd_chars = self.simd_optimizer.get_performance_characteristics();
        metrics.simd_operations_per_second =
            simd_chars.get("simd_speedup").unwrap_or(&1.0) * 1000000.0;

        // GPU memory usage
        if let Some(device) = self.get_optimal_device() {
            metrics.gpu_memory_usage_mb = device.memory_mb as f64 * 0.6; // Mock 60% usage
        }
    }

    /// Get current hardware metrics
    pub async fn get_metrics(&self) -> HardwareMetrics {
        self.metrics.read().await.clone()
    }

    /// Get hardware capabilities
    pub fn get_capabilities(&self) -> &HardwareCapabilities {
        &self.capabilities
    }

    /// Benchmark hardware optimization performance
    pub async fn benchmark(&self, _model_path: &str, num_requests: usize) -> Result<f64> {
        tracing::info!(
            "Benchmarking hardware optimization with {} requests",
            num_requests
        );

        let start_time = std::time::Instant::now();

        // Simulate hardware-accelerated inference
        for _ in 0..num_requests {
            // Mock inference time based on hardware capabilities
            let inference_time = if self.get_optimal_device().is_some() {
                std::time::Duration::from_millis(10) // Fast GPU inference
            } else {
                std::time::Duration::from_millis(50) // Slower CPU inference
            };

            tokio::time::sleep(inference_time).await;
        }

        let total_time = start_time.elapsed();
        let requests_per_second = num_requests as f64 / total_time.as_secs_f64();

        // Calculate performance multiplier
        let baseline_rps = 10.0; // Baseline requests per second
        let performance_multiplier = requests_per_second / baseline_rps;

        tracing::info!(
            "Hardware benchmark completed: {:.2} requests/second ({:.2}x speedup)",
            requests_per_second,
            performance_multiplier
        );

        Ok(performance_multiplier)
    }
}

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

    #[tokio::test]
    async fn test_hardware_optimizer_creation() {
        let config = HardwareConfig::default();
        let optimizer = HardwareOptimizer::new(config).await;
        assert!(optimizer.is_ok());
    }

    #[test]
    fn test_simd_optimizer() {
        let optimizer = SimdOptimizer::new();
        assert!(optimizer.optimal_vector_size >= 8);
        assert!(!optimizer.supported_instruction_sets.is_empty());
    }

    #[tokio::test]
    async fn test_simd_tensor_operations() {
        let optimizer = SimdOptimizer::new();
        let test_data = vec![1.0f32; 1000];
        let result = optimizer.optimize_tensor_operations(&test_data).await;
        assert!(result.is_ok());
        assert_eq!(result.unwrap().len(), test_data.len());
    }

    #[test]
    fn test_cuda_optimizer_creation() {
        // This will only succeed if CUDA is available or simulated
        // SAFETY: No other threads are accessing this environment variable in this test
        unsafe { std::env::set_var("SIMULATE_CUDA", "1") };
        let optimizer = CudaOptimizer::new();
        assert!(optimizer.is_ok());
    }

    #[test]
    fn test_metal_optimizer_creation() {
        // SAFETY: No other threads are accessing this environment variable in this test
        unsafe { std::env::set_var("SIMULATE_METAL", "1") };
        let optimizer = MetalOptimizer::new();
        assert!(optimizer.is_ok());
    }
}