Domain Flow Repo Software Architecture
This file provides guidance when working with code in this repository.
Project Overview
Section titled “Project Overview”Domain Flow Architecture (DFA) is a header-only C++ library for building parallelizing compilers that analyze and optimize DL (Deep Learning) graphs. The project implements tools to read and analyze MLIR bytecode, finding efficient schedules and spatial reductions for executing DL graphs on various hardware configurations.
Core Concept
Section titled “Core Concept”The architecture represents DL graphs as domain flow graphs - chains of operators where each operator:
- Is defined by a System of Uniform or Affine Recurrence Equations (SURE or SARE)
- Has a domain of computation derived from tensor operands
- Executes in hypothesized multi-dimensional data paths
Unlike MLIR’s linalg/affine dialects, which represent loop nests and memory views, the DFA dialect represents operators and domain flows with the goal of finding spatial reductions that avoid resource contention.
Build System
Section titled “Build System”Prerequisites
Section titled “Prerequisites”- CMake 3.28+
- C++20 compiler (GCC 10+, Clang 12+, MSVC 2022+)
- vcpkg (Windows only, for dependency management)
- LLVM/MLIR (optional, only for MLIR tools)
Platform notes:
- Linux/macOS: Uses native system packages (apt, dnf, brew)
- Windows: Uses vcpkg for C++ dependencies
CMake Configuration Strategy
Section titled “CMake Configuration Strategy”The project uses CMake Presets with platform-specific templates:
- CMakePresets.json (committed) - Shared base presets, platform-agnostic
- CMakeUserPresets.json.Linux.template (committed) - Linux configuration template (no vcpkg)
- CMakeUserPresets.json.Windows.template (committed) - Windows configuration template (with vcpkg)
- CMakeUserPresets.json (gitignored) - Your personal configuration
Initial Setup - Linux
Section titled “Initial Setup - Linux”# 1. Copy the Linux templatecp CMakeUserPresets.json.Linux.template CMakeUserPresets.json
# 2. Edit to set your LLVM path (if using MLIR tools)# Linux uses native system packages, no vcpkg neededInitial Setup - Windows
Section titled “Initial Setup - Windows”# 1. Setup vcpkg (Windows only)git clone https://github.com/Microsoft/vcpkg.gitcd vcpkg.\bootstrap-vcpkg.bat
# 2. Copy the Windows templatecp CMakeUserPresets.json.Windows.template CMakeUserPresets.json
# 3. Edit to set your paths:# - VCPKG_ROOT: C:/path/to/vcpkg# - LLVM_PROJECT_ROOT: C:/path/to/llvm-project (if using MLIR)See SETUP.md for complete platform-specific setup instructions.
Available Base Presets
Section titled “Available Base Presets”Inherit from these in CMakeUserPresets.json:
Ninja-Debug/Ninja-Release: Ninja generator builds (all platforms)VS17-Debug/VS17-Release: Visual Studio 2022 builds (Windows)
Platform-specific requirements:
- Linux: No vcpkg, uses native system packages
- Windows: Uses vcpkg for dependencies (add
CMAKE_TOOLCHAIN_FILEin user presets) - LLVM/MLIR: Set
LLVM_PROJECT_ROOTenvironment variable in user presets
Build Options
Section titled “Build Options”Configure with CMake options (all default to OFF unless noted):
# Core options-DBUILD_TESTING=ON # CMake standard; default for DOMAINFLOW_BUILD_TESTING when root-DDOMAINFLOW_BUILD_TESTING=ON # Build and register tests (default: BUILD_TESTING as root, OFF as subproject)-DDOMAINFLOW_VERBOSE_TESTS=ON # Print all test output
# Feature toggles-DDOMAINFLOW_TOOLS=ON # Enable dfg/rdg tools-DDOMAINFLOW_POLYHEDRAL=ON # Enable polyhedral tools (default: ON)-DDOMAINFLOW_MLIR_TOOLS=ON # Enable MLIR integration (requires LLVM)-DDOMAINFLOW_DSE=ON # Enable design space exploration tools-DDOMAINFLOW_VISUALIZATION=ON # Enable visualization tools-DDOMAINFLOW_MATPLOT_TOOLS=ON # Enable matplotlib plotting-DDOMAINFLOW_DATABASE_TOOLS=ON # Enable database toolsBuild Commands
Section titled “Build Commands”After setting up CMakeUserPresets.json:
# Configure using your user preset (creates build/user-ninja-release/)cmake --preset user-ninja-release
# Build all targetscmake --build build/user-ninja-release
# Run testsctest --test-dir build/user-ninja-release
# Or build with optionscmake --preset user-ninja-release -DDOMAINFLOW_TOOLS=ON -DDOMAINFLOW_DSE=ONcmake --build build/user-ninja-releaseImportant: The build directory name matches your preset name (e.g., build/user-ninja-release/), not the base preset name.
Cleaning Build
Section titled “Cleaning Build”If you encounter CMake cache issues:
rm -rf build/user-ninja-releasecmake --preset user-ninja-releaseTesting
Section titled “Testing”Tests are organized by component:
src/json/tests/- JSON library testssrc/graph/tests/- Base graph library testssrc/dfa/tests/- Domain flow architecture testssrc/dfa/tests/sim/- SURE simulator tests (functional simulation, schedule legality, .dfg import)
To run a single test executable:
./build/Ninja-Release/bin/dfa_test_nameArchitecture
Section titled “Architecture”Header-Only Library Structure
Section titled “Header-Only Library Structure”All core functionality is header-only in include/:
include/dfa/- Domain flow architecture coreinclude/graph/- Base graph data structuresinclude/energy/- Energy modeling and estimationinclude/util/- Utilities
The src/dfa/ directory contains only legacy skeleton CMakeLists files (as of 2025-03-29).
Key Components
Section titled “Key Components”Domain Flow Graph (include/dfa/domain_flow_graph.hpp)
Section titled “Domain Flow Graph (include/dfa/domain_flow_graph.hpp)”- Built on
sw::graph::directed_graph<DomainFlowNode, DomainFlowEdge> - Tracks source and sink nodes for domain flow
- Supports node depth assignment and subgraph extraction
- Key methods:
addNode(),addEdge(),assignNodeDepths(),distributeConstants()
Domain of Computation (include/dfa/domain_of_computation.hpp)
Section titled “Domain of Computation (include/dfa/domain_of_computation.hpp)”- Represents the index space over which an operator computes
- Defined by constraint sets (affine inequalities)
- Used for dependency analysis and scheduling
Core Abstractions
Section titled “Core Abstractions”- Operators (
domain_flow_operator.hpp): Computation nodes defined by affine recurrence equations - Index Spaces (
index_space.hpp): Multi-dimensional iteration domains - Schedules (
schedule.hpp): Mappings from computation space to time - Wavefronts (
wavefront.hpp): Parallel execution fronts - Transformations (
transformation.hpp): Affine loop transformations
SURE Simulator (include/dfa/sim/)
Section titled “SURE Simulator (include/dfa/sim/)”A standalone, header-only functional simulator for Systems of Uniform/Affine
Recurrence Equations: numeric evaluation with boundary/operand semantics,
free schedule derivation, schedule legality checking (tau.theta >= 1),
memory-cardinality (peak live values) analysis, eviction-based execution, and a
.dfg import path that lowers DomainFlowGraphs into runnable recurrence systems.
See docs/sure-simulator.md for the why/what/how with worked examples.
dfg tools (tools/dfg/)
Section titled “dfg tools (tools/dfg/)”Domain flow graph analysis and manipulation:
analyzer.cpp- Graph analysisdomain_flow.cpp- DFG constructionwavefront.cpp- Wavefront extractionpipeline_alignment.cpp- Pipeline schedulingdomain_confluence.cpp- Domain merging analysis
dfactl (sim/)
Section titled “dfactl (sim/)”The SURE simulator CLI (built with DOMAINFLOW_TOOLS=ON): runs built-in recurrence
specs (matmul, matvec, qr) or imported .dfg graphs under free or linear
schedules, and reports legality and memory cardinality. See docs/sure-simulator.md.
dse tools (tools/dse/)
Section titled “dse tools (tools/dse/)”Design space exploration for finding optimal hardware mappings.
opt tools (tools/opt/)
Section titled “opt tools (tools/opt/)”MLIR optimization pass tools. Requires LLVM/MLIR:
dfa-opt: MLIR optimizer with DFA passes- Links against MLIR dialects: TOSA, Linalg, Tensor, Func, etc.
import tools (tools/import/)
Section titled “import tools (tools/import/)”MLIR import utilities for converting MLIR bytecode to DFG.
MLIR Integration
Section titled “MLIR Integration”When DOMAINFLOW_MLIR_TOOLS=ON, the project integrates with LLVM/MLIR:
include/dfa/mlir/- MLIR dialect interfaces (TOSA, Torch, StableHLO)include/dfa/dfa_mlir.hpp- MLIR-DFA bridge- Requires
MLIR_DIRpointing to MLIR CMake config
Workloads
Section titled “Workloads”workloads/ contains example DFG generators:
workloads/dnn/- Deep neural network workloadsworkloads/nla/- Numerical linear algebraworkloads/dsp/- Digital signal processingworkloads/cnn/- Convolutional neural networksworkloads/ctl/- Control flow examplesworkloads/dfa/- Domain flow specific examples
Development Workflow
Section titled “Development Workflow”Adding New DFG Operators
Section titled “Adding New DFG Operators”- Define operator in
include/dfa/domain_flow_operator.hpp - Implement domain computation in
include/dfa/domain_of_computation.hpp - Add test in
src/dfa/tests/ - Optionally add workload example in
workloads/
Working with Tests
Section titled “Working with Tests”Each .cpp file in test directories becomes a separate executable via the compile_all macro. Tests are automatically discovered and registered with CTest when DOMAINFLOW_BUILD_TESTING=ON.
Debugging
Section titled “Debugging”The DOMAINFLOW_CMAKE_TRACE option enables verbose CMake variable tracing during configuration.
Historical Context
Section titled “Historical Context”Domain Flow Architecture originates from E. Theodore Omtzigt’s Yale PhD dissertation (1990-1993) “Domain Flow and Streaming Architectures: A Paradigm for Efficient Parallel Computation”. The approach emphasizes:
- Minimizing data movement (primary energy cost)
- Maximizing concurrency and data locality
- Streaming execution driven by data availability
- Static scheduling for efficient resource usage
See docs/domain-flow-history.md for detailed comparison with systolic arrays, spatial dataflow accelerators, CGRAs, and neuromorphic architectures.
Key Design Principles
Section titled “Key Design Principles”- Data Movement Minimization: Domain flows are designed to maximize on-chip data reuse
- Static Scheduling: Compile-time analysis determines execution order
- Spatial Mapping: Algorithms map to hardware fabric topologies
- Domain Decomposition: Problems structured by their computational domains
- Header-Only Design: Ease of integration without library dependencies