Trait ComputeServer

Source
pub trait ComputeServer:
    Send
    + Debug
    + Sized {
    type Kernel: Send;
    type Info: Debug + Send + Sync;
    type Storage: ComputeStorage;
    type Feature: Ord + Copy + Debug + Send + Sync;

Show 14 methods // Required methods fn read( &mut self, bindings: Vec<Binding>, ) -> impl Future<Output = Vec<Vec<u8>>> + Send + 'static; fn read_tensor( &mut self, bindings: Vec<BindingWithMeta>, ) -> impl Future<Output = Vec<Vec<u8>>> + Send + 'static; fn get_resource( &mut self, binding: Binding, ) -> BindingResource<<Self::Storage as ComputeStorage>::Resource>; fn create(&mut self, data: &[u8]) -> Handle; fn create_tensor( &mut self, data: &[u8], shape: &[usize], elem_size: usize, ) -> (Handle, Vec<usize>); fn empty(&mut self, size: usize) -> Handle; fn empty_tensor( &mut self, shape: &[usize], elem_size: usize, ) -> (Handle, Vec<usize>); unsafe fn execute( &mut self, kernel: Self::Kernel, count: CubeCount, bindings: Bindings, kind: ExecutionMode, ); fn flush(&mut self); fn sync(&mut self) -> impl Future<Output = ()> + Send + 'static; fn memory_usage(&self) -> MemoryUsage; fn memory_cleanup(&mut self); fn start_profile(&mut self); fn end_profile(&mut self) -> ProfileDuration;
}
Expand description

The compute server is responsible for handling resources and computations over resources.

Everything in the server is mutable, therefore it should be solely accessed through the compute channel for thread safety.

Required Associated Types§

Source

type Kernel: Send

The kernel type defines the computation algorithms.

Source

type Info: Debug + Send + Sync

Information that can be retrieved for the runtime.

Source

type Storage: ComputeStorage

The storage type defines how data is stored and accessed.

Source

type Feature: Ord + Copy + Debug + Send + Sync

The type of the features supported by the server.

Required Methods§

Source

fn read( &mut self, bindings: Vec<Binding>, ) -> impl Future<Output = Vec<Vec<u8>>> + Send + 'static

Given bindings, returns the owned resources as bytes.

Source

fn read_tensor( &mut self, bindings: Vec<BindingWithMeta>, ) -> impl Future<Output = Vec<Vec<u8>>> + Send + 'static

Given tensor handles, returns the owned resources as bytes.

Source

fn get_resource( &mut self, binding: Binding, ) -> BindingResource<<Self::Storage as ComputeStorage>::Resource>

Given a resource handle, returns the storage resource.

Source

fn create(&mut self, data: &[u8]) -> Handle

Given a resource as bytes, stores it and returns the memory handle.

Source

fn create_tensor( &mut self, data: &[u8], shape: &[usize], elem_size: usize, ) -> (Handle, Vec<usize>)

Given a resource as bytes with shape, stores it and returns the tensor handle. May or may not be contiguous, depending on what’s best for the given runtime. Always use strides to index. For example, in CUDA, this will allocate a padded tensor where the last dimension is padded to the cache lines, so row access is faster.

Source

fn empty(&mut self, size: usize) -> Handle

Reserves size bytes in the storage, and returns a handle over them.

Source

fn empty_tensor( &mut self, shape: &[usize], elem_size: usize, ) -> (Handle, Vec<usize>)

Reserves shape bytes in the storage, and returns a handle to it.

Source

unsafe fn execute( &mut self, kernel: Self::Kernel, count: CubeCount, bindings: Bindings, kind: ExecutionMode, )

Executes the kernel over the given memory handles.

Kernels have mutable access to every resource they are given and are responsible of determining which should be read or written.

§Safety

When executing with mode ExecutionMode::Unchecked, out-of-bound reads and writes can happen.

Source

fn flush(&mut self)

Flush all outstanding tasks in the server.

Source

fn sync(&mut self) -> impl Future<Output = ()> + Send + 'static

Wait for the completion of every task in the server.

Source

fn memory_usage(&self) -> MemoryUsage

The current memory usage of the server.

Source

fn memory_cleanup(&mut self)

Ask the server to release memory that it can release.

Source

fn start_profile(&mut self)

Enable collecting timestamps.

Source

fn end_profile(&mut self) -> ProfileDuration

Disable collecting timestamps.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§