#![allow(missing_docs)]
#[cfg(any(feature = "gpu", feature = "gpu-wasm"))]
mod batch;
#[cfg(any(feature = "gpu", feature = "gpu-wasm"))]
mod device;
#[cfg(all(feature = "gpu", not(target_arch = "wasm32")))]
mod pool;
#[cfg(any(feature = "gpu", feature = "gpu-wasm"))]
pub mod shaders;
#[cfg(any(feature = "gpu", feature = "gpu-wasm"))]
pub mod runtime;
mod partition_view;
mod tensor_view;
mod tiled_reduction;
pub use partition_view::{PartitionView, TileInfo};
pub use tensor_view::{MemoryLayout, TensorView};
pub use tiled_reduction::{
tiled_max_2d, tiled_min_2d, tiled_reduce_2d, tiled_reduce_partial, tiled_sum_2d, MaxOp, MinOp,
ReduceOp, SumOp, TILE_SIZE,
};
#[cfg(all(feature = "gpu", not(target_arch = "wasm32")))]
pub use batch::{BufferId, GpuCommandBatch, PipelineCache};
#[cfg(any(feature = "gpu", feature = "gpu-wasm"))]
pub use device::GpuDevice;
#[cfg(any(feature = "gpu", feature = "gpu-wasm"))]
pub use wgpu;
#[cfg(all(feature = "gpu", not(target_arch = "wasm32")))]
pub use pool::GpuDevicePool;
#[cfg(any(feature = "gpu", feature = "gpu-wasm"))]
pub use device::linalg::cached_matmul::GpuMatmulCache;
#[cfg(any(feature = "gpu", feature = "gpu-wasm"))]
pub use device::linalg::wgsl_forward::{QkvLoRA, WgslForwardPass};
#[cfg(all(feature = "gpu", not(target_arch = "wasm32")))]
mod backend_ops;
#[cfg(all(feature = "gpu", not(target_arch = "wasm32")))]
#[derive(Clone)]
pub struct GpuBackend {
device: Option<GpuDevice>,
}
#[cfg(all(feature = "gpu", not(target_arch = "wasm32")))]
impl GpuBackend {
pub fn new() -> Self {
Self { device: None }
}
fn ensure_device(&mut self) -> Result<&GpuDevice, String> {
if self.device.is_none() {
self.device = Some(GpuDevice::new()?);
}
Ok(self.device.as_ref().expect("device initialized above"))
}
pub fn is_available() -> bool {
GpuDevice::is_available()
}
}
#[cfg(all(feature = "gpu", not(target_arch = "wasm32")))]
impl Default for GpuBackend {
fn default() -> Self {
Self::new()
}
}
#[cfg(any(not(feature = "gpu"), target_arch = "wasm32"))]
#[derive(Clone)]
pub struct GpuBackend;
#[cfg(any(not(feature = "gpu"), target_arch = "wasm32"))]
impl GpuBackend {
pub fn new() -> Self {
Self
}
pub fn is_available() -> bool {
false
}
}
#[cfg(any(not(feature = "gpu"), target_arch = "wasm32"))]
impl Default for GpuBackend {
fn default() -> Self {
Self
}
}
#[cfg(test)]
#[cfg(not(feature = "gpu"))]
mod stub_tests {
use super::*;
#[test]
fn test_gpu_backend_stub_new() {
let _backend = GpuBackend::new();
}
#[test]
fn test_gpu_backend_stub_is_available() {
assert!(!GpuBackend::is_available());
}
#[test]
fn test_gpu_backend_stub_default() {
let _ = GpuBackend;
}
#[test]
fn test_gpu_backend_stub_clone() {
let backend = GpuBackend::new();
let _cloned = backend.clone();
}
}
#[cfg(test)]
#[cfg(feature = "gpu")]
mod tests_gpu;