vyre_runtime/routing/mod.rs
1//! High-level execution routing engine.
2//!
3//! Substrate-neutral policies that consume [`vyre_foundation::execution_plan::ExecutionPlan`]
4//! facts and map them to concrete backend strategies.
5
6use vyre_foundation::execution_plan::ExecutionPlan;
7
8/// Target backend category chosen by the router.
9#[derive(Clone, Copy, Debug, Eq, PartialEq)]
10#[non_exhaustive]
11pub enum RoutingDecision {
12 /// Legacy explicit reference route.
13 ///
14 /// The standard runtime policy does not select this automatically; callers
15 /// that require GPU execution should treat this as an opt-in diagnostic
16 /// route, never as an implicit fallback.
17 CpuSimd,
18 /// Use the default GPU pipeline.
19 GpuPipeline,
20 /// Use the persistent megakernel.
21 PersistentMegakernel,
22}
23
24/// Operator-visible routing evidence.
25#[derive(Clone, Copy, Debug, Eq, PartialEq)]
26pub struct RoutingExplanation {
27 /// Policy name that made the decision.
28 pub policy: &'static str,
29 /// Final route selected by the runtime.
30 pub decision: RoutingDecision,
31 /// Stable short reason for the selected route.
32 pub reason: &'static str,
33}
34
35/// Pluggable routing policy.
36pub trait RoutingPolicy: Send + Sync {
37 /// Name of the policy for diagnostics.
38 fn name(&self) -> &'static str;
39
40 /// Decide which backend route to take for a given plan.
41 fn route(&self, plan: &ExecutionPlan) -> RoutingDecision;
42
43 /// Decide which backend route to take and explain the decision.
44 fn route_with_explanation(&self, plan: &ExecutionPlan) -> RoutingExplanation {
45 RoutingExplanation {
46 policy: self.name(),
47 decision: self.route(plan),
48 reason: "policy returned route without extended evidence",
49 }
50 }
51}
52
53/// The standard routing engine.
54pub struct RoutingEngine {
55 policy: Box<dyn RoutingPolicy>,
56}
57
58impl RoutingEngine {
59 /// Create a new engine with the given policy.
60 pub fn new(policy: impl RoutingPolicy + 'static) -> Self {
61 Self {
62 policy: Box::new(policy),
63 }
64 }
65
66 /// Route a program to a backend.
67 pub fn route(&self, plan: &ExecutionPlan) -> RoutingDecision {
68 self.policy.route(plan)
69 }
70
71 /// Route a program and return operator-visible evidence.
72 pub fn route_with_explanation(&self, plan: &ExecutionPlan) -> RoutingExplanation {
73 self.policy.route_with_explanation(plan)
74 }
75}
76pub mod standard_policy;