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