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-linux / src / device.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 | //! Linux Compute Device implementation for Grace Blackwell GB10. |
| 17 | //! |
| 18 | //! No CUDA (FB-1 cut 6): GB10 memory is one unified LPDDR5x pool and, on ATS/HMM systems, |
| 19 | //! "all system memory is implicitly managed memory, requiring no special allocation" |
| 20 | //! (CUDA Programming Guide, Understanding Memory > Unified Memory). Buffers are plain |
| 21 | //! anonymous mappings; the Omega GPU engine stages what the chip reads into its own |
| 22 | //! allocations, so copies, zeroing and fences here are synchronous host operations. |
| 23 | |
| 24 | use crate::buffer::{LinuxMemoryKind, LinuxUnifiedBuffer, ResidencyPolicy}; |
| 25 | use aien_platform::{ |
| 26 | BufferLayout, BufferRegion, ComputeDevice, ComputeWork, Fence, MemoryDevice, PlatformError, |
| 27 | }; |
| 28 | use core::sync::atomic::{AtomicU64, Ordering}; |
| 29 | |
| 30 | pub struct LinuxComputeDevice { |
| 31 | device_id: u32, |
| 32 | fence_counter: AtomicU64, |
| 33 | } |
| 34 | |
| 35 | impl LinuxComputeDevice { |
| 36 | pub fn new() -> Self { |
| 37 | Self::with_device_id(0) |
| 38 | } |
| 39 | |
| 40 | pub fn with_device_id(device_id: u32) -> Self { |
| 41 | Self { |
| 42 | device_id, |
| 43 | fence_counter: AtomicU64::new(1), |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | pub fn device_id(&self) -> u32 { |
| 48 | self.device_id |
| 49 | } |
| 50 | |
| 51 | pub fn preferred_memory_kind(&self) -> LinuxMemoryKind { |
| 52 | LinuxMemoryKind::AtsSystem |
| 53 | } |
| 54 | |
| 55 | fn next_fence(&self) -> Fence { |
| 56 | Fence(self.fence_counter.fetch_add(1, Ordering::SeqCst)) |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | impl Default for LinuxComputeDevice { |
| 61 | fn default() -> Self { |
| 62 | Self::new() |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | impl ComputeDevice for LinuxComputeDevice { |
| 67 | type Buffer = LinuxUnifiedBuffer; |
| 68 | |
| 69 | fn alloc(&self, layout: BufferLayout) -> Result<Self::Buffer, PlatformError> { |
| 70 | let kind = self.preferred_memory_kind(); |
| 71 | LinuxUnifiedBuffer::allocate(layout, kind, ResidencyPolicy::FaultIn) |
| 72 | } |
| 73 | |
| 74 | fn submit(&self, _work: ComputeWork<'_>) -> Result<Fence, PlatformError> { |
| 75 | Ok(self.next_fence()) |
| 76 | } |
| 77 | |
| 78 | fn synchronize(&self, _fence: Fence) -> Result<(), PlatformError> { |
| 79 | Ok(()) |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | impl MemoryDevice for LinuxComputeDevice { |
| 84 | fn copy(&self, src: BufferRegion, dst: BufferRegion) -> Result<Fence, PlatformError> { |
| 85 | if src.len != dst.len { |
| 86 | return Err(PlatformError::InvalidLayout); |
| 87 | } |
| 88 | if src.len != 0 { |
| 89 | unsafe { |
| 90 | core::ptr::copy( |
| 91 | src.address.0 as *const u8, |
| 92 | dst.address.0 as *mut u8, |
| 93 | src.len, |
| 94 | ); |
| 95 | } |
| 96 | } |
| 97 | Ok(self.next_fence()) |
| 98 | } |
| 99 | |
| 100 | fn zero(&self, dst: BufferRegion) -> Result<Fence, PlatformError> { |
| 101 | if dst.len != 0 { |
| 102 | unsafe { |
| 103 | core::ptr::write_bytes(dst.address.0 as *mut u8, 0, dst.len); |
| 104 | } |
| 105 | } |
| 106 | Ok(self.next_fence()) |
| 107 | } |
| 108 | } |