interplane.Get Omega
Read in your language

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

branch main Branches Tags History

aien-sovereign-core-mv / crates / aien-platform-linux / src / lib.rs

195 lines · 6163 bytes Raw Blame History
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//! Linux and Grace Blackwell GB10 platform driver cell for the AIEN runtime.
17
18pub mod buffer;
19pub mod device;
20pub mod queue;
21pub mod telemetry;
22
23pub use buffer::{LinuxMemoryKind, LinuxUnifiedBuffer, ResidencyPolicy};
24pub use device::LinuxComputeDevice;
25pub use queue::LinuxWorkQueue;
26pub use telemetry::LinuxTelemetrySource;
27
28#[cfg(test)]
29mod tests {
30 use super::*;
31 use aien_platform::{
32 BufferLayout, ComputeDevice, InferenceWork, KvHandle, ModelHandle, Priority,
33 TelemetrySource, UnifiedBuffer, WorkQueue,
34 };
35
36 #[test]
37 fn test_linux_unified_buffer_allocation_and_read_write() {
38 let layout = BufferLayout::new(65536, 128);
39 let mut buf = LinuxUnifiedBuffer::allocate(
40 layout,
41 LinuxMemoryKind::AtsSystem,
42 ResidencyPolicy::FaultIn,
43 )
44 .expect("Failed to allocate LinuxUnifiedBuffer");
45
46 assert_eq!(buf.len(), 65536);
47 assert!(buf.device_address().0 != 0);
48 assert_eq!(buf.device_address().0 % 128, 0);
49
50 unsafe {
51 let p = buf.as_mut_ptr();
52 *p = 42;
53 *p.add(65535) = 99;
54 assert_eq!(*buf.as_ptr(), 42);
55 assert_eq!(*buf.as_ptr().add(65535), 99);
56 }
57 }
58
59 #[test]
60 fn test_linux_compute_device_allocation() {
61 let device = LinuxComputeDevice::new();
62 let layout = BufferLayout::new(1024 * 1024, 256);
63 let buf = device
64 .alloc(layout)
65 .expect("Failed to allocate from LinuxComputeDevice");
66
67 assert_eq!(buf.len(), 1024 * 1024);
68 assert_eq!(buf.device_address().0 % 256, 0);
69 }
70
71 #[test]
72 fn test_linux_memory_device_copy_and_zero() {
73 use aien_platform::{BufferRegion, MemoryDevice};
74
75 let device = LinuxComputeDevice::new();
76 let layout = BufferLayout::new(4096, 128);
77 let mut buf_src = device.alloc(layout).expect("alloc src");
78 let mut buf_dst = device.alloc(layout).expect("alloc dst");
79
80 unsafe {
81 for i in 0..4096 {
82 *buf_src.as_mut_ptr().add(i) = (i % 251) as u8;
83 *buf_dst.as_mut_ptr().add(i) = 0xFF;
84 }
85 }
86
87 let src_region = BufferRegion {
88 address: buf_src.device_address(),
89 offset: 0,
90 len: 4096,
91 };
92 let dst_region = BufferRegion {
93 address: buf_dst.device_address(),
94 offset: 0,
95 len: 4096,
96 };
97
98 let fence = device.copy(src_region, dst_region).expect("device copy");
99 device.synchronize(fence).expect("synchronize copy");
100
101 unsafe {
102 for i in 0..4096 {
103 assert_eq!(
104 *buf_dst.as_ptr().add(i),
105 (i % 251) as u8,
106 "copy mismatch at index {}",
107 i
108 );
109 }
110 }
111
112 let fence_zero = device.zero(dst_region).expect("device zero");
113 device.synchronize(fence_zero).expect("synchronize zero");
114
115 unsafe {
116 for i in 0..4096 {
117 assert_eq!(*buf_dst.as_ptr().add(i), 0, "zero mismatch at index {}", i);
118 }
119 }
120 }
121
122 #[test]
123 fn test_linux_work_queue_priority_and_deadline() {
124 let queue = LinuxWorkQueue::new(64);
125 let w_bg = InferenceWork {
126 sequence: 1,
127 model: ModelHandle(1),
128 kv: KvHandle(1),
129 priority: Priority::Background,
130 deadline: None,
131 branch_parent: None,
132 next_token_budget: 16,
133 };
134 let w_rt = InferenceWork {
135 sequence: 2,
136 model: ModelHandle(1),
137 kv: KvHandle(2),
138 priority: Priority::Realtime,
139 deadline: Some(100),
140 branch_parent: None,
141 next_token_budget: 16,
142 };
143 let w_rt_earlier = InferenceWork {
144 sequence: 3,
145 model: ModelHandle(1),
146 kv: KvHandle(3),
147 priority: Priority::Realtime,
148 deadline: Some(50),
149 branch_parent: None,
150 next_token_budget: 16,
151 };
152
153 queue.push(w_bg).expect("Push background failed");
154 queue.push(w_rt).expect("Push realtime failed");
155 queue
156 .push(w_rt_earlier)
157 .expect("Push earlier realtime failed");
158
159 assert_eq!(queue.len(), 3);
160
161 let first = queue.pop().expect("Pop first");
162 assert_eq!(first.sequence, 3);
163
164 let second = queue.pop().expect("Pop second");
165 assert_eq!(second.sequence, 2);
166
167 let third = queue.pop().expect("Pop third");
168 assert_eq!(third.sequence, 1);
169
170 assert!(queue.is_empty());
171 }
172
173 #[test]
174 fn test_linux_device_allocates_plain_system_memory() {
175 let device = LinuxComputeDevice::new();
176 assert_eq!(device.preferred_memory_kind(), LinuxMemoryKind::AtsSystem);
177 let buf = device
178 .alloc(BufferLayout {
179 size: 8192,
180 align: 4096,
181 })
182 .expect("alloc");
183 assert_eq!(buf.kind(), LinuxMemoryKind::AtsSystem);
184 assert_eq!(buf.as_ptr() as usize % 4096, 0);
185 }
186
187 #[test]
188 fn test_linux_telemetry_source_snapshot() {
189 let source = LinuxTelemetrySource::new();
190 let snap = source.snapshot().expect("Snapshot failed");
191 assert!(!snap.architecture.is_empty());
192 assert!(!snap.target.is_empty());
193 assert!(snap.clock_ticks > 0);
194 }
195}