Skip to main content

Worker

Struct Worker 

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

工人句柄,丢掉时线程退出并释放上下文。

Implementations§

Source§

impl Worker

Source

pub fn spawn(index: usize) -> Result<Worker, String>

打开第 index 块卡并启动工人线程(内核 JIT 在这里完成)。 打不开时返回原因,调用方退回 CPU。

Source

pub fn info(&self) -> &GpuInfo

打开时查到的设备情况。

Source

pub fn call<R: Send>( &self, f: impl for<'c, 'g> FnOnce(&'c Ctx<'g>) -> R + Send, ) -> Result<R, String>

在工人线程上执行 f 并等结果。工作按提交顺序一个接一个执行。

Source§

impl Worker

Source

pub fn call_timeout<R: Send + 'static>( &self, f: impl for<'c, 'g> FnOnce(&'c Ctx<'g>) -> R + Send + 'static, wait: Duration, ) -> Result<R, WaitError>

同 Worker::call,但最多等 wait。调用方到时间可以走开,所以闭包不能借东西('static)。

Trait Implementations§

Source§

impl Drop for Worker

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

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.