LCOV - code coverage report
Current view: top level - aicpu_schedule/datadump - datadump_event_process.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 96.4 % 84 81
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              : 
      11              : #include "aicpusd_event_process.h"
      12              : #include <iomanip>
      13              : #include <securec.h>
      14              : #include <memory>
      15              : #include "aicpu_event_struct.h"
      16              : #include "ascend_hal.h"
      17              : #include "aicpusd_threads_process.h"
      18              : #include "dump_task.h"
      19              : #include "tsd.h"
      20              : #include "aicpu_sched/common/aicpu_task_struct.h"
      21              : #include "aicpusd_resource_manager.h"
      22              : #include "aicpusd_drv_manager.h"
      23              : #include "aicpusd_model_execute.h"
      24              : #include "aicpusd_profiler.h"
      25              : #include "aicpusd_monitor.h"
      26              : #include "aicpusd_msg_send.h"
      27              : #include "profiling_adp.h"
      28              : #include "aicpu_context.h"
      29              : #include "aicpu_engine.h"
      30              : #include "common/aicpusd_util.h"
      31              : #include "aicpusd_cust_so_manager.h"
      32              : #include "aicpusd_model_err_process.h"
      33              : #include "aicpu_async_event.h"
      34              : #include "aicpusd_context.h"
      35              : #include "type_def.h"
      36              : 
      37              : namespace AicpuSchedule {
      38              :     /**
      39              :      * @ingroup AicpuEventProcess
      40              :      * @brief it is used to construct a object of AicpuEventProcess.
      41              :      */
      42            1 :     AicpuEventProcess::AicpuEventProcess()
      43            1 :         : exitQueueFlag_(false)
      44              :     {
      45            1 :     }
      46              : 
      47              :     /**
      48              :      * @ingroup AicpuEventProcess
      49              :      * @brief it is used to destructor a object of AicpuEventProcess.
      50              :      */
      51            1 :     AicpuEventProcess::~AicpuEventProcess() {}
      52              : 
      53            6 :     AicpuEventProcess &AicpuEventProcess::GetInstance()
      54              :     {
      55            6 :         static AicpuEventProcess instance;
      56            6 :         return instance;
      57              :     }
      58              : 
      59              :     /**
      60              :     * @ingroup AicpuEventProcess
      61              :     * @brief it use to process data dump event.
      62              :     * @param [in] ctrlMsg : the struct of control task.
      63              :     * @return AICPU_SCHEDULE_OK: success, other: error code
      64              :     */
      65            2 :     int32_t AicpuEventProcess::ProcessDumpDataEvent(AicpuSqeAdapter &aicpuSqeAdapter) const
      66              :     {
      67            2 :         AicpuSchedule::OpDumpTaskManager &opDumpTaskMgr = AicpuSchedule::OpDumpTaskManager::GetInstance();
      68            2 :         AicpuSqeAdapter::AicpuDataDumpInfo info {};
      69            2 :         aicpuSqeAdapter.GetAicpuDataDumpInfo(info);
      70            2 :         aicpusd_info("Begin to dump data, stream id[%u], task id[%u], debug stream id[%u], debug task id[%u]," 
      71              :                      "is model[%u]", info.dump_stream_id, info.dump_task_id,
      72              :                      info.debug_dump_stream_id, info.debug_dump_task_id, info.is_model);
      73              :         // reserved 是否有用??
      74            2 :         int32_t ret = AICPU_SCHEDULE_OK;
      75            2 :         TaskInfoExt dumpTaskInfo(static_cast<volatile uint32_t>(info.dump_stream_id),
      76            2 :                                         static_cast<volatile uint32_t>(info.dump_task_id));
      77            2 :         if (info.is_debug && FeatureCtrl::IsNoNeedDumpOpDebugProduct()) {
      78            0 :             aicpusd_warn("Op debug dump is not supported, stream id[%u],"
      79              :                             " task id[%u], stream id1[%u], task id1[%u], is model[%u],",
      80              :                             info.dump_stream_id, info.dump_task_id, info.debug_dump_stream_id, info.debug_dump_task_id,
      81              :                             info.is_model);
      82              :         } else {
      83            2 :             uint32_t fileNameTaskId = info.is_debug ? info.debug_dump_task_id : info.dump_task_id;
      84            2 :             uint32_t fileNameStreamId = info.is_debug ? info.debug_dump_stream_id : info.dump_stream_id;
      85            2 :             DumpFileName dumpFileName(fileNameStreamId, fileNameTaskId);
      86            2 :             ret = opDumpTaskMgr.DumpOpInfo(dumpTaskInfo, dumpFileName);
      87              :         }
      88            2 :         if (info.is_model && info.is_debug) {
      89            2 :             TaskInfoExt debugdumpTaskInfo(static_cast<volatile uint32_t>(info.debug_dump_stream_id),
      90            2 :                                   static_cast<volatile uint32_t>(info.debug_dump_task_id));
      91            2 :             DumpFileName dumpFileName(info.debug_dump_stream_id, info.debug_dump_task_id);
      92            2 :             const int32_t tmpRet = opDumpTaskMgr.DumpOpInfo(debugdumpTaskInfo, dumpFileName);
      93            2 :             ret = (ret == AICPU_SCHEDULE_OK)? tmpRet : ret;
      94              :         } // 模型流溢出检测
      95            4 :         return SendDumpResponceInfo(aicpuSqeAdapter, ret);
      96              :     }
      97              : 
      98              :     /**
      99              :     * @ingroup AicpuEventProcess
     100              :     * @brief it use to process FFTSPlus data dump event.
     101              :     * @param [in] ctrlMsg : the struct of control task.
     102              :     * @return AICPU_SCHEDULE_OK: success, other: error code
     103              :     */
     104            2 :     int32_t AicpuEventProcess::ProcessDumpFFTSPlusDataEvent(AicpuSqeAdapter &aicpuSqeAdapter) const
     105              :     {
     106            2 :         AicpuSchedule::OpDumpTaskManager &opDumpTaskMgr = AicpuSchedule::OpDumpTaskManager::GetInstance();
     107            2 :         AicpuSqeAdapter::AicpuDumpFFTSPlusDataInfo info {};
     108            2 :         aicpuSqeAdapter.GetAicpuDumpFFTSPlusDataInfo(info);
     109            2 :         aicpusd_info("Begin to dump FFTSPlus data, stream id[%u], task id[%u], stream id1[%u], task id1[%u], " \
     110              :                      "model id[%u], context id[%u], thread id[%u], reserved[%u].",
     111              :                      info.i.stream_id, info.i.task_id, info.i.stream_id1, info.i.task_id1, static_cast<uint32_t>(info.i.model_id), info.i.context_id, info.i.thread_id, info.i.reserved[0]);
     112              : 
     113            2 :         int32_t ret = AICPU_SCHEDULE_OK;
     114            2 :         bool validDumpParam = false;
     115            2 :         if ((info.i.task_id != INVALID_VAL) && (info.i.stream_id != INVALID_VAL)) {
     116            2 :             validDumpParam = true;
     117            2 :             const bool isFftsPlusOverflow = (info.i.task_id1 != INVALID_VAL) && (info.i.stream_id1 != INVALID_VAL);
     118            2 :             uint32_t contextId = static_cast<volatile uint32_t>(info.i.context_id);
     119            2 :             uint32_t threadId = static_cast<volatile uint32_t>(info.i.thread_id);
     120            2 :             if (isFftsPlusOverflow) {
     121            2 :                 contextId = INVALID_VAL;
     122            2 :                 threadId = INVALID_VAL;
     123              :             }
     124            2 :             TaskInfoExt dumpTaskInfo(static_cast<volatile uint32_t>(info.i.stream_id),
     125            2 :                                            static_cast<volatile uint32_t>(info.i.task_id),
     126              :                                            contextId,
     127            2 :                                            threadId);
     128            2 :             DumpFileName dumpFileName(info.i.stream_id1, info.i.task_id1, info.i.context_id, info.i.thread_id);
     129            2 :             ret = opDumpTaskMgr.DumpOpInfo(dumpTaskInfo, dumpFileName);
     130              :         }
     131            2 :         if ((info.i.task_id1 != INVALID_VAL) && (info.i.stream_id1 != INVALID_VAL)) {
     132            2 :             validDumpParam = true;
     133            2 :             TaskInfoExt dumpTaskInfo(static_cast<volatile uint32_t>(info.i.stream_id1),
     134            2 :                                            static_cast<volatile uint32_t>(info.i.task_id1),
     135            2 :                                            static_cast<volatile uint32_t>(info.i.context_id),
     136            2 :                                            static_cast<volatile uint32_t>(info.i.thread_id));
     137            2 :             DumpFileName dumpFileName(info.i.stream_id1, info.i.task_id1, info.i.context_id, info.i.thread_id);
     138            2 :             const int32_t tmpRet = opDumpTaskMgr.DumpOpInfo(dumpTaskInfo, dumpFileName);
     139            2 :             ret = (ret == AICPU_SCHEDULE_OK)? tmpRet : ret;
     140              :         }
     141              : 
     142            2 :         if (!validDumpParam) {
     143            0 :             aicpusd_err("Invalid dump FFTSPlus param, stream id[%hu], task id[%hu], stream id1[%hu], task id1[%hu], " \
     144              :                         "context id[%hu], thread id[%u].",
     145              :                         info.i.stream_id, info.i.task_id, info.i.stream_id1,
     146              :                         info.i.task_id1, info.i.context_id, info.i.thread_id);
     147            0 :             ret = AICPU_SCHEDULE_ERROR_DUMP_FAILED;
     148              :         }
     149              : 
     150            4 :         return SendDumpResponceInfo(aicpuSqeAdapter, ret);
     151              :     }
     152              : 
     153            4 :  int32_t AicpuEventProcess::SendDumpResponceInfo(AicpuSqeAdapter &adapter,  const int32_t &dumpRet) const
     154              :     {        
     155            4 :         aicpusd_info("Begin to send response information using tsDevSendMsgAsync function.");
     156            4 :         auto ret = adapter.AicpuDumpResponseToTs(dumpRet);
     157            4 :         aicpusd_info("Finished to send dump report information, ret[%d].", ret);
     158            4 :         if (ret != AICPU_SCHEDULE_OK) {
     159            2 :             aicpusd_err("Failed to response info, ret[%d]", ret);
     160            2 :             return AICPU_SCHEDULE_ERROR_INNER_ERROR;
     161              :         }
     162            2 :         return AICPU_SCHEDULE_OK;
     163              :     }
     164              : 
     165              :     /**
     166              :     * @ingroup AicpuEventProcess
     167              :     * @brief it use to process op mapping load event.
     168              :     * @param [in] ctrlMsg : the struct of control task.
     169              :     * @return AICPU_SCHEDULE_OK: success, other: error code
     170              :     */
     171            2 :     int32_t AicpuEventProcess::ProcessLoadOpMappingEvent(AicpuSqeAdapter &aicpuSqeAdapter) const
     172              :     {
     173            2 :         aicpusd_info("Begin to load op mapping event.");
     174            2 :         AicpuSqeAdapter::AicpuDataDumpInfoLoad info {};
     175            2 :         aicpuSqeAdapter.GetAicpuDataDumpInfoLoad(info);
     176              :         const char_t * const opMappingInfo =
     177            2 :             PtrToPtr<void, char_t>(ValueToPtr(info.dumpinfoPtr));
     178            2 :         const uint32_t len = info.length;
     179            2 :         AicpuSchedule::OpDumpTaskManager &opDumpTaskMgr = AicpuSchedule::OpDumpTaskManager::GetInstance();
     180            2 :          int32_t ret = opDumpTaskMgr.LoadOpMappingInfo(opMappingInfo, len, aicpuSqeAdapter);
     181              :         // send response information to ts.
     182            2 :         aicpusd_info("Begin to send response information using tsDevSendMsgAsync function; load ret[%d].", ret);
     183            2 :         ret = aicpuSqeAdapter.AicpuDataDumpLoadResponseToTs(ret);
     184            2 :         aicpusd_info("Finished to send dump load info report info, ret[%d].", ret);
     185              : 
     186            2 :         if (ret != AICPU_SCHEDULE_OK) {
     187            1 :             aicpusd_err("Failed to response info, ret[%d]", ret);
     188            1 :             return AICPU_SCHEDULE_ERROR_INNER_ERROR;
     189              :         }
     190            1 :         return AICPU_SCHEDULE_OK;
     191              :     }
     192              : }
        

Generated by: LCOV version 2.0-1