aien-sovereign-core-mv
AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.
Brought by drakestapleton
aien-sovereign-core-mv / crates / aien-platform / src / lib.rs
| 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | |
| 16 | //! Pure no_std platform traits and capability abstractions for the AIEN and SparkOS runtime. |
| 17 | //! Eliminates POSIX/Linux concepts (PathBuf, Command, sockets, threads, procfs) from core cognition and scheduling. |
| 18 | |
| 19 | #![no_std] |
| 20 | |
| 21 | extern crate alloc; |
| 22 | |
| 23 | use alloc::string::String; |
| 24 | |
| 25 | pub mod compute; |
| 26 | pub mod memory; |
| 27 | pub mod objects; |
| 28 | pub mod queue; |
| 29 | pub mod runtime; |
| 30 | pub mod task; |
| 31 | pub mod telemetry; |
| 32 | |
| 33 | pub use compute::{ |
| 34 | BufferLayout, BufferRegion, ComputeDevice, ComputeWork, DeviceAddress, Fence, MemoryDevice, |
| 35 | UnifiedBuffer, |
| 36 | }; |
| 37 | pub use memory::{MemoryEntity, MemoryService, RecallQuery, RecallResult}; |
| 38 | pub use objects::{ObjectId, ObjectRef, ObjectStore, ObjectWrite}; |
| 39 | pub use queue::{ |
| 40 | InferenceWork, KvHandle, ModelHandle, Priority, QueueError, SequenceId, Ticks, WorkQueue, |
| 41 | }; |
| 42 | pub use runtime::Runtime; |
| 43 | pub use task::{TaskExecutor, TaskRequest, TaskResult}; |
| 44 | pub use telemetry::{TelemetrySnapshot, TelemetrySource}; |
| 45 | |
| 46 | /// Fundamental platform error enumeration free of host OS dependencies. |
| 47 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 48 | pub enum PlatformError { |
| 49 | OutOfMemory, |
| 50 | DeviceUnavailable, |
| 51 | InvalidLayout, |
| 52 | QueueFull, |
| 53 | QueueEmpty, |
| 54 | TaskRejected(String), |
| 55 | ObjectNotFound(ObjectId), |
| 56 | AccessDenied, |
| 57 | HardwareFault(String), |
| 58 | UnsupportedOperation, |
| 59 | } |
| 60 | |
| 61 | impl core::fmt::Display for PlatformError { |
| 62 | fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 63 | match self { |
| 64 | Self::OutOfMemory => write!(f, "Platform error: out of physical/unified memory"), |
| 65 | Self::DeviceUnavailable => write!(f, "Platform error: compute device unavailable"), |
| 66 | Self::InvalidLayout => write!(f, "Platform error: invalid buffer layout or alignment"), |
| 67 | Self::QueueFull => write!(f, "Platform error: work queue capacity exceeded"), |
| 68 | Self::QueueEmpty => write!(f, "Platform error: work queue empty"), |
| 69 | Self::TaskRejected(msg) => { |
| 70 | write!(f, "Platform error: task execution rejected: {}", msg) |
| 71 | } |
| 72 | Self::ObjectNotFound(id) => write!(f, "Platform error: object {:?} not found", id), |
| 73 | Self::AccessDenied => write!(f, "Platform error: capability access denied"), |
| 74 | Self::HardwareFault(msg) => write!(f, "Platform error: hardware fault: {}", msg), |
| 75 | Self::UnsupportedOperation => write!( |
| 76 | f, |
| 77 | "Platform error: unsupported operation on target substrate" |
| 78 | ), |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | #[cfg(test)] |
| 84 | mod tests { |
| 85 | use super::*; |
| 86 | use alloc::string::ToString; |
| 87 | |
| 88 | #[test] |
| 89 | fn test_platform_error_display() { |
| 90 | assert_eq!( |
| 91 | PlatformError::OutOfMemory.to_string(), |
| 92 | "Platform error: out of physical/unified memory" |
| 93 | ); |
| 94 | assert_eq!( |
| 95 | PlatformError::DeviceUnavailable.to_string(), |
| 96 | "Platform error: compute device unavailable" |
| 97 | ); |
| 98 | assert_eq!( |
| 99 | PlatformError::QueueFull.to_string(), |
| 100 | "Platform error: work queue capacity exceeded" |
| 101 | ); |
| 102 | assert_eq!( |
| 103 | PlatformError::AccessDenied.to_string(), |
| 104 | "Platform error: capability access denied" |
| 105 | ); |
| 106 | assert_eq!( |
| 107 | PlatformError::TaskRejected("timeout".into()).to_string(), |
| 108 | "Platform error: task execution rejected: timeout" |
| 109 | ); |
| 110 | } |
| 111 | |
| 112 | #[test] |
| 113 | fn test_queue_priority_ordering() { |
| 114 | assert!(Priority::Realtime > Priority::Interactive); |
| 115 | assert!(Priority::Interactive > Priority::Normal); |
| 116 | assert!(Priority::Normal > Priority::Background); |
| 117 | } |
| 118 | |
| 119 | #[test] |
| 120 | fn test_buffer_layout() { |
| 121 | let layout = BufferLayout::new(4096, 128); |
| 122 | assert_eq!(layout.size, 4096); |
| 123 | assert_eq!(layout.align, 128); |
| 124 | } |
| 125 | |
| 126 | #[test] |
| 127 | fn test_telemetry_snapshot() { |
| 128 | let snap = TelemetrySnapshot { |
| 129 | architecture: "aarch64".into(), |
| 130 | target: "gb10".into(), |
| 131 | clock_ticks: 1_000_000, |
| 132 | memory_used_bytes: 1024 * 1024 * 100, |
| 133 | memory_total_bytes: 1024 * 1024 * 1024 * 128, |
| 134 | active_sequences: 8, |
| 135 | }; |
| 136 | assert_eq!(snap.architecture, "aarch64"); |
| 137 | assert_eq!(snap.target, "gb10"); |
| 138 | assert_eq!(snap.active_sequences, 8); |
| 139 | } |
| 140 | } |