用途:在昇腾(Ascend)平台校验并构建 Triton 算子开发所需环境,覆盖 CANN、Python、torch/torch_npu、triton-ascend 及 PATH 等设置,适合配置环境、检查安装、验证可用性。
使用方式按顺序执行,每步依赖前一步成功,必须在同一终端完成。前置为必读官方在线文档 https://triton-ascend.readthedocs.io/zh-cn/latest/quick_start.html 与安装指南,按其中最新版本要求执行,文内版本表仅供参考。
步骤:1) CANN:执行 npu-smi info、which bisheng,无输出时尝试 source /usr/local/Ascend/cann/set_env.sh 或 source /usr/local/Ascend/ascend-toolkit/set_env.sh。2) Python:which python3、python3 --version;必要时 export PATH="/usr/bin:$PATH"。3) 按需装 Miniconda 并 conda create -n triton python=<官方要求版本>。4) torch:pip list | grep "torch",按需 pip install torch==<版本>、pip install torch_npu==<版本>,并用 python3 -c "import torch; print(torch.version)" 与简单张量代码验证。5) triton-ascend:pip list | grep "triton",卸载原生 triton 后 pip install triton-ascend。验证需完整阅读 scripts/01-vector-add.py 后运行,输出差异为 0.0 视为通过。
限制与故障处理:原生 triton 与 triton-ascend 不可共存;缺编译器可 apt-get install g++,源码编译缺依赖可 sudo apt install zlib1g-dev clang-15 lld-15。失败时保留报错与命令序列;不要跳过文档、CANN 检查或环境验证。