获取当前系统cycle数,若换算成时间需要按照50MHz的频率,时间单位为us,换算公式为:time = (cycle数/50) us 。
1 | __aicore__ inline int64_t GetSystemCycle() |
无
返回int64类型的系统cycle数。
该接口是PIPE_S流水,若需要测试其他流水的指令时间,需要在调用该接口前通过PipeBarrier插入对应流水的同步,具体请参考调用示例。
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 }; |
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 |