#![deny(unsafe_code)]
mod hostbuf;
#[cfg(feature = "vyre-foundation")]
pub mod ir_safe;
mod markers;
pub mod wire;
#[cfg(feature = "vyre-foundation")]
use std::sync::Arc;
pub use markers::{
ArithAdd, ArithMul, BitwiseAnd, BitwiseOr, BitwiseXor, Clz, CombineOp, CompareEq, CompareLt,
Gather, HashBlake3, HashFnv1a, PatternMatchDfa, PatternMatchLiteral, Popcount, Reduce,
RegionId, Scan, Scatter, ShiftLeft, ShiftRight, Shuffle,
};
#[cfg(feature = "vyre-foundation")]
use vyre_foundation::ir::model::expr::Ident;
#[cfg(feature = "vyre-foundation")]
use vyre_foundation::ir::{BufferDecl, DataType, Expr, Node, Program};
#[cfg(feature = "vyre-foundation")]
pub(crate) fn invalid_output_program(
op_id: &'static str,
output: &str,
data_type: DataType,
message: String,
) -> Program {
Program::wrapped(
vec![BufferDecl::output(output, 0, data_type).with_count(1)],
[1, 1, 1],
vec![Node::Region {
generator: Ident::from(op_id),
source_region: None,
body: Arc::new(vec![Node::trap(Expr::u32(0), message)]),
}],
)
}
#[cfg(any(feature = "graph", feature = "math", feature = "geom", feature = "opt"))]
pub(crate) fn fixed_mul_16_16_expr(left: Expr, right: Expr) -> Expr {
let low = Expr::mul(left.clone(), right.clone());
let unsigned_high = Expr::mulhi(left.clone(), right.clone());
let left_sign_mask = Expr::sub(Expr::u32(0), Expr::shr(left.clone(), Expr::u32(31)));
let right_sign_mask = Expr::sub(Expr::u32(0), Expr::shr(right.clone(), Expr::u32(31)));
let correction_left = Expr::bitand(left_sign_mask, right);
let correction_right = Expr::bitand(right_sign_mask, left);
let signed_high = Expr::sub(Expr::sub(unsigned_high, correction_left), correction_right);
Expr::bitor(
Expr::shr(low, Expr::u32(16)),
Expr::shl(signed_high, Expr::u32(16)),
)
}
#[cfg(any(feature = "graph", feature = "math", feature = "geom", feature = "opt"))]
pub(crate) fn fixed_sdiv_by_positive_expr(numerator: Expr, denominator: Expr) -> Expr {
let sign_mask = Expr::sub(Expr::u32(0), Expr::shr(numerator.clone(), Expr::u32(31)));
let magnitude = Expr::sub(
Expr::bitxor(numerator, sign_mask.clone()),
sign_mask.clone(),
);
let quotient = Expr::div(magnitude, denominator);
Expr::sub(Expr::bitxor(quotient, sign_mask.clone()), sign_mask)
}
#[cfg(any(feature = "graph", feature = "math"))]
pub(crate) mod fixed_u32_matmul;
#[cfg(any(feature = "label", feature = "predicate"))]
pub(crate) mod nodeset_filter;
pub mod range;
#[cfg(feature = "inventory-registry")]
pub mod harness;
#[cfg(feature = "text")]
pub mod text;
#[cfg(feature = "matching")]
pub mod matching;
#[cfg(feature = "decode")]
pub mod decode;
#[cfg(feature = "nfa")]
pub mod nfa;
#[cfg(feature = "hash")]
pub mod hash;
#[cfg(feature = "math")]
pub mod math;
#[cfg(feature = "parsing")]
pub mod parsing;
#[cfg(feature = "nn")]
pub mod nn;
#[cfg(feature = "graph")]
pub mod graph;
#[cfg(feature = "geom")]
pub mod geom;
#[cfg(feature = "opt")]
pub mod opt;
#[cfg(feature = "topology")]
pub mod topology;
#[cfg(feature = "visual")]
pub mod visual;
#[cfg(feature = "effects")]
pub mod effects;
#[cfg(feature = "types")]
pub mod types;
#[cfg(feature = "cat")]
pub mod cat;
#[cfg(feature = "zx")]
pub mod zx;
#[cfg(feature = "dnnf")]
pub mod dnnf;
#[cfg(feature = "bitset")]
pub mod bitset;
#[cfg(feature = "reduce")]
pub mod reduce;
#[cfg(feature = "label")]
pub mod label;
#[cfg(feature = "predicate")]
pub mod predicate;
#[cfg(feature = "fixpoint")]
pub mod fixpoint;
#[cfg(any(
feature = "text",
feature = "matching",
feature = "decode",
feature = "math",
feature = "nn",
feature = "hash",
feature = "parsing",
feature = "graph",
feature = "bitset",
feature = "reduce",
feature = "label",
feature = "predicate",
feature = "fixpoint",
))]
pub mod vfs;
#[cfg(feature = "vyre-foundation")]
pub mod serial_data {
pub use vyre_foundation::serial::envelope::{
test_helpers, EnvelopeError, WireReader, WireWriter,
};
}
pub mod prelude {
pub use crate::wire::{
append_f32_slice_le_bytes, append_packed_byte_lane, append_u32_slice_le_bytes,
decode_f32_le_bytes_all, decode_i32_le_bytes_all, decode_u16_le_bytes_all,
decode_u32_le_bytes_all, decode_u64_le_bytes_all, pack_bytes_as_u32_slice,
pack_bytes_as_u32_slice_min_words, pack_f32_slice, pack_f32_slice_into,
pack_f32_slice_into_uninit, pack_i32_slice, pack_i32_slice_into, pack_u16_slice,
pack_u16_slice_into, pack_u32_slice, pack_u32_slice_into, pack_u32_slice_into_uninit,
pack_u32_slice_min_words_into, pack_u64_slice, pack_u64_slice_into, read_f32_le_word,
read_u32_le_word, unpack_f32_slice, unpack_f32_slice_into, unpack_u32_slice_into,
};
}
#[cfg(feature = "predicate")]
pub(crate) mod program_region {
use std::sync::Arc;
use vyre_foundation::ir::model::expr::{GeneratorRef, Ident};
use vyre_foundation::ir::{Node, Program};
pub(crate) fn tag_program(parent_op_id: &str, program: Program) -> Program {
Program::wrapped(
program.buffers().to_vec(),
program.workgroup_size(),
vec![Node::Region {
generator: Ident::from(parent_op_id),
source_region: None,
body: Arc::new(reparent_program_children(&program, parent_op_id)),
}],
)
}
fn reparent_program_children(program: &Program, parent_op_id: &str) -> Vec<Node> {
let parent = GeneratorRef {
name: parent_op_id.to_string(),
};
program
.entry()
.iter()
.cloned()
.map(|node| reparent_entry_node(node, &parent))
.collect()
}
fn reparent_entry_node(node: Node, parent: &GeneratorRef) -> Node {
match node {
Node::Region {
generator, body, ..
} => Node::Region {
generator,
source_region: Some(parent.clone()),
body,
},
other => Node::Region {
generator: Ident::from(Program::ROOT_REGION_GENERATOR),
source_region: Some(parent.clone()),
body: Arc::new(vec![other]),
},
}
}
}