Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# computegraph-rs

AD-agnostic tensor computation graph engine in Rust.
Operation-agnostic computation graph engine in Rust.

Provides fragment-based graph construction, logical resolution,
Provides graph construction, logical resolution,
physical materialization, SSA compilation, and evaluation.

Fully generic over `Op: GraphOp` — never references specific primitives.
Fully generic over `Operation: GraphOperation`; it never references specific
primitive operation sets.

## Part of the tensor4all v2 stack

```text
computegraph-rs ← this crate
chainrules-rs ← AD trait definitions
tidu-rs ← AD graph transforms
tenferro-rs ← concrete tensor primitives
```
24 changes: 12 additions & 12 deletions src/compile.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
use std::collections::HashMap;

use crate::materialize::MaterializedGraph;
use crate::traits::GraphOp;
use crate::types::GlobalValKey;
use crate::traits::GraphOperation;
use crate::types::ValueKey;

/// A single instruction in the compiled program.
pub struct Instruction<Op: GraphOp> {
pub op: Op,
pub struct Instruction<Op: GraphOperation> {
pub operation: Op,
pub inputs: Vec<usize>,
pub outputs: Vec<usize>,
}

/// SSA-form compiled program. Each slot is written exactly once.
pub struct CompiledProgram<Op: GraphOp> {
pub struct CompiledProgram<Op: GraphOperation> {
pub instructions: Vec<Instruction<Op>>,
pub input_slots: Vec<usize>,
pub output_slots: Vec<usize>,
pub n_slots: usize,
}

/// Compiles a materialized graph into an SSA instruction sequence.
pub fn compile<Op: GraphOp>(graph: &MaterializedGraph<Op>) -> CompiledProgram<Op> {
pub fn compile<Op: GraphOperation>(graph: &MaterializedGraph<Op>) -> CompiledProgram<Op> {
let instructions = graph
.ops
.operations
.iter()
.map(|op_node| Instruction {
op: op_node.op.clone(),
operation: op_node.operation.clone(),
inputs: op_node.inputs.clone(),
outputs: op_node.outputs.clone(),
})
.collect();

let input_slots = graph
.vals
.values
.iter()
.enumerate()
.filter(|(_, val)| val.producer.is_none())
.map(|(index, _)| index)
.collect();

let key_to_index: HashMap<&GlobalValKey<Op>, usize> = graph
.vals
let key_to_index: HashMap<&ValueKey<Op>, usize> = graph
.values
.iter()
.enumerate()
.map(|(index, val)| (&val.key, index))
Expand All @@ -67,6 +67,6 @@ pub fn compile<Op: GraphOp>(graph: &MaterializedGraph<Op>) -> CompiledProgram<Op
instructions,
input_slots,
output_slots,
n_slots: graph.vals.len(),
n_slots: graph.values.len(),
}
}
8 changes: 4 additions & 4 deletions src/eval.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::compile::CompiledProgram;
use crate::traits::EvalGraphOp;
use crate::traits::EvaluableGraphOperation;

impl<Op: EvalGraphOp> CompiledProgram<Op> {
impl<Op: EvaluableGraphOperation> CompiledProgram<Op> {
/// Executes the compiled program with the given inputs.
pub fn eval(&self, ctx: &mut Op::Context, inputs: &[&Op::Operand]) -> Vec<Op::Operand> {
assert_eq!(
Expand Down Expand Up @@ -31,12 +31,12 @@ impl<Op: EvalGraphOp> CompiledProgram<Op> {
})
.collect();

let outputs = instruction.op.eval(ctx, &input_vals);
let outputs = instruction.operation.eval(ctx, &input_vals);
assert_eq!(
outputs.len(),
instruction.outputs.len(),
"operation {:?} produced {} outputs, expected {}",
instruction.op,
instruction.operation,
outputs.len(),
instruction.outputs.len()
);
Expand Down
196 changes: 0 additions & 196 deletions src/fragment.rs

This file was deleted.

Loading
Loading