mod reduce_1d;
mod tiled_2d;
#[cfg(any(feature = "gpu", feature = "gpu-wasm"))]
use super::super::runtime;
use super::super::shaders;
use super::GpuDevice;
impl GpuDevice {
#[cfg(all(feature = "gpu", not(target_arch = "wasm32")))]
pub fn tiled_sum_2d(&self, data: &[f32], width: usize, height: usize) -> Result<f32, String> {
runtime::block_on(self.tiled_sum_2d_async(data, width, height))
}
pub async fn tiled_sum_2d_async(
&self,
data: &[f32],
width: usize,
height: usize,
) -> Result<f32, String> {
self.tiled_reduce_2d_async(
data,
width,
height,
shaders::TILED_SUM_REDUCTION_SHADER,
"TiledSum",
0.0, |partials| partials.iter().sum(),
)
.await
}
#[cfg(all(feature = "gpu", not(target_arch = "wasm32")))]
pub fn tiled_max_2d(&self, data: &[f32], width: usize, height: usize) -> Result<f32, String> {
runtime::block_on(self.tiled_max_2d_async(data, width, height))
}
pub async fn tiled_max_2d_async(
&self,
data: &[f32],
width: usize,
height: usize,
) -> Result<f32, String> {
self.tiled_reduce_2d_async(
data,
width,
height,
shaders::TILED_MAX_REDUCTION_SHADER,
"TiledMax",
f32::NEG_INFINITY, |partials| partials.iter().copied().fold(f32::NEG_INFINITY, f32::max),
)
.await
}
#[cfg(all(feature = "gpu", not(target_arch = "wasm32")))]
pub fn tiled_min_2d(&self, data: &[f32], width: usize, height: usize) -> Result<f32, String> {
runtime::block_on(self.tiled_min_2d_async(data, width, height))
}
pub async fn tiled_min_2d_async(
&self,
data: &[f32],
width: usize,
height: usize,
) -> Result<f32, String> {
self.tiled_reduce_2d_async(
data,
width,
height,
shaders::TILED_MIN_REDUCTION_SHADER,
"TiledMin",
f32::INFINITY, |partials| partials.iter().copied().fold(f32::INFINITY, f32::min),
)
.await
}
}