Ascend NPU生态

华为 NPU 概念

达芬奇架构

cat /usr/local/Ascend/ascend-toolkit/latest/x86_64-linux/ascend_toolkit_install.info

npu-smi 对标 nvidia-smi

$ watch -n 1 npu-smi info

msprof 对标 nsprof

AscendCL

cann 对标 cuda

MindIE-RT 对标 TensorRT

MindIE-ATB 面向Transformer模型的加速库(Ascend Transformer Boost)

onnx ep支持

onnx 算子支持

ATC 模型文件转换工具 ATC落地的是一个工具,把各种模型格式的表达,转换为om格式,由NPU推理执行。 这里就涉及如何让ATC认识自定义算子。

atc --model=hello.onnx --framework=5 --output=hello.om --input_shape="input_ids:1,5;att_mask:1,5;token_type_ids:1,5"  --soc_version=Ascend910B2C

msame 推理小工具 om模型文件推理小程序,源码里可以看出典型的asendCL推理用法。 https://gitee.com/ascend/tools/tree/master/msame

device/context/stream三个抽象概念的关系

https://www.hiascend.com/document/detail/zh/CANNCommunityEdition/80RC2alpha003/devguide/appdevg/aclcppdevg/aclcppdevg_000004.html

线程

Unified Buffer(UB)

UB 是唯一可编程的片上存储,所有 Cube 计算必须从 UB 读取数据。 NPU 的 Cube 单元理论算力高达 256 TFLOPS(FP16),但若数据供给不足,实际利用率可能低于 20%。

UB 的使命:作为 Global Memory 与 Cube 之间的“蓄水池”,通过预取 + 分块,确保计算单元永不“饿死”。

理想数据流:Global Memory → (DMA) → UB → (Load) → Cube Registers → Compute

开发接口

MindIE

面向Transformer模型的加速库(Ascend Transformer Boost)

几种attention的加速实现

AscendCL

Ascend C

Ascend C API的操作数都是Tensor类型

TBE&AI CPU

硬件

NPU集成了多种硬件加速器(也叫加速引擎),比如AiCore/AiVec/AiCpu(按照优先级排列)等,在图编译阶段会按照优先级为算子选择合适的引擎,即当同一个算子被多种引擎支持时,会选择优先级高的那个。

REF

https://gitee.com/ascend/samples/tree/master

https://ascendai.csdn.net/698610690a2f6a37c5906172.html

*****
Written by Lu.dev on 01 June 2024