TritonFusion:基于 Triton 的多平台算子适配库项目

Triton算子多平台适配库,适配英伟达GPU、华为昇腾NPU、国产沐曦类GPU

Branch1Tags0
FilesLast commitLast update
5 months ago
4 months ago
4 months ago
5 months ago
5 months ago
4 months ago

TritonFusion

Triton 算子多平台适配库,适配英伟达 GPU、华为昇腾 NPU、国产沐曦类 GPU。

仓库结构

TritonFusion/
├── ops-basic/                 # 基础 Triton 算子
│   ├── reshape/
│   │   ├── task_desc.py/json  # 任务描述
│   │   ├── npu/               # Ascend NPU
│   │   │   ├── kernel.py
│   │   │   ├── test_npu.py
│   │   │   └── README.md
│   │   ├── gpu/               # NVIDIA GPU
│   │   │   ├── kernel.py
│   │   │   ├── test_gpu.py
│   │   │   └── README.md
│   │   └── musa/              # 沐曦 MUSA(待开发)
│   ├── permute/
│   ├── split/
│   ├── dropout_add_layernorm/
│   ├── conv_bn_relu/
│   └── depthwise_pointwise_conv/
├── ops-adv/                   # 高级 Triton 算子(待补充)
└── .gitignore                 # Python 缓存忽略规则

算子目录规范

每个算子按 {算子名}/{平台}/ 组织:

{op_name}/
├── README.md                # 算子总览(三平台状态)
├── task_desc.py             # 算子任务描述(含 Model + 输入函数)
├── task_desc.json           # 多 case 输入规格(JSONL,可选)
├── npu/                     # Ascend NPU 实现
│   ├── README.md
│   ├── kernel.py            # Triton-Ascend kernel 代码
│   ├── test_npu.py          # NPU 平台一键测试脚本
│   └── ...
├── gpu/                     # NVIDIA GPU 实现
│   ├── README.md
│   ├── kernel.py            # Triton-CUDA kernel 代码
│   ├── test_gpu.py          # GPU 平台一键测试脚本
│   └── ...
└── musa/                    # 沐曦 MUSA 实现(待开发)

平台

平台 目录 状态
华为 Ascend NPU npu/ 6/6 基础算子已在 NPU 验证通过(精度 + 性能落盘 summary.json)
NVIDIA GPU gpu/ 5/6 基础算子 Triton-CUDA 代码已实现,待 GPU 硬件实测
沐曦 MUSA musa/ 待开发

当前开发环境为 Ascend NPU,无 CUDA 设备,故 GPU 实现暂未在硬件上跑通验证。 GPU 端可用 tools/benchmark_gpu.py(需 CUDA 环境)做批量精度比对 + 跑分。

状态图例

  • ✅ 已验证:代码实现且在对应硬件上验证通过(精度 / 性能落盘)
  • 🟡 代码就绪:实现完成但尚未在该平台硬件实测
  • ⏳ 待开发

ops-basic 基础算子清单

算子 分类 NPU GPU MUSA 文档
reshape ops-basic ✅ 🟡 ⏳ README
permute ops-basic ✅ 🟡 ⏳ README
split ops-basic ✅ 🟡 ⏳ README
dropout_add_layernorm ops-basic ✅ 🟡 ⏳ README
conv_bn_relu ops-basic ✅ 🟡 ⏳ README
depthwise_pointwise_conv ops-basic ✅ ⏳ ⏳ README

使用方式

import sys
sys.path.insert(0, "/path/to/TritonFusion/ops-basic/reshape/npu")
from kernel import ModelNew

model = ModelNew()
x = torch.randn(2, 3, 4, device="npu")
output = model(x, (6, 4))

每个平台目录下有独立测试脚本,可直接运行验证:

python3 ops-basic/reshape/npu/test_npu.py
python3 ops-basic/reshape/gpu/test_gpu.py

各算子详细说明见 ops-basic/{op}/README.md 以及对应平台目录下的 npu/README.md、gpu/README.md。

Introduction

Triton算子多平台适配库,适配英伟达GPU、华为昇腾NPU、国产沐曦类GPU

Customize your domain