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

117 lines · 5426 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 FP8 GEMV API (`src/omega_gpu_fp8_api.h`, OWN-30B cuts 5-6) 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_fp8_gemv_grouped_f32` defined in that archive.
23//! * `AIEN_OMEGA_DIR=<checkout>`: native when the checkout has `src/omega_gpu_fp8_api.h`.
24//!
25//! `cfg(has_omega_fp8_slots)` (Expert Ribbon slot pools, omega#533) is set when the archive defines
26//! `omega_gpu_fp8_slots_alloc` or the checkout has `src/omega_gpu_fp8_slots.h`.
27//!
28//! `cfg(has_omega_fp8gemm)` (the prefill grouped GEMM) is set when the archive defines
29//! `omega_gpu_fp8gemm_f32` or the checkout has `src/omega_gpu_fp8gemm_api.h`.
30//! `cfg(has_omega_fp8_grouped_rule)` (L310 one-wave lever, `omega_gpu_fp8_grouped_ctas_auto`) is set when the
31//! archive defines that symbol or the checkout header declares it.
32//! * otherwise: stub (every call returns `Unavailable`).
33//!
34//! `cfg(has_omega_fp8)` is set only when native. A stub never fails the build: the bf16
35//! path in the model code stays usable, and `is_native()` says which one a binary carries.
36use std::path::Path;
37use std::process::Command;
38
39fn main() {
40 println!("cargo:rustc-check-cfg=cfg(has_omega_fp8)");
41 println!("cargo:rustc-check-cfg=cfg(has_omega_fp8_dev)");
42 println!("cargo:rustc-check-cfg=cfg(has_omega_fp8gemm)");
43 println!("cargo:rustc-check-cfg=cfg(has_omega_fp8_grouped_rule)");
44 println!("cargo:rustc-check-cfg=cfg(has_omega_fp8_slots)");
45 for v in [
46 "AIEN_FORCE_CPU_STUB",
47 "AIEN_OMEGA_GPU_LIB",
48 "AIEN_OMEGA_DIR",
49 ] {
50 println!("cargo:rerun-if-env-changed={v}");
51 }
52 if std::env::var("AIEN_FORCE_CPU_STUB").as_deref() == Ok("1") {
53 return;
54 }
55 if let Ok(lib) = std::env::var("AIEN_OMEGA_GPU_LIB") {
56 println!("cargo:rerun-if-changed={lib}");
57 if archive_defines(Path::new(&lib), "omega_gpu_fp8_gemv_grouped_f32") {
58 println!("cargo:rustc-cfg=has_omega_fp8");
59 if archive_defines(Path::new(&lib), "omega_gpu_fp8_gemv_grouped_dev")
60 && archive_defines(Path::new(&lib), "omega_gpu_fp8_tensor_entry")
61 {
62 println!("cargo:rustc-cfg=has_omega_fp8_dev");
63 }
64 if archive_defines(Path::new(&lib), "omega_gpu_fp8gemm_f32") {
65 println!("cargo:rustc-cfg=has_omega_fp8gemm");
66 }
67 if archive_defines(Path::new(&lib), "omega_gpu_fp8_grouped_ctas_auto") {
68 println!("cargo:rustc-cfg=has_omega_fp8_grouped_rule");
69 }
70 if archive_defines(Path::new(&lib), "omega_gpu_fp8_slots_alloc") {
71 println!("cargo:rustc-cfg=has_omega_fp8_slots");
72 }
73 } else {
74 println!("cargo:warning=aien-omega-fp8: {lib} does not define the FP8 GEMV API; FP8 calls are stubbed");
75 }
76 return;
77 }
78 if let Ok(dir) = std::env::var("AIEN_OMEGA_DIR") {
79 let header = Path::new(&dir).join("src/omega_gpu_fp8_api.h");
80 println!("cargo:rerun-if-changed={}", header.display());
81 if header.is_file() {
82 println!("cargo:rustc-cfg=has_omega_fp8");
83 if std::fs::read_to_string(&header).is_ok_and(|t| {
84 t.contains("omega_gpu_fp8_gemv_grouped_dev")
85 && t.contains("omega_gpu_fp8_tensor_entry")
86 }) {
87 println!("cargo:rustc-cfg=has_omega_fp8_dev");
88 }
89 if Path::new(&dir)
90 .join("src/omega_gpu_fp8gemm_api.h")
91 .is_file()
92 {
93 println!("cargo:rustc-cfg=has_omega_fp8gemm");
94 }
95 if std::fs::read_to_string(&header)
96 .is_ok_and(|t| t.contains("omega_gpu_fp8_grouped_ctas_auto"))
97 {
98 println!("cargo:rustc-cfg=has_omega_fp8_grouped_rule");
99 }
100 if Path::new(&dir).join("src/omega_gpu_fp8_slots.h").is_file() {
101 println!("cargo:rustc-cfg=has_omega_fp8_slots");
102 }
103 } else {
104 println!("cargo:warning=aien-omega-fp8: {dir} has no src/omega_gpu_fp8_api.h (omega before OWN-30B cut 5); FP8 calls are stubbed");
105 }
106 }
107}
108
109fn archive_defines(lib: &Path, symbol: &str) -> bool {
110 let Ok(out) = Command::new("nm").arg(lib).output() else {
111 println!("cargo:warning=aien-omega-fp8: nm not available, assuming the archive lacks the FP8 GEMV API");
112 return false;
113 };
114 String::from_utf8_lossy(&out.stdout)
115 .lines()
116 .any(|l| l.ends_with(&format!(" T {symbol}")))
117}