GroupedBroadcast 算子脚本使用指南

可用脚本总览

operators/grouped_broadcast/tests/
├── quick_rebuild.sh              # 快速编译+安装(不测试)
├── rebuild_and_test.sh           # 一键编译+安装+测试(推荐)
├── REBUILD_GUIDE.md              # 详细文档
│
├── st/
│   ├── run.sh                    # ST 测试(功能验证)
│   └── test_grouped_broadcast_python.py  # Python Golden 对比
│
├── perf/
│   ├── build_perf.sh             # 构建性能测试程序
│   ├── quick_prof.sh             # 快速性能采集(CSV)
│   ├── simulator_timeline.sh     # Simulator 时序(trace.json)
│   ├── timeline_detail.sh        # TimelineDetail(可能失败)
│   ├── CAMODEL_GUIDE.md          # Simulator/Camodel 指南
│   ├── TIMELINE_ISSUE.md         # TimelineDetail 问题排查
│   └── README.md                 # 性能测试文档
│
└── ut/
    └── run.sh                    # UT 测试(Tiling/API 单元测试)

按场景选择脚本

场景 1: 修改代码后重新编译(推荐)

# 一键编译、安装、测试(交互式选择)
cd tests
bash rebuild_and_test.sh

# 流程:
#   [Step 1] 编译算子
#   [Step 2] 安装算子
#   [Step 3] 设置环境
#   [Step 4] 可选:运行 ST 测试
#   [Step 5] 可选:运行性能测试

场景 2: 快速编译安装(不测试)

# 仅编译+安装,快速验证编译是否成功
cd tests
bash quick_rebuild.sh

# 流程:
#   [Step 1] 编译算子
#   [Step 2] 安装算子
#   [Step 3] 设置环境
#   完成!可以手动运行测试

场景 3: 仅运行测试(不重新编译)

# 设置环境
source /home/developer/Ascend/cann-9.0.0/bin/setenv.bash
source $ASCEND_OPP_PATH/vendors/grouped_broadcast_custom/bin/set_env.bash

# ST 测试(功能验证)
cd tests/st
bash run.sh

# 性能测试(选择一个)
cd tests/perf
bash quick_prof.sh        # 快速 CSV(推荐)
bash simulator_timeline.sh # Simulator trace.json
bash timeline_detail.sh    # TimelineDetail(可能失败)

场景 4: UT 测试(单元测试)

# 测试 Tiling、InferShape、op_api 逻辑
cd tests/ut
bash run.sh

场景 5: Python Golden 对比

# 使用 Python 对比 NPU 输出与 Golden
cd tests/st
python3 test_grouped_broadcast_python.py --mode binary

# 或正确性自测
python3 test_grouped_broadcast_python.py --mode correctness

详细流程

修改 Tiling/Kernel 后完整流程

Step 1: 修改代码

# 修改 Tiling
vim op_host/arch22/grouped_broadcast_tiling.cpp

# 修改 Kernel
vim op_kernel/arch22/grouped_broadcast.cpp

Step 2: 编译安装

# 快速编译安装
cd tests
bash quick_rebuild.sh

# 或一键编译测试
bash rebuild_and_test.sh

Step 3: 验证结果

# 查看 ST 测试结果
cat ../st/build-real/test_summary.txt

# 查看性能数据
cat ../perf/msprof_output/OPPROF_*/OpBasicInfo.csv

Step 4: 查看时序图(可选)

cd ../perf
bash simulator_timeline.sh

# 导入 MindStudio Insight
# File → Import → simulator_output/OPPROF_*/simulator/trace.json

性能测试选项对比

脚本 输出 优势 适用场景
quick_prof.sh CSV(8个文件) 快速、真实硬件性能 性能验收、瓶颈定位
simulator_timeline.sh trace.json(122MB) 完整时序、指令级分析 流水线调试、优化
timeline_detail.sh visualize_data.bin(可能失败) 真实硬件时序 不推荐(自定义算子受限)

推荐:

  • 开发阶段:simulator_timeline.sh → 查看流水线
  • 调优阶段:quick_prof.sh → 定位瓶颈
  • 验收阶段:quick_prof.sh → Task Duration 验收

环境设置

必要环境变量:

# CANN 环境
source /home/developer/Ascend/cann-9.0.0/bin/setenv.bash

# 自定义算子环境(每次安装后需要重新设置)
source $ASCEND_OPP_PATH/vendors/grouped_broadcast_custom/bin/set_env.bash

验证环境:

echo $ASCEND_HOME_PATH
echo $ASCEND_OPP_PATH
echo $ASCEND_CUSTOM_OPP_PATH
echo $LD_LIBRARY_PATH | grep grouped_broadcast_custom

常见错误处理

错误 1: 编译失败

# 查看错误
bash build.sh --soc=ascend910b -j8 2>&1 | tee build.log | grep -E "error|Error"

# 清理重新编译
bash build.sh --soc=ascend910b --make_clean -j8
bash build.sh --soc=ascend910b -j8

错误 2: ST 测试失败

# 查看错误详情
bash tests/st/run.sh 2>&1 | grep -A 10 "FAIL"

# 使用 Python Golden 对比
cd tests/st
python3 test_grouped_broadcast_python.py --mode binary

错误 3: 性能数据异常

# 查看 CSV
cat tests/perf/msprof_output/OPPROF_*/OpBasicInfo.csv

# 使用 Simulator 查看详细时序
bash tests/perf/simulator_timeline.sh
cat tests/perf/simulator_output/OPPROF_*/simulator/core0.veccore0/core0.veccore0_instr_exe.csv

错误 4: visualize_data.bin 无数据

# 问题:TimelineDetail 采集失败(自定义算子受限)
# 解决:使用 Simulator

bash tests/perf/simulator_timeline.sh

# 查看详细排查文档
cat tests/perf/TIMELINE_ISSUE.md

快速命令参考

# === 快速编译安装 ===
cd tests && bash quick_rebuild.sh

# === 一键编译测试 ===
cd tests && bash rebuild_and_test.sh

# === ST 测试 ===
cd tests/st && bash run.sh

# === UT 测试 ===
cd tests/ut && bash run.sh

# === Python Golden ===
cd tests/st && python3 test_grouped_broadcast_python.py --mode binary

# === 性能 CSV ===
cd tests/perf && bash quick_prof.sh

# === Simulator 时序 ===
cd tests/perf && bash simulator_timeline.sh

# === 查看结果 ===
cat tests/st/build-real/test_summary.txt
cat tests/perf/msprof_output/OPPROF_*/OpBasicInfo.csv
ls -lh tests/perf/simulator_output/OPPROF_*/simulator/trace.json

推荐工作流:

# 修改代码
vim op_kernel/arch22/grouped_broadcast.cpp

# 快速编译安装
cd tests && bash quick_rebuild.sh

# 运行 ST 测试
cd st && bash run.sh

# 运行性能测试
cd perf && bash quick_prof.sh

# 查看时序图(可选)
bash simulator_timeline.sh

详细文档:

  • tests/REBUILD_GUIDE.md - 编译运行详细指南
  • tests/perf/CAMODEL_GUIDE.md - Simulator/Camodel 使用指南
  • tests/perf/TIMELINE_ISSUE.md - TimelineDetail 问题排查