# deepseek-ai/deepgemm-ascend architecture

> Architecture diagram of the GitHub repository deepseek-ai/deepgemm-ascend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/deepseek-ai/deepgemm-ascend
- Repository: https://github.com/deepseek-ai/deepgemm-ascend

## Overview

DeepGEMM Ascend is a Python-accessible C++/Ascend kernel library for low-precision matrix operations and inference workloads. The principal workflow is Python caller → registered C++ API → operation-specific kernel/JIT runtime → Ascend execution. Its distinct capabilities include dense and grouped GEMM, attention logits, MegaMoE, Mega mHC/MegaGate, scaling-factor layout transforms, ACLNN reference operations, and experimental model kernels. The README documents these capabilities; unsampled kernel internals and optional integrations are represented conservatively where call paths are not shown.

Main entry points: [`csrc/python_api.cpp`](https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/python_api.cpp) (C++ extension), [`csrc/jit/jit.hpp`](https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/jit/jit.hpp) (JIT runtime), [`csrc/apis/gemm.hpp`](https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/apis/gemm.hpp) (GEMM APIs), [`csrc/apis/attention.hpp`](https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/apis/attention.hpp) (Attention logits)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Python interface"]
  node_extension["C++ extension<br/>[python_api.cpp]"]
  node_package["Python package<br/>[__init__.py]"]
end

subgraph group_compute["Compute APIs"]
  node_gemm["GEMM APIs<br/>[gemm.hpp]"]
  node_einsum["Einsum APIs<br/>[einsum.hpp]"]
  node_attention["Attention logits<br/>[attention.hpp]"]
  node_aclnn["ACLNN references<br/>[aclnn.hpp]"]
end

subgraph group_runtime["JIT runtime"]
  node_jit["JIT runtime<br/>[jit.hpp]"]
  node_heuristics["Kernel selection<br/>[heuristics.hpp]"]
  node_gemm_kernels["GEMM kernels"]
end

subgraph group_inference["Inference features"]
  node_mega_moe["MegaMoE<br/>[mega_moe.hpp]"]
  node_mega_mhc["Mega mHC<br/>[mega_mhc.hpp]"]
  node_mega_gate["MegaGate<br/>[mega_gate.hpp]"]
  node_experimental["Experimental kernels"]
  node_tilelang["HC prenorm<br/>[hc_prenorm.py]"]
end

subgraph group_support["Layouts and references"]
  node_layout["Layout transforms<br/>[layout.hpp]"]
  node_layout_utils["Tensor layout utilities<br/>[layout.hpp]"]
  node_runtime_api["Runtime controls<br/>[runtime.hpp]"]
  node_comm["Collective buffers<br/>[hccl.hpp]"]
end

node_caller(("Python caller"))

node_caller -->|"calls"| node_package
node_package -->|"imports"| node_extension
node_extension -->|"registers"| node_gemm
node_extension -->|"registers"| node_einsum
node_extension -->|"registers"| node_attention
node_extension -->|"registers"| node_aclnn
node_extension -->|"registers"| node_mega_moe
node_extension -->|"registers"| node_mega_mhc
node_extension -->|"registers"| node_mega_gate
node_extension -->|"registers"| node_experimental
node_extension -->|"registers"| node_runtime_api
node_gemm -.->|"dispatches"| node_gemm_kernels
node_gemm -.->|"selects"| node_heuristics
node_einsum -->|"uses"| node_gemm
node_attention -.->|"launches"| node_jit
node_gemm -.->|"compiles"| node_jit
node_mega_moe -->|"uses buffers"| node_comm
node_mega_moe -.->|"compiles"| node_jit
node_mega_mhc -.->|"compiles"| node_jit
node_mega_gate -.->|"compiles"| node_jit
node_experimental -->|"compiles"| node_jit
node_layout -.->|"uses"| node_layout_utils
node_attention -.->|"validates"| node_layout_utils
node_tilelang -.->|"called by"| node_caller

