vyre 0.4.0

GPU compute intermediate representation with a standard operation library
Documentation
use crate::ir::{Expr, Program};
use crate::ops::AlgebraicLaw;
use crate::ops::{OpSpec, U32_INPUTS, U32_OUTPUTS};

// WGSL lowering marker for `reductions.reduce_min_u32`.
//
// No special handling is needed. The generic Category A lowerer emits the
// sequential reduction composition.

impl ReduceMinU32 {
    /// Declarative operation specification.
    pub const SPEC: OpSpec = OpSpec::composition(
        "reductions.reduce_min_u32",
        U32_INPUTS,
        U32_OUTPUTS,
        LAWS,
        Self::program,
    );

    /// Build the canonical sequential reduction program.
    #[must_use]
    pub fn program() -> Program {
        crate::ops::reductions::programs::reduce_u32_program(u32::MAX, |acc, value| {
            Expr::select(Expr::le(acc.clone(), value.clone()), acc, value)
        })
    }
}

pub const LAWS: &[AlgebraicLaw] = &[
    AlgebraicLaw::Associative,
    AlgebraicLaw::Identity { element: u32::MAX },
];

/// u32 minimum reduction.
#[derive(Debug, Clone, Copy, Default)]
pub struct ReduceMinU32;