LCOV - code coverage report
Current view: top level - acl/utils - data_type_utils.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 62.3 % 175 109
Test Date: 2026-08-31 10:05:54 Functions: 85.0 % 20 17

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2026 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 ACL_UTILS_DATA_TYPE_UTILS_H
      12              : #define ACL_UTILS_DATA_TYPE_UTILS_H
      13              : 
      14              : #include <unordered_map>
      15              : #include <memory>
      16              : #include <string>
      17              : #include "securec.h"
      18              : #include "acl/acl_base.h"
      19              : #include "acl/acl_rt.h"
      20              : #include "acl/acl_tdt_queue.h"
      21              : #include "runtime/base.h"
      22              : #include "runtime/config.h"
      23              : #include "acl/acl_tdt.h"
      24              : #include "tdt/data_common.h"
      25              : #include "acl_tdt_channel/tensor_data_transfer.h"
      26              : 
      27              : namespace acl {
      28              : 
      29              : const char* GetDataTypeDesc(aclDataType type);
      30              : const char* GetMemcpyKindDesc(aclrtMemcpyKind kind);
      31              : 
      32            8 : inline const char* GetExceptionExpandTypeDesc(rtExceptionExpandType_t type)
      33              : {
      34              :     static const std::unordered_map<rtExceptionExpandType_t, const char*> exceptionExpandTypeDescMap = {
      35              :         {RT_EXCEPTION_INVALID, "EXCEPTION_INVALID(0)"}, {RT_EXCEPTION_FFTS_PLUS, "EXCEPTION_FFTS_PLUS(1)"},
      36              :         {RT_EXCEPTION_AICORE, "EXCEPTION_AICORE(2)"},   {RT_EXCEPTION_UB, "EXCEPTION_UB(3)"},
      37              :         {RT_EXCEPTION_CCU, "EXCEPTION_CCU(4)"},         {RT_EXCEPTION_FUSION, "EXCEPTION_FUSION(5)"},
      38              :         {RT_EXCEPTION_AICPU, "EXCEPTION_AICPU(6)"},
      39           23 :     };
      40              : 
      41            8 :     auto it = exceptionExpandTypeDescMap.find(type);
      42            8 :     if (it != exceptionExpandTypeDescMap.end()) {
      43            8 :         return it->second;
      44              :     }
      45              :     static thread_local char enumBuf[32];
      46            0 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(type));
      47            0 :     enumBuf[sizeof(enumBuf) - 1U] = '\0';
      48            0 :     return enumBuf;
      49              : }
      50              : 
      51            2 : inline const char* GetGroupAttrDesc(aclrtGroupAttr attr)
      52              : {
      53              :     static const std::unordered_map<aclrtGroupAttr, const char*> groupAttrDescMap = {
      54              :         {ACL_GROUP_AICORE_INT, "GROUP_AICORE_INT(0)"}, {ACL_GROUP_AIV_INT, "GROUP_AIV_INT(1)"},
      55              :         {ACL_GROUP_AIC_INT, "GROUP_AIC_INT(2)"},       {ACL_GROUP_SDMANUM_INT, "GROUP_SDMANUM_INT(3)"},
      56              :         {ACL_GROUP_ASQNUM_INT, "GROUP_ASQNUM_INT(4)"}, {ACL_GROUP_GROUPID_INT, "GROUP_GROUPID_INT(5)"},
      57            4 :     };
      58              : 
      59            2 :     auto it = groupAttrDescMap.find(attr);
      60            2 :     if (it != groupAttrDescMap.end()) {
      61            0 :         return it->second;
      62              :     }
      63              :     static thread_local char enumBuf[32];
      64            2 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(attr));
      65            2 :     enumBuf[sizeof(enumBuf) - 1U] = '\0';
      66            2 :     return enumBuf;
      67              : }
      68              : 
      69           10 : inline const char* GetTsIdDesc(aclrtTsId tsId)
      70              : {
      71              :     static const std::unordered_map<aclrtTsId, const char*> tsIdDescMap = {
      72              :         {ACL_TS_ID_AICORE, "TS_ID_AICORE(0)"},
      73              :         {ACL_TS_ID_AIVECTOR, "TS_ID_AIVECTOR(1)"},
      74              :         {ACL_TS_ID_RESERVED, "TS_ID_RESERVED(2)"},
      75           12 :     };
      76              : 
      77           10 :     auto it = tsIdDescMap.find(tsId);
      78           10 :     if (it != tsIdDescMap.end()) {
      79           10 :         return it->second;
      80              :     }
      81              :     static thread_local char enumBuf[32];
      82            0 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(tsId));
      83            0 :     enumBuf[sizeof(enumBuf) - 1U] = '\0';
      84            0 :     return enumBuf;
      85              : }
      86              : 
      87            0 : inline const char* GetQueueRouteQueryModeDesc(acltdtQueueRouteQueryMode mode)
      88              : {
      89              :     static const std::unordered_map<acltdtQueueRouteQueryMode, const char*> queueRouteQueryModeDescMap = {
      90              :         {ACL_TDT_QUEUE_ROUTE_QUERY_SRC, "TDT_QUEUE_ROUTE_QUERY_SRC(0)"},
      91              :         {ACL_TDT_QUEUE_ROUTE_QUERY_DST, "TDT_QUEUE_ROUTE_QUERY_DST(1)"},
      92              :         {ACL_TDT_QUEUE_ROUTE_QUERY_SRC_AND_DST, "TDT_QUEUE_ROUTE_QUERY_SRC_AND_DST(2)"},
      93              :         {ACL_TDT_QUEUE_ROUTE_QUERY_ABNORMAL, "TDT_QUEUE_ROUTE_QUERY_ABNORMAL(100)"},
      94            0 :     };
      95              : 
      96            0 :     auto it = queueRouteQueryModeDescMap.find(mode);
      97            0 :     if (it != queueRouteQueryModeDescMap.end()) {
      98            0 :         return it->second;
      99              :     }
     100              :     static thread_local char enumBuf[32];
     101            0 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(mode));
     102            0 :     enumBuf[sizeof(enumBuf) - 1U] = '\0';
     103            0 :     return enumBuf;
     104              : }
     105              : 
     106            2 : inline const char* GetQueueAttrTypeDesc(acltdtQueueAttrType type)
     107              : {
     108              :     static const std::unordered_map<acltdtQueueAttrType, const char*> queueAttrTypeDescMap = {
     109              :         {ACL_TDT_QUEUE_NAME_PTR, "TDT_QUEUE_NAME_PTR(0)"},
     110              :         {ACL_TDT_QUEUE_DEPTH_UINT32, "TDT_QUEUE_DEPTH_UINT32(1)"},
     111            4 :     };
     112              : 
     113            2 :     auto it = queueAttrTypeDescMap.find(type);
     114            2 :     if (it != queueAttrTypeDescMap.end()) {
     115            2 :         return it->second;
     116              :     }
     117              :     static thread_local char enumBuf[32];
     118            0 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(type));
     119            0 :     enumBuf[sizeof(enumBuf) - 1U] = '\0';
     120            0 :     return enumBuf;
     121              : }
     122              : 
     123            3 : inline const char* GetQueueRouteParamTypeDesc(acltdtQueueRouteParamType type)
     124              : {
     125              :     static const std::unordered_map<acltdtQueueRouteParamType, const char*> queueRouteParamTypeDescMap = {
     126              :         {ACL_TDT_QUEUE_ROUTE_SRC_UINT32, "TDT_QUEUE_ROUTE_SRC_UINT32(0)"},
     127              :         {ACL_TDT_QUEUE_ROUTE_DST_UINT32, "TDT_QUEUE_ROUTE_DST_UINT32(1)"},
     128              :         {ACL_TDT_QUEUE_ROUTE_STATUS_INT32, "TDT_QUEUE_ROUTE_STATUS_INT32(2)"},
     129            5 :     };
     130              : 
     131            3 :     auto it = queueRouteParamTypeDescMap.find(type);
     132            3 :     if (it != queueRouteParamTypeDescMap.end()) {
     133            3 :         return it->second;
     134              :     }
     135              :     static thread_local char enumBuf[32];
     136            0 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(type));
     137            0 :     enumBuf[sizeof(enumBuf) - 1U] = '\0';
     138            0 :     return enumBuf;
     139              : }
     140              : 
     141            0 : inline const char* GetQueueRouteQueryInfoParamTypeDesc(acltdtQueueRouteQueryInfoParamType type)
     142              : {
     143              :     static const std::unordered_map<acltdtQueueRouteQueryInfoParamType, const char*>
     144              :         queueRouteQueryInfoParamTypeDescMap = {
     145              :             {ACL_TDT_QUEUE_ROUTE_QUERY_MODE_ENUM, "TDT_QUEUE_ROUTE_QUERY_MODE_ENUM(0)"},
     146              :             {ACL_TDT_QUEUE_ROUTE_QUERY_SRC_ID_UINT32, "TDT_QUEUE_ROUTE_QUERY_SRC_ID_UINT32(1)"},
     147              :             {ACL_TDT_QUEUE_ROUTE_QUERY_DST_ID_UINT32, "TDT_QUEUE_ROUTE_QUERY_DST_ID_UINT32(2)"},
     148            0 :         };
     149              : 
     150            0 :     auto it = queueRouteQueryInfoParamTypeDescMap.find(type);
     151            0 :     if (it != queueRouteQueryInfoParamTypeDescMap.end()) {
     152            0 :         return it->second;
     153              :     }
     154              :     static thread_local char enumBuf[32];
     155            0 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(type));
     156            0 :     enumBuf[sizeof(enumBuf) - 1U] = '\0';
     157            0 :     return enumBuf;
     158              : }
     159              : 
     160            2 : inline const char* GetAllocBufTypeDesc(acltdtAllocBufType type)
     161              : {
     162              :     static const std::unordered_map<acltdtAllocBufType, const char*> allocBufTypeDescMap = {
     163              :         {ACL_TDT_NORMAL_MEM, "TDT_NORMAL_MEM(0)"},
     164              :         {ACL_TDT_DVPP_MEM, "TDT_DVPP_MEM(1)"},
     165            4 :     };
     166              : 
     167            2 :     auto it = allocBufTypeDescMap.find(type);
     168            2 :     if (it != allocBufTypeDescMap.end()) {
     169            0 :         return it->second;
     170              :     }
     171              :     static thread_local char enumBuf[32];
     172            2 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(type));
     173            2 :     enumBuf[sizeof(enumBuf) - 1U] = '\0';
     174            2 :     return enumBuf;
     175              : }
     176              : 
     177           10 : inline const char* GetTensorTypeDesc(acltdtTensorType type)
     178              : {
     179              :     static const std::unordered_map<acltdtTensorType, const char*> tensorTypeDescMap = {
     180              :         {ACL_TENSOR_DATA_UNDEFINED, "TENSOR_DATA_UNDEFINED(-1)"},
     181              :         {ACL_TENSOR_DATA_TENSOR, "TENSOR_DATA_TENSOR(0)"},
     182              :         {ACL_TENSOR_DATA_END_OF_SEQUENCE, "TENSOR_DATA_END_OF_SEQUENCE(1)"},
     183              :         {ACL_TENSOR_DATA_ABNORMAL, "TENSOR_DATA_ABNORMAL(2)"},
     184              :         {ACL_TENSOR_DATA_SLICE_TENSOR, "TENSOR_DATA_SLICE_TENSOR(3)"},
     185              :         {ACL_TENSOR_DATA_END_TENSOR, "TENSOR_DATA_END_TENSOR(4)"},
     186           12 :     };
     187              : 
     188           10 :     auto it = tensorTypeDescMap.find(type);
     189           10 :     if (it != tensorTypeDescMap.end()) {
     190            9 :         return it->second;
     191              :     }
     192              :     static thread_local char enumBuf[32];
     193            1 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(type));
     194            1 :     enumBuf[sizeof(enumBuf) - 1U] = '\0';
     195            1 :     return enumBuf;
     196              : }
     197              : 
     198           44 : inline const char* GetSysParamOptDesc(aclSysParamOpt opt)
     199              : {
     200              :     // OPT_STRONG_CONSISTENCY has the same value as the deprecated enum ACL_OPT_STRONG_CONSISTENCY (=2).
     201              :     // Defined as static_cast to bypass the ACL_DEPRECATED_MESSAGE warning under -Werror compilation.
     202           44 :     constexpr aclSysParamOpt OPT_STRONG_CONSISTENCY = static_cast<aclSysParamOpt>(2);
     203              :     static const std::unordered_map<aclSysParamOpt, const char*> sysParamOptDescMap = {
     204              :         {ACL_OPT_DETERMINISTIC, "OPT_DETERMINISTIC(0)"},
     205              :         {ACL_OPT_ENABLE_DEBUG_KERNEL, "OPT_ENABLE_DEBUG_KERNEL(1)"},
     206              :         {OPT_STRONG_CONSISTENCY, "OPT_STRONG_CONSISTENCY(2)"},
     207              :         {ACL_OPT_ENABLE_KERNEL_EARLY_START, "ACL_OPT_ENABLE_KERNEL_EARLY_START(3)"},
     208           46 :     };
     209              : 
     210           44 :     auto it = sysParamOptDescMap.find(opt);
     211           44 :     if (it != sysParamOptDescMap.end()) {
     212           25 :         return it->second;
     213              :     }
     214              :     static thread_local char enumBuf[32];
     215           19 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(opt));
     216           19 :     enumBuf[sizeof(enumBuf) - 1U] = '\0';
     217           19 :     return enumBuf;
     218              : }
     219              : 
     220            4 : inline const char* GetCallbackBlockTypeDesc(aclrtCallbackBlockType type)
     221              : {
     222              :     static const std::unordered_map<aclrtCallbackBlockType, const char*> callbackBlockTypeDescMap = {
     223              :         {ACL_CALLBACK_NO_BLOCK, "CALLBACK_NO_BLOCK(0)"},
     224              :         {ACL_CALLBACK_BLOCK, "CALLBACK_BLOCK(1)"},
     225            6 :     };
     226              : 
     227            4 :     auto it = callbackBlockTypeDescMap.find(type);
     228            4 :     if (it != callbackBlockTypeDescMap.end()) {
     229            0 :         return it->second;
     230              :     }
     231              :     static thread_local char enumBuf[32];
     232            4 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(type));
     233            4 :     enumBuf[sizeof(enumBuf) - 1U] = '\0';
     234            4 :     return enumBuf;
     235              : }
     236              : 
     237            7 : inline const char* GetMemLocationTypeDesc(aclrtMemLocationType type)
     238              : {
     239              :     static const std::unordered_map<aclrtMemLocationType, const char*> memLocationTypeDescMap = {
     240              :         {ACL_MEM_LOCATION_TYPE_HOST, "MEM_LOCATION_TYPE_HOST(0)"},
     241              :         {ACL_MEM_LOCATION_TYPE_DEVICE, "MEM_LOCATION_TYPE_DEVICE(1)"},
     242              :         {ACL_MEM_LOCATION_TYPE_UNREGISTERED, "MEM_LOCATION_TYPE_UNREGISTERED(2)"},
     243              :         {ACL_MEM_LOCATION_TYPE_MANAGED, "MEM_LOCATION_TYPE_MANAGED(3)"},
     244              :         {ACL_MEM_LOCATION_TYPE_HOST_NUMA, "MEM_LOCATION_TYPE_HOST_NUMA(4)"},
     245            9 :     };
     246              : 
     247            7 :     auto it = memLocationTypeDescMap.find(type);
     248            7 :     if (it != memLocationTypeDescMap.end()) {
     249            7 :         return it->second;
     250              :     }
     251              :     static thread_local char enumBuf[32];
     252            0 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(type));
     253            0 :     enumBuf[sizeof(enumBuf) - 1U] = '\0';
     254            0 :     return enumBuf;
     255              : }
     256              : 
     257            0 : inline const char* GetMemAllocationTypeDesc(aclrtMemAllocationType type)
     258              : {
     259              :     static const std::unordered_map<aclrtMemAllocationType, const char*> memAllocationTypeDescMap = {
     260              :         {ACL_MEM_ALLOCATION_TYPE_PINNED, "MEM_ALLOCATION_TYPE_PINNED(0)"},
     261            0 :     };
     262              : 
     263            0 :     auto it = memAllocationTypeDescMap.find(type);
     264            0 :     if (it != memAllocationTypeDescMap.end()) {
     265            0 :         return it->second;
     266              :     }
     267              :     static thread_local char enumBuf[32];
     268            0 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(type));
     269            0 :     enumBuf[sizeof(enumBuf) - 1U] = '\0';
     270            0 :     return enumBuf;
     271              : }
     272              : 
     273            4 : inline const char* GetTdtDataTypeDesc(tdt::TdtDataType type)
     274              : {
     275              :     static const std::unordered_map<tdt::TdtDataType, const char*> tdtDataTypeDescMap = {
     276              :         {tdt::TDT_IMAGE_LABEL, "TDT_IMAGE_LABEL(0)"},
     277              :         {tdt::TDT_TFRECORD, "TDT_TFRECORD(1)"},
     278              :         {tdt::TDT_DATA_LABEL, "TDT_DATA_LABEL(2)"},
     279              :         {tdt::TDT_END_OF_SEQUENCE, "TDT_END_OF_SEQUENCE(3)"},
     280              :         {tdt::TDT_TENSOR, "TDT_TENSOR(4)"},
     281              :         {tdt::TDT_ABNORMAL, "TDT_ABNORMAL(5)"},
     282              :         {tdt::TDT_DATATYPE_MAX, "TDT_DATATYPE_MAX(6)"},
     283            6 :     };
     284              : 
     285            4 :     auto it = tdtDataTypeDescMap.find(type);
     286            4 :     if (it != tdtDataTypeDescMap.end()) {
     287            4 :         return it->second;
     288              :     }
     289              :     static thread_local char enumBuf[32];
     290            0 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(type));
     291            0 :     enumBuf[sizeof(enumBuf) - 1U] = '\0';
     292            0 :     return enumBuf;
     293              : }
     294              : 
     295            1 : inline const char* GetTdtDataTypeDescV2(int32_t type)
     296              : {
     297              :     static constexpr int32_t TDT_V2_TENSOR = 0;
     298              :     static constexpr int32_t TDT_V2_END_OF_SEQUENCE = 1;
     299              :     static constexpr int32_t TDT_V2_ABNORMAL = 2;
     300              :     static constexpr int32_t TDT_V2_SLICE_TENSOR = 3;
     301              :     static constexpr int32_t TDT_V2_END_TENSOR = 4;
     302              :     static const std::unordered_map<int32_t, const char*> tdtDataTypeDescV2Map = {
     303              :         {TDT_V2_TENSOR, "TDT_V2_TENSOR(0)"},         {TDT_V2_END_OF_SEQUENCE, "TDT_V2_END_OF_SEQUENCE(1)"},
     304              :         {TDT_V2_ABNORMAL, "TDT_V2_ABNORMAL(2)"},     {TDT_V2_SLICE_TENSOR, "TDT_V2_SLICE_TENSOR(3)"},
     305              :         {TDT_V2_END_TENSOR, "TDT_V2_END_TENSOR(4)"},
     306            3 :     };
     307              : 
     308            1 :     auto it = tdtDataTypeDescV2Map.find(type);
     309            1 :     if (it != tdtDataTypeDescV2Map.end()) {
     310            0 :         return it->second;
     311              :     }
     312              :     static thread_local char enumBuf[32];
     313            1 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", type);
     314            1 :     enumBuf[sizeof(enumBuf) - 1U] = '\0';
     315            1 :     return enumBuf;
     316              : }
     317              : 
     318           15 : inline const char* GetRunModeDesc(aclrtRunMode mode)
     319              : {
     320              :     static const std::unordered_map<aclrtRunMode, const char*> runModeDescMap = {
     321              :         {ACL_DEVICE, "DEVICE(0)"},
     322              :         {ACL_HOST, "HOST(1)"},
     323           17 :     };
     324              : 
     325           15 :     auto it = runModeDescMap.find(mode);
     326           15 :     if (it != runModeDescMap.end()) {
     327           15 :         return it->second;
     328              :     }
     329              :     static thread_local char enumBuf[32];
     330            0 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(mode));
     331            0 :     enumBuf[sizeof(enumBuf) - 1U] = '\0';
     332            0 :     return enumBuf;
     333              : }
     334              : 
     335            8 : inline const char* GetCaptureModeDesc(aclmdlRICaptureMode mode)
     336              : {
     337            8 :     switch (mode) {
     338            5 :         case ACL_MODEL_RI_CAPTURE_MODE_GLOBAL:
     339            5 :             return "MODEL_RI_CAPTURE_MODE_GLOBAL(0)";
     340            0 :         case ACL_MODEL_RI_CAPTURE_MODE_THREAD_LOCAL:
     341            0 :             return "MODEL_RI_CAPTURE_MODE_THREAD_LOCAL(1)";
     342            3 :         case ACL_MODEL_RI_CAPTURE_MODE_RELAXED:
     343            3 :             return "MODEL_RI_CAPTURE_MODE_RELAXED(2)";
     344            0 :         default:
     345            0 :             break;
     346              :     }
     347              :     static thread_local char enumBuf[32];
     348            0 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(mode));
     349            0 :     enumBuf[sizeof(enumBuf) - 1U] = '\0';
     350            0 :     return enumBuf;
     351              : }
     352              : 
     353            4 : inline const char* GetLastErrLevelDesc(aclrtLastErrLevel level)
     354              : {
     355              :     static const std::unordered_map<aclrtLastErrLevel, const char*> lastErrLevelDescMap = {
     356              :         {ACL_RT_THREAD_LEVEL, "THREAD_LEVEL(0)"},
     357            6 :     };
     358              : 
     359            4 :     auto it = lastErrLevelDescMap.find(level);
     360            4 :     if (it != lastErrLevelDescMap.end()) {
     361            2 :         return it->second;
     362              :     }
     363              :     static thread_local char enumBuf[32];
     364            2 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(level));
     365            2 :     enumBuf[sizeof(enumBuf) - 1U] = '\0';
     366            2 :     return enumBuf;
     367              : }
     368              : 
     369            6 : inline const char* GetDeviceInfoDesc(aclDeviceInfo info)
     370              : {
     371              :     static const std::unordered_map<aclDeviceInfo, const char*> deviceInfoDescMap = {
     372              :         {ACL_DEVICE_INFO_UNDEFINED, "DEVICE_INFO_UNDEFINED(-1)"},
     373              :         {ACL_DEVICE_INFO_AI_CORE_NUM, "DEVICE_INFO_AI_CORE_NUM(0)"},
     374              :         {ACL_DEVICE_INFO_VECTOR_CORE_NUM, "DEVICE_INFO_VECTOR_CORE_NUM(1)"},
     375              :         {ACL_DEVICE_INFO_L2_SIZE, "DEVICE_INFO_L2_SIZE(2)"},
     376            8 :     };
     377              : 
     378            6 :     auto it = deviceInfoDescMap.find(info);
     379            6 :     if (it != deviceInfoDescMap.end()) {
     380            6 :         return it->second;
     381              :     }
     382              :     static thread_local char enumBuf[32];
     383            0 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(info));
     384            0 :     enumBuf[sizeof(enumBuf) - 1U] = '\0';
     385            0 :     return enumBuf;
     386              : }
     387              : 
     388              : const char* GetCannAttrDesc(aclCannAttr attr);
     389              : const char* GetDevResLimitTypeDesc(aclrtDevResLimitType type);
     390              : const char* GetReduceKindDesc(aclrtReduceKind kind);
     391              : const char* GetMemLinkTypeDesc(aclrtMemLinkType type);
     392              : const char* GetErrorTypeDesc(aclrtErrorType type);
     393              : const char* GetStreamAttrDesc(aclrtStreamAttr attr);
     394              : const char* GetConditionDesc(aclrtCondition condition);
     395              : const char* GetCompareDataTypeDesc(aclrtCompareDataType type);
     396              : 
     397              : const char* GetMemAttrDesc(aclrtMemAttr attr);
     398              : 
     399              : const char* GetIpcMemAttrTypeDesc(aclrtIpcMemAttrType type);
     400              : const char* GetFloatOverflowModeDesc(aclrtFloatOverflowMode mode);
     401              : const char* GetCmoTypeDesc(aclrtCmoType type);
     402              : const char* GetDeviceLimitDesc(aclrtDeviceLimit limit);
     403              : 
     404            6 : static inline std::string DatasetMemTypeToString(const datasetMemType type)
     405              : {
     406            6 :     std::string result;
     407            6 :     switch (type) {
     408            0 :         case MEM_UNKNOWN:
     409            0 :             result = "MEM_UNKNOWN(0)";
     410            0 :             break;
     411            3 :         case MEM_HOST:
     412            3 :             result = "MEM_HOST(1)";
     413            3 :             break;
     414            3 :         case MEM_DEVICE:
     415            3 :             result = "MEM_DEVICE(2)";
     416            3 :             break;
     417            0 :         default:
     418            0 :             result = "UNKNOWN(" + std::to_string(static_cast<int32_t>(type)) + ")";
     419            0 :             break;
     420              :     }
     421            6 :     return result;
     422            0 : }
     423              : 
     424              : } // namespace acl
     425              : 
     426              : #endif // ACL_UTILS_DATA_TYPE_UTILS_H
        

Generated by: LCOV version 2.0-1