LCOV - code coverage report
Current view: top level - aicpu_processer - ae_def.hpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 3 3
Test Date: 2026-08-12 11:05:02 Functions: 100.0 % 1 1

            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 _AE_DEFINE_H_
      12              : #define _AE_DEFINE_H_
      13              : 
      14              : #include <unistd.h>
      15              : #include <sys/syscall.h>
      16              : #include "aicpu_engine.h"
      17              : #include "aicpu_engine_struct.h"
      18              : #ifdef RUN_ON_AICPU
      19              : #include "aicpuprocess_weak_log.h"
      20              : #else
      21              : #define CCECPU 0
      22              : #endif
      23              : 
      24              : #include <stdlib.h>
      25              : #include <stdio.h>
      26              : #include <stdint.h>
      27              : #if defined(RUN_ON_AICPU) && defined(AE_PERF_LOG)
      28              : #include <sys/time.h>
      29              : #endif
      30              : #ifdef _AOSCORE_
      31              : #include <pthread.h>
      32              : #endif
      33              : namespace cce {
      34              : using char_t = char;
      35              : 
      36              : enum class AicpuOpErrorCode : uint32_t {
      37              :     AICPU_TASK_WATI_FLAG = 101U,             // aicpu task wait flag
      38              :     AICPU_END_OF_SEQUENCE_FLAG = 201U,       // aicpu end of sequence flag
      39              :     AICPU_TASK_ABORT = 301U,                 // ccl kernel task abort flag
      40              :     AICPU_SILENT_FAULT = 501U,               // aicpu silent fault flag
      41              :     AICPU_DETECT_FAULT = 502U,               // aicpu detect fault flag
      42              :     AICPU_DETECT_FAULT_NORAS = 503U,         // aicpu detect fault flag no RAS
      43              :     AICPU_DETECT_LOW_BIT_FAULT = 504U,       // aicpu detect low-bit fault flag
      44              :     AICPU_DETECT_LOW_BIT_FAULT_NORAS = 505U, // aicpu detect low-bit fault flag no RAS
      45              :     AICPU_KFC_PASSTHROUGH_START = 1000U,     // aicpu will passthrough errcode to rts
      46              :     AICPU_KFC_PASSTHROUGH_END = 1099U
      47              : };
      48              : 
      49           39 : inline long GetTid()
      50              : {
      51           39 :     thread_local static long tid = syscall(__NR_gettid);
      52           39 :     return tid;
      53              : }
      54              : 
      55              : #ifdef __GNUC__
      56              : #define likely(X) __builtin_expect((static_cast<int64_t>(X)), 1L)
      57              : #define unlikely(X) __builtin_expect((static_cast<int64_t>(X)), 0L)
      58              : #else
      59              : #define likely(X) (X)
      60              : #define unlikely(X) (X)
      61              : #endif
      62              : 
      63              : #define AE_MODULE_ID CCECPU
      64              : 
      65              : #ifdef RUN_ON_AICPU
      66              : 
      67              : #define AE_ERR_LOG(id, fmt, args...)                                                                         \
      68              :     do {                                                                                                     \
      69              :         if (&DlogRecord != nullptr) {                                                                        \
      70              :             dlog_error(                                                                                      \
      71              :                 static_cast<int32_t>(AE_MODULE_ID), "[%s][tid:%ld][AICPU_PROCESSER] " fmt, &__FUNCTION__[0], \
      72              :                 cce::GetTid(), ##args);                                                                      \
      73              :         }                                                                                                    \
      74              :     } while (0)
      75              : 
      76              : #define AE_WARN_LOG(id, fmt, args...)                                                                        \
      77              :     do {                                                                                                     \
      78              :         if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) {                                       \
      79              :             dlog_warn(                                                                                       \
      80              :                 static_cast<int32_t>(AE_MODULE_ID), "[%s][tid:%ld][AICPU_PROCESSER] " fmt, &__FUNCTION__[0], \
      81              :                 cce::GetTid(), ##args);                                                                      \
      82              :         }                                                                                                    \
      83              :     } while (0)
      84              : 
      85              : #define AE_INFO_LOG(id, fmt, args...)                                                                        \
      86              :     do {                                                                                                     \
      87              :         if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) {                                       \
      88              :             dlog_info(                                                                                       \
      89              :                 static_cast<int32_t>(AE_MODULE_ID), "[%s][tid:%ld][AICPU_PROCESSER] " fmt, &__FUNCTION__[0], \
      90              :                 cce::GetTid(), ##args);                                                                      \
      91              :         }                                                                                                    \
      92              :     } while (0)
      93              : 
      94              : #define AE_DEBUG_LOG(id, fmt, args...)                                                                       \
      95              :     do {                                                                                                     \
      96              :         if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) {                                       \
      97              :             dlog_debug(                                                                                      \
      98              :                 static_cast<int32_t>(AE_MODULE_ID), "[%s][tid:%ld][AICPU_PROCESSER] " fmt, &__FUNCTION__[0], \
      99              :                 cce::GetTid(), ##args);                                                                      \
     100              :         }                                                                                                    \
     101              :     } while (0)
     102              : 
     103              : #define AE_RUN_INFO_LOG(id, fmt, args...)                                                                        \
     104              :     do {                                                                                                         \
     105              :         if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) {                                           \
     106              :             dlog_info(                                                                                           \
     107              :                 static_cast<int32_t>(static_cast<uint32_t>(AE_MODULE_ID) | static_cast<uint32_t>(RUN_LOG_MASK)), \
     108              :                 "[%s][tid:%ld][AICPU_PROCESSER] " fmt, &__FUNCTION__[0], cce::GetTid(), ##args);                 \
     109              :         }                                                                                                        \
     110              :     } while (0)
     111              : 
     112              : #define AE_RUN_WARN_LOG(id, fmt, args...)                                                                        \
     113              :     do {                                                                                                         \
     114              :         if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) {                                           \
     115              :             dlog_warn(                                                                                           \
     116              :                 static_cast<int32_t>(static_cast<uint32_t>(AE_MODULE_ID) | static_cast<uint32_t>(RUN_LOG_MASK)), \
     117              :                 "[%s][tid:%ld][AICPU_PROCESSER] " fmt, &__FUNCTION__[0], cce::GetTid(), ##args);                 \
     118              :         }                                                                                                        \
     119              :     } while (0)
     120              : 
     121              : #define AE_MEMORY_LOG(id, fmt, args...)                                                                      \
     122              :     do {                                                                                                     \
     123              :         if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) {                                       \
     124              :             dlog_info(                                                                                       \
     125              :                 static_cast<int32_t>(AE_MODULE_ID), "[%s][tid:%ld][AICPU_PROCESSER] " fmt, &__FUNCTION__[0], \
     126              :                 cce::GetTid(), ##args);                                                                      \
     127              :         }                                                                                                    \
     128              :     } while (0)
     129              : 
     130              : #else
     131              : #define AE_ERR_LOG(id, fmt, args...) printf("[ERROR] [%s:%d][AICPU_PROCESSER] " fmt "\n", __FILE__, __LINE__, ##args)
     132              : #define AE_WARN_LOG(id, fmt, args...) printf("[ERROR] [%s:%d][AICPU_PROCESSER] " fmt "\n", __FILE__, __LINE__, ##args)
     133              : #define AE_INFO_LOG(id, fmt, args...) printf("[INFO] [%s:%d][AICPU_PROCESSER] " fmt "\n", __FILE__, __LINE__, ##args)
     134              : #define AE_DEBUG_LOG(id, fmt, args...) printf("[DEBUG] [%s:%d][AICPU_PROCESSER] " fmt "\n", __FILE__, __LINE__, ##args)
     135              : #define AE_MEMORY_LOG(id, fmt, args...) printf("[INFO] [%s:%d][AICPU_PROCESSER] " fmt "\n", __FILE__, __LINE__, ##args)
     136              : #define AE_RUN_INFO_LOG(id, fmt, args...) \
     137              :     printf("[INFO] [%s:%d][AICPU_PROCESSER] " fmt "\n", __FILE__, __LINE__, ##args)
     138              : #define AE_RUN_WARN_LOG(id, fmt, args...) \
     139              :     printf("[WARN] [%s:%d][AICPU_PROCESSER] " fmt "\n", __FILE__, __LINE__, ##args)
     140              : #endif
     141              : 
     142              : // perf log feature
     143              : #if defined(RUN_ON_AICPU) && defined(AE_PERF_LOG)
     144              : #define FUNC_PROFILE_START            \
     145              :     struct timeval ts;                \
     146              :     (void)gettimeofday(&ts, nullptr); \
     147              :     const uint64_t startUsec = (static_cast<uint64_t>(ts.tv_sec) * 1000000LU) + static_cast<uint64_t>(ts.tv_usec);
     148              : 
     149              : #define FUNC_PROFILE_END                                                                                         \
     150              :     (void)gettimeofday(&ts, nullptr);                                                                            \
     151              :     const uint64_t endUsec = (static_cast<uint64_t>(ts.tv_sec) * 1000000LU) + static_cast<uint64_t>(ts.tv_usec); \
     152              :     const uint64_t costUsec = endUsec - startUsec;                                                               \
     153              :     AE_INFO_LOG(AE_MODULE_ID, "[PERF] start=%lu, end=%lu, use=%lu us\n", startUsec, endUsec, costUsec);
     154              : #else
     155              : #define FUNC_PROFILE_START
     156              : #define FUNC_PROFILE_END
     157              : #endif
     158              : 
     159              : using tAERwLock = pthread_rwlock_t;
     160              : #define AE_RW_LOCK_RD_LOCK(lock) (void)pthread_rwlock_rdlock(lock)
     161              : #define AE_RW_LOCK_WR_LOCK(lock) (void)pthread_rwlock_wrlock(lock)
     162              : #define AE_RW_LOCK_UN_LOCK(lock) (void)pthread_rwlock_unlock(lock)
     163              : #define AE_RW_LOCK_DESTROY(lock) (void)pthread_rwlock_destroy(lock)
     164              : 
     165              : #define AE_SINGLETON_CREAT(CLASS)                       \
     166              :     do {                                                \
     167              :         mtx_.lock();                                    \
     168              :         if (instance_ != nullptr) {                     \
     169              :             mtx_.unlock();                              \
     170              :             return instance_;                           \
     171              :         } else {                                        \
     172              :             if (instance_ == nullptr) {                 \
     173              :                 instance_ = new (std::nothrow) CLASS(); \
     174              :                 if (instance_ == nullptr) {             \
     175              :                     mtx_.unlock();                      \
     176              :                     return nullptr;                     \
     177              :                 }                                       \
     178              :                 (void)instance_->Init();                \
     179              :             }                                           \
     180              :             mtx_.unlock();                              \
     181              :                                                         \
     182              :             return instance_;                           \
     183              :         }                                               \
     184              :     } while (0)
     185              : 
     186              : #define AE_SINGLETON_DESTROY()      \
     187              :     do {                            \
     188              :         mtx_.lock();                \
     189              :         if (instance_ == nullptr) { \
     190              :             mtx_.unlock();          \
     191              :             return;                 \
     192              :         }                           \
     193              :         delete instance_;           \
     194              :         instance_ = nullptr;        \
     195              :         mtx_.unlock();              \
     196              :                                     \
     197              :     } while (0)
     198              : 
     199              : } // namespace cce
     200              : #endif
        

Generated by: LCOV version 2.0-1