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-omega-moe / build.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 | //! Decides whether omega's MoE window API (`src/omega_gpu_moe_api.h`, OWN-30B cut 2) is linked. |
| 17 | //! |
| 18 | //! The archive itself is linked by `aien-omega-gpu`'s build script (this crate only declares |
| 19 | //! the extra symbols), so the decision mirrors its inputs: |
| 20 | //! * `AIEN_FORCE_CPU_STUB=1`: stub. |
| 21 | //! * `AIEN_OMEGA_GPU_LIB=<archive>`: native when `nm` finds |
| 22 | //! `omega_gpu_matmul_resident_windows_f32` defined in that archive. |
| 23 | //! * `AIEN_OMEGA_DIR=<checkout>`: native when the checkout has `src/omega_gpu_moe_api.h`. |
| 24 | //! * otherwise: stub (every call returns `Unavailable`). |
| 25 | //! |
| 26 | //! `cfg(has_omega_moe)` is set only when native. A stub never fails the build: the whole-tensor |
| 27 | //! fallback in the model code stays usable, and `is_native()` says which one a binary carries. |
| 28 | use std::path::Path; |
| 29 | use std::process::Command; |
| 30 | |
| 31 | fn main() { |
| 32 | println!("cargo:rustc-check-cfg=cfg(has_omega_moe)"); |
| 33 | for v in [ |
| 34 | "AIEN_FORCE_CPU_STUB", |
| 35 | "AIEN_OMEGA_GPU_LIB", |
| 36 | "AIEN_OMEGA_DIR", |
| 37 | ] { |
| 38 | println!("cargo:rerun-if-env-changed={v}"); |
| 39 | } |
| 40 | if std::env::var("AIEN_FORCE_CPU_STUB").as_deref() == Ok("1") { |
| 41 | return; |
| 42 | } |
| 43 | if let Ok(lib) = std::env::var("AIEN_OMEGA_GPU_LIB") { |
| 44 | println!("cargo:rerun-if-changed={lib}"); |
| 45 | if archive_defines(Path::new(&lib), "omega_gpu_matmul_resident_windows_f32") { |
| 46 | println!("cargo:rustc-cfg=has_omega_moe"); |
| 47 | } else { |
| 48 | println!("cargo:warning=aien-omega-moe: {lib} does not define the MoE window API; window calls are stubbed"); |
| 49 | } |
| 50 | return; |
| 51 | } |
| 52 | if let Ok(dir) = std::env::var("AIEN_OMEGA_DIR") { |
| 53 | let header = Path::new(&dir).join("src/omega_gpu_moe_api.h"); |
| 54 | println!("cargo:rerun-if-changed={}", header.display()); |
| 55 | if header.is_file() { |
| 56 | println!("cargo:rustc-cfg=has_omega_moe"); |
| 57 | } else { |
| 58 | println!("cargo:warning=aien-omega-moe: {dir} has no src/omega_gpu_moe_api.h (omega before OWN-30B cut 2); window calls are stubbed"); |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | fn archive_defines(lib: &Path, symbol: &str) -> bool { |
| 64 | let Ok(out) = Command::new("nm").arg(lib).output() else { |
| 65 | println!("cargo:warning=aien-omega-moe: nm not available, assuming the archive lacks the MoE window API"); |
| 66 | return false; |
| 67 | }; |
| 68 | String::from_utf8_lossy(&out.stdout) |
| 69 | .lines() |
| 70 | .any(|l| l.ends_with(&format!(" T {symbol}"))) |
| 71 | } |