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-pf / 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 which parts of omega's prefill API are linked (pattern of `aien-omega-fp8/build.rs`). |
| 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>`: `nm` decides per symbol. |
| 22 | //! * `AIEN_OMEGA_DIR=<checkout>`: the headers decide (`src/omega_gpu_prefill.h`, |
| 23 | //! `src/omega_gpu_prefill_attn_api.h`). |
| 24 | //! |
| 25 | //! `cfg(has_omega_pf)`: `omega_gpu_pf_qgemm` defined (quantiser, QMMA grouped GEMM, pf buffers). |
| 26 | //! `cfg(has_omega_pattn)`: `omega_gpu_prefill_attn` defined (host-pointer prefill attention). |
| 27 | //! `cfg(has_omega_pattn_dev)`: `omega_gpu_prefill_attn_dev` defined (device-pointer entry). |
| 28 | //! Otherwise every call returns `Unavailable`; a stub never fails the build. |
| 29 | use std::path::Path; |
| 30 | use std::process::Command; |
| 31 | |
| 32 | fn main() { |
| 33 | for c in [ |
| 34 | "has_omega_pf", |
| 35 | "has_omega_pattn", |
| 36 | "has_omega_pattn_dev", |
| 37 | "has_omega_pf_scoped", |
| 38 | "has_omega_pf_reading", |
| 39 | ] { |
| 40 | println!("cargo:rustc-check-cfg=cfg({c})"); |
| 41 | } |
| 42 | println!("cargo:rustc-check-cfg=cfg(has_omega_pfhost)"); |
| 43 | for v in [ |
| 44 | "AIEN_FORCE_CPU_STUB", |
| 45 | "AIEN_OMEGA_GPU_LIB", |
| 46 | "AIEN_OMEGA_DIR", |
| 47 | ] { |
| 48 | println!("cargo:rerun-if-env-changed={v}"); |
| 49 | } |
| 50 | if std::env::var("AIEN_FORCE_CPU_STUB").as_deref() == Ok("1") { |
| 51 | return; |
| 52 | } |
| 53 | if let Ok(lib) = std::env::var("AIEN_OMEGA_GPU_LIB") { |
| 54 | println!("cargo:rerun-if-changed={lib}"); |
| 55 | let syms = defined_symbols(Path::new(&lib)); |
| 56 | let has = |s: &str| syms.iter().any(|d| d == s); |
| 57 | if has("omega_gpu_pf_qgemm") && has("omega_gpu_pf_quant") && has("omega_gpu_pf_alloc_dev") { |
| 58 | println!("cargo:rustc-cfg=has_omega_pf"); |
| 59 | if has("omega_gpu_pf_qgemm_scoped") && has("omega_gpu_pf_qgemm_scoped_bm") { |
| 60 | println!("cargo:rustc-cfg=has_omega_pf_scoped"); |
| 61 | if has("omega_gpu_pf_qgemm_reading_option") |
| 62 | && has("omega_gpu_pf_qgemm_workspace_fits") |
| 63 | { |
| 64 | println!("cargo:rustc-cfg=has_omega_pf_reading"); |
| 65 | } |
| 66 | } |
| 67 | } else { |
| 68 | println!("cargo:warning=aien-omega-pf: {lib} does not define omega_gpu_pf_qgemm; prefill GEMM calls are stubbed"); |
| 69 | } |
| 70 | if has("omega_gpu_prefill_attn") { |
| 71 | println!("cargo:rustc-cfg=has_omega_pattn"); |
| 72 | if has("omega_gpu_prefill_attn_dev") { |
| 73 | println!("cargo:rustc-cfg=has_omega_pattn_dev"); |
| 74 | } |
| 75 | } else { |
| 76 | println!("cargo:warning=aien-omega-pf: {lib} does not define omega_gpu_prefill_attn; prefill attention is stubbed"); |
| 77 | } |
| 78 | // W-L1G-D: router logits + MoE combine (omega_gpu_pfhost.h) |
| 79 | if has("omega_gpu_pf_qgemm") |
| 80 | && has("omega_gpu_pf_router_logits") |
| 81 | && has("omega_gpu_pf_moe_combine") |
| 82 | && has("omega_gpu_pf_router_pack") |
| 83 | && has("omega_gpu_pf_router_rows") |
| 84 | { |
| 85 | println!("cargo:rustc-cfg=has_omega_pfhost"); |
| 86 | } |
| 87 | return; |
| 88 | } |
| 89 | if let Ok(dir) = std::env::var("AIEN_OMEGA_DIR") { |
| 90 | let pf = Path::new(&dir).join("src/omega_gpu_prefill.h"); |
| 91 | let pa = Path::new(&dir).join("src/omega_gpu_prefill_attn_api.h"); |
| 92 | println!("cargo:rerun-if-changed={}", pf.display()); |
| 93 | println!("cargo:rerun-if-changed={}", pa.display()); |
| 94 | // W-L1G-D: router logits + MoE combine (omega_gpu_pfhost.h) |
| 95 | let ph = Path::new(&dir).join("src/omega_gpu_pfhost.h"); |
| 96 | println!("cargo:rerun-if-changed={}", ph.display()); |
| 97 | if std::fs::read_to_string(&ph).is_ok_and(|t| { |
| 98 | t.contains("omega_gpu_pf_router_logits(") && t.contains("omega_gpu_pf_moe_combine(") |
| 99 | }) { |
| 100 | println!("cargo:rustc-cfg=has_omega_pfhost"); |
| 101 | } |
| 102 | if std::fs::read_to_string(&pf) |
| 103 | .is_ok_and(|t| t.contains("omega_gpu_pf_qgemm(") && t.contains("omega_gpu_pf_quant(")) |
| 104 | { |
| 105 | println!("cargo:rustc-cfg=has_omega_pf"); |
| 106 | if std::fs::read_to_string(&pf).is_ok_and(|t| { |
| 107 | t.contains("omega_gpu_pf_qgemm_scoped(") |
| 108 | && t.contains("omega_gpu_pf_qgemm_scoped_bm(") |
| 109 | }) { |
| 110 | println!("cargo:rustc-cfg=has_omega_pf_scoped"); |
| 111 | if std::fs::read_to_string(&pf).is_ok_and(|t| { |
| 112 | t.contains("omega_gpu_pf_qgemm_reading_option(") |
| 113 | && t.contains("omega_gpu_pf_qgemm_workspace_fits(") |
| 114 | }) { |
| 115 | println!("cargo:rustc-cfg=has_omega_pf_reading"); |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | if let Ok(t) = std::fs::read_to_string(&pa) { |
| 120 | if t.contains("omega_gpu_prefill_attn(") { |
| 121 | println!("cargo:rustc-cfg=has_omega_pattn"); |
| 122 | if t.contains("omega_gpu_prefill_attn_dev(") { |
| 123 | println!("cargo:rustc-cfg=has_omega_pattn_dev"); |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | fn defined_symbols(lib: &Path) -> Vec<String> { |
| 131 | let Ok(out) = Command::new("nm").arg(lib).output() else { |
| 132 | println!("cargo:warning=aien-omega-pf: nm not available, assuming the archive lacks the prefill API"); |
| 133 | return Vec::new(); |
| 134 | }; |
| 135 | String::from_utf8_lossy(&out.stdout) |
| 136 | .lines() |
| 137 | .filter_map(|l| l.split_once(" T ").map(|(_, s)| s.to_string())) |
| 138 | .collect() |
| 139 | } |