Skip to main content

svod_codegen/
types.rs

1//! Types for code generation.
2
3use svod_dtype::DType;
4
5// Re-export new unified types from device crate
6pub use svod_device::device::{ProgramSpec, Variable};
7pub use svod_dtype::DeviceSpec;
8
9/// A rendered kernel ready for compilation and execution.
10#[derive(Debug, Clone)]
11pub struct RenderedKernel {
12    /// The generated code (LLVM IR, CUDA C, etc.)
13    pub code: String,
14
15    /// Kernel name (used as entry point and for debugging/caching).
16    pub name: String,
17
18    /// Buffer argument information.
19    pub buffer_args: Vec<BufferArg>,
20
21    /// Variable names in order (for populating vars array at runtime).
22    pub var_names: Vec<String>,
23}
24
25/// Information about a buffer argument to the kernel.
26#[derive(Debug, Clone)]
27pub struct BufferArg {
28    /// Argument index.
29    pub index: usize,
30
31    /// Buffer name.
32    pub name: String,
33
34    /// Data type.
35    pub dtype: DType,
36
37    /// Whether this is an output buffer.
38    pub is_output: bool,
39}
40
41impl RenderedKernel {
42    /// Create a new rendered kernel.
43    pub fn new(code: String, name: String) -> Self {
44        Self { code, name, buffer_args: Vec::new(), var_names: Vec::new() }
45    }
46
47    /// Add a buffer argument.
48    pub fn add_buffer_arg(&mut self, arg: BufferArg) {
49        self.buffer_args.push(arg);
50    }
51}