# hicann/ops-transformer architecture

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

- Interactive diagram: https://gitdiagram.com/hicann/ops-transformer
- Repository: https://github.com/hicann/ops-transformer

## Overview

ops-transformer is a CANN library of transformer-oriented accelerator operators, spanning attention, MoE, grouped matrix multiplication, and communication/computation fusion. Users invoke operator APIs with tensors and receive computed tensor results; the repository also exposes PyTorch extensions for selected operators. The graph captures documented capability areas and sampled implementation layers. The tree and excerpts do not establish most operator-to-operator runtime calls, so those are not chained; unsampled capabilities are represented at their supported directory paths.

Main entry points: [`mc2/common/op_kernel/mc2_templates/scheduler/pipeline_builder.h`](https://github.com/hicann/ops-transformer/blob/master/mc2/common/op_kernel/mc2_templates/scheduler/pipeline_builder.h) (Pipeline stage wiring), [`attention`](https://github.com/hicann/ops-transformer/tree/master/attention) (Attention operators), [`mc2/matmul_allto_all/op_kernel/matmul_allto_all_pipeline.h`](https://github.com/hicann/ops-transformer/blob/master/mc2/matmul_allto_all/op_kernel/matmul_allto_all_pipeline.h) (Matmul all-to-all), [`mc2/allto_all_matmul/op_kernel/allto_all_matmul_pipeline.h`](https://github.com/hicann/ops-transformer/blob/master/mc2/allto_all_matmul/op_kernel/allto_all_matmul_pipeline.h) (All-to-all matmul)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_attention["Attention operators"]
  node_attention_ops["Attention operators"]
  node_block_sparse["Block sparse attention"]
  node_attention_update["Attention update"]
  node_worker_schedule["Attention worker scheduler"]
  node_worker_combine["Attention worker combine"]
  node_res_prepare["Block result preparation"]
  node_res_update["Block result update"]
  node_mla_prolog["MLA prolog"]
end

subgraph group_moe["MoE operators"]
  node_moe_ops["MoE operators"]
  node_moe_init["MoE routing init"]
  node_moe_finalize["MoE routing finalize"]
end

subgraph group_gmm["Grouped matmul"]
  node_gmm_ops["Grouped matmul operators"]
  node_gmm_a16w4["A16W4 quant controller"]
  node_gmm_swiglu["Quantized SwiGLU"]
  node_gmm_swiglu_v2["Quantized SwiGLU v2"]
  node_gmm_finalize["GMM routing finalize"]
end

subgraph group_mc2["Communication fusion"]
  node_mc2_ops["Collective operators"]
  node_matmul_alltoall["Matmul all-to-all"]
  node_alltoall_matmul["All-to-all matmul"]
  node_alltoallv_gmm["All-to-all-v quant GMM"]
  node_reduce_scatter["Reduce-scatter tiling"]
  node_mc2_pipeline["Pipeline stage wiring<br/>[pipeline_builder.h]"]
end

subgraph group_support["Operator internals"]
  node_attention_buffer["Attention buffer manager"]
  node_attn_buffer["Attention buffer<br/>[attn_buffer.h]"]
  node_rope_a22["Rotary embedding A2"]
  node_rope_a35["Rotary embedding A5"]
  node_quant_mixcore["Mix-core synchronization"]
  node_matmul_pipeline["SwiGLU pipeline helper"]
  node_matmul_v2_pipeline["SwiGLU v2 helper"]
end

node_user(("Model or caller"))

node_user -.->|"invokes"| node_attention_ops
node_user -.->|"invokes"| node_moe_ops
node_user -.->|"invokes"| node_gmm_ops
node_user -.->|"invokes"| node_mc2_ops
node_attention_buffer -->|"uses"| node_attn_buffer
node_rope_a22 -.->|"supports MLA"| node_attention_ops
node_rope_a35 -.->|"supports MLA"| node_attention_ops
node_matmul_pipeline -->|"stages computation"| node_gmm_swiglu
node_matmul_v2_pipeline -->|"stages computation"| node_gmm_swiglu_v2
node_mc2_pipeline -->|"provides stages"| node_matmul_alltoall
node_mc2_pipeline -->|"provides stages"| node_alltoall_matmul
node_matmul_alltoall -->|"uses stages"| node_mc2_pipeline
node_alltoall_matmul -->|"uses stages"| node_mc2_pipeline

click node_attention_ops "https://github.com/hicann/ops-transformer/tree/master/attention"
click node_block_sparse "https://github.com/hicann/ops-transformer/blob/master/attention/block_sparse_attention/op_kernel/arch35/block_sparse_attention_kernel_arch35_regular.h"
click node_attention_update "https://github.com/hicann/ops-transformer/blob/master/attention/attention_update/op_kernel/attention_update.cpp"
click node_worker_schedule "https://github.com/hicann/ops-transformer/blob/master/attention/attention_worker_scheduler/op_kernel_aicpu/attention_worker_scheduler_aicpu.cpp"
click node_worker_combine "https://github.com/hicann/ops-transformer/blob/master/attention/attention_worker_combine/op_kernel/attention_worker_combine.cpp"
click node_res_prepare "https://github.com/hicann/ops-transformer/blob/master/attention/block_attn_res_prepare/op_kernel/block_attn_res_prepare_apt.cpp"
click node_res_update "https://github.com/hicann/ops-transformer/blob/master/attention/block_attn_res_update/op_kernel/block_attn_res_update.cpp"
click node_mla_prolog "https://github.com/hicann/ops-transformer/blob/master/attention/mla_prolog/op_kernel/arch35/service_rotary_position_embedding_arch35.h"
click node_moe_ops "https://github.com/hicann/ops-transformer/tree/master/moe"
click node_moe_init "https://github.com/hicann/ops-transformer/blob/master/moe/moe_init_routing_v3/op_host/moe_init_routing_v3_tiling_arch35.cpp"
click node_moe_finalize "https://github.com/hicann/ops-transformer/blob/master/moe/moe_finalize_routing/op_host/moe_finalize_routing_tiling.cpp"
click node_gmm_ops "https://github.com/hicann/ops-transformer/blob/master/gmm/grouped_matmul/op_kernel/grouped_matmul_kernel.h"
click node_gmm_a16w4 "https://github.com/hicann/ops-transformer/blob/master/gmm/grouped_matmul/op_kernel/a16w4_msd/grouped_matmul_weight_quant_a16w4_msd_controller.h"
click node_gmm_swiglu "https://github.com/hicann/ops-transformer/blob/master/gmm/grouped_matmul_swiglu_quant/op_kernel/grouped_matmul_swiglu_pipeline.h"
click node_gmm_swiglu_v2 "https://github.com/hicann/ops-transformer/blob/master/gmm/grouped_matmul_swiglu_quant_v2/op_kernel/grouped_matmul_swiglu_quant_v2_a8w4_msd_pipeline.h"
click node_gmm_finalize "https://github.com/hicann/ops-transformer/blob/master/gmm/grouped_matmul_finalize_routing/op_kernel/arch35/weight_quant_basic_block/gmm_fr_weight_quant_resplit_controller.h"
click node_mc2_ops "https://github.com/hicann/ops-transformer/tree/master/mc2"
click node_matmul_alltoall "https://github.com/hicann/ops-transformer/blob/master/mc2/matmul_allto_all/op_kernel/matmul_allto_all_pipeline.h"
click node_alltoall_matmul "https://github.com/hicann/ops-transformer/blob/master/mc2/allto_all_matmul/op_kernel/allto_all_matmul_pipeline.h"
click node_alltoallv_gmm "https://github.com/hicann/ops-transformer/blob/master/mc2/allto_allv_quant_grouped_mat_mul/op_kernel/mc2_templates/communication/a2av_permute_engine.h"
click node_reduce_scatter "https://github.com/hicann/ops-transformer/blob/master/mc2/matmul_reduce_scatter_v2/op_host/op_tiling/arch22/matmul_reduce_scatter_v2_smallm_rank8_pipeline_rules.h"
click node_mc2_pipeline "https://github.com/hicann/ops-transformer/blob/master/mc2/common/op_kernel/mc2_templates/scheduler/pipeline_builder.h"
click node_attention_buffer "https://github.com/hicann/ops-transformer/blob/master/attention/common/op_kernel/attn_buffer_manager.h"
click node_attn_buffer "https://github.com/hicann/ops-transformer/blob/master/attention/common/op_kernel/attn_buffer.h"
click node_rope_a22 "https://github.com/hicann/ops-transformer/blob/master/attention/mla_prolog/op_kernel/arch22/service_rotary_position_embedding_arch22.h"
click node_rope_a35 "https://github.com/hicann/ops-transformer/blob/master/attention/mla_prolog/op_kernel/arch35/service_rotary_position_embedding_arch35.h"
click node_quant_mixcore "https://github.com/hicann/ops-transformer/blob/master/mc2/3rd/weight_quant_batch_matmul_v2/op_kernel/arch35/catlass/pipeline/pipeline_stage_mixcore.h"
click node_matmul_pipeline "https://github.com/hicann/ops-transformer/blob/master/gmm/grouped_matmul_swiglu_quant/op_kernel/grouped_matmul_swiglu_pipeline.h"
click node_matmul_v2_pipeline "https://github.com/hicann/ops-transformer/blob/master/gmm/grouped_matmul_swiglu_quant_v2/op_kernel/grouped_matmul_swiglu_quant_v2_a8w4_msd_pipeline.h"

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_attention_ops,node_block_sparse,node_attention_update,node_worker_schedule,node_worker_combine,node_res_prepare,node_res_update,node_mla_prolog toneBlue
class node_moe_ops,node_moe_init,node_moe_finalize toneAmber
class node_gmm_ops,node_gmm_a16w4,node_gmm_swiglu,node_gmm_swiglu_v2,node_gmm_finalize toneMint
class node_mc2_ops,node_matmul_alltoall,node_alltoall_matmul,node_alltoallv_gmm,node_reduce_scatter,node_mc2_pipeline toneRose
class node_attention_buffer,node_attn_buffer,node_rope_a22,node_rope_a35,node_quant_mixcore,node_matmul_pipeline,node_matmul_v2_pipeline,node_user toneIndigo
```

## Components

### Attention operators

- [Attention operators](https://github.com/hicann/ops-transformer/tree/master/attention): `attention`
- [Block sparse attention](https://github.com/hicann/ops-transformer/blob/master/attention/block_sparse_attention/op_kernel/arch35/block_sparse_attention_kernel_arch35_regular.h): `attention/block_sparse_attention/op_kernel/arch35/block_sparse_attention_kernel_arch35_regular.h`
- [Attention update](https://github.com/hicann/ops-transformer/blob/master/attention/attention_update/op_kernel/attention_update.cpp): `attention/attention_update/op_kernel/attention_update.cpp`
- [Attention worker scheduler](https://github.com/hicann/ops-transformer/blob/master/attention/attention_worker_scheduler/op_kernel_aicpu/attention_worker_scheduler_aicpu.cpp): `attention/attention_worker_scheduler/op_kernel_aicpu/attention_worker_scheduler_aicpu.cpp`
- [Attention worker combine](https://github.com/hicann/ops-transformer/blob/master/attention/attention_worker_combine/op_kernel/attention_worker_combine.cpp): `attention/attention_worker_combine/op_kernel/attention_worker_combine.cpp`
- [Block result preparation](https://github.com/hicann/ops-transformer/blob/master/attention/block_attn_res_prepare/op_kernel/block_attn_res_prepare_apt.cpp): `attention/block_attn_res_prepare/op_kernel/block_attn_res_prepare_apt.cpp`
- [Block result update](https://github.com/hicann/ops-transformer/blob/master/attention/block_attn_res_update/op_kernel/block_attn_res_update.cpp): `attention/block_attn_res_update/op_kernel/block_attn_res_update.cpp`
- [MLA prolog](https://github.com/hicann/ops-transformer/blob/master/attention/mla_prolog/op_kernel/arch35/service_rotary_position_embedding_arch35.h): `attention/mla_prolog/op_kernel/arch35/service_rotary_position_embedding_arch35.h`

### MoE operators

- [MoE operators](https://github.com/hicann/ops-transformer/tree/master/moe): `moe`
- [MoE routing init](https://github.com/hicann/ops-transformer/blob/master/moe/moe_init_routing_v3/op_host/moe_init_routing_v3_tiling_arch35.cpp): `moe/moe_init_routing_v3/op_host/moe_init_routing_v3_tiling_arch35.cpp`
- [MoE routing finalize](https://github.com/hicann/ops-transformer/blob/master/moe/moe_finalize_routing/op_host/moe_finalize_routing_tiling.cpp): `moe/moe_finalize_routing/op_host/moe_finalize_routing_tiling.cpp`

### Grouped matmul

- [Grouped matmul operators](https://github.com/hicann/ops-transformer/blob/master/gmm/grouped_matmul/op_kernel/grouped_matmul_kernel.h): `gmm/grouped_matmul/op_kernel/grouped_matmul_kernel.h`
- [A16W4 quant controller](https://github.com/hicann/ops-transformer/blob/master/gmm/grouped_matmul/op_kernel/a16w4_msd/grouped_matmul_weight_quant_a16w4_msd_controller.h): `gmm/grouped_matmul/op_kernel/a16w4_msd/grouped_matmul_weight_quant_a16w4_msd_controller.h`
- [Quantized SwiGLU](https://github.com/hicann/ops-transformer/blob/master/gmm/grouped_matmul_swiglu_quant/op_kernel/grouped_matmul_swiglu_pipeline.h): `gmm/grouped_matmul_swiglu_quant/op_kernel/grouped_matmul_swiglu_pipeline.h`
- [Quantized SwiGLU v2](https://github.com/hicann/ops-transformer/blob/master/gmm/grouped_matmul_swiglu_quant_v2/op_kernel/grouped_matmul_swiglu_quant_v2_a8w4_msd_pipeline.h): `gmm/grouped_matmul_swiglu_quant_v2/op_kernel/grouped_matmul_swiglu_quant_v2_a8w4_msd_pipeline.h`
- [GMM routing finalize](https://github.com/hicann/ops-transformer/blob/master/gmm/grouped_matmul_finalize_routing/op_kernel/arch35/weight_quant_basic_block/gmm_fr_weight_quant_resplit_controller.h): `gmm/grouped_matmul_finalize_routing/op_kernel/arch35/weight_quant_basic_block/gmm_fr_weight_quant_resplit_controller.h`

### Communication fusion

- [Collective operators](https://github.com/hicann/ops-transformer/tree/master/mc2): `mc2`
- [Matmul all-to-all](https://github.com/hicann/ops-transformer/blob/master/mc2/matmul_allto_all/op_kernel/matmul_allto_all_pipeline.h): `mc2/matmul_allto_all/op_kernel/matmul_allto_all_pipeline.h`
- [All-to-all matmul](https://github.com/hicann/ops-transformer/blob/master/mc2/allto_all_matmul/op_kernel/allto_all_matmul_pipeline.h): `mc2/allto_all_matmul/op_kernel/allto_all_matmul_pipeline.h`
- [All-to-all-v quant GMM](https://github.com/hicann/ops-transformer/blob/master/mc2/allto_allv_quant_grouped_mat_mul/op_kernel/mc2_templates/communication/a2av_permute_engine.h): `mc2/allto_allv_quant_grouped_mat_mul/op_kernel/mc2_templates/communication/a2av_permute_engine.h`
- [Reduce-scatter tiling](https://github.com/hicann/ops-transformer/blob/master/mc2/matmul_reduce_scatter_v2/op_host/op_tiling/arch22/matmul_reduce_scatter_v2_smallm_rank8_pipeline_rules.h): `mc2/matmul_reduce_scatter_v2/op_host/op_tiling/arch22/matmul_reduce_scatter_v2_smallm_rank8_pipeline_rules.h`
- [Pipeline stage wiring](https://github.com/hicann/ops-transformer/blob/master/mc2/common/op_kernel/mc2_templates/scheduler/pipeline_builder.h): `mc2/common/op_kernel/mc2_templates/scheduler/pipeline_builder.h`

### Operator internals

- [Attention buffer manager](https://github.com/hicann/ops-transformer/blob/master/attention/common/op_kernel/attn_buffer_manager.h): `attention/common/op_kernel/attn_buffer_manager.h`
- [Attention buffer](https://github.com/hicann/ops-transformer/blob/master/attention/common/op_kernel/attn_buffer.h): `attention/common/op_kernel/attn_buffer.h`
- [Rotary embedding A2](https://github.com/hicann/ops-transformer/blob/master/attention/mla_prolog/op_kernel/arch22/service_rotary_position_embedding_arch22.h): `attention/mla_prolog/op_kernel/arch22/service_rotary_position_embedding_arch22.h`
- [Rotary embedding A5](https://github.com/hicann/ops-transformer/blob/master/attention/mla_prolog/op_kernel/arch35/service_rotary_position_embedding_arch35.h): `attention/mla_prolog/op_kernel/arch35/service_rotary_position_embedding_arch35.h`
- [Mix-core synchronization](https://github.com/hicann/ops-transformer/blob/master/mc2/3rd/weight_quant_batch_matmul_v2/op_kernel/arch35/catlass/pipeline/pipeline_stage_mixcore.h): `mc2/3rd/weight_quant_batch_matmul_v2/op_kernel/arch35/catlass/pipeline/pipeline_stage_mixcore.h`
- [SwiGLU pipeline helper](https://github.com/hicann/ops-transformer/blob/master/gmm/grouped_matmul_swiglu_quant/op_kernel/grouped_matmul_swiglu_pipeline.h): `gmm/grouped_matmul_swiglu_quant/op_kernel/grouped_matmul_swiglu_pipeline.h`
- [SwiGLU v2 helper](https://github.com/hicann/ops-transformer/blob/master/gmm/grouped_matmul_swiglu_quant_v2/op_kernel/grouped_matmul_swiglu_quant_v2_a8w4_msd_pipeline.h): `gmm/grouped_matmul_swiglu_quant_v2/op_kernel/grouped_matmul_swiglu_quant_v2_a8w4_msd_pipeline.h`

### Other components

- **Model or caller**

## Connections

- Model or caller → Attention operators: invokes
- Model or caller → MoE operators: invokes
- Model or caller → Grouped matmul operators: invokes
- Model or caller → Collective operators: invokes
- Attention buffer manager → Attention buffer: uses (evidence: `attention/common/op_kernel/attn_buffer_manager.h`)
- Rotary embedding A2 → Attention operators: supports MLA (evidence: `attention/mla_prolog/op_kernel/arch22/service_rotary_position_embedding_arch22.h`)
- Rotary embedding A5 → Attention operators: supports MLA (evidence: `attention/mla_prolog/op_kernel/arch35/service_rotary_position_embedding_arch35.h`)
- SwiGLU pipeline helper → Quantized SwiGLU: stages computation (evidence: `gmm/grouped_matmul_swiglu_quant/op_kernel/grouped_matmul_swiglu_pipeline.h`)
- SwiGLU v2 helper → Quantized SwiGLU v2: stages computation (evidence: `gmm/grouped_matmul_swiglu_quant_v2/op_kernel/grouped_matmul_swiglu_quant_v2_a8w4_msd_pipeline.h`)
- Pipeline stage wiring → Matmul all-to-all: provides stages (evidence: `mc2/common/op_kernel/mc2_templates/scheduler/pipeline_builder.h`)
- Pipeline stage wiring → All-to-all matmul: provides stages (evidence: `mc2/common/op_kernel/mc2_templates/scheduler/pipeline_builder.h`)
- Matmul all-to-all → Pipeline stage wiring: uses stages (evidence: `mc2/matmul_allto_all/op_kernel/matmul_allto_all_pipeline.h`)
- All-to-all matmul → Pipeline stage wiring: uses stages (evidence: `mc2/allto_all_matmul/op_kernel/allto_all_matmul_pipeline.h`)
