use std::fmt;
use crate::backend::staging_reserve::CudaStorageReserveFailure;
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum CudaEGraphKernelPlanError {
ZeroThreadsPerBlock,
ZeroMaxBlocksPerLaunch,
CountOverflow {
field: &'static str,
},
InvalidPtxTarget {
target_sm: u32,
},
ImageViewMismatch {
field: &'static str,
image: usize,
view: usize,
},
ImageColumnOutOfBounds {
column: &'static str,
row: u32,
start: usize,
end: usize,
len: usize,
},
SignaturePairOrdinalOutOfBounds {
bucket_index: u32,
pair_ordinal: u64,
candidate_pair_count: u64,
},
SignatureBucketRowsOutOfBounds {
bucket_index: u32,
first_bucket_row: usize,
row_count: usize,
bucket_rows_len: usize,
},
StorageReserveFailed {
field: &'static str,
requested: usize,
message: String,
},
}
impl CudaStorageReserveFailure for CudaEGraphKernelPlanError {
fn storage_reserve_failed(field: &'static str, requested: usize, message: String) -> Self {
Self::StorageReserveFailed {
field,
requested,
message,
}
}
}
impl fmt::Display for CudaEGraphKernelPlanError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::ZeroThreadsPerBlock => write!(
f,
"CUDA e-graph kernel planner received zero threads per block. Fix: choose a non-zero launch width before planning equality-saturation work."
),
Self::ZeroMaxBlocksPerLaunch => write!(
f,
"CUDA e-graph kernel planner received zero max blocks per launch. Fix: choose a non-zero launch partition limit."
),
Self::CountOverflow { field } => write!(
f,
"CUDA e-graph kernel planner overflowed while computing {field}. Fix: shard the resident e-graph image before launch planning."
),
Self::InvalidPtxTarget { target_sm } => write!(
f,
"CUDA e-graph structural-equivalence PTX generation received invalid sm_{target_sm}. Fix: pass the backend's probed CUDA PTX target."
),
Self::ImageViewMismatch { field, image, view } => write!(
f,
"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."
),
Self::ImageColumnOutOfBounds {
column,
row,
start,
end,
len,
} => write!(
f,
"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."
),
Self::SignaturePairOrdinalOutOfBounds {
bucket_index,
pair_ordinal,
candidate_pair_count,
} => write!(
f,
"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."
),
Self::SignatureBucketRowsOutOfBounds {
bucket_index,
first_bucket_row,
row_count,
bucket_rows_len,
} => write!(
f,
"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.",
first_bucket_row.saturating_add(*row_count)
),
Self::StorageReserveFailed {
field,
requested,
message,
} => write!(
f,
"CUDA e-graph kernel planner could not reserve {requested} {field} entries: {message}. Fix: shard the resident e-graph image before launch planning."
),
}
}
}
impl std::error::Error for CudaEGraphKernelPlanError {}