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_count`.
//
// No special handling is needed. The generic Category A lowerer emits the
// sequential reduction composition.

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

    /// Build the canonical sequential count program.
    #[must_use]
    pub fn program() -> Program {
        crate::ops::reductions::programs::reduce_u32_program(0, |acc, value| {
            Expr::add(
                acc,
                Expr::select(Expr::ne(value, Expr::u32(0)), Expr::u32(1), Expr::u32(0)),
            )
        })
    }
}

pub const LAWS: &[AlgebraicLaw] = &[AlgebraicLaw::Bounded {
    lo: 0,
    hi: u32::MAX,
}];

/// Counts values satisfying the spec predicate `value != 0`.
#[derive(Debug, Clone, Copy, Default)]
pub struct ReduceCount;