vyre_runtime/routing/
standard_policy.rs1use super::{RoutingDecision, RoutingExplanation, RoutingPolicy};
4use vyre_foundation::execution_plan::{ExecutionPlan, PolicyRoute, SchedulingPolicy};
5
6pub struct StandardPolicy;
8
9impl RoutingPolicy for StandardPolicy {
10 fn name(&self) -> &'static str {
11 "standard-megakernel-first"
12 }
13
14 fn route(&self, plan: &ExecutionPlan) -> RoutingDecision {
15 self.route_with_explanation(plan).decision
16 }
17
18 fn route_with_explanation(&self, plan: &ExecutionPlan) -> RoutingExplanation {
19 match SchedulingPolicy::standard().route(plan.fusion.node_count, plan.memory.static_bytes) {
20 PolicyRoute::CpuSimd => RoutingExplanation {
21 policy: self.name(),
22 decision: RoutingDecision::PersistentMegakernel,
23 reason: "standard policy overrides CPU SIMD suggestion to persistent megakernel for release execution",
24 },
25 PolicyRoute::GpuPipeline => RoutingExplanation {
26 policy: self.name(),
27 decision: RoutingDecision::PersistentMegakernel,
28 reason: "standard policy promotes GPU pipeline suggestion to persistent megakernel for resident execution",
29 },
30 PolicyRoute::PersistentMegakernel => RoutingExplanation {
31 policy: self.name(),
32 decision: RoutingDecision::PersistentMegakernel,
33 reason: "scheduling policy selected persistent megakernel directly",
34 },
35 }
36 }
37}
38
39#[cfg(test)]
40mod tests {
41 use super::*;
42 use vyre_foundation::execution_plan::{
43 AccuracyPlan, AccuracyStrategy, AutotunePlan, AutotuneStrategy, DispatchStrategy,
44 ExecutionPlan, FusionPlan, FusionStrategy, LayoutStrategy, MemoryPlan, ProvenancePlan,
45 ProvenanceStrategy, ReadbackStrategy, StrategyPlan,
46 };
47 use vyre_foundation::program_caps::RequiredCapabilities;
48
49 fn plan(node_count: usize, static_bytes: u64) -> ExecutionPlan {
50 ExecutionPlan {
51 program_fingerprint: [0; 32],
52 required_capabilities: RequiredCapabilities::default(),
53 fusion: FusionPlan {
54 entry_op_id: None,
55 top_level_regions: 1,
56 node_count,
57 batch_fusion_candidate: false,
58 },
59 memory: MemoryPlan {
60 buffers: Vec::new(),
61 static_bytes,
62 dynamic_buffers: 0,
63 visible_readback_bytes: 0,
64 avoided_readback_bytes: 0,
65 },
66 provenance: ProvenancePlan {
67 top_level_region_wrapped: true,
68 region_count: 1,
69 emit_region_trace: false,
70 },
71 accuracy: AccuracyPlan {
72 shadow_reference_recommended: false,
73 reason: "test fixture",
74 },
75 autotune: AutotunePlan {
76 recommended: false,
77 parallel_region_size: [1, 1, 1],
78 recommended_workgroup_size: [1, 1, 1],
79 recommended_tile: [1, 1, 1],
80 recommended_vector_pack_bits: 32,
81 recommended_unroll_depth: 1,
82 reason: "test fixture",
83 },
84 strategy: StrategyPlan {
85 fusion: FusionStrategy::Isolated,
86 dispatch: DispatchStrategy::PersistentRuntime,
87 accuracy: AccuracyStrategy::Direct,
88 autotune: AutotuneStrategy::DeclaredShape,
89 provenance: ProvenanceStrategy::Minimal,
90 layout: LayoutStrategy::Empty,
91 readback: ReadbackStrategy::Full { bytes: 0 },
92 },
93 tracks: Vec::new(),
94 }
95 }
96
97 #[test]
98 fn standard_policy_explains_persistent_megakernel_override() {
99 let policy = StandardPolicy;
100 let explanation = policy.route_with_explanation(&plan(1, 1));
101
102 assert_eq!(explanation.policy, "standard-megakernel-first");
103 assert_eq!(explanation.decision, RoutingDecision::PersistentMegakernel);
104 assert!(
105 explanation.reason.contains("persistent megakernel"),
106 "Fix: routing explanation must expose why persistent execution was selected: {explanation:?}"
107 );
108 }
109
110 #[test]
111 fn routing_engine_exposes_policy_explanation() {
112 let engine = crate::routing::RoutingEngine::new(StandardPolicy);
113 let explanation = engine.route_with_explanation(&plan(128, 1 << 20));
114
115 assert_eq!(explanation.policy, "standard-megakernel-first");
116 assert_eq!(explanation.decision, RoutingDecision::PersistentMegakernel);
117 assert!(!explanation.reason.is_empty());
118 }
119}