# madhavkannank/rules_ml_toolchain architecture

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

- Interactive diagram: https://gitdiagram.com/madhavkannank/rules_ml_toolchain
- Repository: https://github.com/madhavkannank/rules_ml_toolchain

## Overview

rules_ml_toolchain is a Bazel ruleset for hermetic C++ and ML-oriented toolchains. A consuming workspace loads dependency setup, registers a target toolchain, then builds or tests with selected platform, LLVM/sysroot, and optional accelerator settings. The README also documents Python wrapping and sanitizer support. The graph preserves these major capabilities; many Starlark implementations are unsampled, so uncertain internal wiring is omitted rather than inferred from directory names.

Main entry points: [`py/rules_pywrap/pywrap.impl.bzl`](https://github.com/madhavkannank/rules_ml_toolchain/blob/main/py/rules_pywrap/pywrap.impl.bzl) (Python Wrapping), [`gpu/cuda/cuda_configure.bzl`](https://github.com/madhavkannank/rules_ml_toolchain/blob/main/gpu/cuda/cuda_configure.bzl) (CUDA Configuration), [`gpu/rocm/hipcc_configure.bzl`](https://github.com/madhavkannank/rules_ml_toolchain/blob/main/gpu/rocm/hipcc_configure.bzl) (ROCm Toolchain), [`gpu/sycl/sycl_configure.bzl`](https://github.com/madhavkannank/rules_ml_toolchain/blob/main/gpu/sycl/sycl_configure.bzl) (SYCL Toolchain)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cc["C++ Toolchains"]
  node_deps["C++ Dependencies"]
  node_toolchain["Platform Toolchains"]
  node_features["Compiler Features<br/>[features.bzl]"]
  node_llvm["LLVM Selection<br/>[llvm.bzl]"]
  node_sysroots["Sysroot Setup<br/>[sysroot.bzl]"]
end

subgraph group_gpu["Accelerator Toolchains"]
  node_cuda["CUDA Configuration<br/>[cuda_configure.bzl]"]
  node_cuda_wrapper["Clang CUDA Wrapper"]
  node_rocm_detect["ROCm Detection"]
  node_rocm_config["ROCm Toolchain"]
  node_sycl_detect["SYCL Detection"]
  node_sycl_config["SYCL Toolchain<br/>[sycl_configure.bzl]"]
  node_nccl["NCCL Integration<br/>[nccl_configure.bzl]"]
  node_nvshmem["NVSHMEM Integration"]
end

subgraph group_python["Python Integration"]
  node_python_config["Python Setup"]
  node_pywrap["Python Wrapping<br/>[pywrap.impl.bzl]"]
  node_def_filter["Export Filtering"]
  node_wrapped_init["Wrapped Module Init<br/>[wrapped_py_init.cc]"]
end

subgraph group_support["Build Support"]
  node_sanitizers["Sanitizer Support<br/>[features.bzl]"]
end

node_workspace(("Consumer Workspace"))

node_workspace -->|"loads dependencies"| node_deps
node_workspace -->|"registers toolchain"| node_toolchain
node_workspace -->|"selects version"| node_llvm
node_workspace -->|"selects sysroot"| node_sysroots
node_workspace -->|"enables features"| node_features
node_workspace -->|"configures sanitizers"| node_sanitizers
node_workspace -->|"initializes CUDA"| node_cuda
node_workspace -.->|"configures ROCm"| node_rocm_config
node_workspace -.->|"configures SYCL"| node_sycl_config
node_workspace -->|"configures NCCL"| node_nccl
node_workspace -->|"configures NVSHMEM"| node_nvshmem
node_workspace -.->|"configures Python"| node_python_config
node_workspace -.->|"uses wrapping rules"| node_pywrap
node_pywrap -.->|"filters exports"| node_def_filter
node_pywrap -.->|"generates module init"| node_wrapped_init
node_rocm_config -.->|"runs detection"| node_rocm_detect
node_sycl_config -.->|"runs detection"| node_sycl_detect
node_cuda -.->|"uses wrapper"| node_cuda_wrapper

click node_deps "https://github.com/madhavkannank/rules_ml_toolchain/blob/main/cc/deps/cc_toolchain_deps.bzl"
click node_toolchain "https://github.com/madhavkannank/rules_ml_toolchain/tree/main/cc/impls"
click node_features "https://github.com/madhavkannank/rules_ml_toolchain/blob/main/cc/features/features.bzl"
click node_llvm "https://github.com/madhavkannank/rules_ml_toolchain/blob/main/cc/llvms/llvm.bzl"
click node_sysroots "https://github.com/madhavkannank/rules_ml_toolchain/blob/main/cc/sysroots/sysroot.bzl"
click node_sanitizers "https://github.com/madhavkannank/rules_ml_toolchain/blob/main/cc/sanitizers/features.bzl"
click node_cuda "https://github.com/madhavkannank/rules_ml_toolchain/blob/main/gpu/cuda/cuda_configure.bzl"
click node_cuda_wrapper "https://github.com/madhavkannank/rules_ml_toolchain/blob/main/cc/cuda/clang/clang_cuda_runtime_wrapper.h"
click node_rocm_detect "https://github.com/madhavkannank/rules_ml_toolchain/blob/main/gpu/rocm/find_rocm_config.py"
click node_rocm_config "https://github.com/madhavkannank/rules_ml_toolchain/blob/main/gpu/rocm/hipcc_configure.bzl"
click node_sycl_detect "https://github.com/madhavkannank/rules_ml_toolchain/blob/main/gpu/sycl/find_sycl_config.py"
click node_sycl_config "https://github.com/madhavkannank/rules_ml_toolchain/blob/main/gpu/sycl/sycl_configure.bzl"
click node_nccl "https://github.com/madhavkannank/rules_ml_toolchain/blob/main/gpu/nccl/nccl_configure.bzl"
click node_nvshmem "https://github.com/madhavkannank/rules_ml_toolchain/blob/main/gpu/nvshmem/nvshmem_redist_init_repository.bzl"
click node_python_config "https://github.com/madhavkannank/rules_ml_toolchain/blob/main/py/python_configure.bzl"
click node_pywrap "https://github.com/madhavkannank/rules_ml_toolchain/blob/main/py/rules_pywrap/pywrap.impl.bzl"
click node_def_filter "https://github.com/madhavkannank/rules_ml_toolchain/blob/main/py/rules_pywrap/def_file_filter_tool.py"
click node_wrapped_init "https://github.com/madhavkannank/rules_ml_toolchain/blob/main/py/rules_pywrap/wrapped_py_init.cc"

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_deps,node_toolchain,node_features,node_llvm,node_sysroots toneBlue
class node_cuda,node_cuda_wrapper,node_rocm_detect,node_rocm_config,node_sycl_detect,node_sycl_config,node_nccl,node_nvshmem toneAmber
class node_python_config,node_pywrap,node_def_filter,node_wrapped_init toneMint
class node_sanitizers toneRose
class node_workspace toneIndigo
```

## Components

### C++ Toolchains

- [C++ Dependencies](https://github.com/madhavkannank/rules_ml_toolchain/blob/main/cc/deps/cc_toolchain_deps.bzl): `cc/deps/cc_toolchain_deps.bzl`
- [Platform Toolchains](https://github.com/madhavkannank/rules_ml_toolchain/tree/main/cc/impls): `cc/impls`
- [Compiler Features](https://github.com/madhavkannank/rules_ml_toolchain/blob/main/cc/features/features.bzl): `cc/features/features.bzl`
- [LLVM Selection](https://github.com/madhavkannank/rules_ml_toolchain/blob/main/cc/llvms/llvm.bzl): `cc/llvms/llvm.bzl`
- [Sysroot Setup](https://github.com/madhavkannank/rules_ml_toolchain/blob/main/cc/sysroots/sysroot.bzl): `cc/sysroots/sysroot.bzl`

### Accelerator Toolchains

- [CUDA Configuration](https://github.com/madhavkannank/rules_ml_toolchain/blob/main/gpu/cuda/cuda_configure.bzl): `gpu/cuda/cuda_configure.bzl`
- [Clang CUDA Wrapper](https://github.com/madhavkannank/rules_ml_toolchain/blob/main/cc/cuda/clang/clang_cuda_runtime_wrapper.h): `cc/cuda/clang/clang_cuda_runtime_wrapper.h`
- [ROCm Detection](https://github.com/madhavkannank/rules_ml_toolchain/blob/main/gpu/rocm/find_rocm_config.py): `gpu/rocm/find_rocm_config.py`
- [ROCm Toolchain](https://github.com/madhavkannank/rules_ml_toolchain/blob/main/gpu/rocm/hipcc_configure.bzl): `gpu/rocm/hipcc_configure.bzl`
- [SYCL Detection](https://github.com/madhavkannank/rules_ml_toolchain/blob/main/gpu/sycl/find_sycl_config.py): `gpu/sycl/find_sycl_config.py`
- [SYCL Toolchain](https://github.com/madhavkannank/rules_ml_toolchain/blob/main/gpu/sycl/sycl_configure.bzl): `gpu/sycl/sycl_configure.bzl`
- [NCCL Integration](https://github.com/madhavkannank/rules_ml_toolchain/blob/main/gpu/nccl/nccl_configure.bzl): `gpu/nccl/nccl_configure.bzl`
- [NVSHMEM Integration](https://github.com/madhavkannank/rules_ml_toolchain/blob/main/gpu/nvshmem/nvshmem_redist_init_repository.bzl): `gpu/nvshmem/nvshmem_redist_init_repository.bzl`

### Python Integration

- [Python Setup](https://github.com/madhavkannank/rules_ml_toolchain/blob/main/py/python_configure.bzl): `py/python_configure.bzl`
- [Python Wrapping](https://github.com/madhavkannank/rules_ml_toolchain/blob/main/py/rules_pywrap/pywrap.impl.bzl): `py/rules_pywrap/pywrap.impl.bzl`
- [Export Filtering](https://github.com/madhavkannank/rules_ml_toolchain/blob/main/py/rules_pywrap/def_file_filter_tool.py): `py/rules_pywrap/def_file_filter_tool.py`
- [Wrapped Module Init](https://github.com/madhavkannank/rules_ml_toolchain/blob/main/py/rules_pywrap/wrapped_py_init.cc): `py/rules_pywrap/wrapped_py_init.cc`

### Build Support

- [Sanitizer Support](https://github.com/madhavkannank/rules_ml_toolchain/blob/main/cc/sanitizers/features.bzl): `cc/sanitizers/features.bzl`

### Other components

- **Consumer Workspace**

## Connections

- Consumer Workspace → C++ Dependencies: loads dependencies (evidence: `README.md`)
- Consumer Workspace → Platform Toolchains: registers toolchain (evidence: `README.md`)
- Consumer Workspace → LLVM Selection: selects version (evidence: `README.md`)
- Consumer Workspace → Sysroot Setup: selects sysroot (evidence: `README.md`)
- Consumer Workspace → Compiler Features: enables features (evidence: `README.md`)
- Consumer Workspace → Sanitizer Support: configures sanitizers (evidence: `README.md`)
- Consumer Workspace → CUDA Configuration: initializes CUDA (evidence: `README.md`)
- Consumer Workspace → ROCm Toolchain: configures ROCm
- Consumer Workspace → SYCL Toolchain: configures SYCL
- Consumer Workspace → NCCL Integration: configures NCCL (evidence: `README.md`)
- Consumer Workspace → NVSHMEM Integration: configures NVSHMEM (evidence: `README.md`)
- Consumer Workspace → Python Setup: configures Python
- Consumer Workspace → Python Wrapping: uses wrapping rules
- Python Wrapping → Export Filtering: filters exports
- Python Wrapping → Wrapped Module Init: generates module init
- ROCm Toolchain → ROCm Detection: runs detection
- SYCL Toolchain → SYCL Detection: runs detection
- CUDA Configuration → Clang CUDA Wrapper: uses wrapper
