昇腾社区首页
中文
注册

GetSystemCycle(ISASI)

功能说明

获取当前系统cycle数,若换算成时间需要按照50MHz的频率,时间单位为us,换算公式为:time = (cycle数/50) us 。

函数原型

1
__aicore__ inline int64_t GetSystemCycle()

参数说明

返回值

返回int64类型的系统cycle数。

支持的型号

Atlas A2 训练系列产品/Atlas 800I A2 推理产品

约束说明

该接口是PIPE_S流水,若需要测试其他流水的指令时间,需要在调用该接口前通过PipeBarrier插入对应流水的同步,具体请参考调用示例

调用示例

  • 如下示例通过GetSystemCycle获取系统cycle数,并换算成时间(单位:us)。
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    #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 = systemCycleBefore - systemCycleAfter; // 执行GetBlockNum指令所用的cycle数
        int64_t CycleToTimeBase = 50; // cycle数转换成时间的基准单位,固定为50
        int64_t GetBlockNumTime = GetBlockNumCycle/CycleToTimeBase; // 执行GetBlockNum指令所用时间,单位为us
    };
    
  • 如下示例为获取矢量计算Add指令时间的关键代码片段,在调用GetSystemCycle之前,插入了PIPE_ALL同步,可以保证相关指令执行完后再获取cycle数。
    1
    2
    3
    4
    5
    6
    7
    8
    PipeBarrier<PIPE_ALL>();
    int64_t systemCycleBefore = AscendC::GetSystemCycle(); // 调用Add指令前的cycle数
    AscendC::Add(dstLocal, src0Local, src1Local, 512);
    PipeBarrier<PIPE_ALL>();
    int64_t systemCycleAfter = AscendC::GetSystemCycle(); // 调用Add指令后的cycle数
    int64_t GetBlockNumCycle = systemCycleBefore - systemCycleAfter; // 执行Add指令所用的cycle数
    int64_t CycleToTimeBase = 50; // cycle数转换成时间的基准单位,固定为50
    int64_t GetBlockNumTime = GetBlockNumCycle/CycleToTimeBase; // 执行Add指令所用时间,单位为us