GetSystemCycle(ISASI)
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
√ |
|
√ |
|
x |
|
x |
|
x |
|
x |
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
The number of cycles in the system.
Constraints
This API is the PIPE_S pipeline. If you want to test the instruction time of other pipelines, insert synchronization of the corresponding pipeline by using PipeBarrier before calling this API. For details, see Examples.
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 = systemCycleAfter - systemCycleBefore; // Number of cycles required for executing GetBlockNum. int64_t CycleToTimeBase = 50; // Base unit for converting cycle counts into time. The value is fixed to 50. int64_t GetBlockNumTime = GetBlockNumCycle/CycleToTimeBase; // Time required for executing GetBlockNum, in μs. };
- The following example shows the key code snippet for obtaining the time of Add for vector computation. Before GetSystemCycle is called, the Pipe_ALL synchronization is inserted to ensure that the number of cycles is obtained after the related instruction is executed.
1 2 3 4 5 6 7 8
PipeBarrier<PIPE_ALL>(); int64_t systemCycleBefore = AscendC::GetSystemCycle(); // Number of cycles before calling Add. AscendC::Add(dstLocal, src0Local, src1Local, 512); PipeBarrier<PIPE_ALL>(); int64_t systemCycleAfter = AscendC::GetSystemCycle(); // Number of cycles after calling Add. int64_t GetBlockNumCycle = systemCycleAfter - systemCycleBefore; // Number of cycles required for executing Add. int64_t CycleToTimeBase = 50; // Base unit for converting cycle counts into time. The value is fixed to 50. int64_t GetBlockNumTime = GetBlockNumCycle/CycleToTimeBase; // Time required for executing Add, in μs.
Parent topic: TPosition