vyre_libs/lib.rs
1//! # vyre-libs - Category A composition ecosystem
2//!
3//! `vyre-libs` composes foundation IR and primitive-owned kernels into reusable programs.
4//!
5//! Almost every function is a **pure Category A composition**: it returns a
6//! [`vyre_foundation::ir::Program`] built entirely from existing vyre IR primitives. The
7//! sole exception is the `math::atomic` family, which are **Category B**
8//! (`Category::Intrinsic`) because they require the backend to own the
9//! `Expr::Atomic` target builder emitter arm (F-IR-35).
10//!
11//! This is the ML/DSP/cryptographic ecosystem layer. Examples:
12//!
13//! ```ignore
14//! use vyre_libs::nn::linear::linear;
15//! let program = linear(/* input_buf */ "x", /* weights */ "w", /* bias */ "b");
16//! // `program` is a standard vyre_foundation::ir::Program you dispatch against any backend.
17//! ```
18//!
19//! ## Domain ownership
20//!
21//! Each public domain module owns its product-level compositions. A domain may
22//! move to a dedicated crate only through a clean public cutover that migrates
23//! every caller and removes the old path. This crate does not promise
24//! compatibility reexports or parallel old/new routes.
25//!
26//! `vyre-graph-stitch` was deliberately omitted - "logical linker for
27//! emitted graphs" is a `vyre-foundation` concern (IR composition),
28//! not a library crate.
29//!
30//! ## Region wrapping
31//!
32//! Every public composition wraps its body in a
33//! [`vyre_foundation::ir::Node::Region`] with a stable generator name. The
34//! optimizer treats Regions as atomic by default (preserves
35//! debuggability + source-mapping); explicit inline passes can unroll
36//! them. This is LLVM's function-vs-always-inline split at IR level.
37//!
38//! ## Feature flags
39//!
40//! Each domain lives behind a feature flag so minimal consumers pay
41//! for only what they use:
42//!
43//! - `math` (default) - linear algebra, scans, broadcasts
44//! - `nn` (default, implies `math`) - neural-net primitives
45//! - `matching` (default) - regex, DFA, substring, multi-pattern
46//! - `crypto` (default) - hashing, MAC, checksums
47//!
48//! Turn defaults off with `default-features = false` and cherry-pick
49//! what you need.
50
51// Semantic catalog entries are immutable values over static identifiers and
52// function pointers, so the standard auto-traits provide Send + Sync without
53// unsafe code.
54#![forbid(unsafe_code)]
55#![deny(missing_docs)]
56#![allow(
57 clippy::too_many_arguments,
58 clippy::needless_range_loop,
59 clippy::double_must_use,
60 clippy::items_after_test_module,
61 clippy::assertions_on_constants,
62 clippy::overly_complex_bool_expr,
63 clippy::filter_map_bool_then
64)]
65// P3.3 nested-dialect reshape: each sub-dialect's single op file
66// shares the sub-dialect's module name (e.g. `math/broadcast/broadcast.rs`).
67// That's the intended shape for community packs that add second/
68// third ops to the same sub-dialect later; the lint would fight
69// the architectural decision.
70#![allow(clippy::module_inception)]
71
72/// Build a trap-only program for registry fixtures or infallible composition wrappers.
73#[allow(dead_code)]
74pub(crate) fn invalid_program(
75 op_id: &'static str,
76 message: impl Into<String>,
77) -> vyre_foundation::ir::Program {
78 let message = message.into();
79 vyre_foundation::ir::Program::wrapped(
80 Vec::new(),
81 [1, 1, 1],
82 vec![region::wrap_anonymous(
83 op_id,
84 vec![vyre_foundation::ir::Node::trap(
85 vyre_foundation::ir::Expr::u32(0),
86 message,
87 )],
88 )],
89 )
90}
91
92/// Region builder - the shared helper every composition routes through.
93pub mod region;
94
95/// Domain-neutral byte-range ordering predicates.
96pub mod range_ordering;
97
98/// `TensorRef` - typed buffer-argument wrapper used by every Cat-A
99/// composition for dtype + shape + name-uniqueness validation.
100pub mod tensor_ref;
101
102pub use tensor_ref::{check_dtype, check_shape, check_unique_names, TensorRef, TensorRefError};
103
104/// Shared builder helpers every Cat-A composition reuses.
105pub mod builder;
106#[cfg(feature = "math-linalg")]
107pub(crate) mod linear_algebra_substrate;
108mod substrate_catalog;
109
110pub use builder::{check_tensors, BuildOptions};
111
112pub mod buffer_names;
113
114/// `ProgramDescriptor` - introspection surface for Cat-A Programs.
115pub mod descriptor;
116
117pub use descriptor::{BufferDescriptor, ProgramDescriptor};
118
119/// Derived view over canonical library operation registrations.
120pub mod operation_catalog;
121
122/// Math dialect - linear algebra, scans, broadcasting.
123#[cfg(any(
124 feature = "math-linalg",
125 feature = "math-scan",
126 feature = "math-broadcast",
127 feature = "math-algebra",
128 feature = "math-succinct"
129))]
130pub mod math;
131
132/// Logical dialect - element-wise boolean composition.
133#[cfg(feature = "logical")]
134pub mod logical;
135
136/// Neural-network dialect - activation, normalization, attention, linear.
137#[cfg(any(
138 feature = "nn-activation",
139 feature = "nn-linear",
140 feature = "nn-norm",
141 feature = "nn-attention"
142))]
143pub mod nn;
144
145/// Pattern-scanning dialect: neutral substring, DFA, NFA, and regex
146/// program builders plus immutable compilation artifacts.
147#[cfg(any(
148 feature = "matching-substring",
149 feature = "matching-dfa",
150 feature = "matching-nfa"
151))]
152pub mod scan;
153
154/// Decode / decompression compositions - base64, hex, DEFLATE (stored),
155/// more coming. Pairs with `vyre-libs::matching::dfa` in the fused
156/// decode→scan pipeline (Innovation I.1).
157#[cfg(feature = "decode")]
158pub mod decode;
159
160/// Hash / checksum dialect - FNV-1a-32, FNV-1a-64, CRC-32, Adler-32,
161/// BLAKE3 compression. Consolidated from the former `vyre-libs::crypto`
162/// module per Migration 3. Every op lives here as a pure Cat-A
163/// composition over existing IR primitives (no dedicated target builder emitter
164/// arm required, per the intrinsic-vs-library rule).
165#[cfg(feature = "hash")]
166pub mod hash;
167
168/// Text-processing compositions for the GPU C parser pipeline
169/// (Phase L1+): byte classification, UTF-8 validation, line index.
170pub mod text;
171
172/// Representation sub-dialect: bit-packing and unpacking.
173pub mod representation;
174
175/// GPU parser infrastructure (Phase L3+): bracket matching, DFA
176/// lexer driver, LR(1) table walker. Grammar tables are generated
177/// host-side by `downstream analyzer-grammar-gen` and loaded as ReadOnly buffers.
178pub mod parsing;
179
180/// Packed AST walks (`ast_walk_*` catalog ops).
181pub mod graph;
182
183/// Security / taint compositions for static program analysis.
184/// Every op registers via `inventory::submit!` and lives under a
185/// stable op id. The implementations compose graph and dataflow
186/// primitives so downstream analyzers lower to one production GPU-facing
187/// surface.
188#[cfg(feature = "security")]
189pub mod security;
190
191/// GPU-accelerated visual effects - blur, shadow, filter chain,
192/// gradient, compositing, and glass material. Tier 3 compositions
193/// over `math::conv1d` (Tier 2.5) and bare IR expressions. The
194/// Molten web engine's visual effect substrate.
195#[cfg(feature = "visual")]
196pub mod visual;
197
198#[cfg(any(
199 feature = "math-linalg",
200 feature = "math-scan",
201 feature = "math-broadcast"
202))]
203pub(crate) use math::elementwise::{f32_elementwise_mul, F32MulRhs};
204#[cfg(feature = "nn-linear-4bit")]
205pub(crate) use math::linalg::{
206 plan_matmul_kernel, F32MatmulMode, MatmulFallbackReason, MatmulKernelCapabilities,
207 MatmulKernelPath, MatmulKernelPlan, MatrixShape,
208};
209
210// vyre-libs::hardware removed (audit 2026-04-21 BLOCKER-1/6).
211// Canonical Cat-C intrinsics live exclusively in
212// `vyre-primitives::hardware`; library compositions of atomic / clamp /
213// lzcnt / tzcnt ops
214// live in `vyre-libs::math::*` (which uses `Expr::Atomic`, `Expr::min`,
215// `Expr::max`, `Expr::popcount` directly per docs/ARCHITECTURE.md).
216//
217// vyre-libs::crypto removed (audit 2026-04-21 BLOCKER-3). Deprecated
218// shim deleted in favor of the canonical path at `vyre-libs::hash`.
219//
220// vyre-libs::composite removed (audit 2026-04-21 BLOCKER-3). The three
221// hash ops that lived there (adler32, crc32, fnv1a64) are canonical at
222// `vyre-libs::hash::*`.
223
224/// Rule-engine dialect - typed conditions, formulas, and program builder used
225/// by detection rule compilers.
226#[cfg(feature = "rule")]
227pub mod rule;
228
229/// Vector-widened string interning. CHD perfect hash
230/// over Tier-B label families - 60k+ function-name strings reduce
231/// to one subgroup-shuffle + one DRAM load on the GPU.
232#[cfg(feature = "intern")]
233pub mod intern;
234
235/// Operation contract presets used by catalog entries.
236pub mod contracts;
237/// Type-signature constants shared across op definitions.
238pub mod signatures;
239/// Re-exports every type-signature constant at the crate root for convenient access.
240pub use signatures::{
241 BOOL_OUTPUTS, BYTES_TO_BYTES_INPUTS, BYTES_TO_BYTES_OUTPUTS, BYTES_TO_U32_OUTPUTS,
242 F32_F32_F32_INPUTS, F32_F32_INPUTS, F32_INPUTS, F32_OUTPUTS, I32_OUTPUTS, U32_INPUTS,
243 U32_OUTPUTS, U32_U32_INPUTS,
244};
245/// Owner-local byte fixtures for semantic operation registrations and tests.
246pub(crate) mod fixture_bytes;
247/// Pre-sweep shader snapshot migration entries, collected via inventory.
248/// `pub(crate)` because the registry is an internal pre-sweep tool -
249/// downstream dialects do not submit through this path.
250pub(crate) mod test_migration;
251
252/// Re-export the small set of vyre types every composition function
253/// returns. Consumers can `use vyre_libs::prelude::*` and get the API
254/// plus the types it returns.
255pub mod prelude {
256 pub use vyre_foundation::ir::model::expr::GeneratorRef;
257 pub use vyre_foundation::ir::{BufferAccess, BufferDecl, DataType, Expr, Node, Program};
258
259 // P2.1 / P2.2: the typed-tensor API + shared builder primitives.
260 // Every Cat-A op ships with a TensorRef-accepting builder; the
261 // prelude exposes the full construction surface so `use
262 // vyre_libs::prelude::*;` is enough to author a new Cat-A op.
263 pub use crate::builder::{check_tensors, BuildOptions};
264 pub use crate::tensor_ref::{
265 check_dtype, check_shape, check_unique_names, TensorRef, TensorRefError,
266 };
267
268 // Region wrapper - every composition emits its body through this.
269 pub use crate::region::{wrap, wrap_anonymous, wrap_child};
270
271 // Built-in Cat-A builders (gated on the relevant feature flags so
272 // minimum-footprint consumers don't pay for the ones they skip).
273 #[cfg(feature = "decode")]
274 pub use crate::decode::{base64_decode, hex_decode, inflate, ziftsieve_gpu};
275 #[cfg(feature = "crypto-blake3")]
276 pub use crate::hash::blake3_compress;
277 #[cfg(feature = "logical")]
278 pub use crate::logical::{nand, nor};
279 #[cfg(feature = "math-algebra")]
280 pub use crate::math::algebra::{
281 bool_semiring_matmul, lattice_join, lattice_meet, semiring_min_plus_mul, sketch_mix,
282 try_bool_semiring_matmul, try_lattice_join, try_lattice_meet, try_semiring_min_plus_mul,
283 try_sketch_mix,
284 };
285 #[cfg(feature = "math-broadcast")]
286 pub use crate::math::broadcast::broadcast;
287 #[cfg(feature = "math-linalg")]
288 pub use crate::math::linalg::{dot, matmul, matmul_tiled, Matmul, MatmulTiled};
289 #[cfg(feature = "math-scan")]
290 pub use crate::math::scan::scan_prefix_sum;
291 #[cfg(feature = "math-succinct")]
292 pub use crate::math::succinct::{
293 rank1_query, rank1_superblocks, try_rank1_query, try_rank1_superblocks,
294 };
295 #[cfg(feature = "nn-activation")]
296 pub use crate::nn::activation::relu;
297 #[cfg(feature = "nn-attention")]
298 pub use crate::nn::attention::{attention, softmax, Attention, Softmax};
299 #[cfg(feature = "nn-linear")]
300 pub use crate::nn::linear::linear;
301 #[cfg(feature = "nn-norm")]
302 pub use crate::nn::norm::{layer_norm, LayerNorm};
303 #[cfg(feature = "matching-dfa")]
304 pub use crate::scan::aho_corasick;
305 #[cfg(feature = "matching-substring")]
306 pub use crate::scan::substring_search;
307}