Skip to main content

Module executor

Module executor 

Source
Expand description

Execution engine for evaluating compute graphs against a KernelRegistry.

An Executor is responsible for:

  • validating runtime input bindings,
  • traversing a Graph in topological order,
  • dispatching each non-input node to its registered kernel, and
  • returning the tensors for all nodes marked as graph outputs.

Execution is deterministic with respect to graph topology because it relies on Graph::topo_sort, which returns a stable topological order.

§Input Binding Model

Execution requires one tensor binding for every OpKind::Input node in the graph. Bindings are passed as a Vec<(NodeId, Tensor)>, where:

  • the NodeId identifies an input node in the graph, and
  • the Tensor is the runtime value to supply for that input.

Bindings are validated before execution begins:

  • each bound node must exist in the graph,
  • each bound node must be an input node,
  • each input node must be bound exactly once, and
  • each bound tensor must match the input node’s declared shape.

§Output Model

The executor returns a HashMap<NodeId, Tensor> containing the computed tensors for all nodes designated as outputs via Graph::set_output_node.

Output values are keyed by the output node’s NodeId. Output ordering is not part of the API contract.

§Errors

Execution may fail for several classes of reasons:

  • graph-level failures (for example, invalid topology),
  • invalid runtime bindings,
  • missing kernel implementations, or
  • kernel execution failures at a specific node.

These are reported via ExecutionError.

§Examples

let mut g = Graph::new();
let a = g.input_node(vec![2, 2]);
let b = g.input_node(vec![2, 2]);
let c = g.add(a, b).expect("Valid add operation should succeed");
g.set_output_node(c).expect("Valid output node should succeed");

let a_tensor = Tensor::zeros(vec![2, 2]).expect("Tensor allocation should succeed");
let b_tensor = Tensor::zeros(vec![2, 2]).expect("Tensor allocation should succeed");

let exec = Executor::new(KernelRegistry::default());
let outputs = exec
    .execute(&g, vec![(a, a_tensor), (b, b_tensor)])
    .expect("Execution should succeed");

assert!(outputs.contains_key(&c));

Structs§

Executor
Executes graphs using kernels registered in a KernelRegistry.

Enums§

ExecutionError
Errors that may occur while validating bindings or executing a graph.