click node_extension "https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/python_api.cpp"
click node_package "https://github.com/deepseek-ai/deepgemm-ascend/blob/main/deep_gemm/__init__.py"
click node_gemm "https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/apis/gemm.hpp"
click node_einsum "https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/apis/einsum.hpp"
click node_attention "https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/apis/attention.hpp"
click node_aclnn "https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/apis/aclnn.hpp"
click node_jit "https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/jit/jit.hpp"
click node_heuristics "https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/jit_kernels/heuristics.hpp"
click node_gemm_kernels "https://github.com/deepseek-ai/deepgemm-ascend/tree/main/csrc/jit_kernels"
click node_mega_moe "https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/apis/mega_moe.hpp"
click node_mega_mhc "https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/apis/mega_mhc.hpp"
click node_mega_gate "https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/apis/mega_gate.hpp"
click node_experimental "https://github.com/deepseek-ai/deepgemm-ascend/tree/main/csrc/experimental"
click node_tilelang "https://github.com/deepseek-ai/deepgemm-ascend/blob/main/deep_gemm/tilelang_ops/hc_prenorm.py"
click node_layout "https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/apis/layout.hpp"
click node_layout_utils "https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/utils/layout.hpp"
click node_runtime_api "https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/apis/runtime.hpp"
click node_comm "https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/backends/hccl.hpp"

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_extension,node_package toneBlue
class node_gemm,node_einsum,node_attention,node_aclnn toneAmber
class node_jit,node_heuristics,node_gemm_kernels toneMint
class node_mega_moe,node_mega_mhc,node_mega_gate,node_experimental,node_tilelang toneRose
class node_layout,node_layout_utils,node_runtime_api,node_comm,node_caller toneIndigo
```

## Components

### Python interface

- [C++ extension](https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/python_api.cpp): `csrc/python_api.cpp`
- [Python package](https://github.com/deepseek-ai/deepgemm-ascend/blob/main/deep_gemm/__init__.py): `deep_gemm/__init__.py`

### Compute APIs

- [GEMM APIs](https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/apis/gemm.hpp): `csrc/apis/gemm.hpp`
- [Einsum APIs](https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/apis/einsum.hpp): `csrc/apis/einsum.hpp`
- [Attention logits](https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/apis/attention.hpp): `csrc/apis/attention.hpp`
- [ACLNN references](https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/apis/aclnn.hpp): `csrc/apis/aclnn.hpp`

### JIT runtime

- [JIT runtime](https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/jit/jit.hpp): `csrc/jit/jit.hpp`
- [Kernel selection](https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/jit_kernels/heuristics.hpp): `csrc/jit_kernels/heuristics.hpp`
- [GEMM kernels](https://github.com/deepseek-ai/deepgemm-ascend/tree/main/csrc/jit_kernels): `csrc/jit_kernels`

### Inference features

- [MegaMoE](https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/apis/mega_moe.hpp): `csrc/apis/mega_moe.hpp`
- [Mega mHC](https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/apis/mega_mhc.hpp): `csrc/apis/mega_mhc.hpp`
- [MegaGate](https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/apis/mega_gate.hpp): `csrc/apis/mega_gate.hpp`
- [Experimental kernels](https://github.com/deepseek-ai/deepgemm-ascend/tree/main/csrc/experimental): `csrc/experimental`
- [HC prenorm](https://github.com/deepseek-ai/deepgemm-ascend/blob/main/deep_gemm/tilelang_ops/hc_prenorm.py): `deep_gemm/tilelang_ops/hc_prenorm.py`

### Layouts and references

- [Layout transforms](https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/apis/layout.hpp): `csrc/apis/layout.hpp`
- [Tensor layout utilities](https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/utils/layout.hpp): `csrc/utils/layout.hpp`
- [Runtime controls](https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/apis/runtime.hpp): `csrc/apis/runtime.hpp`
- [Collective buffers](https://github.com/deepseek-ai/deepgemm-ascend/blob/main/csrc/backends/hccl.hpp): `csrc/backends/hccl.hpp`

### Other components

- **Python caller**

## Connections

- Python caller → Python package: calls (evidence: `README.md`)
- Python package → C++ extension: imports (evidence: `deep_gemm/__init__.py`)
- C++ extension → GEMM APIs: registers (evidence: `csrc/python_api.cpp`)
- C++ extension → Einsum APIs: registers (evidence: `csrc/python_api.cpp`)
- C++ extension → Attention logits: registers (evidence: `csrc/python_api.cpp`)
- C++ extension → ACLNN references: registers (evidence: `csrc/python_api.cpp`)
- C++ extension → MegaMoE: registers (evidence: `csrc/python_api.cpp`)
- C++ extension → Mega mHC: registers (evidence: `csrc/python_api.cpp`)
- C++ extension → MegaGate: registers (evidence: `csrc/python_api.cpp`)
- C++ extension → Experimental kernels: registers (evidence: `csrc/python_api.cpp`)
- C++ extension → Runtime controls: registers (evidence: `csrc/python_api.cpp`)
- GEMM APIs → GEMM kernels: dispatches (evidence: `csrc/apis/gemm.hpp`)
- GEMM APIs → Kernel selection: selects
- Einsum APIs → GEMM APIs: uses (evidence: `csrc/apis/einsum.hpp`)
- Attention logits → JIT runtime: launches
- GEMM APIs → JIT runtime: compiles
- MegaMoE → Collective buffers: uses buffers (evidence: `csrc/apis/mega_moe.hpp`)
- MegaMoE → JIT runtime: compiles (evidence: `csrc/apis/mega_moe.hpp`)
- Mega mHC → JIT runtime: compiles
- MegaGate → JIT runtime: compiles
- Experimental kernels → JIT runtime: compiles (evidence: `csrc/experimental/v41f_qkv_lora.hpp`)
- Layout transforms → Tensor layout utilities: uses
- Attention logits → Tensor layout utilities: validates (evidence: `csrc/apis/attention.hpp`)
- HC prenorm → Python caller: called by
