ParallelInference

Struct ParallelInference 

Source
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

Source

pub async fn new( num_workers: Option<usize>, ) -> Result<ParallelInference, JsValue>

Create a new ParallelInference instance.

§Arguments
  • num_workers - Number of workers to spawn. If None, uses optimal count.
§Returns

A Promise that resolves to ParallelInference instance.

§Example (JavaScript)
const inference = await ParallelInference.new(4);
Source

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 A
  • n - Number of columns in B
  • k - Number of columns in A / rows in B
§Returns

Result matrix C as Float32Array

Source

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 heads
  • head_dim - Dimension of each head
  • seq_len - Sequence length
§Returns

Output tensor (batch_size, num_heads, seq_len, head_dim)

Source

pub async fn layer_norm( &mut self, input: &[f32], gamma: &[f32], beta: &[f32], epsilon: f32, ) -> Result<Vec<f32>, JsValue>

Perform parallel layer normalization.

§Arguments
  • input - Input tensor
  • gamma - Scale parameter
  • beta - Shift parameter
  • epsilon - Small constant for numerical stability
§Returns

Normalized tensor

Source

pub fn worker_count(&self) -> usize

Get the number of active workers.

Source

pub fn is_shared_memory_available(&self) -> bool

Check if SharedArrayBuffer is available.

Source

pub fn is_cross_origin_isolated(&self) -> bool

Check if the page is cross-origin isolated.

Source

pub fn is_atomics_available(&self) -> bool

Check if Atomics API is available.

Source

pub fn get_optimal_worker_count() -> usize

Get optimal worker count for the current hardware.

Source

pub fn terminate(&mut self)

Terminate all workers and clean up resources.

Source

pub fn get_stats(&self) -> Result<String, JsValue>

Get statistics about worker pool.

Trait Implementations§

Source§

impl Drop for ParallelInference

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl From<ParallelInference> for JsValue

Source§

fn from(value: ParallelInference) -> Self

Converts to this type from the input type.
Source§

impl FromWasmAbi for ParallelInference

Source§

type Abi = u32

The Wasm ABI type that this converts from when coming back out from the ABI boundary.
Source§

unsafe fn from_abi(js: u32) -> Self

Recover a Self from Self::Abi. Read more
Source§

impl IntoWasmAbi for ParallelInference

Source§

type Abi = u32

The Wasm ABI type that this converts into when crossing the ABI boundary.
Source§

fn into_abi(self) -> u32

Convert self into Self::Abi so that it can be sent across the wasm ABI boundary.
Source§

impl LongRefFromWasmAbi for ParallelInference

Source§

type Abi = u32

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRef<ParallelInference>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl OptionFromWasmAbi for ParallelInference

Source§

fn is_none(abi: &Self::Abi) -> bool

Tests whether the argument is a “none” instance. If so it will be deserialized as None, and otherwise it will be passed to FromWasmAbi.
Source§

impl OptionIntoWasmAbi for ParallelInference

Source§

fn none() -> Self::Abi

Returns an ABI instance indicating “none”, which JS will interpret as the None branch of this option. Read more
Source§

impl RefFromWasmAbi for ParallelInference

Source§

type Abi = u32

The Wasm ABI type references to Self are recovered from.
Source§

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§

unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor

Recover a Self::Anchor from Self::Abi. Read more
Source§

impl RefMutFromWasmAbi for ParallelInference

Source§

type Abi = u32

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRefMut<ParallelInference>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl TryFromJsValue for ParallelInference

Source§

fn try_from_js_value(value: JsValue) -> Result<Self, JsValue>

Performs the conversion.
Source§

fn try_from_js_value_ref(value: &JsValue) -> Option<Self>

Performs the conversion.
Source§

impl VectorFromWasmAbi for ParallelInference

Source§

impl VectorIntoWasmAbi for ParallelInference

Source§

impl WasmDescribe for ParallelInference

Source§

impl WasmDescribeVector for ParallelInference

Source§

impl SupportsConstructor for ParallelInference

Source§

impl SupportsInstanceProperty for ParallelInference

Source§

impl SupportsStaticProperty for ParallelInference

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ReturnWasmAbi for T
where T: IntoWasmAbi,

Source§

type Abi = <T as IntoWasmAbi>::Abi

Same as IntoWasmAbi::Abi
Source§

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.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.