Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 : #ifndef AICPUSD_DUMP_TASK_H
11 : #define AICPUSD_DUMP_TASK_H
12 :
13 : #include <cmath>
14 : #include <map>
15 : #include <memory>
16 : #include <mutex>
17 : #include <set>
18 : #include <sstream>
19 : #include <string>
20 : #include <vector>
21 : #include "Eigen/Dense"
22 : #include "aicpusd_status.h"
23 : #include "dump_data.pb.h"
24 : #include "op_mapping_info.pb.h"
25 : #include "dump/adump_device_pub.h"
26 : #include "aicpusd_common.h"
27 : #include "type_def.h"
28 : #include "datadump_kfc_interface.h"
29 : #include "aicpusd_sqe_adapter.h"
30 :
31 : #define DATADUMP_MAKE_SHARED(exec_expr0, exec_expr1) \
32 : try { \
33 : exec_expr0; \
34 : } catch (const std::bad_alloc& err) { \
35 : aicpusd_err("bad alloc for object, reason is [%s]", err.what()); \
36 : exec_expr1; \
37 : } catch (const std::exception& err) { \
38 : aicpusd_err("make shared failed for object failed, reason is [%s]", err.what()); \
39 : exec_expr1; \
40 : } catch (...) { \
41 : aicpusd_err("make shared failed. reason is [%s]", strerror(errno)); \
42 : exec_expr1; \
43 : }
44 :
45 : #ifdef __cplusplus
46 : extern "C" {
47 : #endif
48 : __attribute__((weak)) bool AdumpStatsOpInitStatus();
49 : #ifdef __cplusplus
50 : }
51 : #endif
52 :
53 : namespace AicpuSchedule {
54 : constexpr uint32_t INVALID_VAL = 65535U;
55 : constexpr uint8_t STARS_DATADUMP_LOAD_INFO = 8;
56 : // datadump for kfc
57 : using AicpuKfcDumpFuncPtr = uint32_t (*)(void*);
58 :
59 : using DumpMode = ::aicpu::dump::DumpData;
60 :
61 121 : static inline void ReplaceStringElem(std::string& str)
62 : {
63 121 : (void)for_each(str.begin(), str.end(), [](char_t& ch) {
64 1364 : if ((ch == ' ') || (ch == '.') || (ch == '/') || (ch == '\\')) {
65 273 : ch = '_';
66 : }
67 1364 : });
68 121 : }
69 : struct MappingInfoOptionalParam {
70 207 : MappingInfoOptionalParam()
71 207 : : hasModelName(false),
72 207 : hasModelId(false),
73 207 : modelId(0U),
74 207 : hasStepId(false),
75 207 : stepIdAddr(nullptr),
76 207 : hasIterationsPerLoop(false),
77 207 : iterationsPerLoopAddr(nullptr),
78 207 : hasLoopCond(false),
79 207 : loopCondAddr(nullptr),
80 207 : hasDumpSwitch(false),
81 207 : dumpSwitchAddr(nullptr)
82 207 : {}
83 :
84 : bool hasModelName;
85 : std::string modelName;
86 : bool hasModelId;
87 : uint32_t modelId;
88 : bool hasStepId;
89 : uint64_t* stepIdAddr;
90 : bool hasIterationsPerLoop;
91 : uint64_t* iterationsPerLoopAddr;
92 : bool hasLoopCond;
93 : uint64_t* loopCondAddr;
94 : bool hasDumpSwitch;
95 : uint64_t* dumpSwitchAddr;
96 : };
97 :
98 : struct IntervalStep {
99 : uint64_t start;
100 : uint64_t end;
101 : };
102 :
103 : struct DumpStep {
104 : std::set<uint64_t> singleStep;
105 : std::vector<IntervalStep> intervalStep;
106 : std::string DebugString() const;
107 : };
108 :
109 : struct TaskInfo {
110 138 : TaskInfo() : streamId_(0U), taskId_(0U), contextId_(INVALID_VAL), threadId_(INVALID_VAL){};
111 :
112 153 : TaskInfo(
113 : const uint32_t streamId, const uint32_t taskId, const uint32_t contextId = INVALID_VAL,
114 : const uint32_t threadId = INVALID_VAL)
115 153 : : streamId_(streamId), taskId_(taskId), contextId_(contextId), threadId_(threadId){};
116 :
117 : uint32_t streamId_;
118 : uint32_t taskId_;
119 : uint32_t contextId_ = INVALID_VAL;
120 : uint32_t threadId_ = INVALID_VAL;
121 : friend bool operator<(const TaskInfo& item1, const TaskInfo& item2);
122 : };
123 :
124 : struct TaskInfoExt {
125 21 : TaskInfoExt()
126 21 : : streamId_(INVALID_VAL),
127 21 : taskId_(INVALID_VAL),
128 21 : contextId_(INVALID_VAL),
129 21 : threadId_(INVALID_VAL),
130 21 : indexId_(INVALID_VAL){};
131 :
132 50 : TaskInfoExt(
133 : const uint32_t streamId, const uint32_t taskId, const uint32_t contextId = INVALID_VAL,
134 : const uint32_t threadId = INVALID_VAL, const uint32_t indexId = INVALID_VAL)
135 50 : : streamId_(streamId), taskId_(taskId), contextId_(contextId), threadId_(threadId), indexId_(indexId){};
136 :
137 : uint32_t streamId_;
138 : uint32_t taskId_;
139 : uint32_t contextId_;
140 : uint32_t threadId_;
141 : uint32_t indexId_;
142 : };
143 :
144 : struct DumpFileName {
145 68 : DumpFileName(
146 : const uint32_t streamId, const uint32_t taskId, const uint32_t contextId = INVALID_VAL,
147 : const uint32_t threadId = INVALID_VAL)
148 68 : : streamId_(streamId), taskId_(taskId), contextId_(contextId), threadId_(threadId){};
149 : uint32_t streamId_;
150 : uint32_t taskId_;
151 : uint32_t contextId_;
152 : uint32_t threadId_;
153 : };
154 :
155 466 : inline bool operator<(const TaskInfo& item1, const TaskInfo& item2)
156 : {
157 466 : if (item1.streamId_ != item2.streamId_) {
158 197 : return item1.streamId_ < item2.streamId_;
159 : }
160 269 : if (item1.taskId_ != item2.taskId_) {
161 89 : return item1.taskId_ < item2.taskId_;
162 : }
163 180 : if (item1.contextId_ != item2.contextId_) {
164 12 : return item1.contextId_ < item2.contextId_;
165 : }
166 168 : return item1.threadId_ < item2.threadId_;
167 : }
168 :
169 : class OpDumpTask {
170 : public:
171 : explicit OpDumpTask(const int32_t hostPid, const uint32_t deviceId);
172 138 : ~OpDumpTask() = default;
173 :
174 : /**
175 : * Preprocess op mapping info.
176 : * @param task task info from op mapping info
177 : * @param basePath base dump path
178 : * @param param optional param
179 : * @param dumpStep step need dump
180 : * @param skipAddressConversion indicates whether to skip address conversion based on addrtype
181 : * @return whather preprocess success
182 : */
183 : StatusCode PreProcessOpMappingInfo(
184 : const aicpu::dump::Task& task, const std::string& basePath, const MappingInfoOptionalParam& param,
185 : const DumpStep& dumpStep, const DumpMode dumpMode, const bool skipAddressConversion = false);
186 : StatusCode UpdatePreProcessFftsPlusInputAndOutput(const aicpu::dump::Context& item);
187 : StatusCode PreProcessUdfOpMappingInfo(uint8_t* dumpInfo, uint64_t length);
188 : /**
189 : * Deal with dump info event.
190 : * @return whather dump success
191 : */
192 : StatusCode DumpOpInfo(const TaskInfoExt& dumpTaskInfo, const DumpFileName& dumpFileName);
193 : StatusCode DumpOpInfo(const uint32_t streamId = INVALID_VAL, const uint32_t taskId = INVALID_VAL);
194 :
195 : /**
196 : * Get model id of this task.
197 : * @param modelId model id
198 : * @return whather get model id success
199 : */
200 : bool GetModelId(uint32_t& modelId) const;
201 :
202 : /**
203 : * Check this task is end graph task or not.
204 : * @return whather is end graph task
205 : */
206 : bool IsEndGraph() const;
207 :
208 : /**
209 : * Update dump number.
210 : * @return void
211 : */
212 : void UpdateDumpNum();
213 :
214 : /**
215 : * Get op name.
216 : * @return op name
217 : */
218 : std::string GetOpName() const;
219 :
220 : /**
221 : * Clear baseDumpData_.
222 : * @return void
223 : */
224 : void ClearBaseDumpData();
225 : bool IsSupportKfcDump();
226 5 : const std::string& GetDumpPath() { return dumpPath_; }
227 5 : const uint32_t GetDeviceId() { return deviceId_; }
228 5 : const int32_t GetHostPid() { return hostPid_; }
229 93 : const std::string& GetOpName() { return opName_; }
230 : void GetKfcDumpInfo(std::shared_ptr<KfcDumpInfo> dumpInfo);
231 : StatusCode Dump(
232 : const std::string& path, char_t* const data, const uint64_t len, IDE_SESSION& ideSession,
233 : const bool isLastSlice) const;
234 :
235 : private:
236 : /**
237 : * Get dump number
238 : * @param dumpNum task dump number
239 : * @return whather get dump param success
240 : */
241 : StatusCode GetDumpNumber(uint64_t& dumpNum);
242 :
243 : /**
244 : * This step need dump or not
245 : * @param step task dump number
246 : * @return whather need dump
247 : */
248 : bool NeedDump(const uint64_t step) const;
249 :
250 : StatusCode PreProcessOutput(const aicpu::dump::Task& task, ::toolkit::dumpdata::DumpData& dumpData);
251 :
252 : StatusCode PreProcessInput(const aicpu::dump::Task& task, ::toolkit::dumpdata::DumpData& dumpData);
253 :
254 : StatusCode PreProcessOpBuffer(const aicpu::dump::Task& task, ::toolkit::dumpdata::DumpData& dumpData);
255 : StatusCode PreProcessWorkspace(const aicpu::dump::Task& task, ::toolkit::dumpdata::DumpData& dumpData);
256 : StatusCode ProcessInputDump(
257 : const ::toolkit::dumpdata::DumpData& dumpData, const std::string& path, IDE_SESSION& ideSession);
258 : StatusCode ProcessOutputDump(
259 : const ::toolkit::dumpdata::DumpData& dumpData, const std::string& path, IDE_SESSION& ideSession);
260 : StatusCode ProcessOpBufferDump(
261 : const ::toolkit::dumpdata::DumpData& dumpData, const std::string& path, IDE_SESSION& ideSession);
262 : StatusCode ProcessOpWorkspaceDump(
263 : const ::toolkit::dumpdata::DumpData& dumpData, const std::string& path, IDE_SESSION& ideSession);
264 :
265 : std::string DumpPath(
266 : const uint64_t nowTime, const uint64_t dumpNumber, const DumpFileName& dumpFileName,
267 : const bool debugFlag = false);
268 :
269 : StatusCode DoDumpTensor(const std::string& dumpFilePath);
270 :
271 : StatusCode ProcessngNoTiliInput();
272 :
273 : StatusCode ProcessngNoTiliOutput();
274 :
275 : void UpdateDumpData();
276 : void UpdateUdfDumpDataTotalSize();
277 : /**
278 : * Get Input DataAddr
279 : * @param i index
280 : * @return void
281 : */
282 : void GetInputDataAddr(uint64_t& dataAddr, const int32_t i);
283 :
284 : /**
285 : * Get Output DataAddr
286 : * @param i index
287 : * @return void
288 : */
289 : void GetOutputDataAddr(uint64_t& dataAddr, const int32_t i);
290 :
291 : StatusCode ProcessDumpOpInfo(const TaskInfoExt& dumpTaskInfo, const std::string& dumpFilePath);
292 : StatusCode ProcessDumpTensor(const std::string& dumpFilePath);
293 : StatusCode ProcessDumpStats(const std::string& dumpFilePath);
294 : StatusCode ProcessDumpStatistic(const TaskInfoExt& dumpTaskInfo, const std::string& dumpFilePath);
295 : StatusCode DoDumpStats(const std::string& dumpFilePath, const std::string& content);
296 : std::string GenerateDataStatsInfo(
297 : uint64_t dataAddr, uint64_t dataSize, ::toolkit::dumpdata::OutputDataType dataType) const;
298 : std::string GenerateDataDimInfo(::toolkit::dumpdata::Shape dataShape) const;
299 : std::string GetDataFormatStr(::toolkit::dumpdata::OutputFormat dataFormat) const;
300 : std::string GetDataTypeStr(::toolkit::dumpdata::OutputDataType dataType) const;
301 : StatusCode ProcessKfcDumpStats(KfcDumpTask& taskInfo, const std::string& dumpFilePath);
302 : bool CheckAndGetKfcDumpStatsAPI();
303 : std::string ShapeDebugString(std::vector<uint64_t> shapeInfo) const;
304 :
305 : std::mutex dumpMtx_;
306 : ::toolkit::dumpdata::DumpData baseDumpData_;
307 : std::string baseDumpPath_;
308 : std::string dumpPath_;
309 : std::string opName_;
310 : std::string opType_;
311 : MappingInfoOptionalParam optionalParam_;
312 : uint64_t taskDumpNum_;
313 : TaskInfo taskInfo_;
314 : ::aicpu::dump::Task::TaskType taskType_;
315 : DumpStep dumpStep_;
316 : std::vector<uint64_t> inputsSize_;
317 : std::vector<uint64_t> outputSize_;
318 : std::vector<uint64_t> inputsOffset_;
319 : std::vector<uint64_t> outputOffset_;
320 : bool endGraph_;
321 : std::vector<uint64_t> inputsBaseAddr_;
322 : std::vector<int32_t> inputsDataType_;
323 : std::vector<int32_t> inputsFormat_;
324 : std::vector<std::vector<uint64_t>> inputsShape_;
325 : std::vector<std::vector<uint64_t>> inputsOriginShape_;
326 : std::vector<uint64_t> outputsBaseAddr_;
327 : std::vector<int32_t> outputsDataType_;
328 : std::vector<int32_t> outputsFormat_;
329 : std::vector<std::vector<uint64_t>> outputsShape_;
330 : std::vector<std::vector<uint64_t>> outputsOriginShape_;
331 : std::vector<int32_t> inputsAddrType_;
332 : std::vector<int32_t> outputsAddrType_;
333 : std::vector<uint64_t> opBufferAddr_;
334 : std::vector<uint64_t> opWorkspaceAddr_;
335 : std::vector<uint64_t> opWorkspaceSize_;
336 : uint64_t inputTotalSize_;
337 : uint64_t outputTotalSize_;
338 : uint64_t opBufferTotalSize_;
339 : uint64_t opWorkspaceTotalSize_;
340 :
341 : std::unique_ptr<char_t[]> buff_;
342 : uint64_t buffSize_;
343 : uint64_t offset_;
344 : bool skipAddressConversion_;
345 : int32_t hostPid_;
346 : uint32_t deviceId_;
347 : DumpMode dumpMode_;
348 : AicpuKfcDumpFuncPtr kfcDumpFunc_ = nullptr;
349 : }; // class OpDumpTask
350 :
351 : class OpDumpTaskManager {
352 : public:
353 : static OpDumpTaskManager& GetInstance();
354 7 : OpDumpTaskManager() = default;
355 7 : ~OpDumpTaskManager() = default;
356 :
357 : /**
358 : * Load op mapping info
359 : * @param infoAddr info address pointer
360 : * @param len info length
361 : * @return whather load success
362 : */
363 : int32_t LoadOpMappingInfo(const char_t* const infoAddr, const uint32_t len, AicpuSqeAdapter& aicpuSqeAdapter);
364 :
365 : int32_t LoadOpMappingInfo(const char_t* const infoAddr, const uint32_t len);
366 :
367 : /**
368 : * Deal with dump info event for know shape.
369 : * @param dumpTaskInfo Dump Task Info
370 : * @param streamId Stream id
371 : * @param taskId Task id
372 : * @return whather dump success
373 : */
374 : int32_t DumpOpInfo(TaskInfoExt& dumpTaskInfo, const DumpFileName& dumpFileName);
375 : int32_t DumpOpInfo(
376 : const uint32_t streamId, const uint32_t taskId, const uint32_t streamId1 = INVALID_VAL,
377 : const uint32_t taskId1 = INVALID_VAL);
378 : int32_t DumpOpInfo(
379 : TaskInfoExt& dumpTaskInfo, const uint32_t streamId, const uint32_t taskId, const uint32_t contextId,
380 : const uint32_t threadId);
381 : /**
382 : * Deal with dump info event for unknow shape.
383 : * @param opMappingInfoAddr op mapping info addr
384 : * @param opMappingInfoLen op mapping info length
385 : * @return whather dump success
386 : */
387 : int32_t DumpOpInfoForUnknowShape(const uint64_t opMappingInfoAddr, const uint64_t opMappingInfoLen) const;
388 :
389 : /**
390 : * clear all resource od data dump for ctrl cpu and minirc
391 : * @return void
392 : */
393 : void ClearResource();
394 :
395 : int32_t DoDump(
396 : const aicpu::dump::OpMappingInfo& opMappingInfo, const MappingInfoOptionalParam& optionalParam) const;
397 : void MakeDumpOpInfoforKfc(const KfcDumpTask& taskinfo, std::shared_ptr<OpDumpTask> dumpTask);
398 : int32_t GetDumpOpTaskDataforKfc(const KfcDumpTask& taskKey, KfcDumpInfo** dumpInfo);
399 : int32_t DumpOpTaskDataforKfc(const KfcDumpTask& taskKey, void* dumpData, uint32_t length) const;
400 : bool IsCustDumpTask(const uint32_t streamId, const uint32_t taskId);
401 : int32_t SetCustDumpTaskFlag(const uint32_t streamId, const uint32_t taskId, const bool flag);
402 : void ClearKfcDumpTaskInfo(const KfcDumpTask& kfcTaskinfo);
403 : int32_t DoDumpBySwitchBitmap(
404 : const aicpu::dump::OpMappingInfo& opMappingInfo, const MappingInfoOptionalParam& optionalParam,
405 : const uint64_t switchBitMap) const;
406 :
407 : private:
408 : OpDumpTaskManager(const OpDumpTaskManager&) = delete;
409 : OpDumpTaskManager& operator=(const OpDumpTaskManager&) = delete;
410 : OpDumpTaskManager(OpDumpTaskManager&&) = delete;
411 : OpDumpTaskManager& operator=(OpDumpTaskManager&&) = delete;
412 :
413 : /**
414 : * Get optional param from op mapping info proto
415 : * @param opMappingInfo op mapping info
416 : * @param optionalParam optional param
417 : * @return void
418 : */
419 : void GetOptionalParam(
420 : const aicpu::dump::OpMappingInfo& opMappingInfo, MappingInfoOptionalParam& optionalParam) const;
421 :
422 : /**
423 : * Update all task dump number of according model id
424 : * @param modelId model id
425 : * @return void
426 : */
427 : void UpdateDumpNumByModelId(const uint32_t modelId);
428 :
429 : /**
430 : * Porcess end graph task if it exist in opDumptasks
431 : * @param opDumptasks tasks
432 : * @return void
433 : */
434 : void ProcessEndGraph(const std::vector<std::shared_ptr<OpDumpTask>>& opDumptasks);
435 :
436 : /**
437 : * Parse dump step from string, like 0|1-20
438 : * @param str dump step string
439 : * @param dumpStep dump step of parse result
440 : * @return whather parse success
441 : */
442 : bool GetDumpStepFromString(const std::string& str, DumpStep& dumpStep) const;
443 :
444 : /**
445 : * Parse dump step from step string
446 : * @param step step string
447 : * @param tmpDumpStep dump step of parse result
448 : * @return whather parse success
449 : */
450 : bool MatchAndInsert(const std::string& step, DumpStep& tmpDumpStep) const;
451 :
452 : /**
453 : * load mapping info
454 : * @param opMappingInfo op mapping info proto
455 : * @return whather load success
456 : */
457 : int32_t Load(const aicpu::dump::OpMappingInfo& opMappingInfo, AicpuSqeAdapter& aicpuSqeAdapter);
458 :
459 : /**
460 : * unload mapping info
461 : * @param opMappingInfo op mapping info proto
462 : * @return whather unload success
463 : */
464 : int32_t Unload(const aicpu::dump::OpMappingInfo& opMappingInfo, AicpuSqeAdapter& aicpuSqeAdapter);
465 :
466 : /**
467 : * clear baseDumpData
468 : * @param TaskInfo taskInfo
469 : * @return void
470 : */
471 : void UnloadClearTaskInfo(const TaskInfo& dumpTaskInfo);
472 : /**
473 : * create OpDumpTask
474 : * @param opDumpTaskPtr hostPid deviceId
475 : * @return create success
476 : */
477 : int32_t CreateOpDumpTask(
478 : std::shared_ptr<OpDumpTask>& opDumpTaskPtr, const int32_t hostPid, const uint32_t deviceId) const;
479 : /**
480 : * create KfcDumpInfo
481 : * @param kfcDumpInfoPtr
482 : * @return create success
483 : */
484 : int32_t CreateKfcDumpInfo(std::shared_ptr<KfcDumpInfo>& kfcDumpInfoPtr) const;
485 : bool EnsureDeviceOpened(const uint32_t deviceId) const;
486 : int32_t GetAndClearOverflowStatus(
487 : const uint32_t deviceId, const uint32_t streamId, const uint32_t opType, uint32_t* status) const;
488 :
489 : private:
490 : std::multimap<TaskInfo, std::shared_ptr<OpDumpTask>> dumpTaskMap_;
491 : std::mutex dumpTaskMapMtx_;
492 : std::mutex kfcDumpTaskMapMtx_;
493 : std::map<uint32_t, std::set<TaskInfo>> modelIdToTask_;
494 : std::map<KfcDumpTask, std::shared_ptr<OpDumpTask>> kfcDumpTaskMap_;
495 : std::map<KfcDumpTask, std::shared_ptr<KfcDumpInfo>> kfcDumpInfoMap_;
496 : std::map<TaskInfo, bool> custDumpTaskMap_;
497 : };
498 :
499 : template <typename T>
500 : class DataStats {
501 : public:
502 119 : DataStats(uint64_t dataAddr, uint64_t dataSize)
503 119 : : maxValue_(0),
504 119 : minValue_(0),
505 119 : avgValue_(0.0),
506 119 : count_(0UL),
507 119 : nanCount_(0UL),
508 119 : negInfCount_(0UL),
509 119 : posInfCount_(0UL),
510 119 : data_(nullptr),
511 119 : dataSize_(dataSize)
512 : {
513 119 : data_ = PtrToPtr<void, T>(ValueToPtr(dataAddr));
514 119 : count_ = dataSize_ / sizeof(T);
515 119 : };
516 :
517 : virtual ~DataStats() = 0;
518 :
519 116 : virtual inline std::string GetDataStatsStr()
520 : {
521 116 : this->Stats();
522 116 : std::ostringstream oss;
523 326 : oss << maxValue_ << "," << minValue_ << "," << avgValue_ << "," << count_ << "," << nanCount_ << ","
524 116 : << negInfCount_ << "," << posInfCount_;
525 232 : return oss.str();
526 116 : };
527 :
528 : protected:
529 0 : virtual inline bool IsNan(T ele) const
530 : {
531 : (void)ele;
532 0 : return true;
533 : }
534 :
535 0 : virtual inline bool IsInf(T ele) const
536 : {
537 : (void)ele;
538 0 : return true;
539 : }
540 :
541 5230 : virtual inline void UpdateAvgValue(T ele, uint64_t i)
542 : {
543 5230 : avgValue_ += (static_cast<double>(ele) - avgValue_) / static_cast<double>(i + 1);
544 5230 : }
545 :
546 119 : virtual inline void AdjustAvgValue()
547 : {
548 119 : if ((negInfCount_ > 0UL) && (posInfCount_ == 0UL)) {
549 0 : avgValue_ = -INFINITY;
550 119 : } else if ((negInfCount_ == 0UL) && (posInfCount_ > 0UL)) {
551 1 : avgValue_ = INFINITY;
552 : }
553 119 : return;
554 : }
555 :
556 : void Stats();
557 :
558 : T maxValue_;
559 : T minValue_;
560 : double avgValue_;
561 : uint64_t count_;
562 : uint64_t nanCount_;
563 : uint64_t negInfCount_;
564 : uint64_t posInfCount_;
565 :
566 : private:
567 119 : inline void ResetStats()
568 : {
569 119 : avgValue_ = static_cast<double>(0.0);
570 119 : nanCount_ = 0UL;
571 119 : negInfCount_ = 0UL;
572 119 : posInfCount_ = 0UL;
573 119 : return;
574 : }
575 :
576 : DataStats(DataStats const&) = delete;
577 : DataStats& operator=(DataStats const&) = delete;
578 : DataStats(DataStats&&) = delete;
579 : DataStats& operator=(DataStats&&) = delete;
580 :
581 : T* data_;
582 : uint64_t dataSize_;
583 : };
584 :
585 : template <typename T>
586 : class NormalDataStats : public DataStats<T> {
587 : public:
588 14 : NormalDataStats(uint64_t dataAddr, uint64_t dataSize) : DataStats<T>(dataAddr, dataSize) {}
589 14 : ~NormalDataStats() = default;
590 :
591 : protected:
592 140 : inline bool IsNan(T ele) const { return std::isnan(ele); }
593 :
594 140 : inline bool IsInf(T ele) const { return std::isinf(ele); }
595 :
596 : private:
597 : NormalDataStats(NormalDataStats const&) = delete;
598 : NormalDataStats& operator=(NormalDataStats const&) = delete;
599 : NormalDataStats(NormalDataStats&&) = delete;
600 : NormalDataStats& operator=(NormalDataStats&&) = delete;
601 : };
602 :
603 : class Uint8DataStats : public NormalDataStats<uint8_t> {
604 : public:
605 2 : Uint8DataStats(uint64_t dataAddr, uint64_t dataSize) : NormalDataStats<uint8_t>(dataAddr, dataSize) {}
606 2 : ~Uint8DataStats() = default;
607 :
608 2 : inline std::string GetDataStatsStr()
609 : {
610 2 : Stats();
611 2 : std::ostringstream oss;
612 2 : oss << static_cast<uint32_t>(maxValue_) << "," << static_cast<uint32_t>(minValue_) << "," << avgValue_ << ","
613 2 : << count_ << "," << nanCount_ << "," << negInfCount_ << "," << posInfCount_;
614 4 : return oss.str();
615 2 : };
616 :
617 : private:
618 : Uint8DataStats(Uint8DataStats const&) = delete;
619 : Uint8DataStats& operator=(Uint8DataStats const&) = delete;
620 : Uint8DataStats(Uint8DataStats&&) = delete;
621 : Uint8DataStats& operator=(Uint8DataStats&&) = delete;
622 : };
623 :
624 : class Int8DataStats : public NormalDataStats<int8_t> {
625 : public:
626 1 : Int8DataStats(uint64_t dataAddr, uint64_t dataSize) : NormalDataStats<int8_t>(dataAddr, dataSize) {}
627 1 : ~Int8DataStats() = default;
628 :
629 1 : inline std::string GetDataStatsStr()
630 : {
631 1 : Stats();
632 1 : std::ostringstream oss;
633 1 : oss << static_cast<int32_t>(maxValue_) << "," << static_cast<int32_t>(minValue_) << "," << avgValue_ << ","
634 1 : << count_ << "," << nanCount_ << "," << negInfCount_ << "," << posInfCount_;
635 2 : return oss.str();
636 1 : };
637 :
638 : private:
639 : Int8DataStats(Int8DataStats const&) = delete;
640 : Int8DataStats& operator=(Int8DataStats const&) = delete;
641 : Int8DataStats(Int8DataStats&&) = delete;
642 : Int8DataStats& operator=(Int8DataStats&&) = delete;
643 : };
644 :
645 : class EigenDataStats : public DataStats<Eigen::half> {
646 : public:
647 105 : EigenDataStats(uint64_t dataAddr, uint64_t dataSize) : DataStats<Eigen::half>(dataAddr, dataSize) {}
648 105 : ~EigenDataStats() = default;
649 :
650 : protected:
651 5090 : inline bool IsNan(Eigen::half ele) const { return Eigen::numext::isnan(ele); }
652 :
653 5090 : inline bool IsInf(Eigen::half ele) const { return Eigen::numext::isinf(ele); }
654 :
655 : private:
656 : EigenDataStats(EigenDataStats const&) = delete;
657 : EigenDataStats& operator=(EigenDataStats const&) = delete;
658 : EigenDataStats(EigenDataStats&&) = delete;
659 : EigenDataStats& operator=(EigenDataStats&&) = delete;
660 : };
661 :
662 : class DumpSessionManager {
663 : public:
664 : static DumpSessionManager& GetInstance();
665 4 : DumpSessionManager() = default;
666 4 : ~DumpSessionManager() = default;
667 :
668 : IDE_SESSION GetSession(int32_t hostPid, uint32_t deviceId);
669 : IDE_SESSION ReacquireSession(int32_t hostPid, uint32_t deviceId);
670 : void CloseAllSessions();
671 : IDE_SESSION CreateIdeDumpSession(int32_t hostPid, uint32_t deviceId) const;
672 :
673 : private:
674 : std::unordered_map<uint64_t, IDE_SESSION> sessionsMap_;
675 : std::mutex mutex_;
676 : };
677 : } // namespace AicpuSchedule
678 :
679 : #endif
|