# nwchemex/tamm architecture

> Architecture diagram of the GitHub repository nwchemex/tamm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nwchemex/tamm
- Repository: https://github.com/nwchemex/tamm

## Overview

1. **What this repository is**
   TAMM is a C++ tensor-algebra runtime and library for many-body scientific computing. The core abstraction is a labeled, tiled tensor system aimed at distributed-memory and accelerator-enabled execution, with Python bindings for higher-level use and extensive domain tests for coupled-cluster workflows.

2. **Top-level layers**
   The codebase is split into:
   - `src/tamm`: the C++ library core
   - `src/python`: the Python extension module
   - `tests`: C++ and Python validation suites
   - `docs`: user/developer documentation
   - `support` and `.github`: build, CI, and HPC deployment helpers  
   This is a library-centric repo, not an application server or standalone service.

3. **Public API and tensor model**
   The main user-facing types live under `src/tamm` and include `tensor`, `labeled_tensor`, `local_tensor`, `tiled_index_space`, `index_space`, `proc_group`, and related utilities. These types define how tensors are named, partitioned into tiles, and mapped onto process groups. The API is designed around algebraic expressions and tensor operations rather than direct raw array manipulation.

4. **Indexing and distribution boundary**
   A major architectural boundary is between symbolic tensor structure and physical placement. `index_space`, `tiled_index_space`, `distribution`, `proc_grid`, `proc_group`, `perm`, `range`, and `boundvec` define the index topology and how tiles are distributed across processes. This layer is what enables both dense and block-sparse style computations in distributed memory.

5. **Operation graph and execution flow**
   Tensor expressions are lowered into an operation DAG and then scheduled/executed. Key components here are `op_base`, `ops`, `op_dag`, `op_executor`, `scheduler`, `runtime_engine`, `work`, and `dag_impl`. The flow is: user tensor expression → operation nodes → dependency analysis → execution plan → runtime dispatch. This is central to how TAMM coordinates multi-step tensor contractions, assignments, and reductions.

6. **Kernel and block operation layer**
   Actual numerical work is separated into block-level plans and kernels. Files such as `block_assign_plan`, `block_mult_plan`, `block_set_plan`, `block_lambda_plan`, `block_operations`, `kernels/assign.hpp`, `kernels/multiply.hpp`, and `kernels/tamm_blas.hpp` show a layered design:
   - high-level tensor ops are decomposed into block operations
   - block ops call CPU/GPU BLAS or specialized transforms
   - block plans handle iteration, staging, and execution order  
   This is the compute boundary where algebraic operations become concrete kernel invocations.

7. **Memory management and buffering**
   TAMM has its own memory subsystem for host, pinned, device, and pooled allocations. The `memory_manager*` files and `mr/` directory provide the resource layer, including host/device/pinned/stream-ordered memory resources, pools, free lists, and per-device management. Supporting pieces like `block_buffer`, `block_scratch`, `local_tensor`, and `spin_tensor` help manage temporary storage and tile residency during execution. This subsystem is important for understanding data movement and performance.

8. **Distributed runtime and communication backends**
   The repository includes explicit support for multiple distributed-memory backends. The presence of `ga_over_upcxx.hpp`, `memory_manager_ga.hpp`, and GA-related tests indicates integration with Global Arrays; `proc_group` and MPI collective tests show MPI-based coordination; `upcxx` support is present through the GA-over-UPC++ bridge. This means TAMM’s execution model can span multiple processes and relies on backend communication libraries rather than a single monolithic runtime.

9. **Accelerator and math-library integration**
   Numeric kernels are split across CPU and GPU implementations (`kernels/cpu_blas.cpp`, `kernels/gpu_blas.cpp`), with device/runtime helpers such as `gpu_streams.hpp`, `sycl_device.hpp`, and `rmm_memory_pool.hpp`. The repo also includes `eigen_*` helpers and `ip_hptt.hpp`, suggesting use of Eigen for some host-side linear algebra and HPTT-style tensor transpositions/permutations. The architecture therefore bridges symbolic tensor ops to heterogeneous backends.

10. **Python binding boundary**
   `src/python/pytamm.cpp` builds a Python extension module that exposes the C++ TAMM functionality. The Python tests cover tensor construction, operations, index spaces, I/O, and coupled-cluster examples, so the binding layer is not a thin utility wrapper; it is a first-class interface for scientific workflows and validation.

