Skip to main content

XlaExecutor

Struct XlaExecutor 

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

Experimental peer executor for XLA/PJRT.

§Examples

use tenferro_runtime::{GraphCompiler, TracedTensor};
use tenferro_xla::XlaExecutor;

let x = TracedTensor::from_vec_col_major(vec![1], vec![2.0_f64]).unwrap();
let mut compiler = GraphCompiler::new();
let y = x.neg().unwrap();
let program = compiler.compile(&y).unwrap();
let module = XlaExecutor::default()
    .lower_compiled_to_stablehlo(&program)
    .unwrap();
assert!(module.as_str().contains("stablehlo.negate"));

Implementations§

Source§

impl XlaExecutor

Source

pub fn new(options: XlaExecutorOptions) -> Self

Create an executor with explicit options.

§Examples
use tenferro_xla::{XlaExecutor, XlaExecutorOptions};

let executor = XlaExecutor::new(XlaExecutorOptions::default());
assert_eq!(executor.options(), XlaExecutorOptions::default());
Source

pub fn from_env() -> Result<Self>

Create an executor by loading PJRT configuration from environment variables.

§Examples
use tenferro_xla::XlaExecutor;

let _ = XlaExecutor::from_env();
§Errors

Returns Error::MissingEnv when the configured plugin-path variable is unset, or Error::PluginLoad with the typed dynamic-library source when the path cannot be loaded.

Source

