Skip to main content

Crate ruxla_pjrt

Crate ruxla_pjrt 

Source
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, …).
ClientOption
An option passed to Plugin::client_with_options.
CompileOptions
Options for Client::compile_with_options.
Device
A device of a Client.
Event
The completion of an execution (LoadedExecutable::execute_with).
ExecuteOptions
Options of LoadedExecutable::execute_with.
LoadedExecutable
A program compiled for and loaded on the devices of a Client.
Plugin
A loaded PJRT plugin.

Enums§

ElementType
The element type of a Buffer.
Error
Errors returned by this crate.
ErrorCode
Error codes of the PJRT C API.

Constants§

CPU_PLUGIN_FILE
The file name of the PJRT CPU plugin on this platform: libpjrt_cpu.dylib on macOS, libpjrt_cpu.so elsewhere (as the builds of zml/pjrt-artifacts name 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§

HostElement
A Rust type that can be copied to and from a Buffer as is.

Type Aliases§

Result
A specialized Result for PJRT operations.