11. **Domain examples and correctness coverage**
   The `tests/tamm/coupledcluster` and `tests/python/coupledcluster` trees show that coupled-cluster chemistry is the primary workload model. The repo also includes broad unit coverage for index spaces, DAGs, tensors, memory profiling, ops, and binding equivalence, plus GA/MPI tests. This suggests the architecture is validated at three levels: core tensor algebra, distributed/runtime integration, and domain-specific end-to-end scientific methods.

12. **Build, packaging, and deployment**
   The project is CMake-driven (`CMakeLists.txt`, per-subdirectory CMake files) with Docker, ReadTheDocs, formatting hooks, and GitHub Actions CI. The `support/jobscripts` directory contains machine-specific launch scripts for HPC systems such as Aurora, Frontier, Perlmutter, and Polaris, indicating the library is intended to run on large-scale supercomputers and needs environment-specific launch/binding configuration.

13. **How data typically flows through the system**
   In the common execution path, a user defines index spaces and tiled tensors, composes operations, and submits them through the TAMM API or Python layer. The runtime builds a DAG, schedules dependent work, pulls tile data through the memory manager, invokes CPU/GPU kernels for each block, and coordinates distributed movement across process groups and communication backends. The result is a layered architecture with clear separation between symbolic tensor definitions, execution planning, memory orchestration, and backend compute/communication.

