Skip to main content

GpuBackend

Struct GpuBackend 

Source
pub struct GpuBackend { /* private fields */ }
Expand description

透明分流的后端。

Implementations§

Source§

impl GpuBackend

Source

pub fn new(worker: SharedWorker) -> Result<GpuBackend, String>

校准开销(几十毫秒)并建好后端。

Source

pub fn costs(&self) -> Costs

校准出来的开销。

Source

pub fn offloaded(&self) -> u64

走了 GPU 的算子个数。

Source

pub fn last_error(&self) -> Option<String>

最近一次 GPU 出错的原因(出错的算子已自动在 CPU 上重算)。

Trait Implementations§

Source§

impl Backend for GpuBackend

Source§

fn matmul(&self, a: &Tensor, b: &Tensor, b_is_weight: bool) -> Option<Vec<f32>>

a[M, K] · b[K, N],行优先。b_is_weight 表示 b 是长期不变的权重,后端可以缓存。
Source§

fn conv2d( &self, x: &Tensor, w: &Tensor, bias: Option<&[f32]>, stride: (usize, usize), pad: (usize, usize), dilation: (usize, usize), groups: usize, ) -> Option<Vec<f32>>

Source§

fn activate(&self, x: &mut [f32], a: Activation) -> bool

原地激活一段内存,走了后端就返回 true。

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.