LCOV - code coverage report
Current view: top level - acl/utils - data_type_utils.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 63.5 % 170 108
Test Date: 2026-08-13 17:07:01 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           24 :     };
      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            4 : 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            6 :     };
     187              : 
     188            4 :     auto it = tensorTypeDescMap.find(type);
     189            4 :     if (it != tensorTypeDescMap.end()) {
     190            3 :         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           43 : 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           43 :     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           45 :     };
     208              : 
     209           43 :     auto it = sysParamOptDescMap.find(opt);
     210           43 :     if (it != sysParamOptDescMap.end()) {
     211           21 :         return it->second;
     212              :     }
     213              :     static thread_local char enumBuf[32];
     214           22 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(opt));
     215           22 :     enumBuf[sizeof(enumBuf) - 1U] = '\0';
     216           22 :     return enumBuf;
     217              : }
     218              : 
     219            4 : inline const char* GetCallbackBlockTypeDesc(aclrtCallbackBlockType type)
     220              : {
     221              :     static const std::unordered_map<aclrtCallbackBlockType, const char*> callbackBlockTypeDescMap = {
     222              :         {ACL_CALLBACK_NO_BLOCK, "CALLBACK_NO_BLOCK(0)"},
     223              :         {ACL_CALLBACK_BLOCK, "CALLBACK_BLOCK(1)"},
     224            6 :     };
     225              : 
     226            4 :     auto it = callbackBlockTypeDescMap.find(type);
     227            4 :     if (it != callbackBlockTypeDescMap.end()) {
     228            0 :         return it->second;
     229              :     }
     230              :     static thread_local char enumBuf[32];
     231            4 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(type));
     232            4 :     enumBuf[sizeof(enumBuf) - 1U] = '\0';
     233            4 :     return enumBuf;
     234              : }
     235              : 
     236            7 : inline const char* GetMemLocationTypeDesc(aclrtMemLocationType type)
     237              : {
     238              :     static const std::unordered_map<aclrtMemLocationType, const char*> memLocationTypeDescMap = {
     239              :         {ACL_MEM_LOCATION_TYPE_HOST, "MEM_LOCATION_TYPE_HOST(0)"},
     240              :         {ACL_MEM_LOCATION_TYPE_DEVICE, "MEM_LOCATION_TYPE_DEVICE(1)"},
     241              :         {ACL_MEM_LOCATION_TYPE_UNREGISTERED, "MEM_LOCATION_TYPE_UNREGISTERED(2)"},
     242              :         {ACL_MEM_LOCATION_TYPE_MANAGED, "MEM_LOCATION_TYPE_MANAGED(3)"},
     243              :         {ACL_MEM_LOCATION_TYPE_HOST_NUMA, "MEM_LOCATION_TYPE_HOST_NUMA(4)"},
     244            9 :     };
     245              : 
     246            7 :     auto it = memLocationTypeDescMap.find(type);
     247            7 :     if (it != memLocationTypeDescMap.end()) {
     248            7 :         return it->second;
     249              :     }
     250              :     static thread_local char enumBuf[32];
     251            0 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(type));
     252            0 :     enumBuf[sizeof(enumBuf) - 1U] = '\0';
     253            0 :     return enumBuf;
     254              : }
     255              : 
     256            0 : inline const char* GetMemAllocationTypeDesc(aclrtMemAllocationType type)
     257              : {
     258              :     static const std::unordered_map<aclrtMemAllocationType, const char*> memAllocationTypeDescMap = {
     259              :         {ACL_MEM_ALLOCATION_TYPE_PINNED, "MEM_ALLOCATION_TYPE_PINNED(0)"},
     260            0 :     };
     261              : 
     262            0 :     auto it = memAllocationTypeDescMap.find(type);
     263            0 :     if (it != memAllocationTypeDescMap.end()) {
     264            0 :         return it->second;
     265              :     }
     266              :     static thread_local char enumBuf[32];
     267            0 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(type));
     268            0 :     enumBuf[sizeof(enumBuf) - 1U] = '\0';
     269            0 :     return enumBuf;
     270              : }
     271              : 
     272            1 : inline const char* GetTdtDataTypeDesc(tdt::TdtDataType type)
     273              : {
     274              :     static const std::unordered_map<tdt::TdtDataType, const char*> tdtDataTypeDescMap = {
     275              :         {tdt::TDT_IMAGE_LABEL, "TDT_IMAGE_LABEL(0)"},
     276              :         {tdt::TDT_TFRECORD, "TDT_TFRECORD(1)"},
     277              :         {tdt::TDT_DATA_LABEL, "TDT_DATA_LABEL(2)"},
     278              :         {tdt::TDT_END_OF_SEQUENCE, "TDT_END_OF_SEQUENCE(3)"},
     279              :         {tdt::TDT_TENSOR, "TDT_TENSOR(4)"},
     280              :         {tdt::TDT_ABNORMAL, "TDT_ABNORMAL(5)"},
     281              :         {tdt::TDT_DATATYPE_MAX, "TDT_DATATYPE_MAX(6)"},
     282            3 :     };
     283              : 
     284            1 :     auto it = tdtDataTypeDescMap.find(type);
     285            1 :     if (it != tdtDataTypeDescMap.end()) {
     286            1 :         return it->second;
     287              :     }
     288              :     static thread_local char enumBuf[32];
     289            0 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(type));
     290            0 :     enumBuf[sizeof(enumBuf) - 1U] = '\0';
     291            0 :     return enumBuf;
     292              : }
     293              : 
     294            1 : inline const char* GetTdtDataTypeDescV2(int32_t type)
     295              : {
     296              :     static constexpr int32_t TDT_V2_TENSOR = 0;
     297              :     static constexpr int32_t TDT_V2_END_OF_SEQUENCE = 1;
     298              :     static constexpr int32_t TDT_V2_ABNORMAL = 2;
     299              :     static constexpr int32_t TDT_V2_SLICE_TENSOR = 3;
     300              :     static constexpr int32_t TDT_V2_END_TENSOR = 4;
     301              :     static const std::unordered_map<int32_t, const char*> tdtDataTypeDescV2Map = {
     302              :         {TDT_V2_TENSOR, "TDT_V2_TENSOR(0)"},         {TDT_V2_END_OF_SEQUENCE, "TDT_V2_END_OF_SEQUENCE(1)"},
     303              :         {TDT_V2_ABNORMAL, "TDT_V2_ABNORMAL(2)"},     {TDT_V2_SLICE_TENSOR, "TDT_V2_SLICE_TENSOR(3)"},
     304              :         {TDT_V2_END_TENSOR, "TDT_V2_END_TENSOR(4)"},
     305            3 :     };
     306              : 
     307            1 :     auto it = tdtDataTypeDescV2Map.find(type);
     308            1 :     if (it != tdtDataTypeDescV2Map.end()) {
     309            0 :         return it->second;
     310              :     }
     311              :     static thread_local char enumBuf[32];
     312            1 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", type);
     313            1 :     enumBuf[sizeof(enumBuf) - 1U] = '\0';
     314            1 :     return enumBuf;
     315              : }
     316              : 
     317            2 : inline const char* GetRunModeDesc(aclrtRunMode mode)
     318              : {
     319              :     static const std::unordered_map<aclrtRunMode, const char*> runModeDescMap = {
     320              :         {ACL_DEVICE, "DEVICE(0)"},
     321              :         {ACL_HOST, "HOST(1)"},
     322            4 :     };
     323              : 
     324            2 :     auto it = runModeDescMap.find(mode);
     325            2 :     if (it != runModeDescMap.end()) {
     326            2 :         return it->second;
     327              :     }
     328              :     static thread_local char enumBuf[32];
     329            0 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(mode));
     330            0 :     enumBuf[sizeof(enumBuf) - 1U] = '\0';
     331            0 :     return enumBuf;
     332              : }
     333              : 
     334            8 : inline const char* GetCaptureModeDesc(aclmdlRICaptureMode mode)
     335              : {
     336              :     static const std::unordered_map<aclmdlRICaptureMode, const char*> captureModeDescMap = {
     337              :         {ACL_MODEL_RI_CAPTURE_MODE_GLOBAL, "MODEL_RI_CAPTURE_MODE_GLOBAL(0)"},
     338              :         {ACL_MODEL_RI_CAPTURE_MODE_THREAD_LOCAL, "MODEL_RI_CAPTURE_MODE_THREAD_LOCAL(1)"},
     339              :         {ACL_MODEL_RI_CAPTURE_MODE_RELAXED, "MODEL_RI_CAPTURE_MODE_RELAXED(2)"},
     340           10 :     };
     341              : 
     342            8 :     auto it = captureModeDescMap.find(mode);
     343            8 :     if (it != captureModeDescMap.end()) {
     344            8 :         return it->second;
     345              :     }
     346              :     static thread_local char enumBuf[32];
     347            0 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(mode));
     348            0 :     enumBuf[sizeof(enumBuf) - 1U] = '\0';
     349            0 :     return enumBuf;
     350              : }
     351              : 
     352            4 : inline const char* GetLastErrLevelDesc(aclrtLastErrLevel level)
     353              : {
     354              :     static const std::unordered_map<aclrtLastErrLevel, const char*> lastErrLevelDescMap = {
     355              :         {ACL_RT_THREAD_LEVEL, "THREAD_LEVEL(0)"},
     356            6 :     };
     357              : 
     358            4 :     auto it = lastErrLevelDescMap.find(level);
     359            4 :     if (it != lastErrLevelDescMap.end()) {
     360            2 :         return it->second;
     361              :     }
     362              :     static thread_local char enumBuf[32];
     363            2 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(level));
     364            2 :     enumBuf[sizeof(enumBuf) - 1U] = '\0';
     365            2 :     return enumBuf;
     366              : }
     367              : 
     368            6 : inline const char* GetDeviceInfoDesc(aclDeviceInfo info)
     369              : {
     370              :     static const std::unordered_map<aclDeviceInfo, const char*> deviceInfoDescMap = {
     371              :         {ACL_DEVICE_INFO_UNDEFINED, "DEVICE_INFO_UNDEFINED(-1)"},
     372              :         {ACL_DEVICE_INFO_AI_CORE_NUM, "DEVICE_INFO_AI_CORE_NUM(0)"},
     373              :         {ACL_DEVICE_INFO_VECTOR_CORE_NUM, "DEVICE_INFO_VECTOR_CORE_NUM(1)"},
     374              :         {ACL_DEVICE_INFO_L2_SIZE, "DEVICE_INFO_L2_SIZE(2)"},
     375            8 :     };
     376              : 
     377            6 :     auto it = deviceInfoDescMap.find(info);
     378            6 :     if (it != deviceInfoDescMap.end()) {
     379            6 :         return it->second;
     380              :     }
     381              :     static thread_local char enumBuf[32];
     382            0 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(info));
     383            0 :     enumBuf[sizeof(enumBuf) - 1U] = '\0';
     384            0 :     return enumBuf;
     385              : }
     386              : 
     387              : const char* GetCannAttrDesc(aclCannAttr attr);
     388              : const char* GetDevResLimitTypeDesc(aclrtDevResLimitType type);
     389              : const char* GetReduceKindDesc(aclrtReduceKind kind);
     390              : const char* GetMemLinkTypeDesc(aclrtMemLinkType type);
     391              : const char* GetErrorTypeDesc(aclrtErrorType type);
     392              : const char* GetStreamAttrDesc(aclrtStreamAttr attr);
     393              : const char* GetConditionDesc(aclrtCondition condition);
     394              : const char* GetCompareDataTypeDesc(aclrtCompareDataType type);
     395              : 
     396              : const char* GetMemAttrDesc(aclrtMemAttr attr);
     397              : 
     398              : const char* GetIpcMemAttrTypeDesc(aclrtIpcMemAttrType type);
     399              : const char* GetFloatOverflowModeDesc(aclrtFloatOverflowMode mode);
     400              : const char* GetCmoTypeDesc(aclrtCmoType type);
     401              : const char* GetDeviceLimitDesc(aclrtDeviceLimit limit);
     402              : 
     403            6 : static inline std::string DatasetMemTypeToString(const datasetMemType type)
     404              : {
     405            6 :     std::string result;
     406            6 :     switch (type) {
     407            0 :         case MEM_UNKNOWN:
     408            0 :             result = "MEM_UNKNOWN(0)";
     409            0 :             break;
     410            3 :         case MEM_HOST:
     411            3 :             result = "MEM_HOST(1)";
     412            3 :             break;
     413            3 :         case MEM_DEVICE:
     414            3 :             result = "MEM_DEVICE(2)";
     415            3 :             break;
     416            0 :         default:
     417            0 :             result = "UNKNOWN(" + std::to_string(static_cast<int32_t>(type)) + ")";
     418            0 :             break;
     419              :     }
     420            6 :     return result;
     421            0 : }
     422              : 
     423              : } // namespace acl
     424              : 
     425              : #endif // ACL_UTILS_DATA_TYPE_UTILS_H
        

Generated by: LCOV version 2.0-1