vyre 0.4.0

GPU compute intermediate representation with a standard operation library
Documentation
use crate::ir::DataType;
use crate::ops::Backend;
use crate::ops::{IntrinsicDescriptor, OpSpec};
pub use crate::ops::hash::reference::kdf::Argon2idParams;

// WGSL lowering source for `hash.argon2id`.

/// Shared WGSL helpers for Argon2id.
pub const WGSL: &str = include_str!("wgsl_shaders/blake2.wgsl");

/// Derive bytes with bounded Argon2id parameters.
///
/// # Errors
///
/// Returns an actionable error when memory exceeds 1 GiB, parallelism exceeds
/// 16, or any required count/length parameter is zero.
pub fn argon2id(password: &[u8], salt: &[u8], params: Argon2idParams) -> Result<Vec<u8>, String> {
    crate::ops::hash::reference::kdf::argon2id(password, salt, params)
}

pub const INPUTS: &[DataType] = &[DataType::Bytes, DataType::Bytes, DataType::U32];

pub const LAWS: &[crate::ops::AlgebraicLaw] = &[];

pub const OUTPUTS: &[DataType] = &[DataType::Bytes];

/// Declarative operation specification for `hash.argon2id`.
pub const SPEC: OpSpec = OpSpec::intrinsic(
    "hash.argon2id",
    INPUTS,
    OUTPUTS,
    LAWS,
    wgsl_only,
    IntrinsicDescriptor::new(
        "hash.argon2id.wgsl",
        "wgsl-argon2id",
        crate::ops::hash::cpu_refs::argon2id,
    ),
);

pub fn wgsl_only(backend: &Backend) -> bool {
    matches!(backend, Backend::Wgsl)
}