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 : #include <mutex>
11 :
12 : #include "dump_stats_param.h"
13 : #include "dump_stats_process.h"
14 : #include "dump_stats_interface.h"
15 :
16 : using namespace kfc_dump_stats;
17 :
18 : namespace {
19 : std::mutex g_kfcDumpStateMutex;
20 : }
21 :
22 : extern "C" {
23 49 : __attribute__((visibility("default"))) uint32_t AdumpStatsOpSrvInit(void* args)
24 : {
25 49 : if (args == nullptr) {
26 2 : IDE_LOGE("Initialization parameter for kfc dump server is null");
27 2 : return static_cast<uint32_t>(KFC_DUMP_E_PARA);
28 : }
29 47 : const std::lock_guard<std::mutex> lk(g_kfcDumpStateMutex);
30 47 : IDE_LOGI("Start to initialize the kfc dump server");
31 47 : auto dumpParam = reinterpret_cast<KfcDumpOpInitParam*>(args);
32 47 : return static_cast<uint32_t>(KfcDumpProcess::InitKfcDumpInfo(dumpParam));
33 47 : }
34 :
35 38 : __attribute__((visibility("default"))) uint32_t AdumpStatsOpSrvLaunch(void* args)
36 : {
37 38 : const std::lock_guard<std::mutex> lk(g_kfcDumpStateMutex);
38 38 : uint64_t kfcSrvStartTime = GetCurCpuTimestamp();
39 38 : if (args == nullptr) {
40 1 : IDE_LOGE("Launch parameter for dump statistics task is null");
41 1 : return static_cast<uint32_t>(KFC_DUMP_E_PARA);
42 : }
43 37 : auto* task = reinterpret_cast<KfcDumpTask*>(args);
44 37 : KfcDumpInfo* dumpInfo = nullptr;
45 37 : IDE_LOGI(
46 : "Receive kfc dump statistics task, streamId[%u] taskId[%u] index[%u]", task->streamId_, task->taskId_,
47 : task->index_);
48 37 : if (AicpuGetOpTaskInfo == nullptr) {
49 0 : IDE_LOGE("AicpuGetOpTaskInfo is unresolved, aicpu scheduler does not support dump statistics");
50 0 : return static_cast<uint32_t>(KFC_DUMP_E_NOT_SUPPORT);
51 : }
52 37 : uint32_t ret = AicpuGetOpTaskInfo(*task, &dumpInfo);
53 37 : if (ret != 0) {
54 2 : IDE_LOGE("Failed to get operator tensor information from aicpu scheduler, ret[%u]", ret);
55 2 : return ret;
56 : }
57 :
58 35 : if (dumpInfo == nullptr) {
59 1 : IDE_LOGE("Aicpu scheduler returned null operator tensor information");
60 1 : return static_cast<uint32_t>(KFC_DUMP_E_INTERNAL);
61 : }
62 34 : ret = static_cast<uint32_t>(KfcDumpProcess::KfcDumpRunStatServer(task, dumpInfo));
63 34 : IDE_LOGI(
64 : "Kfc dump statistics task is finished, time cost[%lu us]",
65 : (GetCurCpuTimestamp() - kfcSrvStartTime) / NSEC_PER_USEC);
66 34 : return ret;
67 38 : }
68 :
69 24 : __attribute__((visibility("default"))) bool AdumpStatsOpInitStatus() { return KfcDumpProcess::GetStatsOpInitStatus(); }
70 : }
|