Main entry points: [`src/tamm/tamm.hpp`](https://github.com/nwchemex/tamm/blob/main/src/tamm/tamm.hpp) (Tensor API), [`src/tamm/block_operations.hpp`](https://github.com/nwchemex/tamm/blob/main/src/tamm/block_operations.hpp) (Block Plans), [`src/tamm/ga_over_upcxx.hpp`](https://github.com/nwchemex/tamm/blob/main/src/tamm/ga_over_upcxx.hpp) (Backends), [`src/tamm/memory_manager.hpp`](https://github.com/nwchemex/tamm/blob/main/src/tamm/memory_manager.hpp) (Memory)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["C++ Core"]
  node_tensor_api["Tensor API<br/>public C++ API<br/>[tamm.hpp]"]
  node_tensors["Tensors<br/>tensor model<br/>[tensor.hpp]"]
  node_indexing["Indexing<br/>index topology<br/>[index_space.hpp]"]
  node_distribution["Distribution<br/>placement layer<br/>[proc_group.hpp]"]
  node_ops["Ops DAG<br/>operation graph<br/>[op_dag.hpp]"]
  node_scheduler["Scheduler<br/>execution planner<br/>[scheduler.hpp]"]
  node_runtime["Runtime<br/>dispatch engine<br/>[runtime_engine.hpp]"]
  node_blocks["Block Plans<br/>block execution"]
  node_kernels["Kernels<br/>[tamm_blas.hpp]"]
  node_memory[("Memory<br/>[memory_manager.hpp]")]
  node_backend_comm["Backends<br/>distributed backend<br/>[ga_over_upcxx.hpp]"]
  node_gpu["GPU Support<br/>heterogeneous runtime<br/>[gpu_streams.hpp]"]
end

subgraph group_bindings["Bindings"]
  node_python_ext["PyTAMM<br/>python extension<br/>[pytamm.cpp]"]
end

subgraph group_validation["Validation"]
  node_cpp_tests["C++ Tests<br/>core validation<br/>[Test_Tensors.cpp]"]
  node_cc_tests["CC Workflows<br/>domain tests<br/>[Test_CCSD.cpp]"]
  node_py_tests["Python Tests<br/>binding validation<br/>[Test_Tensors.py]"]
end

subgraph group_support["Tooling"]
  node_docs["Docs<br/>[index.rst]"]
  node_build_ci["Build & CI<br/>build system<br/>[CMakeLists.txt]"]
  node_hpc_jobs["HPC Jobs<br/>deployment scripts"]
end

node_tensor_api -->|"defines"| node_tensors
node_tensor_api -->|"uses"| node_indexing
node_tensor_api -->|"lowers to"| node_ops
node_indexing -->|"maps to"| node_distribution
node_ops -->|"analyzed by"| node_scheduler
node_scheduler -->|"drives"| node_runtime
node_runtime -->|"dispatches"| node_blocks
node_blocks -->|"invokes"| node_kernels
node_blocks -->|"uses"| node_memory
node_memory -->|"integrates"| node_backend_comm
node_memory -->|"allocates"| node_gpu
node_kernels -->|"supports"| node_gpu
node_backend_comm -->|"coordinates"| node_distribution
node_python_ext -->|"binds"| node_tensor_api
node_py_tests -->|"validates"| node_python_ext
node_cpp_tests -->|"validates"| node_tensor_api
node_cc_tests -->|"exercises"| node_blocks
node_cc_tests -->|"exercises"| node_backend_comm
node_docs -->|"documents"| node_tensor_api
node_build_ci -->|"builds"| node_python_ext
node_build_ci -->|"runs"| node_cpp_tests
node_hpc_jobs -->|"deploys"| node_backend_comm

click node_tensor_api "https://github.com/nwchemex/tamm/blob/main/src/tamm/tamm.hpp"
click node_tensors "https://github.com/nwchemex/tamm/blob/main/src/tamm/tensor.hpp"
click node_indexing "https://github.com/nwchemex/tamm/blob/main/src/tamm/index_space.hpp"
click node_distribution "https://github.com/nwchemex/tamm/blob/main/src/tamm/proc_group.hpp"
click node_ops "https://github.com/nwchemex/tamm/blob/main/src/tamm/op_dag.hpp"
click node_scheduler "https://github.com/nwchemex/tamm/blob/main/src/tamm/scheduler.hpp"
click node_runtime "https://github.com/nwchemex/tamm/blob/main/src/tamm/runtime_engine.hpp"
click node_blocks "https://github.com/nwchemex/tamm/blob/main/src/tamm/block_operations.hpp"
click node_kernels "https://github.com/nwchemex/tamm/blob/main/src/tamm/kernels/tamm_blas.hpp"
click node_memory "https://github.com/nwchemex/tamm/blob/main/src/tamm/memory_manager.hpp"
click node_backend_comm "https://github.com/nwchemex/tamm/blob/main/src/tamm/ga_over_upcxx.hpp"
click node_gpu "https://github.com/nwchemex/tamm/blob/main/src/tamm/gpu_streams.hpp"
click node_python_ext "https://github.com/nwchemex/tamm/blob/main/src/python/pytamm.cpp"
click node_cpp_tests "https://github.com/nwchemex/tamm/blob/main/tests/tamm/Test_Tensors.cpp"
click node_cc_tests "https://github.com/nwchemex/tamm/blob/main/tests/tamm/coupledcluster/Test_CCSD.cpp"
click node_py_tests "https://github.com/nwchemex/tamm/blob/main/tests/python/Test_Tensors.py"
click node_docs "https://github.com/nwchemex/tamm/blob/main/docs/index.rst"
click node_build_ci "https://github.com/nwchemex/tamm/blob/main/CMakeLists.txt"
click node_hpc_jobs "https://github.com/nwchemex/tamm/tree/main/support/jobscripts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_tensor_api,node_tensors,node_indexing,node_distribution,node_ops,node_scheduler,node_runtime,node_blocks,node_kernels,node_memory,node_backend_comm,node_gpu toneBlue
class node_python_ext toneAmber
class node_cpp_tests,node_cc_tests,node_py_tests toneMint
class node_docs,node_build_ci,node_hpc_jobs toneRose
```

## Components

### C++ Core

Primary tensor-algebra runtime and library implementation.

- [Tensor API](https://github.com/nwchemex/tamm/blob/main/src/tamm/tamm.hpp): public C++ API · User-facing tensor objects and expression surface. · `src/tamm/tamm.hpp`
- [Tensors](https://github.com/nwchemex/tamm/blob/main/src/tamm/tensor.hpp): tensor model · Tensor, labeled tensor, local tensor, and storage variants. · `src/tamm/tensor.hpp`
- [Indexing](https://github.com/nwchemex/tamm/blob/main/src/tamm/index_space.hpp): index topology · Index spaces, tiled index spaces, ranges, permutations, and bounds. · `src/tamm/index_space.hpp`
- [Distribution](https://github.com/nwchemex/tamm/blob/main/src/tamm/proc_group.hpp): placement layer · Process groups, grids, and tile-to-process mapping. · `src/tamm/proc_group.hpp`
- [Ops DAG](https://github.com/nwchemex/tamm/blob/main/src/tamm/op_dag.hpp): operation graph · Operation nodes, dependencies, and lowering of tensor expressions. · `src/tamm/op_dag.hpp`
- [Scheduler](https://github.com/nwchemex/tamm/blob/main/src/tamm/scheduler.hpp): execution planner · Dependency analysis, work scheduling, and runtime coordination. · `src/tamm/scheduler.hpp`
- [Runtime](https://github.com/nwchemex/tamm/blob/main/src/tamm/runtime_engine.hpp): dispatch engine · Execution context and runtime engine that drive operation execution. · `src/tamm/runtime_engine.hpp`
- [Block Plans](https://github.com/nwchemex/tamm/blob/main/src/tamm/block_operations.hpp): block execution · Block-level assign, multiply, set, and lambda plans. · `src/tamm/block_operations.hpp`
- [Kernels](https://github.com/nwchemex/tamm/blob/main/src/tamm/kernels/tamm_blas.hpp): numeric kernels · CPU/GPU BLAS and tensor kernel entry points. · `src/tamm/kernels/tamm_blas.hpp`
- [Memory](https://github.com/nwchemex/tamm/blob/main/src/tamm/memory_manager.hpp): memory subsystem · Memory managers, resources, buffering, and scratch storage. · `src/tamm/memory_manager.hpp`
- [Backends](https://github.com/nwchemex/tamm/blob/main/src/tamm/ga_over_upcxx.hpp): distributed backend · MPI/GA/UPC++-oriented communication and memory integration. · `src/tamm/ga_over_upcxx.hpp`
- [GPU Support](https://github.com/nwchemex/tamm/blob/main/src/tamm/gpu_streams.hpp): heterogeneous runtime · GPU streams, device helpers, and accelerator memory pool integration. · `src/tamm/gpu_streams.hpp`

### Bindings

Python extension layer for higher-level use.

- [PyTAMM](https://github.com/nwchemex/tamm/blob/main/src/python/pytamm.cpp): python extension · C++ extension module exposing TAMM to Python. · `src/python/pytamm.cpp`

### Validation

C++ and Python tests, including coupled-cluster workflows.

- [C++ Tests](https://github.com/nwchemex/tamm/blob/main/tests/tamm/Test_Tensors.cpp): core validation · Unit and integration tests for tensors, DAGs, memory, and process groups. · `tests/tamm/Test_Tensors.cpp`
- [CC Workflows](https://github.com/nwchemex/tamm/blob/main/tests/tamm/coupledcluster/Test_CCSD.cpp): domain tests · Coupled-cluster and DLPNO scientific workflow validation. · `tests/tamm/coupledcluster/Test_CCSD.cpp`
- [Python Tests](https://github.com/nwchemex/tamm/blob/main/tests/python/Test_Tensors.py): binding validation · Python-side API, tensor, I/O, and coupled-cluster tests. · `tests/python/Test_Tensors.py`

### Tooling

Build, docs, CI, and HPC launch helpers.

- [Docs](https://github.com/nwchemex/tamm/blob/main/docs/index.rst): user/developer docs · User guide, developer guide, and API documentation source. · `docs/index.rst`
- [Build & CI](https://github.com/nwchemex/tamm/blob/main/CMakeLists.txt): build system · CMake, GitHub Actions, Docker, and release automation. · `CMakeLists.txt`
- [HPC Jobs](https://github.com/nwchemex/tamm/tree/main/support/jobscripts): deployment scripts · System-specific job scripts and launch helpers for supercomputers. · `support/jobscripts`

## Connections

- Tensor API → Tensors: defines · Public API is built around tensor object types.
- Tensor API → Indexing: uses · Tensor construction depends on symbolic index structure.
- Tensor API → Ops DAG: lowers to · Tensor expressions are converted into operation graphs.
- Indexing → Distribution: maps to · Index topology is placed onto process groups and grids.
- Ops DAG → Scheduler: analyzed by · DAG dependencies are scheduled for execution.
- Scheduler → Runtime: drives · Scheduler hands executable work to the runtime engine.
- Runtime → Block Plans: dispatches · Runtime executes block-level plans for tensor operations.
- Block Plans → Kernels: invokes · Block plans call numerical kernels for actual compute.
- Block Plans → Memory: uses · Block execution stages data through the memory subsystem.
- Memory → Backends: integrates · Memory managers support distributed backends and communication layers.
- Memory → GPU Support: allocates · Memory resources cover host, pinned, and device storage.
- Kernels → GPU Support: supports · Kernel implementations split across CPU and GPU paths.
- Backends → Distribution: coordinates · Process groups and backend communication shape distribution.
- PyTAMM → Tensor API: binds · Python exposes the C++ tensor API.
- Python Tests → PyTAMM: validates · Python tests exercise the extension module and workflows.
- C++ Tests → Tensor API: validates · C++ tests cover core tensor and runtime behavior.
- CC Workflows → Block Plans: exercises · Coupled-cluster tests stress the block execution path.
- CC Workflows → Backends: exercises · Domain tests include distributed communication paths.
- Docs → Tensor API: documents · Documentation explains tensor construction and operations.
- Build & CI → PyTAMM: builds · CMake and CI build the Python module and C++ library.
- Build & CI → C++ Tests: runs · CI orchestrates native validation suites.
- HPC Jobs → Backends: deploys · Job scripts configure HPC execution and MPI/GA environments.
