Skip to main content

Module loop_fusion

Module loop_fusion 

Source
Expand description

Loop fusion optimization pass.

This module provides optimization passes that fuse multiple loops/reductions over the same axes to improve cache locality and reduce memory traffic.

§Overview

Loop fusion combines multiple consecutive operations that iterate over the same axis into a single fused operation. This optimization:

  • Reduces memory traffic (fewer intermediate tensors)
  • Improves cache locality (better temporal locality)
  • Reduces loop overhead (fewer loop iterations)

§Fusion Criteria

Two loops can be fused if:

  1. They iterate over the same axis/axes
  2. They have compatible domains
  3. There are no dependencies that prevent fusion
  4. The fused operation doesn’t exceed memory constraints

§Examples

use tensorlogic_compiler::passes::fuse_loops;
use tensorlogic_ir::EinsumGraph;

let graph = EinsumGraph::new();
let (fused_graph, stats) = fuse_loops(&graph);

Structs§

LoopFusionConfig
Configuration for loop fusion optimization.
LoopFusionStats
Statistics from loop fusion optimization.

Functions§

estimate_fusion_benefit
Estimate the benefit of fusing a group of nodes.
fuse_loops
Fuse loops in an einsum graph.
fuse_loops_with_config
Fuse loops with custom configuration.