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 "hwts_kernel_dfx.h"
12 :
13 : #include "aicpu_prof.h"
14 : #include "aicpusd_profiler.h"
15 : #include "profiling_adp.h"
16 : #include "aicpusd_monitor.h"
17 : #include "aicpusd_threads_process.h"
18 : #include "aicpusd_hal_interface_ref.h"
19 : #include "tsd.h"
20 : #include "aicpusd_drv_manager.h"
21 : #include "aicpusd_model_err_process.h"
22 : #include "dump_task.h"
23 : #include "hwts_kernel_common.h"
24 :
25 : namespace AicpuSchedule {
26 : namespace {
27 : const std::string CFG_LOG_ADDR = "CfgLogAddr";
28 : const std::string DUMP_DATA_INFO = "DumpDataInfo";
29 : } // namespace
30 :
31 1 : int32_t CfgLogAddrTsKernel::Compute(const aicpu::HwtsTsKernel& tsKernelInfo)
32 : {
33 1 : aicpusd_info("Begin to process ts kernel CfgLogAddr event.");
34 1 : const auto cfgMsg = PtrToPtr<void, aicpu::AicpuConfigMsg>(ValueToPtr(tsKernelInfo.kernelBase.cceKernel.paramBase));
35 1 : if (cfgMsg == nullptr) {
36 0 : aicpusd_err("param base for config log is null.");
37 0 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
38 : }
39 :
40 1 : AicpuModelErrProc::GetInstance().ProcessLogBuffCfgMsg(*cfgMsg);
41 1 : return AICPU_SCHEDULE_OK;
42 : }
43 :
44 8 : int32_t DumpDataInfoTsKernel::Compute(const aicpu::HwtsTsKernel& tsKernelInfo)
45 : {
46 8 : aicpusd_info("Begin to process ts kernel dump data event");
47 8 : const aicpu::HwtsCceKernel& kernel = tsKernelInfo.kernelBase.cceKernel;
48 : // dump op has two param, one is protobuf addr
49 8 : constexpr uint32_t singleOpDumpParamNum = 2U;
50 8 : constexpr size_t len = sizeof(aicpu::AicpuParamHead) + (singleOpDumpParamNum * sizeof(uint64_t));
51 8 : const aicpu::AicpuParamHead* const paramHead = PtrToPtr<void, aicpu::AicpuParamHead>(ValueToPtr(kernel.paramBase));
52 8 : if (paramHead == nullptr) {
53 0 : aicpusd_err("paramHead for DumpDataKernel is nullptr");
54 0 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
55 : }
56 :
57 8 : if (static_cast<size_t>(paramHead->length) != len) {
58 0 : aicpusd_err("data dump param length[%u] shoulf be [%zu]", paramHead->length, len);
59 0 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
60 : }
61 :
62 8 : const auto ioAddrBase = PtrToPtr<void, uint64_t>(ValueToPtr(kernel.paramBase + sizeof(aicpu::AicpuParamHead)));
63 8 : const uint64_t opMappingInfoAddr = ioAddrBase[0];
64 8 : const uint64_t* const lenAddr = PtrToPtr<void, uint64_t>(ValueToPtr(ioAddrBase[1]));
65 8 : if (lenAddr == nullptr) {
66 0 : aicpusd_err("data dump proto length address is null");
67 0 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
68 : }
69 :
70 8 : aicpusd_info("Get proto len from address[%llu]", ioAddrBase[1]);
71 8 : const uint64_t opMappingInfoLen = *lenAddr;
72 8 : aicpusd_info("Proto len[%llu] from address[%llu]", opMappingInfoLen, opMappingInfoAddr);
73 :
74 8 : const AicpuSchedule::OpDumpTaskManager& dumpTaskMgr = AicpuSchedule::OpDumpTaskManager::GetInstance();
75 8 : return dumpTaskMgr.DumpOpInfoForUnknowShape(opMappingInfoAddr, opMappingInfoLen);
76 : }
77 :
78 : REGISTER_HWTS_KERNEL(CFG_LOG_ADDR, CfgLogAddrTsKernel);
79 : REGISTER_HWTS_KERNEL(DUMP_DATA_INFO, DumpDataInfoTsKernel);
80 : } // namespace AicpuSchedule
|