MUSA Compute Sanitizer 快速入门
本文用最短路径说明如何使用 mt-compute-sanitizer 包装原始 MUSA 程序、保存日志并判断结果。
前置条件
确保已经安装 MUSA Driver、MUSA Toolkit 和 MUSA Compute Sanitizer。
# 查看 GPU 和 Driver 信息
mthreads-gmi
# 查看 Toolkit / 编译器版本
/usr/local/musa/bin/mcc --version
# 查看 Compute Sanitizer 版本和帮助
/usr/local/musa/bin/mt-compute-sanitizer --version
/usr/local/musa/bin/mt-compute-sanitizer -h
备注
如果 shell 中找不到 mt-compute-sanitizer,请先确认 /usr/local/musa/bin 是否在 PATH 中,或直接使用完整路径 /usr/local/musa/bin/mt-compute-sanitizer。
第一次运行
1. 准备示例程序
假设您已有一个 MUSA 程序 vectorAdd:
# -g 生成调试信息,方便 sanitizer 输出更有用的定位信息
/usr/local/musa/bin/mcc -g -O2 vectorAdd.cu -o vectorAdd
如果没有现成的 MUSA 程序,可以参考 MUSA SDK 文档中的示例代码。
2. 普通运行原始程序
先确认原始程序自身可以运行,并保存应用输出和退出码:
./vectorAdd > vectorAdd.plain.out 2>&1
echo PLAIN_STATUS=$?
3. 使用 sanitizer 运行
推荐总是使用 --log-file 保存 sanitizer 日志:
/usr/local/musa/bin/mt-compute-sanitizer \
--log-file vectorAdd.san.log \
./vectorAdd \
> vectorAdd.san.out 2>&1
| 文件 | 内容 |
|---|---|
vectorAdd.san.log | sanitizer 检查到的 OOB、API error 和 ERROR SUMMARY。 |
vectorAdd.san.out | 程序自己的输出、stderr、测试框架日志。 |
4. 查看结果
grep "ERROR SUMMARY" vectorAdd.san.log
grep -n "Out of bounds memory access\|Program hit musaError\|ERROR SUMMARY" vectorAdd.san.log
无错误时应看到:
========= COMPUTE-SANITIZER
========= ERROR SUMMARY: 0 error
有错误时,ERROR SUMMARY 会非 0。例如 OOB 输出可能为:
========= COMPUTE-SANITIZER
========= ERROR SUMMARY: 448 errors
========= ERROR SUMMARY: 448 errors were not printed. Use --print-limit option to adjust the number of printed errors
该示例说明:错误数量很多时,summary 仍会统计总错误数;如果详细错误被截断,可通过 --print-limit 调整打印数量。