Experimental machine learning framework featuring a graph-based JIT compiler.
- Compile-time shape, dtype, and device checking
- Opt-in half-precision (
f16) and bfloat16 (bf16) support - Advanced AI compiler optimizations:
- Elementwise JIT kernel fusion
- Automatic inlining and in-placing
- Constant folding
- Dead code elimination
- Multi-device support (CPU, optional CUDA)
- Graph visualization (requires Graphviz)
- Zero-cost abstractions with idiomatic Rust API
Add constensor-core to your Cargo.toml:
[dependencies]
constensor-core = "0.1.1"To enable optional features (CUDA, half-precision, bfloat16):
[dependencies.constensor-core]
version = "0.1.1"
features = ["cuda", "half", "bfloat"]Or using cargo add:
cargo add constensor-coreuse constensor_core::{Cpu, Graph, GraphTensor, Tensor, R2};
fn main() {
// Create an empty computation graph
let mut graph: Graph<f32> = Graph::empty();
// Define graph tensors
let x = GraphTensor::<R2<3, 4>, f32, Cpu>::fill(&mut graph, 1.0);
let y = GraphTensor::<R2<3, 4>, f32, Cpu>::fill(&mut graph, 2.0);
// Build computation
let z = y.clone() + y * x;
// Optimize the graph
graph.optimize();
// Visualize the optimized graph (requires Graphviz)
graph.visualize("graph.png").unwrap();
// Execute and retrieve the result
let tensor: Tensor<R2<3, 4>, f32, Cpu> = z.to_tensor().unwrap();
assert_eq!(tensor.data().unwrap().to_vec(), vec![vec![4.0; 4]; 3]);
}Run the provided examples:
cargo run --example hello_world --features half
cargo run --example matmul --features cuda,bfloatSee more examples in constensor-core/examples.
API documentation is available on docs.rs.
Contributions are welcome! Please open issues and submit pull requests.
-
Run tests with all features:
cargo test --workspace --features "cuda half bfloat"
-
Format code:
cargo fmt --all -
Lint code:
cargo clippy --all-targets -- -D warnings
Licensed under MIT. See LICENSE for details.