Skip to main content

Client

Struct Client 

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

A client of one platform (CPU, CUDA, …).

A client owns the devices of its platform, compiles programs, and creates buffers. It is reference-counted, so clones are cheap and refer to the same client.

Implementations§

Source§

impl Client

Source

pub fn platform_name(&self) -> Result<String>

Returns the name of the platform, such as "cpu" or "cuda".

§Errors

Returns an error if the plugin fails to report the name.

Source

pub fn devices(&self) -> Result<Vec<Device>>

Returns the devices this client can use.

§Errors

Returns an error if the plugin fails to list the devices.

Source

pub fn compile(&self, mlir: &str) -> Result<LoadedExecutable>

Compiles a StableHLO program in the MLIR text format.

The program must have a public function named main, which becomes the entry point of the executable.

§Errors

Returns an error if the program cannot be parsed or compiled.

Source

pub fn compile_with_options( &self, mlir: &str, options: &CompileOptions, ) -> Result<LoadedExecutable>

Compiles a StableHLO program with the given options.

§Errors

Returns an error if the program cannot be parsed or compiled.

Source

pub fn buffer_from_host<T: HostElement>( &self, data: &[T], dims: &[i64], ) -> Result<Buffer>

Copies host data to a new buffer on the first device.

dims is the shape of the buffer in row-major order. Its product must equal data.len().

§Errors

Returns an error if the shape does not match the data, if the client has no device, or if the transfer fails.

Source

pub fn buffer_from_host_array(&self, array: &HostArray) -> Result<Buffer>

Copies a host array to a new buffer on the first device.

§Errors

Returns an error if the client has no device or the transfer fails.

Source

pub fn buffer_from_host_bytes( &self, bytes: &[u8], ty: ElementType, dims: &[i64], device: &Device, ) -> Result<Buffer>

Copies raw host bytes to a new buffer on device.

bytes holds the elements in row-major order and native byte order.

§Errors

Returns an error if the size of bytes does not match ty and dims, if device belongs to another client, or if the transfer fails.

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.