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
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();§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.
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");§Errors
Returns Error::MissingEnv when var is unset, or Error::PluginLoad
with the typed dynamic-library source when its value cannot be loaded.
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: &SemanticProgram,
) -> Result<StableHloModule>
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.
Sourcepub fn lower_compiled_to_stablehlo(
&self,
program: &CompiledGraph,
) -> Result<StableHloModule>
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.
Sourcepub fn run_many_with_inputs(
&self,
program: &SemanticProgram,
inputs: &[&Tensor],
) -> Result<Vec<Tensor>>
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.
Sourcepub fn run_compiled_many_with_inputs(
&self,
program: &CompiledGraph,
inputs: &[&Tensor],
) -> Result<Vec<Tensor>>
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.
Sourcepub fn run_with_inputs(
&self,
program: &SemanticProgram,
inputs: &[&Tensor],
) -> Result<Tensor>
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.
Sourcepub fn run_compiled_with_inputs(
&self,
program: &CompiledGraph,
inputs: &[&Tensor],
) -> Result<Tensor>
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
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more