Skip to main content

rlx_runtime/
capabilities.rs

1// RLX — versatile ML compiler + runtime.
2// Copyright (C) 2026 Eugene Hauptmann, Nataliya Kosmyna.
3// SPDX-License-Identifier: MIT OR Apache-2.0
4
5//! Declared optional features of an [`crate::ExecutableGraph`].
6//!
7//! The [`ExecutableGraph`](crate::ExecutableGraph) trait grew a long tail of
8//! defaulted methods (MoE residency, GPU handles, KV row feeds, async
9//! pipeline, …). Most backends leave those as no-ops / `false`. Callers that
10//! need to branch on support should prefer:
11//!
12//! 1. [`ExecutableGraph::capabilities`] for a cheap advisory bitmask, then
13//! 2. the concrete method's return value (`false` / `None`) as the source of
14//!    truth — capabilities can lag a backend that forgot to override them.
15//!
16//! Method groups on [`ExecutableGraph`](crate::ExecutableGraph):
17//!
18//! | Group | Methods |
19//! |-------|---------|
20//! | Core run | `set_param`, `run`, `run_raw`, `run_slots`, `arena_ptr`, `finalize_params` |
21//! | Clone | `clone_box` |
22//! | Extent / RNG | `set_active_extent`, `set_rng`, `rng` |
23//! | MoE | `set_moe_resident_experts*`, `enable_moe_topk_capture`, `take_moe_*` |
24//! | Persistent / GPU handles | `bind_handle`, `read_handle`, `bind_gpu_handle`, … |
25//! | KV resident | `register_kv_row_feed`, `feed_kv_row`, `seed_resident_kv_prefix_from`, … |
26//! | Typed I/O | `set_param_typed`, `run_typed` |
27//! | Async pipeline | `commit_no_wait`, `sync_pending`, `run_pipelined` |
28
29/// Advisory feature flags for a compiled executable.
30#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
31pub struct ExecutableCapabilities {
32    /// [`crate::ExecutableGraph::clone_box`] is implemented (not the default panic).
33    pub clone: bool,
34    /// MoE residency / TopK capture hooks are live.
35    pub moe: bool,
36    /// Persistent named handles (`bind_handle` / `read_handle`).
37    pub persistent_handles: bool,
38    /// GPU-resident input handles (`bind_gpu_handle`, feeds, …).
39    pub gpu_handles: bool,
40    /// Device-resident KV row feed / D2D seed path.
41    pub kv_resident: bool,
42    /// Native non-F32 `set_param_typed` / `run_typed` (not F32-only default).
43    pub typed_io: bool,
44    /// `commit_no_wait` / `run_pipelined` do real async work.
45    pub async_pipeline: bool,
46    /// `set_active_extent` is honored for bucketed decode.
47    pub active_extent: bool,
48}
49
50impl ExecutableCapabilities {
51    /// All bits clear — every optional hook is a no-op / unsupported.
52    pub const NONE: Self = Self {
53        clone: false,
54        moe: false,
55        persistent_handles: false,
56        gpu_handles: false,
57        kv_resident: false,
58        typed_io: false,
59        async_pipeline: false,
60        active_extent: false,
61    };
62
63    /// Human-readable list of enabled capability names (for `device_report`).
64    pub fn enabled_names(self) -> Vec<&'static str> {
65        let mut out = Vec::new();
66        if self.clone {
67            out.push("clone");
68        }
69        if self.moe {
70            out.push("moe");
71        }
72        if self.persistent_handles {
73            out.push("persistent_handles");
74        }
75        if self.gpu_handles {
76            out.push("gpu_handles");
77        }
78        if self.kv_resident {
79            out.push("kv_resident");
80        }
81        if self.typed_io {
82            out.push("typed_io");
83        }
84        if self.async_pipeline {
85            out.push("async_pipeline");
86        }
87        if self.active_extent {
88            out.push("active_extent");
89        }
90        out
91    }
92}