Expand description
PJRT runtime for ruxla.
This crate loads PJRT plugins (shared libraries that implement the PJRT C API), compiles StableHLO programs with them, and runs the resulting executables on CPUs and GPUs.
The entry point is Plugin. A plugin creates a Client, which owns
the devices of one platform. A client compiles StableHLO text into a
LoadedExecutable and moves data between the host and the devices as
Buffers.
§Examples
use ruxla_pjrt::{ElementType, Plugin};
let plugin = Plugin::load(ruxla_pjrt::CPU_PLUGIN_FILE)?;
let client = plugin.client()?;
let exe = client.compile(
r#"
func.func public @main(%x: tensor<2xf32>) -> tensor<2xf32> {
%0 = stablehlo.add %x, %x : tensor<2xf32>
return %0 : tensor<2xf32>
}
"#,
)?;
let x = client.buffer_from_host(&[1.0f32, 2.0], &[2])?;
let y = exe.execute(&[&x])?;
assert_eq!(y[0].element_type()?, ElementType::F32);
assert_eq!(y[0].to_vec::<f32>()?, [2.0, 4.0]);Modules§
- ffi
- XLA FFI: calling Rust functions from compiled programs.
- linalg
- ruxla’s FFI handlers for linear algebra.
Structs§
- Buffer
- An array stored on a device.
- Client
- A client of one platform (CPU, CUDA, …).
- Client
Option - An option passed to
Plugin::client_with_options. - Compile
Options - Options for
Client::compile_with_options. - Device
- A device of a
Client. - Event
- The completion of an execution (
LoadedExecutable::execute_with). - Execute
Options - Options of
LoadedExecutable::execute_with. - Loaded
Executable - A program compiled for and loaded on the devices of a
Client. - Plugin
- A loaded PJRT plugin.
Enums§
- Element
Type - The element type of a
Buffer. - Error
- Errors returned by this crate.
- Error
Code - Error codes of the PJRT C API.
Constants§
- CPU_
PLUGIN_ FILE - The file name of the PJRT CPU plugin on this platform:
libpjrt_cpu.dylibon macOS,libpjrt_cpu.soelsewhere (as the builds ofzml/pjrt-artifactsname it). - CUDA_
PLUGIN_ FILE - The file name of the PJRT CUDA plugin (as JAX’s
jax[cuda13]installs it; CUDA plugins exist for Linux only).
Traits§
- Host
Element - A Rust type that can be copied to and from a
Bufferas is.