pub struct ParallelInference { /* private fields */ }Expand description
Main parallel inference interface for WASM.
Provides high-level API for parallel compute operations in the browser. Automatically manages worker pool and shared memory.
Implementations§
Source§impl ParallelInference
impl ParallelInference
Sourcepub async fn matmul(
&mut self,
a: &[f32],
b: &[f32],
m: usize,
n: usize,
k: usize,
) -> Result<Vec<f32>, JsValue>
pub async fn matmul( &mut self, a: &[f32], b: &[f32], m: usize, n: usize, k: usize, ) -> Result<Vec<f32>, JsValue>
Perform parallel matrix multiplication.
Computes C = A * B where:
- A is m x k
- B is k x n
- C is m x n
§Arguments
a- Matrix A as flat array (row-major)b- Matrix B as flat array (row-major)m- Number of rows in An- Number of columns in Bk- Number of columns in A / rows in B
§Returns
Result matrix C as Float32Array
Sourcepub async fn parallel_attention(
&mut self,
q: &[f32],
k: &[f32],
v: &[f32],
num_heads: usize,
head_dim: usize,
seq_len: usize,
) -> Result<Vec<f32>, JsValue>
pub async fn parallel_attention( &mut self, q: &[f32], k: &[f32], v: &[f32], num_heads: usize, head_dim: usize, seq_len: usize, ) -> Result<Vec<f32>, JsValue>
Perform parallel multi-head attention.
Computes softmax(Q * K^T / sqrt(d_k)) * V for each attention head.
§Arguments
q- Query tensor (batch_size, num_heads, seq_len, head_dim)k- Key tensor (batch_size, num_heads, seq_len, head_dim)v- Value tensor (batch_size, num_heads, seq_len, head_dim)num_heads- Number of attention headshead_dim- Dimension of each headseq_len- Sequence length
§Returns
Output tensor (batch_size, num_heads, seq_len, head_dim)
Sourcepub async fn layer_norm(
&mut self,
input: &[f32],
gamma: &[f32],
beta: &[f32],
epsilon: f32,
) -> Result<Vec<f32>, JsValue>
pub async fn layer_norm( &mut self, input: &[f32], gamma: &[f32], beta: &[f32], epsilon: f32, ) -> Result<Vec<f32>, JsValue>
Sourcepub fn worker_count(&self) -> usize
pub fn worker_count(&self) -> usize
Get the number of active workers.
Check if SharedArrayBuffer is available.
Sourcepub fn is_cross_origin_isolated(&self) -> bool
pub fn is_cross_origin_isolated(&self) -> bool
Check if the page is cross-origin isolated.
Sourcepub fn is_atomics_available(&self) -> bool
pub fn is_atomics_available(&self) -> bool
Check if Atomics API is available.
Sourcepub fn get_optimal_worker_count() -> usize
pub fn get_optimal_worker_count() -> usize
Get optimal worker count for the current hardware.
Trait Implementations§
Source§impl Drop for ParallelInference
impl Drop for ParallelInference
Source§impl From<ParallelInference> for JsValue
impl From<ParallelInference> for JsValue
Source§fn from(value: ParallelInference) -> Self
fn from(value: ParallelInference) -> Self
Converts to this type from the input type.
Source§impl FromWasmAbi for ParallelInference
impl FromWasmAbi for ParallelInference
Source§impl IntoWasmAbi for ParallelInference
impl IntoWasmAbi for ParallelInference
Source§impl RefFromWasmAbi for ParallelInference
impl RefFromWasmAbi for ParallelInference
Source§type Anchor = RcRef<ParallelInference>
type Anchor = RcRef<ParallelInference>
The type that holds the reference to
Self for the duration of the
invocation of the function that has an &Self parameter. This is
required to ensure that the lifetimes don’t persist beyond one function
call, and so that they remain anonymous.Source§impl TryFromJsValue for ParallelInference
impl TryFromJsValue for ParallelInference
Source§impl VectorFromWasmAbi for ParallelInference
impl VectorFromWasmAbi for ParallelInference
type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi
unsafe fn vector_from_abi(js: Self::Abi) -> Box<[ParallelInference]>
Source§impl VectorIntoWasmAbi for ParallelInference
impl VectorIntoWasmAbi for ParallelInference
type Abi = <Box<[JsValue]> as IntoWasmAbi>::Abi
fn vector_into_abi(vector: Box<[ParallelInference]>) -> Self::Abi
Source§impl WasmDescribeVector for ParallelInference
impl WasmDescribeVector for ParallelInference
impl SupportsConstructor for ParallelInference
impl SupportsInstanceProperty for ParallelInference
impl SupportsStaticProperty for ParallelInference
Auto Trait Implementations§
impl !Freeze for ParallelInference
impl !RefUnwindSafe for ParallelInference
impl !Send for ParallelInference
impl !Sync for ParallelInference
impl Unpin for ParallelInference
impl UnwindSafe for ParallelInference
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
Source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
Same as
IntoWasmAbi::AbiSource§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
Same as
IntoWasmAbi::into_abi, except that it may throw and never
return in the case of Err.