mod compute;
#[cfg(test)]
mod tests;
use crate::error::{BarracudaError, Result};
use crate::tensor::Tensor;
#[repr(C)]
#[derive(Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroable)]
pub(crate) struct NonZeroParams {
pub input_size: u32,
pub _padding: [u32; 3],
}
pub struct NonZero {
input: Tensor,
}
impl NonZero {
pub fn new(input: Tensor) -> Result<Self> {
if input.is_empty() {
return Err(BarracudaError::invalid_op(
"nonzero",
"Cannot find nonzero elements in empty tensor",
));
}
Ok(Self { input })
}
pub(super) fn wgsl_shader() -> &'static str {
static SHADER: std::sync::LazyLock<String> = std::sync::LazyLock::new(|| {
include_str!("../../shaders/misc/nonzero_f64.wgsl").to_string()
});
std::sync::LazyLock::force(&SHADER).as_str()
}
pub(super) fn prefix_sum_shader() -> &'static str {
include_str!("../../shaders/misc/prefix_sum.wgsl")
}
pub(super) fn mask_convert_shader() -> &'static str {
static SHADER: std::sync::LazyLock<String> = std::sync::LazyLock::new(|| {
include_str!("../../shaders/misc/mask_convert_f64.wgsl").to_string()
});
std::sync::LazyLock::force(&SHADER).as_str()
}
pub(super) fn u32_to_f32_shader() -> &'static str {
static SHADER: std::sync::LazyLock<String> = std::sync::LazyLock::new(|| {
include_str!("../../shaders/misc/u32_to_f32_f64.wgsl").to_string()
});
std::sync::LazyLock::force(&SHADER).as_str()
}
pub(super) fn input(&self) -> &Tensor {
&self.input
}
}