vyre 0.4.0

GPU compute intermediate representation with a standard operation library
Documentation
// Shared builders for rule condition operations.

use crate::ir::{BufferDecl, DataType, Expr, Node, Program};
use crate::ops::{AlgebraicLaw, OpSpec};


/// Rule condition operation input types.
pub const INPUTS: &[DataType] = &[
    DataType::U32,
    DataType::U32,
    DataType::U32,
    DataType::U32,
    DataType::U32,
    DataType::U32,
];

/// Rule condition operation output types.
pub const OUTPUTS: &[DataType] = &[DataType::U32];

/// Rule condition operation laws.
pub const LAWS: &[AlgebraicLaw] = &[AlgebraicLaw::Bounded { lo: 0, hi: 1 }];

/// Stable workgroup size for scalar rule leaf operations.
pub const WORKGROUP_SIZE: [u32; 3] = [1, 1, 1];

/// Create an operation specification for one rule condition.
#[must_use]
pub const fn spec(id: &'static str, build: fn() -> Program) -> OpSpec {
    OpSpec::composition_inlinable(id, INPUTS, OUTPUTS, LAWS, build)
}

/// Build a scalar condition program.
#[must_use]
pub fn condition_program(compute: fn() -> Expr) -> Program {
    Program::new(
        vec![
            BufferDecl::read("rule_id", 0, DataType::U32),
            BufferDecl::read("pattern_id", 1, DataType::U32),
            BufferDecl::read("pattern_state", 2, DataType::U32),
            BufferDecl::read("pattern_count", 3, DataType::U32),
            BufferDecl::read("file_size", 4, DataType::U32),
            BufferDecl::read("threshold", 5, DataType::U32),
            BufferDecl::output("out", 6, DataType::U32),
        ],
        WORKGROUP_SIZE,
        vec![Node::store("out", Expr::u32(0), compute())],
    )
}

/// Read the pattern state argument.
#[must_use]
pub fn pattern_state() -> Expr {
    Expr::load("pattern_state", Expr::u32(0))
}

/// Read the pattern count argument.
#[must_use]
pub fn pattern_count() -> Expr {
    Expr::load("pattern_count", Expr::u32(0))
}

/// Read the file size argument.
#[must_use]
pub fn file_size() -> Expr {
    Expr::load("file_size", Expr::u32(0))
}

/// Read the threshold argument.
#[must_use]
pub fn threshold() -> Expr {
    Expr::load("threshold", Expr::u32(0))
}