GetSystemCycle(ISASI)

Function Usage

Obtains the number of cycles in the current system. If the number of cycles is converted to time (unit: μs), the frequency must be 50 MHz. The conversion formula is as follows: Time = (Number of cycles/50) μs.

Prototype

1
__aicore__ inline int64_t GetSystemCycle()

Parameters

None

Returns

Returns the number of system cycles of the int64 type.

Availability

Atlas A2 training products/Atlas A2 inference products

Atlas A3 training products/Atlas A3 inference products

Constraints

None

Examples

In the following example, GetSystemCycle is used to obtain the number of system cycles and convert the number into time (unit: μs).
 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(); // Number of cycles before calling GetBlockNum.
    loopSize = totalSize / AscendC::GetBlockNum();
    int64_t systemCycleAfter = AscendC::GetSystemCycle(); // Number of cycles after calling GetBlockNum.
    int64_t GetBlockNumCycle = systemCycleBefore - systemCycleAfter; // Number of cycles required for executing GetBlockNum.
    int64_t CycleToTimeBase = 50; // Base unit for converting cycle counts into time. The value is always 50.
    int64_t GetBlockNumTime = GetBlockNumCycle/CycleToTimeBase; // Time required for executing GetBlockNum, in μs.
};