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
impl XlaExecutor
Sourcepub fn new(options: XlaExecutorOptions) -> Self
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());Sourcepub fn from_env() -> Result<Self>
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();Sourcepub fn from_env_var(var: &'static str) -> Result<Self>
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");Sourcepub fn options(&self) -> XlaExecutorOptions
pub fn options(&self) -> XlaExecutorOptions
Return the executor options.
§Examples
use tenferro_xla::XlaExecutor;
assert_eq!(XlaExecutor::default().options(), Default::default());Sourcepub fn has_loaded_pjrt_plugin(&self) -> bool
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());Sourcepub fn lower_to_stablehlo(
&self,
program: &GraphProgram,
) -> Result<StableHloModule>
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"));Sourcepub fn run_many_with_inputs(
&self,
program: &GraphProgram,
inputs: &[&Tensor],
) -> Result<Vec<Tensor>>
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));Sourcepub fn run_with_inputs(
&self,
program: &GraphProgram,
inputs: &[&Tensor],
) -> Result<Tensor>
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
impl Debug for XlaExecutor
Auto Trait Implementations§
impl Freeze for XlaExecutor
impl RefUnwindSafe for XlaExecutor
impl !Send for XlaExecutor
impl !Sync for XlaExecutor
impl Unpin for XlaExecutor
impl UnsafeUnpin for XlaExecutor
impl UnwindSafe for XlaExecutor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more