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 program = compiler.compile(&x.neg()).unwrap();
let module = XlaExecutor::default().lower_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();
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");
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: &GraphProgram, ) -> 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 program = compiler.compile(&x.neg()).unwrap();
let module = XlaExecutor::default().lower_to_stablehlo(&program).unwrap();
assert!(module.as_str().contains("stablehlo.negate"));
Source

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

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

Inputs must match [GraphProgram::input_specs] 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 program = compiler.compile(&x.neg()).unwrap();
let input = Tensor::from_vec_col_major(vec![1], vec![2.0_f64]).unwrap();
let err = XlaExecutor::default()
    .run_many_with_inputs(&program, &[&input])
    .unwrap_err();
assert!(matches!(err, Error::PjrtFeatureDisabled | Error::PjrtPluginNotLoaded));
Source

pub fn run_with_inputs( &self, program: &GraphProgram, 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 program = compiler.compile(&x.neg()).unwrap();
let input = Tensor::from_vec_col_major(vec![1], vec![2.0_f64]).unwrap();
let err = XlaExecutor::default().run_with_inputs(&program, &[&input]).unwrap_err();
assert!(matches!(err, Error::PjrtFeatureDisabled | Error::PjrtPluginNotLoaded));

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.