LCOV - code coverage report
Current view: top level - acl/utils - data_type_utils.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 59.0 % 144 85
Test Date: 2026-07-28 10:53:01 Functions: 73.7 % 19 14

            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            2 : inline const char* GetDataTypeDesc(aclDataType type)
      30              : {
      31              :     static const std::unordered_map<aclDataType, const char*> dataTypeDescMap = {
      32              :         {ACL_DT_UNDEFINED, "DT_UNDEFINED(-1)"},
      33              :         {ACL_FLOAT, "FLOAT(0)"},
      34              :         {ACL_FLOAT16, "FLOAT16(1)"},
      35              :         {ACL_INT8, "INT8(2)"},
      36              :         {ACL_INT32, "INT32(3)"},
      37              :         {ACL_UINT8, "UINT8(4)"},
      38              :         {ACL_INT16, "INT16(6)"},
      39              :         {ACL_UINT16, "UINT16(7)"},
      40              :         {ACL_UINT32, "UINT32(8)"},
      41              :         {ACL_INT64, "INT64(9)"},
      42              :         {ACL_UINT64, "UINT64(10)"},
      43              :         {ACL_DOUBLE, "DOUBLE(11)"},
      44              :         {ACL_BOOL, "BOOL(12)"},
      45              :         {ACL_STRING, "STRING(13)"},
      46              :         {ACL_COMPLEX64, "COMPLEX64(16)"},
      47              :         {ACL_COMPLEX128, "COMPLEX128(17)"},
      48              :         {ACL_BF16, "BF16(27)"},
      49              :         {ACL_INT4, "INT4(29)"},
      50              :         {ACL_UINT1, "UINT1(30)"},
      51              :         {ACL_COMPLEX32, "COMPLEX32(33)"},
      52              :         {ACL_HIFLOAT8, "HIFLOAT8(34)"},
      53              :         {ACL_FLOAT8_E5M2, "FLOAT8_E5M2(35)"},
      54              :         {ACL_FLOAT8_E4M3FN, "FLOAT8_E4M3FN(36)"},
      55              :         {ACL_FLOAT8_E8M0, "FLOAT8_E8M0(37)"},
      56              :         {ACL_FLOAT6_E3M2, "FLOAT6_E3M2(38)"},
      57              :         {ACL_FLOAT6_E2M3, "FLOAT6_E2M3(39)"},
      58              :         {ACL_FLOAT4_E2M1, "FLOAT4_E2M1(40)"},
      59              :         {ACL_FLOAT4_E1M2, "FLOAT4_E1M2(41)"},
      60           13 :     };
      61              : 
      62            2 :     auto it = dataTypeDescMap.find(type);
      63            2 :     if (it != dataTypeDescMap.end()) {
      64            2 :         return it->second;
      65              :     }
      66              :     static thread_local char enumBuf[32];
      67            0 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(type));
      68            0 :     return enumBuf;
      69              : }
      70              : 
      71           36 : inline const char* GetMemcpyKindDesc(aclrtMemcpyKind kind)
      72              : {
      73              :     static const std::unordered_map<aclrtMemcpyKind, const char*> memcpyKindDescMap = {
      74              :         {ACL_MEMCPY_HOST_TO_HOST, "MEMCPY_HOST_TO_HOST(0)"},
      75              :         {ACL_MEMCPY_HOST_TO_DEVICE, "MEMCPY_HOST_TO_DEVICE(1)"},
      76              :         {ACL_MEMCPY_DEVICE_TO_HOST, "MEMCPY_DEVICE_TO_HOST(2)"},
      77              :         {ACL_MEMCPY_DEVICE_TO_DEVICE, "MEMCPY_DEVICE_TO_DEVICE(3)"},
      78              :         {ACL_MEMCPY_DEFAULT, "MEMCPY_DEFAULT(4)"},
      79              :         {ACL_MEMCPY_HOST_TO_BUF_TO_DEVICE, "MEMCPY_HOST_TO_BUF_TO_DEVICE(5)"},
      80              :         {ACL_MEMCPY_INNER_DEVICE_TO_DEVICE, "MEMCPY_INNER_DEVICE_TO_DEVICE(6)"},
      81              :         {ACL_MEMCPY_INTER_DEVICE_TO_DEVICE, "MEMCPY_INTER_DEVICE_TO_DEVICE(7)"},
      82           38 :     };
      83              : 
      84           36 :     auto it = memcpyKindDescMap.find(kind);
      85           36 :     if (it != memcpyKindDescMap.end()) {
      86           16 :         return it->second;
      87              :     }
      88              :     static thread_local char enumBuf[32];
      89           20 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(kind));
      90           20 :     return enumBuf;
      91              : }
      92              : 
      93            4 : inline const char* GetExceptionExpandTypeDesc(rtExceptionExpandType_t type)
      94              : {
      95              :     static const std::unordered_map<rtExceptionExpandType_t, const char*> exceptionExpandTypeDescMap = {
      96              :         {RT_EXCEPTION_INVALID, "EXCEPTION_INVALID(0)"}, {RT_EXCEPTION_FFTS_PLUS, "EXCEPTION_FFTS_PLUS(1)"},
      97              :         {RT_EXCEPTION_AICORE, "EXCEPTION_AICORE(2)"},   {RT_EXCEPTION_UB, "EXCEPTION_UB(3)"},
      98              :         {RT_EXCEPTION_CCU, "EXCEPTION_CCU(4)"},         {RT_EXCEPTION_FUSION, "EXCEPTION_FUSION(5)"},
      99              :         {RT_EXCEPTION_AICPU, "EXCEPTION_AICPU(6)"},
     100            6 :     };
     101              : 
     102            4 :     auto it = exceptionExpandTypeDescMap.find(type);
     103            4 :     if (it != exceptionExpandTypeDescMap.end()) {
     104            4 :         return it->second;
     105              :     }
     106              :     static thread_local char enumBuf[32];
     107            0 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(type));
     108            0 :     return enumBuf;
     109              : }
     110              : 
     111            2 : inline const char* GetGroupAttrDesc(aclrtGroupAttr attr)
     112              : {
     113              :     static const std::unordered_map<aclrtGroupAttr, const char*> groupAttrDescMap = {
     114              :         {ACL_GROUP_AICORE_INT, "GROUP_AICORE_INT(0)"}, {ACL_GROUP_AIV_INT, "GROUP_AIV_INT(1)"},
     115              :         {ACL_GROUP_AIC_INT, "GROUP_AIC_INT(2)"},       {ACL_GROUP_SDMANUM_INT, "GROUP_SDMANUM_INT(3)"},
     116              :         {ACL_GROUP_ASQNUM_INT, "GROUP_ASQNUM_INT(4)"}, {ACL_GROUP_GROUPID_INT, "GROUP_GROUPID_INT(5)"},
     117            4 :     };
     118              : 
     119            2 :     auto it = groupAttrDescMap.find(attr);
     120            2 :     if (it != groupAttrDescMap.end()) {
     121            0 :         return it->second;
     122              :     }
     123              :     static thread_local char enumBuf[32];
     124            2 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(attr));
     125            2 :     return enumBuf;
     126              : }
     127              : 
     128            2 : inline const char* GetTsIdDesc(aclrtTsId tsId)
     129              : {
     130              :     static const std::unordered_map<aclrtTsId, const char*> tsIdDescMap = {
     131              :         {ACL_TS_ID_AICORE, "TS_ID_AICORE(0)"},
     132              :         {ACL_TS_ID_AIVECTOR, "TS_ID_AIVECTOR(1)"},
     133              :         {ACL_TS_ID_RESERVED, "TS_ID_RESERVED(2)"},
     134            4 :     };
     135              : 
     136            2 :     auto it = tsIdDescMap.find(tsId);
     137            2 :     if (it != tsIdDescMap.end()) {
     138            2 :         return it->second;
     139              :     }
     140              :     static thread_local char enumBuf[32];
     141            0 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(tsId));
     142            0 :     return enumBuf;
     143              : }
     144              : 
     145            0 : inline const char* GetQueueRouteQueryModeDesc(acltdtQueueRouteQueryMode mode)
     146              : {
     147              :     static const std::unordered_map<acltdtQueueRouteQueryMode, const char*> queueRouteQueryModeDescMap = {
     148              :         {ACL_TDT_QUEUE_ROUTE_QUERY_SRC, "TDT_QUEUE_ROUTE_QUERY_SRC(0)"},
     149              :         {ACL_TDT_QUEUE_ROUTE_QUERY_DST, "TDT_QUEUE_ROUTE_QUERY_DST(1)"},
     150              :         {ACL_TDT_QUEUE_ROUTE_QUERY_SRC_AND_DST, "TDT_QUEUE_ROUTE_QUERY_SRC_AND_DST(2)"},
     151              :         {ACL_TDT_QUEUE_ROUTE_QUERY_ABNORMAL, "TDT_QUEUE_ROUTE_QUERY_ABNORMAL(100)"},
     152            0 :     };
     153              : 
     154            0 :     auto it = queueRouteQueryModeDescMap.find(mode);
     155            0 :     if (it != queueRouteQueryModeDescMap.end()) {
     156            0 :         return it->second;
     157              :     }
     158              :     static thread_local char enumBuf[32];
     159            0 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(mode));
     160            0 :     return enumBuf;
     161              : }
     162              : 
     163            0 : inline const char* GetQueueAttrTypeDesc(acltdtQueueAttrType type)
     164              : {
     165              :     static const std::unordered_map<acltdtQueueAttrType, const char*> queueAttrTypeDescMap = {
     166              :         {ACL_TDT_QUEUE_NAME_PTR, "TDT_QUEUE_NAME_PTR(0)"},
     167              :         {ACL_TDT_QUEUE_DEPTH_UINT32, "TDT_QUEUE_DEPTH_UINT32(1)"},
     168            0 :     };
     169              : 
     170            0 :     auto it = queueAttrTypeDescMap.find(type);
     171            0 :     if (it != queueAttrTypeDescMap.end()) {
     172            0 :         return it->second;
     173              :     }
     174              :     static thread_local char enumBuf[32];
     175            0 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(type));
     176            0 :     return enumBuf;
     177              : }
     178              : 
     179            0 : inline const char* GetQueueRouteParamTypeDesc(acltdtQueueRouteParamType type)
     180              : {
     181              :     static const std::unordered_map<acltdtQueueRouteParamType, const char*> queueRouteParamTypeDescMap = {
     182              :         {ACL_TDT_QUEUE_ROUTE_SRC_UINT32, "TDT_QUEUE_ROUTE_SRC_UINT32(0)"},
     183              :         {ACL_TDT_QUEUE_ROUTE_DST_UINT32, "TDT_QUEUE_ROUTE_DST_UINT32(1)"},
     184              :         {ACL_TDT_QUEUE_ROUTE_STATUS_INT32, "TDT_QUEUE_ROUTE_STATUS_INT32(2)"},
     185            0 :     };
     186              : 
     187            0 :     auto it = queueRouteParamTypeDescMap.find(type);
     188            0 :     if (it != queueRouteParamTypeDescMap.end()) {
     189            0 :         return it->second;
     190              :     }
     191              :     static thread_local char enumBuf[32];
     192            0 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(type));
     193            0 :     return enumBuf;
     194              : }
     195              : 
     196            0 : inline const char* GetQueueRouteQueryInfoParamTypeDesc(acltdtQueueRouteQueryInfoParamType type)
     197              : {
     198              :     static const std::unordered_map<acltdtQueueRouteQueryInfoParamType, const char*>
     199              :         queueRouteQueryInfoParamTypeDescMap = {
     200              :             {ACL_TDT_QUEUE_ROUTE_QUERY_MODE_ENUM, "TDT_QUEUE_ROUTE_QUERY_MODE_ENUM(0)"},
     201              :             {ACL_TDT_QUEUE_ROUTE_QUERY_SRC_ID_UINT32, "TDT_QUEUE_ROUTE_QUERY_SRC_ID_UINT32(1)"},
     202              :             {ACL_TDT_QUEUE_ROUTE_QUERY_DST_ID_UINT32, "TDT_QUEUE_ROUTE_QUERY_DST_ID_UINT32(2)"},
     203            0 :         };
     204              : 
     205            0 :     auto it = queueRouteQueryInfoParamTypeDescMap.find(type);
     206            0 :     if (it != queueRouteQueryInfoParamTypeDescMap.end()) {
     207            0 :         return it->second;
     208              :     }
     209              :     static thread_local char enumBuf[32];
     210            0 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(type));
     211            0 :     return enumBuf;
     212              : }
     213              : 
     214            2 : inline const char* GetAllocBufTypeDesc(acltdtAllocBufType type)
     215              : {
     216              :     static const std::unordered_map<acltdtAllocBufType, const char*> allocBufTypeDescMap = {
     217              :         {ACL_TDT_NORMAL_MEM, "TDT_NORMAL_MEM(0)"},
     218              :         {ACL_TDT_DVPP_MEM, "TDT_DVPP_MEM(1)"},
     219            4 :     };
     220              : 
     221            2 :     auto it = allocBufTypeDescMap.find(type);
     222            2 :     if (it != allocBufTypeDescMap.end()) {
     223            0 :         return it->second;
     224              :     }
     225              :     static thread_local char enumBuf[32];
     226            2 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(type));
     227            2 :     return enumBuf;
     228              : }
     229              : 
     230            4 : inline const char* GetTensorTypeDesc(acltdtTensorType type)
     231              : {
     232              :     static const std::unordered_map<acltdtTensorType, const char*> tensorTypeDescMap = {
     233              :         {ACL_TENSOR_DATA_UNDEFINED, "TENSOR_DATA_UNDEFINED(-1)"},
     234              :         {ACL_TENSOR_DATA_TENSOR, "TENSOR_DATA_TENSOR(0)"},
     235              :         {ACL_TENSOR_DATA_END_OF_SEQUENCE, "TENSOR_DATA_END_OF_SEQUENCE(1)"},
     236              :         {ACL_TENSOR_DATA_ABNORMAL, "TENSOR_DATA_ABNORMAL(2)"},
     237              :         {ACL_TENSOR_DATA_SLICE_TENSOR, "TENSOR_DATA_SLICE_TENSOR(3)"},
     238              :         {ACL_TENSOR_DATA_END_TENSOR, "TENSOR_DATA_END_TENSOR(4)"},
     239            6 :     };
     240              : 
     241            4 :     auto it = tensorTypeDescMap.find(type);
     242            4 :     if (it != tensorTypeDescMap.end()) {
     243            3 :         return it->second;
     244              :     }
     245              :     static thread_local char enumBuf[32];
     246            1 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(type));
     247            1 :     return enumBuf;
     248              : }
     249              : 
     250           16 : inline const char* GetSysParamOptDesc(aclSysParamOpt opt)
     251              : {
     252              :     // OPT_STRONG_CONSISTENCY has the same value as the deprecated enum ACL_OPT_STRONG_CONSISTENCY (=2).
     253              :     // Defined as static_cast to bypass the ACL_DEPRECATED_MESSAGE warning under -Werror compilation.
     254           16 :     constexpr aclSysParamOpt OPT_STRONG_CONSISTENCY = static_cast<aclSysParamOpt>(2);
     255              :     static const std::unordered_map<aclSysParamOpt, const char*> sysParamOptDescMap = {
     256              :         {ACL_OPT_DETERMINISTIC, "ACL_OPT_DETERMINISTIC(0)"},
     257              :         {ACL_OPT_ENABLE_DEBUG_KERNEL, "ACL_OPT_ENABLE_DEBUG_KERNEL(1)"},
     258              :         {OPT_STRONG_CONSISTENCY, "ACL_OPT_STRONG_CONSISTENCY(2)"},
     259           18 :     };
     260              : 
     261           16 :     auto it = sysParamOptDescMap.find(opt);
     262           16 :     if (it != sysParamOptDescMap.end()) {
     263            0 :         return it->second;
     264              :     }
     265              :     static thread_local char enumBuf[32];
     266           16 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(opt));
     267           16 :     return enumBuf;
     268              : }
     269              : 
     270            4 : inline const char* GetCallbackBlockTypeDesc(aclrtCallbackBlockType type)
     271              : {
     272              :     static const std::unordered_map<aclrtCallbackBlockType, const char*> callbackBlockTypeDescMap = {
     273              :         {ACL_CALLBACK_NO_BLOCK, "CALLBACK_NO_BLOCK(0)"},
     274              :         {ACL_CALLBACK_BLOCK, "CALLBACK_BLOCK(1)"},
     275            6 :     };
     276              : 
     277            4 :     auto it = callbackBlockTypeDescMap.find(type);
     278            4 :     if (it != callbackBlockTypeDescMap.end()) {
     279            0 :         return it->second;
     280              :     }
     281              :     static thread_local char enumBuf[32];
     282            4 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(type));
     283            4 :     return enumBuf;
     284              : }
     285              : 
     286            6 : inline const char* GetMemLocationTypeDesc(aclrtMemLocationType type)
     287              : {
     288              :     static const std::unordered_map<aclrtMemLocationType, const char*> memLocationTypeDescMap = {
     289              :         {ACL_MEM_LOCATION_TYPE_HOST, "ACL_MEM_LOCATION_TYPE_HOST(0)"},
     290              :         {ACL_MEM_LOCATION_TYPE_DEVICE, "ACL_MEM_LOCATION_TYPE_DEVICE(1)"},
     291              :         {ACL_MEM_LOCATION_TYPE_UNREGISTERED, "ACL_MEM_LOCATION_TYPE_UNREGISTERED(2)"},
     292              :         {ACL_MEM_LOCATION_TYPE_MANAGED, "ACL_MEM_LOCATION_TYPE_MANAGED(3)"},
     293              :         {ACL_MEM_LOCATION_TYPE_HOST_NUMA, "ACL_MEM_LOCATION_TYPE_HOST_NUMA(4)"},
     294            8 :     };
     295              : 
     296            6 :     auto it = memLocationTypeDescMap.find(type);
     297            6 :     if (it != memLocationTypeDescMap.end()) {
     298            6 :         return it->second;
     299              :     }
     300              :     static thread_local char enumBuf[32];
     301            0 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(type));
     302            0 :     return enumBuf;
     303              : }
     304              : 
     305            0 : inline const char* GetMemAllocationTypeDesc(aclrtMemAllocationType type)
     306              : {
     307              :     static const std::unordered_map<aclrtMemAllocationType, const char*> memAllocationTypeDescMap = {
     308              :         {ACL_MEM_ALLOCATION_TYPE_PINNED, "MEM_ALLOCATION_TYPE_PINNED(0)"},
     309            0 :     };
     310              : 
     311            0 :     auto it = memAllocationTypeDescMap.find(type);
     312            0 :     if (it != memAllocationTypeDescMap.end()) {
     313            0 :         return it->second;
     314              :     }
     315              :     static thread_local char enumBuf[32];
     316            0 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(type));
     317            0 :     return enumBuf;
     318              : }
     319              : 
     320            1 : inline const char* GetTdtDataTypeDesc(tdt::TdtDataType type)
     321              : {
     322              :     static const std::unordered_map<tdt::TdtDataType, const char*> tdtDataTypeDescMap = {
     323              :         {tdt::TDT_IMAGE_LABEL, "TDT_IMAGE_LABEL(0)"},
     324              :         {tdt::TDT_TFRECORD, "TDT_TFRECORD(1)"},
     325              :         {tdt::TDT_DATA_LABEL, "TDT_DATA_LABEL(2)"},
     326              :         {tdt::TDT_END_OF_SEQUENCE, "TDT_END_OF_SEQUENCE(3)"},
     327              :         {tdt::TDT_TENSOR, "TDT_TENSOR(4)"},
     328              :         {tdt::TDT_ABNORMAL, "TDT_ABNORMAL(5)"},
     329              :         {tdt::TDT_DATATYPE_MAX, "TDT_DATATYPE_MAX(6)"},
     330            3 :     };
     331              : 
     332            1 :     auto it = tdtDataTypeDescMap.find(type);
     333            1 :     if (it != tdtDataTypeDescMap.end()) {
     334            1 :         return it->second;
     335              :     }
     336              :     static thread_local char enumBuf[32];
     337            0 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(type));
     338            0 :     return enumBuf;
     339              : }
     340              : 
     341            1 : inline const char* GetTdtDataTypeDescV2(int32_t type)
     342              : {
     343              :     static constexpr int32_t TDT_V2_TENSOR = 0;
     344              :     static constexpr int32_t TDT_V2_END_OF_SEQUENCE = 1;
     345              :     static constexpr int32_t TDT_V2_ABNORMAL = 2;
     346              :     static constexpr int32_t TDT_V2_SLICE_TENSOR = 3;
     347              :     static constexpr int32_t TDT_V2_END_TENSOR = 4;
     348              :     static const std::unordered_map<int32_t, const char*> tdtDataTypeDescV2Map = {
     349              :         {TDT_V2_TENSOR, "TDT_V2_TENSOR(0)"},         {TDT_V2_END_OF_SEQUENCE, "TDT_V2_END_OF_SEQUENCE(1)"},
     350              :         {TDT_V2_ABNORMAL, "TDT_V2_ABNORMAL(2)"},     {TDT_V2_SLICE_TENSOR, "TDT_V2_SLICE_TENSOR(3)"},
     351              :         {TDT_V2_END_TENSOR, "TDT_V2_END_TENSOR(4)"},
     352            3 :     };
     353              : 
     354            1 :     auto it = tdtDataTypeDescV2Map.find(type);
     355            1 :     if (it != tdtDataTypeDescV2Map.end()) {
     356            0 :         return it->second;
     357              :     }
     358              :     static thread_local char enumBuf[32];
     359            1 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", type);
     360            1 :     return enumBuf;
     361              : }
     362              : 
     363              : inline const char* GetRunModeDesc(aclrtRunMode mode)
     364              : {
     365              :     static const std::unordered_map<aclrtRunMode, const char*> runModeDescMap = {
     366              :         {ACL_DEVICE, "DEVICE(0)"},
     367              :         {ACL_HOST, "HOST(1)"},
     368              :     };
     369              : 
     370              :     auto it = runModeDescMap.find(mode);
     371              :     if (it != runModeDescMap.end()) {
     372              :         return it->second;
     373              :     }
     374              :     static thread_local char enumBuf[32];
     375              :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(mode));
     376              :     return enumBuf;
     377              : }
     378              : 
     379              : inline const char* GetCaptureModeDesc(aclmdlRICaptureMode mode)
     380              : {
     381              :     static const std::unordered_map<aclmdlRICaptureMode, const char*> captureModeDescMap = {
     382              :         {ACL_MODEL_RI_CAPTURE_MODE_GLOBAL, "MODEL_RI_CAPTURE_MODE_GLOBAL(0)"},
     383              :         {ACL_MODEL_RI_CAPTURE_MODE_THREAD_LOCAL, "MODEL_RI_CAPTURE_MODE_THREAD_LOCAL(1)"},
     384              :         {ACL_MODEL_RI_CAPTURE_MODE_RELAXED, "MODEL_RI_CAPTURE_MODE_RELAXED(2)"},
     385              :     };
     386              : 
     387              :     auto it = captureModeDescMap.find(mode);
     388              :     if (it != captureModeDescMap.end()) {
     389              :         return it->second;
     390              :     }
     391              :     static thread_local char enumBuf[32];
     392              :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(mode));
     393              :     return enumBuf;
     394              : }
     395              : 
     396              : inline const char* GetLastErrLevelDesc(aclrtLastErrLevel level)
     397              : {
     398              :     static const std::unordered_map<aclrtLastErrLevel, const char*> lastErrLevelDescMap = {
     399              :         {ACL_RT_THREAD_LEVEL, "THREAD_LEVEL(0)"},
     400              :     };
     401              : 
     402              :     auto it = lastErrLevelDescMap.find(level);
     403              :     if (it != lastErrLevelDescMap.end()) {
     404              :         return it->second;
     405              :     }
     406              :     static thread_local char enumBuf[32];
     407              :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(level));
     408              :     return enumBuf;
     409              : }
     410              : 
     411              : inline const char* GetDeviceInfoDesc(aclDeviceInfo info)
     412              : {
     413              :     static const std::unordered_map<aclDeviceInfo, const char*> deviceInfoDescMap = {
     414              :         {ACL_DEVICE_INFO_UNDEFINED, "DEVICE_INFO_UNDEFINED(-1)"},
     415              :         {ACL_DEVICE_INFO_AI_CORE_NUM, "DEVICE_INFO_AI_CORE_NUM(0)"},
     416              :         {ACL_DEVICE_INFO_VECTOR_CORE_NUM, "DEVICE_INFO_VECTOR_CORE_NUM(1)"},
     417              :         {ACL_DEVICE_INFO_L2_SIZE, "DEVICE_INFO_L2_SIZE(2)"},
     418              :     };
     419              : 
     420              :     auto it = deviceInfoDescMap.find(info);
     421              :     if (it != deviceInfoDescMap.end()) {
     422              :         return it->second;
     423              :     }
     424              :     static thread_local char enumBuf[32];
     425              :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(info));
     426              :     return enumBuf;
     427              : }
     428              : 
     429           16 : inline const char* GetMemAttrDesc(aclrtMemAttr attr)
     430              : {
     431              :     static const std::unordered_map<aclrtMemAttr, const char*> memAttrDescMap = {
     432              :         {ACL_DDR_MEM, "DDR_MEM(0)"},
     433              :         {ACL_HBM_MEM, "HBM_MEM(1)"},
     434              :         {ACL_DDR_MEM_HUGE, "DDR_MEM_HUGE(2)"},
     435              :         {ACL_DDR_MEM_NORMAL, "DDR_MEM_NORMAL(3)"},
     436              :         {ACL_HBM_MEM_HUGE, "HBM_MEM_HUGE(4)"},
     437              :         {ACL_HBM_MEM_NORMAL, "HBM_MEM_NORMAL(5)"},
     438              :         {ACL_DDR_MEM_P2P_HUGE, "DDR_MEM_P2P_HUGE(6)"},
     439              :         {ACL_DDR_MEM_P2P_NORMAL, "DDR_MEM_P2P_NORMAL(7)"},
     440              :         {ACL_HBM_MEM_P2P_HUGE, "HBM_MEM_P2P_HUGE(8)"},
     441              :         {ACL_HBM_MEM_P2P_NORMAL, "HBM_MEM_P2P_NORMAL(9)"},
     442              :         {ACL_HBM_MEM_HUGE1G, "HBM_MEM_HUGE1G(10)"},
     443              :         {ACL_HBM_MEM_P2P_HUGE1G, "HBM_MEM_P2P_HUGE1G(11)"},
     444              :         {ACL_MEM_NORMAL, "MEM_NORMAL(12)"},
     445              :         {ACL_MEM_HUGE, "MEM_HUGE(13)"},
     446              :         {ACL_MEM_HUGE1G, "MEM_HUGE1G(14)"},
     447              :         {ACL_MEM_P2P_NORMAL, "MEM_P2P_NORMAL(15)"},
     448              :         {ACL_MEM_P2P_HUGE, "MEM_P2P_HUGE(16)"},
     449              :         {ACL_MEM_P2P_HUGE1G, "MEM_P2P_HUGE1G(17)"},
     450           18 :     };
     451              : 
     452           16 :     auto it = memAttrDescMap.find(attr);
     453           16 :     if (it != memAttrDescMap.end()) {
     454           16 :         return it->second;
     455              :     }
     456              :     static thread_local char enumBuf[32];
     457            0 :     (void)snprintf_s(enumBuf, sizeof(enumBuf), sizeof(enumBuf) - 1, "UNKNOWN(%d)", static_cast<int32_t>(attr));
     458            0 :     return enumBuf;
     459              : }
     460              : 
     461            6 : static inline std::string DatasetMemTypeToString(const datasetMemType type)
     462              : {
     463            6 :     std::string result;
     464            6 :     switch (type) {
     465            0 :         case MEM_UNKNOWN:
     466            0 :             result = "MEM_UNKNOWN(0)";
     467            0 :             break;
     468            3 :         case MEM_HOST:
     469            3 :             result = "MEM_HOST(1)";
     470            3 :             break;
     471            3 :         case MEM_DEVICE:
     472            3 :             result = "MEM_DEVICE(2)";
     473            3 :             break;
     474            0 :         default:
     475            0 :             result = "UNKNOWN(" + std::to_string(static_cast<int32_t>(type)) + ")";
     476            0 :             break;
     477              :     }
     478            6 :     return result;
     479            0 : }
     480              : 
     481              : } // namespace acl
     482              : 
     483              : #endif // ACL_UTILS_DATA_TYPE_UTILS_H
        

Generated by: LCOV version 2.0-1