Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #ifndef __AICPU_HCCL_COMMON_H__
12 : #define __AICPU_HCCL_COMMON_H__
13 :
14 : #include "profiling_manager_device.h"
15 : #include "dtype_common.h"
16 : #include "log.h"
17 : #include "sal_pub.h"
18 :
19 1033 : inline uint32_t DataUnitSize(HcclDataType dataType)
20 : {
21 1033 : if (dataType >= HCCL_DATA_TYPE_RESERVED) {
22 0 : HCCL_ERROR("[dataUnitSize]data type[%s] out of range[%d, %d]", GetDataTypeEnumStr(dataType).c_str(),
23 : HCCL_DATA_TYPE_INT8, HCCL_DATA_TYPE_RESERVED - 1);
24 0 : return 0;
25 : }
26 :
27 1033 : return SIZE_TABLE[dataType];
28 : }
29 :
30 : #define NSEC_PER_SEC 1000000000U
31 :
32 297083623 : inline u64 GetCurCpuTimestamp(bool isProfTime = false)
33 : {
34 : #ifndef CCL_LLT
35 : if (isProfTime && dfx::ProfilingManager::GetProfL1State()) {
36 : uint64_t cntvct;
37 : AsmCntvc(cntvct);
38 : return cntvct;
39 : } else {
40 : struct timespec timestamp;
41 : (void)clock_gettime(CLOCK_MONOTONIC_RAW, ×tamp);
42 : return static_cast<u64>((timestamp.tv_sec * NSEC_PER_SEC) + (timestamp.tv_nsec));
43 : }
44 : #else
45 45836223 : struct timespec timestamp;
46 297083623 : (void)clock_gettime(CLOCK_MONOTONIC_RAW, ×tamp);
47 297083623 : return static_cast<u64>((timestamp.tv_sec * NSEC_PER_SEC) + (timestamp.tv_nsec));
48 : #endif
49 : }
50 :
51 : #endif // __AICPU_HCCL_COMMON_HPP__
|