vyre_driver_cuda/egraph_kernel_plan/
error.rs1use std::fmt;
2
3use crate::backend::staging_reserve::CudaStorageReserveFailure;
4
5#[derive(Clone, Debug, Eq, PartialEq)]
7pub enum CudaEGraphKernelPlanError {
8 ZeroThreadsPerBlock,
10 ZeroMaxBlocksPerLaunch,
12 CountOverflow {
14 field: &'static str,
16 },
17 InvalidPtxTarget {
19 target_sm: u32,
21 },
22 ImageViewMismatch {
24 field: &'static str,
26 image: usize,
28 view: usize,
30 },
31 ImageColumnOutOfBounds {
33 column: &'static str,
35 row: u32,
37 start: usize,
39 end: usize,
41 len: usize,
43 },
44 SignaturePairOrdinalOutOfBounds {
46 bucket_index: u32,
48 pair_ordinal: u64,
50 candidate_pair_count: u64,
52 },
53 SignatureBucketRowsOutOfBounds {
55 bucket_index: u32,
57 first_bucket_row: usize,
59 row_count: usize,
61 bucket_rows_len: usize,
63 },
64 StorageReserveFailed {
66 field: &'static str,
68 requested: usize,
70 message: String,
72 },
73}
74
75impl CudaStorageReserveFailure for CudaEGraphKernelPlanError {
76 fn storage_reserve_failed(field: &'static str, requested: usize, message: String) -> Self {
77 Self::StorageReserveFailed {
78 field,
79 requested,
80 message,
81 }
82 }
83}
84
85impl fmt::Display for CudaEGraphKernelPlanError {
86 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
87 match self {
88 Self::ZeroThreadsPerBlock => write!(
89 f,
90 "CUDA e-graph kernel planner received zero threads per block. Fix: choose a non-zero launch width before planning equality-saturation work."
91 ),
92 Self::ZeroMaxBlocksPerLaunch => write!(
93 f,
94 "CUDA e-graph kernel planner received zero max blocks per launch. Fix: choose a non-zero launch partition limit."
95 ),
96 Self::CountOverflow { field } => write!(
97 f,
98 "CUDA e-graph kernel planner overflowed while computing {field}. Fix: shard the resident e-graph image before launch planning."
99 ),
100 Self::InvalidPtxTarget { target_sm } => write!(
101 f,
102 "CUDA e-graph structural-equivalence PTX generation received invalid sm_{target_sm}. Fix: pass the backend's probed CUDA PTX target."
103 ),
104 Self::ImageViewMismatch { field, image, view } => write!(
105 f,
106 "CUDA e-graph kernel planner received mismatched {field}: packed image has {image}, kernel view has {view}. Fix: build the view from the same upload plan/image."
107 ),
108 Self::ImageColumnOutOfBounds {
109 column,
110 row,
111 start,
112 end,
113 len,
114 } => write!(
115 f,
116 "CUDA e-graph kernel planner decoded row {row} span {column}[{start}..{end}) but {column} has {len} entries. Fix: rebuild the packed e-graph image from a validated snapshot."
117 ),
118 Self::SignaturePairOrdinalOutOfBounds {
119 bucket_index,
120 pair_ordinal,
121 candidate_pair_count,
122 } => write!(
123 f,
124 "CUDA e-graph signature bucket {bucket_index} pair ordinal {pair_ordinal} is outside {candidate_pair_count} candidate pairs. Fix: launch only planned pair-wave ranges."
125 ),
126 Self::SignatureBucketRowsOutOfBounds {
127 bucket_index,
128 first_bucket_row,
129 row_count,
130 bucket_rows_len,
131 } => write!(
132 f,
133 "CUDA e-graph signature bucket {bucket_index} row range [{first_bucket_row}..{}) exceeds bucket row table length {bucket_rows_len}. Fix: rebuild the signature bucket plan.",
134 first_bucket_row.saturating_add(*row_count)
135 ),
136 Self::StorageReserveFailed {
137 field,
138 requested,
139 message,
140 } => write!(
141 f,
142 "CUDA e-graph kernel planner could not reserve {requested} {field} entries: {message}. Fix: shard the resident e-graph image before launch planning."
143 ),
144 }
145 }
146}
147
148impl std::error::Error for CudaEGraphKernelPlanError {}