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-omega-bf16 / build.rs

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