vyre 0.2.0

GPU bytecode condition engine
Documentation
#![forbid(unsafe_code)]
#![warn(missing_docs)]
#![allow(
    clippy::duplicated_attributes,
    clippy::type_complexity,
    clippy::cast_lossless,
    clippy::cast_possible_truncation,
    clippy::cast_sign_loss,
    clippy::cast_possible_wrap,
    clippy::missing_errors_doc,
    clippy::must_use_candidate,
    clippy::needless_raw_string_hashes,
    clippy::module_name_repetitions,
    clippy::similar_names,
    clippy::too_many_lines
)]
#![cfg_attr(
    not(test),
    deny(
        clippy::unwrap_used,
        clippy::expect_used,
        clippy::todo,
        clippy::unimplemented,
        clippy::panic
    )
)]
#![allow(clippy::module_name_repetitions, clippy::must_use_candidate)]

//! # vyre — GPU bytecode condition engine
//!
//! The first GPU-native rule condition evaluator. Compiles boolean conditions
//! to bytecode, uploads to GPU compute shaders, and evaluates millions of
//! rules against file data in parallel.
//!
//! vyre is the execution engine. It does not parse rules — frontends like
//! [`yaragpu`](https://crates.io/crates/yaragpu) (YARA) or `surgec` (SURGE)
//! compile their respective languages to `vyre::Program` bytecode.
//!
//! # Architecture
//!
//! ```text
//! ┌──────────────┐     ┌──────────────┐     ┌──────────────┐
//! │  YARA / SURGE │────▶│   Bytecode   │────▶│  GPU Shader  │
//! │   Frontend    │     │   Programs   │     │  Evaluation  │
//! └──────────────┘     └──────────────┘     └──────────────┘
//!                              │                     │
//!                       vyre::Program          vyre::evaluate()
//! ```
//!
//! # Example
//!
//! ```rust,no_run
//! use vyre::{Program, FileContext, evaluate};
//!
//! // Programs are compiled by a frontend (yaragpu, surgec)
//! let programs: Vec<Program> = vec![/* ... */];
//! let matches: Vec<matchkit::Match> = vec![/* pattern matches */];
//! let file_ctx = FileContext::default();
//!
//! // Evaluate all rule conditions on GPU
//! let results: Vec<bool> = evaluate(&programs, &matches, file_ctx)?;
//! # Ok::<(), vyre::Error>(())
//! ```
//!
//! # GPU Only
//!
//! vyre requires a GPU. There is no CPU fallback by design — if you need
//! CPU rule evaluation, use the YARA library directly. vyre exists because
//! GPU evaluation is 1000x faster at scale.

/// Bytecode instruction set, opcodes, and program serialization.
pub mod bytecode;
/// Error types for bytecode validation and GPU operations.
pub mod error;
/// GPU pipeline: shader compilation, buffer management, dispatch.
#[cfg(feature = "gpu")]
pub mod gpu;
/// WGSL compute shader generation for the bytecode ISA.
#[cfg(feature = "gpu")]
pub mod shaders;

mod file_context;

pub use bytecode::{Instruction, Opcode, Program, BYTECODE_MAGIC};
pub use error::{Error, Result};
pub use file_context::FileContext;

/// Strategy for GPU rule evaluation.
#[cfg(feature = "gpu")]
pub use shaders::parallel_eval_shader::ExecutionStrategy;

/// Maximum iterations for `for` loops in bytecode evaluation.
/// Shared between GPU shader and any future execution backend
/// to guarantee identical behavior.
pub const MAX_FOR_ITERATIONS: u32 = 4096;

/// Low-level GPU evaluation entry point.
///
/// For most users, the `yaragpu` or `surgec` frontends provide
/// a higher-level API that handles program compilation and match
/// orchestration. Use this directly only when building a custom frontend.
///
/// # Errors
///
/// Returns [`Error::Gpu`] if no GPU adapter is available or the
/// shader dispatch fails.
#[cfg(feature = "gpu")]
pub use gpu::gpu_pipeline::execute_gpu as evaluate_raw;

#[cfg(feature = "gpu")]
pub use gpu::gpu_pipeline::cached_device;

/// Build the additive parallel evaluation shader for independent conditions.
#[cfg(feature = "gpu")]
pub use shaders::parallel_eval_shader::build_parallel_eval_shader;