mod compute;
#[cfg(test)]
mod tests;
use crate::error::Result;
use crate::tensor::Tensor;
pub struct MaskedSelect {
input: Tensor,
mask: Tensor,
}
impl MaskedSelect {
pub fn new(input: Tensor, mask: Tensor) -> Result<Self> {
if input.shape() != mask.shape() {
return Err(crate::error::BarracudaError::ShapeMismatch {
expected: input.shape().to_vec(),
actual: mask.shape().to_vec(),
});
}
Ok(Self { input, mask })
}
pub(super) fn wgsl_shader() -> &'static str {
{
static S: std::sync::LazyLock<String> = std::sync::LazyLock::new(|| {
include_str!("../../shaders/tensor/masked_select_f64.wgsl").to_string()
});
&S
}
}
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 input(&self) -> &Tensor {
&self.input
}
pub(super) fn mask(&self) -> &Tensor {
&self.mask
}
pub fn execute(self) -> Result<Tensor> {
compute::execute_masked_select(self)
}
}