rlx_oneapi/lib.rs
1// RLX — versatile ML compiler + runtime.
2// Copyright (C) 2026 Eugene Hauptmann, Nataliya Kosmyna.
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, version 3.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program. If not, see <https://www.gnu.org/licenses/>.
15
16//! RLX Intel oneAPI backend — the dedicated `Device::OneApi` path for Intel
17//! Arc / Data Center Max GPUs via the **Level Zero** runtime.
18//!
19//! Layout mirrors the other native GPU backends (rlx-cuda / rlx-vulkan):
20//! - `level_zero` — hand-rolled `ze_*` FFI, dynamic-loaded (`libze_loader`);
21//! builds + links with no oneAPI runtime present (macOS / CI).
22//! - `device` — driver/device/context/compute-queue singleton; gracefully
23//! unavailable when no Level Zero GPU is reachable.
24//! - `kernels` — embedded OpenCL-C→SPIR-V blobs (`build.rs` via `ocloc`) +
25//! their `ze_module`/`ze_kernel` cache.
26//! - `arena` — f32-uniform USM-shared buffer for the native dispatch path.
27//! - `host` — `rlx-cpu` reference eval (whole-graph on the dev box; per-op
28//! fallback on hardware).
29//! - `backend` — `OneApiExecutable`: legalize → run (native dispatch when a
30//! device + kernels exist, else the CPU-reference interpreter).
31//!
32//! ## Status
33//!
34//! The Level Zero bring-up, SPIR-V module/kernel wiring, USM arena, and per-op
35//! dispatch are implemented but **not yet validated on Intel hardware** — there
36//! is none on the dev box. Until then every op is served by the bit-exact
37//! `rlx-cpu` reference, so the backend is *correct* everywhere and *native* on
38//! Arc / Data Center Max pending bring-up. See `README.md` for the validation
39//! plan and the SPIR-V flavor (OpenCL-Kernel vs Vulkan-Shader) rationale.
40
41pub mod arena;
42pub mod backend;
43pub mod device;
44pub mod host;
45pub mod kernels;
46pub mod level_zero;
47
48/// True if a Level Zero GPU device is reachable on this system. The runtime
49/// registry only registers `Device::OneApi` when this returns `true`, so hosts
50/// with no oneAPI runtime (macOS, CI) fall through cleanly.
51pub fn is_available() -> bool {
52 device::oneapi_device().is_some()
53}
54
55/// Human-readable name of the selected Intel device, if any.
56pub fn device_name() -> Option<String> {
57 device::oneapi_device().map(|d| d.name.clone())
58}
59
60/// Whether native SPIR-V kernels were embedded for this build (Intel oneAPI
61/// build host with `ocloc` + `RLX_ONEAPI_BUILD_KERNELS=1`). When `false`, the
62/// native path serves every op through the CPU reference.
63pub fn has_native_kernels() -> bool {
64 kernels::kernels_built()
65}