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
impl Client
Sourcepub fn platform_name(&self) -> Result<String>
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.
Sourcepub fn devices(&self) -> Result<Vec<Device>>
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.
Sourcepub fn compile(&self, mlir: &str) -> Result<LoadedExecutable>
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.
Sourcepub fn compile_with_options(
&self,
mlir: &str,
options: &CompileOptions,
) -> Result<LoadedExecutable>
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.
Sourcepub fn buffer_from_host<T: HostElement>(
&self,
data: &[T],
dims: &[i64],
) -> Result<Buffer>
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.
Sourcepub fn buffer_from_host_array(&self, array: &HostArray) -> Result<Buffer>
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.
Sourcepub fn buffer_from_host_bytes(
&self,
bytes: &[u8],
ty: ElementType,
dims: &[i64],
device: &Device,
) -> Result<Buffer>
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.