use crate::graph::program_graph::BINDING_PRIMITIVE_START;
pub(crate) const OP_ID: &str = "vyre-primitives::graph::csr_forward_or_changed";
pub(crate) const CSR_FORWARD_OR_CHANGED_FRONTIER_BUFFER: u32 = BINDING_PRIMITIVE_START;
pub(crate) const CSR_FORWARD_OR_CHANGED_CHANGED_BUFFER: u32 = BINDING_PRIMITIVE_START + 1;
pub(crate) const CSR_FORWARD_OR_CHANGED_WORKGROUP_SIZE: [u32; 3] = [1, 1, 1];
pub(crate) const CSR_FORWARD_OR_CHANGED_PARALLEL_WORKGROUP_SIZE: [u32; 3] = [256, 1, 1];
pub(crate) const CSR_FORWARD_OR_CHANGED_HISTORY_FAST_PATH_MAX_ITERS: u32 = 64;
#[must_use]
pub const fn csr_forward_or_changed_parallel_grid(node_count: u32) -> [u32; 3] {
[
ceil_div_u32(
at_least_one(node_count),
CSR_FORWARD_OR_CHANGED_PARALLEL_WORKGROUP_SIZE[0],
),
1,
1,
]
}
#[must_use]
pub const fn csr_forward_or_changed_parallel_batch_grid(
node_count: u32,
query_count: u32,
) -> [u32; 3] {
[
ceil_div_u32(
at_least_one(node_count),
CSR_FORWARD_OR_CHANGED_PARALLEL_WORKGROUP_SIZE[0],
),
at_least_one(query_count),
1,
]
}
const fn at_least_one(value: u32) -> u32 {
if value == 0 {
1
} else {
value
}
}
const fn ceil_div_u32(value: u32, divisor: u32) -> u32 {
((value - 1) / divisor) + 1
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct CsrForwardOrChangedLayout {
pub node_count: u32,
pub node_words: usize,
pub edge_offset_words: usize,
pub edge_storage_words: usize,
pub shape_edge_count: u32,
pub frontier_words: usize,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct CsrForwardOrChangedProgramKey {
layout: CsrForwardOrChangedLayout,
allow_mask: u32,
changed_slots: u32,
uses_changed_history: bool,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct CsrForwardOrChangedStaticInputKey {
pub program_key: CsrForwardOrChangedProgramKey,
pub edge_offset_words: usize,
pub edge_storage_words: usize,
pub changed_words: usize,
pub edge_offsets_hash: u64,
pub edge_targets_hash: u64,
pub edge_kind_mask_hash: u64,
}
impl CsrForwardOrChangedProgramKey {
#[must_use]
pub(crate) const fn new(
layout: CsrForwardOrChangedLayout,
allow_mask: u32,
changed_slots: u32,
uses_changed_history: bool,
) -> Self {
Self {
layout,
allow_mask,
changed_slots,
uses_changed_history,
}
}
#[must_use]
pub const fn layout(&self) -> CsrForwardOrChangedLayout {
self.layout
}
#[must_use]
pub const fn allow_mask(&self) -> u32 {
self.allow_mask
}
#[must_use]
pub const fn changed_slots(&self) -> u32 {
self.changed_slots
}
#[must_use]
pub const fn uses_changed_history(&self) -> bool {
self.uses_changed_history
}
}