在样例工程使用Profiling工具进行性能采集【免费下载链接】shmemCANN SHMEM 是面向昇腾平台的多机多卡内存通信库基于OpenSHMEM 标准协议实现跨设备的高效内存访问与数据同步。项目地址: https://gitcode.com/cann/shmem本小节介绍基于GetSystemCycle的Profiling工具进行分析数据搬运操作的耗时通过采集系统时钟周期数并转换为实际时间精准量化不同Block计算核、不同Frame埋点 ID下的MTE搬运性能。Profiling工具核心特性 按 Block核和 Frame埋点 ID维度统计操作执行次数count和总耗时周期cycles 自动将周期数转换为微秒us精确到三位小数位输出 仅显示有有效数据的Block和Frame过滤空数据提升可读性关于GetSystemCycle的详细介绍可参考GetSystemCycle。插入调试代码插入打点修改kernel代码在需要打点的位置前后插入SHMEMI_PROF_START和SHMEMI_PROF_END具体可参考examples/allgather/allgather_kernel.cpp。--- a/examples/allgather/allgather_kernel.cpp b/examples/allgather/allgather_kernel.cpp -12,6 12,9 #include acl/acl.h #include shmem.h // shmem prof #include utils/prof/shmemi_prof.h #undef inline #include opdev/fp16_t.h #include opdev/bfloat16.h -72,6 75,7 ACLSHMEM_DEVICE void all_gather_origin(__gm__ T *input, __gm__ T *output, __gm__ int64_t times 0; int64_t flag 0; while (copy_total_size copy_ub_size) { SHMEMI_PROF_START(0); aclshmemx_mte_put_nbi(gva_data_gm aivIndex * len_per_core times * copy_ub_num, input_gm aivIndex * len_per_core times * copy_ub_num, tmp_buff, copy_ub_size, copy_ub_num, my_rank, EVENT_ID0); -80,7 84,7 ACLSHMEM_DEVICE void all_gather_origin(__gm__ T *input, __gm__ T *output, __gm__ times 1; flag times magic; aclshmemx_signal_op(gva_sync_gm flag_offset, flag, ACLSHMEM_SIGNAL_SET, my_rank); - SHMEMI_PROF_END(0); AscendC::SetFlagAscendC::HardEvent::S_MTE2(EVENT_ID0); AscendC::WaitFlagAscendC::HardEvent::S_MTE2(EVENT_ID0);在host侧的应用程序中增加profiling数据展示具体可参考examples/allgather/main.cpp--- a/examples/allgather/main.cpp b/examples/allgather/main.cpp -120,6 120,8 int test_aclshmem_all_gather(int rank_id, int n_ranks) } status aclrtSynchronizeStream(stream); aclshmemx_show_prof(nullptr, true); // Result Check T *output_host; size_t output_size n_ranks * trans_size * sizeof(T);注意只打印采集的pe和block无数据的会跳过打印。编译运行按照如上步骤修改完后进行编译算子样例。bash scripts/build.sh -examples在examples/allgather目录执行demo:export SHMEM_CYCLE_PROF_PE0 # 设置需要采集的pe当前仅支持采集某个指定的pe bash run.sh -ranks 2观察其demo打印会有如下样式打印 BlockID FrameID Cycles Count AvgTime(us) ------------------------------------------------------------ 0 0 7506966 34050 4.409 1 0 7485800 34050 4.397 2 0 8290500 34050 4.870 3 0 8279083 34050 4.863 4 0 8255644 34050 4.849 5 0 8275272 34050 4.861 6 0 8429026 34050 4.951 7 0 8404425 34050 4.937 字段描述keyworddescriptionBlockIDDevice核的indexFrameID埋点IDCycles系统cycle数Count执行总次数AvgTime(us)执行平均时间【免费下载链接】shmemCANN SHMEM 是面向昇腾平台的多机多卡内存通信库基于OpenSHMEM 标准协议实现跨设备的高效内存访问与数据同步。项目地址: https://gitcode.com/cann/shmem创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考