pub struct GraphCompiler { /* private fields */ }Expand description
Compiler for traced tensor graphs.
A graph compiler lowers one or more TracedTensor outputs to a reusable
GraphProgram without requiring a backend.
§Examples
use tenferro_runtime::{GraphCompiler, TracedTensor};
let x = TracedTensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0]).unwrap();
let y = (&x + &x).unwrap();
let mut compiler = GraphCompiler::new();
let program = compiler.compile(&y).unwrap();
assert_eq!(program.output_count(), 1);Implementations§
Source§impl GraphCompiler
impl GraphCompiler
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a compiler with bounded default caches.
§Examples
use tenferro_runtime::GraphCompiler;
let compiler = GraphCompiler::new();
assert_eq!(compiler.compile_cache_len(), 0);Sourcepub fn with_compiler_options(compiler_options: CompilerOptions) -> Self
pub fn with_compiler_options(compiler_options: CompilerOptions) -> Self
Create a compiler with explicit lowering and optimizer options.
§Examples
use tenferro_runtime::{CompilerOptions, OptimizerConfig};
use tenferro_runtime::GraphCompiler;
let compiler = GraphCompiler::with_compiler_options(CompilerOptions {
optimizer: OptimizerConfig {
dot_decomposer: true,
..OptimizerConfig::default()
},
});
assert!(compiler.compiler_options().optimizer.dot_decomposer);Sourcepub fn compile(&mut self, output: &TracedTensor) -> Result<GraphProgram>
pub fn compile(&mut self, output: &TracedTensor) -> Result<GraphProgram>
Compile one traced output into a graph program.
§Examples
use tenferro_runtime::{GraphCompiler, TracedTensor};
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();
assert_eq!(program.input_count(), 1);Sourcepub fn compile_many(
&mut self,
outputs: &[&TracedTensor],
) -> Result<GraphProgram>
pub fn compile_many( &mut self, outputs: &[&TracedTensor], ) -> Result<GraphProgram>
Compile multiple traced outputs into one graph program.
§Examples
use tenferro_runtime::{GraphCompiler, TracedTensor};
let x = TracedTensor::from_vec_col_major(vec![1], vec![2.0_f64]).unwrap();
let y = x.neg();
let mut compiler = GraphCompiler::new();
let program = compiler.compile_many(&[&x, &y]).unwrap();
assert_eq!(program.output_count(), 2);Sourcepub fn compile_with_input_specs(
&mut self,
output: &TracedTensor,
bindings: &[(&TracedTensor, DType, &[usize])],
) -> Result<GraphProgram>
pub fn compile_with_input_specs( &mut self, output: &TracedTensor, bindings: &[(&TracedTensor, DType, &[usize])], ) -> Result<GraphProgram>
Compile one traced output with concrete placeholder specs.
§Examples
use tenferro_runtime::{DType, GraphCompiler, TracedTensor};
let x = TracedTensor::input_symbolic_shape(DType::F64, 1).unwrap();
let mut compiler = GraphCompiler::new();
let program = compiler
.compile_with_input_specs(&x.neg(), &[(&x, DType::F64, &[3])])
.unwrap();
assert_eq!(program.input_specs()[0].shape(), &[3]);Sourcepub fn compile_cache_len(&self) -> usize
pub fn compile_cache_len(&self) -> usize
Number of compiled programs currently retained.
§Examples
use tenferro_runtime::GraphCompiler;
let compiler = GraphCompiler::new();
assert_eq!(compiler.compile_cache_len(), 0);Sourcepub fn compile_cache_capacity(&self) -> NonZeroUsize
pub fn compile_cache_capacity(&self) -> NonZeroUsize
Current compiled-program cache capacity.
§Examples
use tenferro_runtime::GraphCompiler;
let compiler = GraphCompiler::new();
assert!(compiler.compile_cache_capacity().get() > 0);Sourcepub fn set_compile_cache_capacity(&mut self, capacity: NonZeroUsize)
pub fn set_compile_cache_capacity(&mut self, capacity: NonZeroUsize)
Resize the compiled-program cache.
§Examples
use std::num::NonZeroUsize;
use tenferro_runtime::GraphCompiler;
let mut compiler = GraphCompiler::new();
compiler.set_compile_cache_capacity(NonZeroUsize::new(2).unwrap());
assert_eq!(compiler.compile_cache_capacity().get(), 2);Sourcepub fn compiler_options(&self) -> CompilerOptions
pub fn compiler_options(&self) -> CompilerOptions
Return the compiler options used for future graph lowerings.
§Examples
use tenferro_runtime::CompilerOptions;
use tenferro_runtime::GraphCompiler;
let compiler = GraphCompiler::new();
assert_eq!(compiler.compiler_options(), CompilerOptions::default());Sourcepub fn set_compiler_options(&mut self, compiler_options: CompilerOptions)
pub fn set_compiler_options(&mut self, compiler_options: CompilerOptions)
Replace compiler options and clear compiled graph cache entries.
§Examples
use tenferro_runtime::{CompilerOptions, OptimizerConfig};
use tenferro_runtime::GraphCompiler;
let mut compiler = GraphCompiler::new();
let options = CompilerOptions {
optimizer: OptimizerConfig {
dot_decomposer: true,
..OptimizerConfig::default()
},
};
compiler.set_compiler_options(options);
assert_eq!(compiler.compiler_options(), options);
assert_eq!(compiler.compile_cache_len(), 0);Sourcepub fn clear_compile_cache(&mut self)
pub fn clear_compile_cache(&mut self)
Clear the compiled-program cache.
§Examples
use tenferro_runtime::GraphCompiler;
let mut compiler = GraphCompiler::new();
compiler.clear_compile_cache();
assert_eq!(compiler.compile_cache_len(), 0);Sourcepub fn clear_extension_caches(&mut self)
pub fn clear_extension_caches(&mut self)
Clear generic extension compile-time cache entries.
§Examples
use tenferro_runtime::GraphCompiler;
let mut compiler = GraphCompiler::new();
compiler.clear_extension_caches();
assert_eq!(compiler.cache_stats().extensions.entries, 0);Sourcepub fn clear_caches(&mut self)
pub fn clear_caches(&mut self)
Clear every cache owned by the compiler.
§Examples
use tenferro_runtime::GraphCompiler;
let mut compiler = GraphCompiler::new();
compiler.clear_caches();
assert_eq!(compiler.cache_stats().compile.entries, 0);Sourcepub fn cache_stats(&self) -> GraphCompilerCacheStats
pub fn cache_stats(&self) -> GraphCompilerCacheStats
Return cache-entry and retained-byte stats.
§Examples
use tenferro_runtime::GraphCompiler;
let compiler = GraphCompiler::new();
let stats = compiler.cache_stats();
assert_eq!(stats.compile.entries, 0);Sourcepub fn extension_caches(&self) -> &ExtensionCacheStore
pub fn extension_caches(&self) -> &ExtensionCacheStore
Borrow generic extension compile-time cache storage.
§Examples
use tenferro_runtime::GraphCompiler;
let compiler = GraphCompiler::new();
assert!(compiler.extension_caches().is_empty());Sourcepub fn extension_caches_mut(&mut self) -> &mut ExtensionCacheStore
pub fn extension_caches_mut(&mut self) -> &mut ExtensionCacheStore
Mutably borrow generic extension compile-time cache storage.
§Examples
use tenferro_runtime::GraphCompiler;
let mut compiler = GraphCompiler::new();
compiler.extension_caches_mut().clear();