Skip to main content

ironaccelerator_core/
kernel.rs

1//! Kernel launch description shared across backends.
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5pub struct LaunchDims {
6    pub grid: (u32, u32, u32),
7    pub block: (u32, u32, u32),
8    /// Dynamic shared / threadgroup memory in bytes.
9    pub shared_bytes: u32,
10}
11
12impl LaunchDims {
13    pub const fn linear(threads: u32, block: u32) -> Self {
14        let grid = threads.div_ceil(block);
15        Self {
16            grid: (grid, 1, 1),
17            block: (block, 1, 1),
18            shared_bytes: 0,
19        }
20    }
21
22    pub const fn elements(self) -> u64 {
23        let g = self.grid.0 as u64 * self.grid.1 as u64 * self.grid.2 as u64;
24        let b = self.block.0 as u64 * self.block.1 as u64 * self.block.2 as u64;
25        g * b
26    }
27}
28
29/// A pre-translated kernel ready to be launched. Backends extend this with
30/// the actual function pointer / pipeline state.
31pub trait KernelLaunch: Send + Sync {
32    fn name(&self) -> &str;
33    fn occupancy_hint(&self) -> u32 {
34        0
35    }
36}