pub struct WebGpuBackend { /* private fields */ }Expand description
Cross-platform GPU compute backend backed by wgpu.
§Lifecycle
WebGpuBackend::new()— create an uninitialised backend.init()— select the best available adapter and create the device.- Use
alloc,copy_htod, compute ops,copy_dtoh,free. synchronize()— wait for all pending GPU work to finish.
Implementations§
Source§impl WebGpuBackend
impl WebGpuBackend
Trait Implementations§
Source§impl ComputeBackend for WebGpuBackend
impl ComputeBackend for WebGpuBackend
Source§fn init(&mut self) -> BackendResult<()>
fn init(&mut self) -> BackendResult<()>
Initialize the backend (select device, create context). Read more
Source§fn is_initialized(&self) -> bool
fn is_initialized(&self) -> bool
Returns
true if the backend is ready for operations.Source§fn gemm(
&self,
_trans_a: BackendTranspose,
_trans_b: BackendTranspose,
m: usize,
n: usize,
k: usize,
_alpha: f64,
_a_ptr: u64,
_lda: usize,
_b_ptr: u64,
_ldb: usize,
_beta: f64,
_c_ptr: u64,
_ldc: usize,
) -> BackendResult<()>
fn gemm( &self, _trans_a: BackendTranspose, _trans_b: BackendTranspose, m: usize, n: usize, k: usize, _alpha: f64, _a_ptr: u64, _lda: usize, _b_ptr: u64, _ldb: usize, _beta: f64, _c_ptr: u64, _ldc: usize, ) -> BackendResult<()>
General matrix multiply:
C = alpha * op(A) * op(B) + beta * C. Read moreSource§fn conv2d_forward(
&self,
_input_ptr: u64,
input_shape: &[usize],
_filter_ptr: u64,
filter_shape: &[usize],
_output_ptr: u64,
output_shape: &[usize],
stride: &[usize],
padding: &[usize],
) -> BackendResult<()>
fn conv2d_forward( &self, _input_ptr: u64, input_shape: &[usize], _filter_ptr: u64, filter_shape: &[usize], _output_ptr: u64, output_shape: &[usize], stride: &[usize], padding: &[usize], ) -> BackendResult<()>
2D convolution forward pass. Read more
Source§fn attention(
&self,
_q_ptr: u64,
_k_ptr: u64,
_v_ptr: u64,
_o_ptr: u64,
_batch: usize,
_heads: usize,
seq_q: usize,
seq_kv: usize,
head_dim: usize,
scale: f64,
_causal: bool,
) -> BackendResult<()>
fn attention( &self, _q_ptr: u64, _k_ptr: u64, _v_ptr: u64, _o_ptr: u64, _batch: usize, _heads: usize, seq_q: usize, seq_kv: usize, head_dim: usize, scale: f64, _causal: bool, ) -> BackendResult<()>
Scaled dot-product attention. Read more
Source§fn reduce(
&self,
_op: ReduceOp,
_input_ptr: u64,
_output_ptr: u64,
shape: &[usize],
axis: usize,
) -> BackendResult<()>
fn reduce( &self, _op: ReduceOp, _input_ptr: u64, _output_ptr: u64, shape: &[usize], axis: usize, ) -> BackendResult<()>
Reduction along an axis. Read more
Source§fn unary(
&self,
_op: UnaryOp,
_input_ptr: u64,
_output_ptr: u64,
n: usize,
) -> BackendResult<()>
fn unary( &self, _op: UnaryOp, _input_ptr: u64, _output_ptr: u64, n: usize, ) -> BackendResult<()>
Element-wise unary operation. Read more
Source§fn binary(
&self,
_op: BinaryOp,
_a_ptr: u64,
_b_ptr: u64,
_output_ptr: u64,
n: usize,
) -> BackendResult<()>
fn binary( &self, _op: BinaryOp, _a_ptr: u64, _b_ptr: u64, _output_ptr: u64, n: usize, ) -> BackendResult<()>
Element-wise binary operation. Read more
Source§fn synchronize(&self) -> BackendResult<()>
fn synchronize(&self) -> BackendResult<()>
Synchronize all pending operations on this backend. Read more
Source§fn free(&self, ptr: u64) -> BackendResult<()>
fn free(&self, ptr: u64) -> BackendResult<()>
Free device memory previously allocated with
alloc.Source§impl Debug for WebGpuBackend
impl Debug for WebGpuBackend
Auto Trait Implementations§
impl Freeze for WebGpuBackend
impl !RefUnwindSafe for WebGpuBackend
impl Send for WebGpuBackend
impl Sync for WebGpuBackend
impl Unpin for WebGpuBackend
impl UnsafeUnpin for WebGpuBackend
impl !UnwindSafe for WebGpuBackend
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more