CANN/asc-devkit:获取系统周期数API

发布时间:2026/7/15 15:00:34
CANN/asc-devkit:获取系统周期数API GetSystemCycle(ISASI)产品支持情况产品是否支持Ascend 950PR/Ascend 950DT√Atlas A3 训练系列产品 / Atlas A3 推理系列产品√Atlas A2 训练系列产品 / Atlas A2 推理系列产品√Atlas 200I/500 A2 推理产品xAtlas 推理系列产品 AI CorexAtlas 推理系列产品 Vector CorexAtlas 训练系列产品x功能说明获取当前系统cycle数。针对Ascend 950PR/Ascend 950DT若换算成时间需要按照1GHz的频率时间单位为us换算公式为time (cycle数/1000) us 。针对Atlas A3 训练系列产品/Atlas A3 推理系列产品若换算成时间需要按照50MHz的频率时间单位为us换算公式为time (cycle数/50) us 。针对Atlas A2 训练系列产品/Atlas A2 推理系列产品若换算成时间需要按照50MHz的频率时间单位为us换算公式为time (cycle数/50) us 。函数原型__aicore__ inline int64_t GetSystemCycle()参数说明无返回值说明返回系统cycle数。约束说明该接口是PIPE_S流水若需要测试其他流水的指令时间需要在调用该接口前通过PipeBarrier插入对应流水的同步具体请参考调用示例。调用示例如下示例通过GetSystemCycle获取系统cycle数并换算成时间单位us。#include kernel_operator.h __aicore__ inline void InitTilingParam(int32_t totalSize, int32_t loopSize) { int64_t systemCycleBefore AscendC::GetSystemCycle(); // 调用GetBlockNum指令前的cycle数 loopSize totalSize / AscendC::GetBlockNum(); int64_t systemCycleAfter AscendC::GetSystemCycle(); // 调用GetBlockNum指令后的cycle数 int64_t GetBlockNumCycle systemCycleAfter - systemCycleBefore; // 执行GetBlockNum指令所用的cycle数 int64_t CycleToTimeBase 50; // cycle数转换成时间的基准单位固定为50 int64_t GetBlockNumTime GetBlockNumCycle/CycleToTimeBase; // 执行GetBlockNum指令所用时间单位为us };如下示例为获取矢量计算Add指令时间的关键代码片段在调用GetSystemCycle之前插入了PIPE_ALL同步可以保证相关指令执行完后再获取cycle数。PipeBarrierPIPE_ALL(); int64_t systemCycleBefore AscendC::GetSystemCycle(); // 调用Add指令前的cycle数 AscendC::Add(dstLocal, src0Local, src1Local, 512); PipeBarrierPIPE_ALL(); int64_t systemCycleAfter AscendC::GetSystemCycle(); // 调用Add指令后的cycle数 int64_t GetBlockNumCycle systemCycleAfter - systemCycleBefore; // 执行Add指令所用的cycle数 int64_t CycleToTimeBase 50; // cycle数转换成时间的基准单位固定为50 int64_t GetBlockNumTime GetBlockNumCycle/CycleToTimeBase; // 执行Add指令所用时间单位为us创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考