How nwchemex/tamm works
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: tamm.hpp Tensor API · block_operations.hpp Block Plans · ga_over_upcxx.hpp Backends · memory_manager.hpp Memory
Components 19
C++ Core
Primary tensor-algebra runtime and library implementation.
- Tensor API · User-facing tensor objects and expression surface.
src/tamm/tamm.hpp - Tensors · Tensor, labeled tensor, local tensor, and storage variants.
src/tamm/tensor.hpp - Indexing · Index spaces, tiled index spaces, ranges, permutations, and bounds.
src/tamm/index_space.hpp - Distribution · Process groups, grids, and tile-to-process mapping.
src/tamm/proc_group.hpp - Ops DAG · Operation nodes, dependencies, and lowering of tensor expressions.
src/tamm/op_dag.hpp - Scheduler · Dependency analysis, work scheduling, and runtime coordination.
src/tamm/scheduler.hpp - Runtime · Execution context and runtime engine that drive operation execution.
src/tamm/runtime_engine.hpp - Block Plans · Block-level assign, multiply, set, and lambda plans.
src/tamm/block_operations.hpp - Kernels · CPU/GPU BLAS and tensor kernel entry points.
src/tamm/kernels/tamm_blas.hpp - Memory · Memory managers, resources, buffering, and scratch storage.
src/tamm/memory_manager.hpp - Backends · MPI/GA/UPC++-oriented communication and memory integration.
src/tamm/ga_over_upcxx.hpp - GPU Support · GPU streams, device helpers, and accelerator memory pool integration.
src/tamm/gpu_streams.hpp
Bindings
Python extension layer for higher-level use.
- PyTAMM · C++ extension module exposing TAMM to Python.
src/python/pytamm.cpp
Validation
C++ and Python tests, including coupled-cluster workflows.
- C++ Tests · Unit and integration tests for tensors, DAGs, memory, and process groups.
tests/tamm/Test_Tensors.cpp - CC Workflows · Coupled-cluster and DLPNO scientific workflow validation.
tests/tamm/coupledcluster/Test_CCSD.cpp - Python Tests · Python-side API, tensor, I/O, and coupled-cluster tests.
tests/python/Test_Tensors.py
Tooling
Build, docs, CI, and HPC launch helpers.
- Docs · User guide, developer guide, and API documentation source.
docs/index.rst - Build & CI · CMake, GitHub Actions, Docker, and release automation.
CMakeLists.txt - HPC Jobs · System-specific job scripts and launch helpers for supercomputers.
support/jobscripts
Connections 22
- 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.