LCOV - code coverage report
Current view: top level - aicpu_cust_schedule/core/dfx - dump_task.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 95.0 % 20 19
Test Date: 2026-07-28 10:54:05 Functions: 100.0 % 7 7

            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 <map>
      14              : #include <memory>
      15              : #include <mutex>
      16              : #include <set>
      17              : #include <string>
      18              : #include <vector>
      19              : #include "aicpusd_status.h"
      20              : #include "dump_data.pb.h"
      21              : #include "op_mapping_info.pb.h"
      22              : #include "dump/adump_device_pub.h"
      23              : #include "aicpusd_common.h"
      24              : #include "aicpusd_sqe_adapter.h"
      25              : 
      26              : namespace AicpuSchedule {
      27              : constexpr uint32_t INVALID_VAL = 65535U;
      28              : constexpr uint8_t STARS_DATADUMP_LOAD_INFO = 8;
      29              : 
      30              : struct MappingInfoOptionalParam {
      31           26 :     MappingInfoOptionalParam() : hasModelName(false),
      32           26 :                                  hasModelId(false),
      33           26 :                                  modelId(0U),
      34           26 :                                  hasStepId(false),
      35           26 :                                  stepIdAddr(nullptr),
      36           26 :                                  hasIterationsPerLoop(false),
      37           26 :                                  iterationsPerLoopAddr(nullptr),
      38           26 :                                  hasLoopCond(false),
      39           26 :                                  loopCondAddr(nullptr) {}
      40              : 
      41              :     bool hasModelName;
      42              :     std::string modelName;
      43              :     bool hasModelId;
      44              :     uint32_t modelId;
      45              :     bool hasStepId;
      46              :     uint64_t *stepIdAddr;
      47              :     bool hasIterationsPerLoop;
      48              :     uint64_t *iterationsPerLoopAddr;
      49              :     bool hasLoopCond;
      50              :     uint64_t *loopCondAddr;
      51              : };
      52              : 
      53              : struct IntervalStep {
      54              :     uint64_t start;
      55              :     uint64_t end;
      56              : };
      57              : 
      58              : struct DumpStep {
      59              :     std::set<uint64_t> singleStep;
      60              :     std::vector<IntervalStep> intervalStep;
      61              :     std::string DebugString();
      62              : };
      63              : 
      64              : struct TaskInfo {
      65           17 :     TaskInfo() : streamId_(0U),
      66           17 :                  taskId_(0U) {};
      67              : 
      68           10 :     TaskInfo(const uint32_t streamId, const uint32_t taskId) : streamId_(streamId),
      69           10 :                                                                taskId_(taskId) {};
      70              : 
      71              :     uint32_t streamId_;
      72              :     uint32_t taskId_;
      73              :     friend bool operator < (const TaskInfo &item1, const TaskInfo &item2);
      74              : };
      75              : 
      76           22 : inline bool operator < (const TaskInfo &item1, const TaskInfo &item2)
      77              : {
      78           22 :     if (item1.streamId_ == item2.streamId_) {
      79           22 :         return item1.taskId_ < item2.taskId_;
      80              :     }
      81            0 :     return item1.streamId_ < item2.streamId_;
      82              : }
      83              : 
      84              : class OpDumpTask {
      85              : public:
      86              :     explicit OpDumpTask(const int32_t hostPid, const uint32_t deviceId);
      87           17 :     ~OpDumpTask() = default;
      88              : 
      89              :      /**
      90              :      * Preprocess op mapping info.
      91              :      * @param  task task info from op mapping info
      92              :      * @param  basePath base dump path
      93              :      * @param  param optional param
      94              :      * @param  dumpStep step need dump
      95              :      * @param  skipAddressConversion indicates whether to skip address conversion based on addrtype
      96              :      * @return whather preprocess success
      97              :      */
      98              :     StatusCode PreProcessOpMappingInfo(const aicpu::dump::Task &task,
      99              :                                        const std::string &basePath,
     100              :                                        const MappingInfoOptionalParam &param,
     101              :                                        const DumpStep &dumpStep,
     102              :                                        const bool skipAddressConversion = false);
     103              : 
     104              :     /**
     105              :      * Deal with dump info event.
     106              :      * @return whather dump success
     107              :      */
     108              :     StatusCode DumpOpInfo(const uint32_t streamId = INVALID_VAL, const uint32_t taskId = INVALID_VAL,
     109              :                           const std::string &dumpDebugInfo = "");
     110              : 
     111              :     /**
     112              :      * Get model id of this task.
     113              :      * @param  modelId model id
     114              :      * @return whather get model id success
     115              :      */
     116              :     bool GetModelId(uint32_t &modelId) const;
     117              : 
     118              :     /**
     119              :      * Check this task is end graph task or not.
     120              :      * @return whather is end graph task
     121              :      */
     122              :     bool IsEndGraph() const;
     123              : 
     124              :     /**
     125              :      * Update dump number.
     126              :      * @return void
     127              :      */
     128              :     void UpdateDumpNum();
     129              : 
     130              :     /**
     131              :      * Get op name.
     132              :      * @return op name
     133              :      */
     134              :     std::string GetOpName() const;
     135              : 
     136              :     /**
     137              :      * Clear baseDumpData_.
     138              :      * @return void
     139              :      */
     140              :     void ClearBaseDumpData();
     141              : 
     142              : private:
     143              :     /**
     144              :      * Get dump number
     145              :      * @param  dumpNum task dump number
     146              :      * @return whather get dump param success
     147              :      */
     148              :     StatusCode GetDumpNumber(uint64_t &dumpNum);
     149              : 
     150              :     /**
     151              :      * This step need dump or not
     152              :      * @param  step task dump number
     153              :      * @return whather need dump
     154              :      */
     155              :     bool NeedDump(const uint64_t step);
     156              : 
     157              :     StatusCode PreProcessOutput(const aicpu::dump::Task &task,
     158              :                                 ::toolkit::dumpdata::DumpData &dumpData);
     159              : 
     160              :     StatusCode PreProcessInput(const aicpu::dump::Task &task,
     161              :                                ::toolkit::dumpdata::DumpData &dumpData);
     162              : 
     163              :     StatusCode PreProcessOpBuffer(const aicpu::dump::Task &task,
     164              :                                   ::toolkit::dumpdata::DumpData &dumpData);
     165              :     StatusCode PreProcessWorkspace(const aicpu::dump::Task &task,
     166              :                                    ::toolkit::dumpdata::DumpData &dumpData);
     167              :     StatusCode ProcessInputDump(const ::toolkit::dumpdata::DumpData &dumpData,
     168              :                                 const std::string &path,
     169              :                                 const IDE_SESSION ideSession);
     170              : 
     171              :     StatusCode ProcessOutputDump(const ::toolkit::dumpdata::DumpData &dumpData,
     172              :                                  const std::string &path,
     173              :                                  const IDE_SESSION ideSession);
     174              : 
     175              :     StatusCode ProcessOpBufferDump(const ::toolkit::dumpdata::DumpData &dumpData,
     176              :                                    const std::string &path,
     177              :                                    const IDE_SESSION ideSession);
     178              : 
     179              :     StatusCode ProcessOpWorkspaceDump(const ::toolkit::dumpdata::DumpData &dumpData,
     180              :                                       const std::string &path,
     181              :                                       const IDE_SESSION ideSession);
     182              : 
     183              :     StatusCode Dump(const std::string &path,
     184              :                     char_t * const data,
     185              :                     const uint64_t len,
     186              :                     const IDE_SESSION ideSession,
     187              :                     const bool isLastSlice) const;
     188              : 
     189              :     std::string DumpPath(const uint64_t nowTime, const uint64_t dumpNumber,
     190              :                          const uint32_t streamId, const uint32_t taskId,
     191              :                          const bool debugFlag = false);
     192              : 
     193              :     StatusCode DoDump(const std::string &dumpFilePath, const std::string &dumpDebugFilePath = "",
     194              :                       const std::string &dumpDebugInfo = "");
     195              : 
     196              : private:
     197              :     std::mutex dumpMtx_;
     198              :     ::toolkit::dumpdata::DumpData baseDumpData_;
     199              :     std::string baseDumpPath_;
     200              :     std::string opName_;
     201              :     std::string opType_;
     202              :     MappingInfoOptionalParam optionalParam_;
     203              :     uint64_t taskDumpNum_;
     204              :     TaskInfo taskInfo_;
     205              :     DumpStep dumpStep_;
     206              :     bool endGraph_;
     207              :     std::vector<uint64_t> inputsBaseAddr_;
     208              :     std::vector<uint64_t> outputsBaseAddr_;
     209              :     std::vector<uint64_t> opBufferAddr_;
     210              :     std::vector<uint64_t> opWorkspaceAddr_;
     211              :     uint64_t inputTotalSize_;
     212              :     uint64_t outputTotalSize_;
     213              :     uint64_t opBufferTotalSize_;
     214              :     uint64_t opWorkspaceTotalSize_;
     215              :     std::unique_ptr<char_t[]> buff_;
     216              :     uint64_t buffSize_;
     217              :     uint64_t offset_;
     218              :     bool skipAddressConversion_;
     219              :     int32_t hostPid_;
     220              :     uint32_t deviceId_;
     221              : };  // class OpDumpTask
     222              : 
     223              : class OpDumpTaskManager {
     224              : public:
     225              :     static OpDumpTaskManager &GetInstance();
     226            1 :     OpDumpTaskManager() = default;
     227            1 :     ~OpDumpTaskManager() = default;
     228              : 
     229              :     /**
     230              :      * Load op mapping info
     231              :      * @param  infoAddr info address pointer
     232              :      * @param  len info length
     233              :      * @return whather load success
     234              :      */
     235              :     int32_t LoadOpMappingInfo(const char_t * const infoAddr, const uint32_t len);
     236              : 
     237              :     /**
     238              :      * Deal with dump info event for know shape.
     239              :      * @param  streamId stream id
     240              :      * @param  taskId task id
     241              :      * @return whather dump success
     242              :      */
     243              :     int32_t DumpOpInfo(const uint32_t streamId, const uint32_t taskId,
     244              :                        const uint32_t streamId1 = INVALID_VAL, const uint32_t taskId1 = INVALID_VAL,
     245              :                        const std::string &dumpDebugInfo = "");
     246              : 
     247              :     /**
     248              :      * Deal with dump info event for unknow shape.
     249              :      * @param  opMappingInfoAddr op mapping info addr
     250              :      * @param  opMappingInfoLen op mapping info length
     251              :      * @return whather dump success
     252              :      */
     253              :     int32_t DumpOpInfoForUnknowShape(const uint64_t opMappingInfoAddr, const uint64_t opMappingInfoLen) const;
     254              : 
     255              :     /**
     256              :      * clear all resource od data dump for ctrl cpu and minirc
     257              :      * @return void
     258              :      */
     259              :     void ClearResource();
     260              : 
     261              :     int32_t DoDump(const aicpu::dump::OpMappingInfo &opMappingInfo) const;
     262              : 
     263              : private:
     264              :     OpDumpTaskManager(const OpDumpTaskManager &) = delete;
     265              :     OpDumpTaskManager &operator=(const OpDumpTaskManager &) = delete;
     266              :     OpDumpTaskManager(OpDumpTaskManager&&) = delete;
     267              :     OpDumpTaskManager& operator=(OpDumpTaskManager&&) = delete;
     268              : 
     269              :     /**
     270              :      * Get optional param from op mapping info proto
     271              :      * @param  opMappingInfo op mapping info
     272              :      * @param  optionalParam optional param
     273              :      * @return void
     274              :      */
     275              :     void GetOptionalParam(const aicpu::dump::OpMappingInfo &opMappingInfo,
     276              :                           MappingInfoOptionalParam &optionalParam) const;
     277              : 
     278              :     /**
     279              :      * Update all task dump number of according model id
     280              :      * @param  modelId model id
     281              :      * @return void
     282              :      */
     283              :     void UpdateDumpNumByModelId(const uint32_t modelId);
     284              : 
     285              :     /**
     286              :      * Porcess end graph task if it exist in opDumptasks
     287              :      * @param  opDumptasks tasks
     288              :      * @return void
     289              :      */
     290              :     void ProcessEndGraph(const std::vector<std::shared_ptr<OpDumpTask>> &opDumptasks);
     291              : 
     292              :     /**
     293              :      * Parse dump step from string, like 0|1-20
     294              :      * @param  str dump step string
     295              :      * @param  dumpStep dump step of parse result
     296              :      * @return whather parse success
     297              :      */
     298              :     bool GetDumpStepFromString(const std::string &str, DumpStep &dumpStep) const;
     299              : 
     300              :     /**
     301              :      * Parse dump step from step string
     302              :      * @param  step step string
     303              :      * @param  tmpDumpStep dump step of parse result
     304              :      * @return whather parse success
     305              :      */
     306              :     bool MatchAndInsert(const std::string &step, DumpStep &tmpDumpStep) const;
     307              : 
     308              :     /**
     309              :      * load mapping info
     310              :      * @param  opMappingInfo op mapping info proto
     311              :      * @return whather load success
     312              :      */
     313              :     int32_t Load(const aicpu::dump::OpMappingInfo &opMappingInfo);
     314              : 
     315              :     /**
     316              :      * unload mapping info
     317              :      * @param  opMappingInfo op mapping info proto
     318              :      * @return whather unload success
     319              :      */
     320              :     int32_t Unload(const aicpu::dump::OpMappingInfo &opMappingInfo);
     321              :     
     322              :     /**
     323              :      * clear baseDumpData
     324              :      * @param  TaskInfo taskInfo
     325              :      * @return void
     326              :      */
     327              :     void UnloadClearTaskInfo(const TaskInfo &taskInfo);
     328              : 
     329              : private:
     330              :     std::multimap<TaskInfo, std::shared_ptr<OpDumpTask>> dumpTaskMap_;
     331              :     std::mutex dumpTaskMapMtx_;
     332              :     std::map<uint32_t, std::set<TaskInfo>> modelIdToTask_;
     333              : };
     334              : }   // namespace aicpu
     335              : 
     336              : #endif
        

Generated by: LCOV version 2.0-1