pub fn from_env_var(var: &'static str) -> Result<Self>

Create an executor by loading a PJRT plugin path from a specific environment variable.

§Examples
use tenferro_xla::XlaExecutor;

let _ = XlaExecutor::from_env_var("__TENFERRO_XLA_DOCS_UNSET");
§Errors

Returns Error::MissingEnv when var is unset, or Error::PluginLoad with the typed dynamic-library source when its value cannot be loaded.

Source

pub fn options(&self) -> XlaExecutorOptions

Return the executor options.

§Examples
use tenferro_xla::XlaExecutor;

assert_eq!(XlaExecutor::default().options(), Default::default());
Source

pub fn has_loaded_pjrt_plugin(&self) -> bool

Return whether this executor owns a loaded PJRT plugin.

§Examples
use tenferro_xla::XlaExecutor;

assert!(!XlaExecutor::default().has_loaded_pjrt_plugin());
Source

pub fn lower_to_stablehlo( &self, program: &SemanticProgram, ) -> Result<StableHloModule>

Lower a graph program to StableHLO without executing it.

§Examples
use tenferro_runtime::{GraphCompiler, TracedTensor};
use tenferro_xla::XlaExecutor;

let x = TracedTensor::from_vec_col_major(vec![1], vec![2.0_f64]).unwrap();
let mut compiler = GraphCompiler::new();
let y = x.neg().unwrap();
let program = compiler.compile(&y).unwrap();
let module = XlaExecutor::default().lower_to_stablehlo(program.program()).unwrap();
assert!(module.as_str().contains("stablehlo.negate"));
§Errors

Returns Error::UnsupportedDType, Error::UnsupportedOp, or Error::NonStaticShape for unsupported graph content, and Error::InvalidProgram for inconsistent graph metadata.

Source

pub fn lower_compiled_to_stablehlo( &self, program: &CompiledGraph, ) -> Result<StableHloModule>

Lower a compiled graph to StableHLO without executing it.

This is the preferred public lowering boundary for graph users. It consumes CompiledGraph directly and does not route through native Runtime execution staging.

§Examples
use tenferro_runtime::{GraphCompiler, TracedTensor};
use tenferro_xla::XlaExecutor;

let x = TracedTensor::from_vec_col_major(vec![1], vec![2.0_f64]).unwrap();
let mut compiler = GraphCompiler::new();
let y = x.neg().unwrap();
let program = compiler.compile(&y).unwrap();
let module = XlaExecutor::default()
    .lower_compiled_to_stablehlo(&program)
    .unwrap();
assert!(module.as_str().contains("stablehlo.negate"));
§Errors

Returns Error::UnsupportedDType, Error::UnsupportedOp, or Error::NonStaticShape for unsupported graph content, and Error::InvalidProgram for inconsistent graph metadata.

Source

pub fn run_many_with_inputs( &self, program: &SemanticProgram, inputs: &[&Tensor], ) -> Result<Vec<Tensor>>

Execute a graph program through a loaded PJRT plugin and return all outputs.

Inputs must match the ordered semantic-program input metadata exactly. This experimental execution path supports the same exact-static-shape, F32/F64 subset as StableHLO lowering.

§Examples
use tenferro_runtime::{GraphCompiler, TracedTensor};
use tenferro_tensor::Tensor;
use tenferro_xla::{Error, XlaExecutor};

let x = TracedTensor::from_vec_col_major(vec![1], vec![2.0_f64]).unwrap();
let mut compiler = GraphCompiler::new();
let y = x.neg().unwrap();
let program = compiler.compile(&y).unwrap();
let input = Tensor::from_vec_col_major(vec![1], vec![2.0_f64]).unwrap();
let err = XlaExecutor::default()
    .run_many_with_inputs(program.program(), &[&input])
    .unwrap_err();
assert!(matches!(err, Error::PjrtFeatureDisabled | Error::PjrtPluginNotLoaded));
§Errors

Returns Error::PjrtFeatureDisabled or Error::PjrtPluginNotLoaded when no PJRT executor is available, Error::InvalidProgram for input count/dtype/shape mismatches, and Error::PjrtCall for vendor status failures.

Source

pub fn run_compiled_many_with_inputs( &self, program: &CompiledGraph, inputs: &[&Tensor], ) -> Result<Vec<Tensor>>

Execute a compiled graph through a loaded PJRT plugin and return all outputs.

This wrapper accepts the same CompiledGraph that native runtime execution consumes, while preserving the current XLA/PJRT exact-static F32/F64 subset. It delegates to the semantic-program PJRT executor and does not route through native Runtime execution.

§Examples
use tenferro_runtime::{GraphCompiler, TracedTensor};
use tenferro_tensor::Tensor;
use tenferro_xla::{Error, XlaExecutor};

let x = TracedTensor::from_vec_col_major(vec![1], vec![2.0_f64]).unwrap();
let mut compiler = GraphCompiler::new();
let y = x.neg().unwrap();
let program = compiler.compile(&y).unwrap();
let input = Tensor::from_vec_col_major(vec![1], vec![2.0_f64]).unwrap();
let err = XlaExecutor::default()
    .run_compiled_many_with_inputs(&program, &[&input])
    .unwrap_err();
assert!(matches!(err, Error::PjrtFeatureDisabled | Error::PjrtPluginNotLoaded));
§Errors

Returns Error::PjrtFeatureDisabled or Error::PjrtPluginNotLoaded when no PJRT executor is available, Error::InvalidProgram for input count/dtype/shape mismatches, and Error::PjrtCall for vendor status failures.

Source

pub fn run_with_inputs( &self, program: &SemanticProgram, inputs: &[&Tensor], ) -> Result<Tensor>

Execute a single-output graph program through a loaded PJRT plugin.

§Examples
use tenferro_runtime::{GraphCompiler, TracedTensor};
use tenferro_tensor::Tensor;
use tenferro_xla::{Error, XlaExecutor};

let x = TracedTensor::from_vec_col_major(vec![1], vec![2.0_f64]).unwrap();
let mut compiler = GraphCompiler::new();
let y = x.neg().unwrap();
let program = compiler.compile(&y).unwrap();
let input = Tensor::from_vec_col_major(vec![1], vec![2.0_f64]).unwrap();
let err = XlaExecutor::default().run_with_inputs(program.program(), &[&input]).unwrap_err();
assert!(matches!(err, Error::PjrtFeatureDisabled | Error::PjrtPluginNotLoaded));
§Errors

Propagates the run_many_with_inputs errors and returns Error::InvalidProgram if the program does not have exactly one output.

Source

pub fn run_compiled_with_inputs( &self, program: &CompiledGraph, inputs: &[&Tensor], ) -> Result<Tensor>

Execute a single-output compiled graph through a loaded PJRT plugin.

§Examples
use tenferro_runtime::{GraphCompiler, TracedTensor};
use tenferro_tensor::Tensor;
use tenferro_xla::{Error, XlaExecutor};

let x = TracedTensor::from_vec_col_major(vec![1], vec![2.0_f64]).unwrap();
let mut compiler = GraphCompiler::new();
let y = x.neg().unwrap();
let program = compiler.compile(&y).unwrap();
let input = Tensor::from_vec_col_major(vec![1], vec![2.0_f64]).unwrap();
let err = XlaExecutor::default()
    .run_compiled_with_inputs(&program, &[&input])
    .unwrap_err();
assert!(matches!(err, Error::PjrtFeatureDisabled | Error::PjrtPluginNotLoaded));
§Errors

Propagates the run_compiled_many_with_inputs errors and returns Error::InvalidProgram if the program does not have exactly one output.

Trait Implementations§

Source§

impl Debug for XlaExecutor

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for XlaExecutor

Source§

fn default() -> Self

Returns the “default value” for a type. 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
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.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.