core:pjrt
A device behind a PJRT plugin, the only public way to run a program on a
TPU. wado run-pjrt hosts it: a program compiles StableHLO, moves buffers
to and from the device, and runs what it compiled. Under any other host a
program runs until its first call of this module, which traps.
Effects
pub interface PjrtHost
A device behind a PJRT plugin, the only public way to run a program on a TPU. It mirrors the calls of PJRT's C API a program needs. A plugin compiles StableHLO, so nothing here says what a tensor means.
fn platform() -> Result<String, String>
#[cm("core:pjrt/pjrt-host@0.1.0#platform")]
The plugin's name for its platform, such as cpu or tpu. A plugin with
no device here reports an error, as it may still compile for a topology.
fn compile(module: String) -> Result<Executable, String>
#[cm("core:pjrt/pjrt-host@0.1.0#compile")] #[cm_params("module")]
Compiles a StableHLO module, in MLIR's text form.
fn analyzed(module: String, topology: String) -> Result<Analysis, String>
#[cm("core:pjrt/pjrt-host@0.1.0#analyzed")] #[cm_params("module", "topology")]
Compiles a StableHLO module for topology, such as v5e:1x1, which
needs no device: what the plugin reports of it. A plugin that runs no
program here may still compile for a device it names.
fn upload(element: ElementType, extents: &ListView<i64>, elements: &ListView<u8>) -> Result<Buffer, String>
#[cm("core:pjrt/pjrt-host@0.1.0#upload")] #[cm_params("element", "extents", "elements")]
A buffer of the elements given little-endian, in row-major order.
Resources
pub resource Buffer
A tensor on the device.
fn to_host(&self) -> Result<ByteList, String>
#[cm("core:pjrt/pjrt-host@0.1.0#[method]buffer.to-host")] #[cm_params("self")]
The elements, little-endian, in row-major order.
fn drop(self)
#[cm("resource-drop")]
Drop the resource. Scope exit drops one that nothing moved.
pub resource Executable
A program compiled for this device.
fn execute(&self, arguments: List<&Buffer>, kept: &ListView<i64>) -> Result<List<Buffer>, String>
#[cm("core:pjrt/pjrt-host@0.1.0#[method]executable.execute")] #[cm_params("self", "arguments", "kept")]
Runs the program. An argument the program updates in place is
donated to its result, and using such a buffer afterwards is an
error, unless kept holds its index, which copies it instead.
fn drop(self)
#[cm("resource-drop")]
Drop the resource. Scope exit drops one that nothing moved.
Structs
pub struct Cost
One figure of a plugin's cost model, such as TPU's optimal_seconds.
name: String
value: f64
pub struct Analysis
The device memory a compiled program needs, and what it costs to run.
argument_bytes: i64
output_bytes: i64
alias_bytes: i64
How much of the arguments the outputs reuse.
temporary_bytes: i64
costs: List<Cost>
Enums
pub enum ElementType
What a buffer's elements are.
