# SHMEM搭配工具算子调测指导 ## msprof shmem后续会适配[msprof算子调优工具](https://www.hiascend.com/document/detail/zh/mindstudio/830/ODtools/Operatordevelopmenttools/atlasopdev_16_0082.html) 当前版本暂不支持,预计Q1支持。 ## mssanitizer shmem已适配[mssanitizer内存检测工具](https://www.hiascend.com/document/detail/zh/mindstudio/830/ODtools/Operatordevelopmenttools/atlasopdev_16_0039.html)(暂不支持软同步竞争检测) **该功能依赖对应 CANN 版本能力,预计社区版 9.0.0-beta.2 支持** **提前尝鲜可自行编译[mssanitizer](https://gitcode.com/Ascend/mssanitizer?source_module=search_project)工具,并将编译产物替换CANN包内部`tools/mssanitizer`** 使能mssanitizer工具能力,在shmem/目录编译: ```sh bash scripts/build.sh -mssanitizer ``` 为算子工程在编译时添加`-g --cce-enable-sanitizer`编译选项。 工具默认开启内存检测能力,即--tool memcheck,一般情况按如下方式拉起可执行文件即可。 ```sh mssanitizer -- application parameter1 parameter2 ... ``` 如果需要更详细的工具能力可参考[mssanitizer内存检测工具](https://www.hiascend.com/document/detail/zh/mindstudio/830/ODtools/Operatordevelopmenttools/atlasopdev_16_0039.html)按如下格式控制参数 ```sh mssanitizer -- ``` ### mssanitizer执行SHMEM自带的example样例 shmem的[AllGather](https://gitcode.com/cann/shmem/tree/master/examples/allgather)样例运行脚本提供了tool选项选择拉起工具。 编译样例且使能工具能力 ```sh bash scripts/build.sh -examples -mssanitizer ``` 用mssanitizer工具拉起allgather样例进行内存检测 ```sh cd examples/allgather bash run.sh -ranks 2 -tool mssanitizer ``` ### 内存越界日志 当内存发生越界时工具会先打屏越界地址,越界内存大小、所属kernel,核号、卡号等信息。 随后打屏越界代码的调用栈。可以协助开发快速定位越界问题以及排查代码漏洞。 ![image](images/tools/mssanitizer_example.png) **注:`aclshmem_malloc`等shmem提供的内存分配接口是对已完成物理地址映射的一大块连续虚拟内存进行划分,不涉及实际的物理内存申请或虚拟内存对物理内存的映射操作。如使用的虚拟地址已完成和已分配物理地址的映射,即使超出`aclshmem_malloc`分配的范围也不会报错,因为该地址对应的内存可以合法使用。** ## profiling shmem提供了Profiling打点工具,通过采集系统时钟周期数并转换为实际时间,精准量化不同Block(计算核)、不同Frame(埋点 ID)下的MTE搬运性能,详细介绍请参考[在示例中使用Profiling工具](profiling.md).