clock

Applicable Products

  • Ascend 950PR&950DT products: Supported
  • Atlas A3 products: Supported
  • Atlas A2 products: Supported
  • Atlas 200I/500 A2 inference products: Not supported
  • Atlas inference products AI Core: Not supported
  • Atlas inference products Vector Core: Not supported
  • Atlas training products: Not supported

Description

This API provides the Clock timestamp function in SIMD and SIMT debugging scenarios. It records the number of clock cycles (Cycle Count) elapsed from program startup to the moment the API is called, enabling precise analysis of execution latency and performance bottlenecks.

Prototype

__aicore__ inline uint64_t clock(void)

The following API is the clock API used in SIMT and is supported only on Ascend 950PR&950DT products.

inline uint64_t clock(void)

Parameters

None

Return Value

Returns the number of clock cycles elapsed from program startup to the moment the API is called.

Constraints

  • SIMT scenario support is as follows:
    • Ascend 950PR&950DT products: Supported.
    • Atlas A3 products: Not supported.
    • Atlas A2 products: Not supported.

Required Header File

To use this API, include the "utils/debug/asc_time.h" header file.

#include "utils/debug/asc_time.h"

Examples

  • SIMT programming scenario:

    __global__ __launch_bounds__(1024) void SimtKernel(uint64_t* dst)
    {
        int idx = threadIdx.x + blockIdx.x * blockDim.x;
        dst[idx] = clock();
    }
  • SIMD and SIMT hybrid programming scenario:

    __simt_vf__ __launch_bounds__(1024) inline void SimtKernel(__gm__ uint64_t* dst)
    {
        int idx = threadIdx.x + blockIdx.x * blockDim.x;
        dst[idx] = clock();
    }
  • SIMD programming scenario:

    __global__ __aicore__ void AicoreKernel(__gm__ uint64_t* dst)
    {
        int idx = AscendC::GetBlockIdx();
        dst[idx] = clock();
    }