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 : #include "aicpu_context.h"
11 : #include "aicpu_pulse.h"
12 :
13 : #include <vector>
14 : #include <memory>
15 : #include <mutex>
16 : #include <thread>
17 :
18 : #include "aicpusd_status.h"
19 :
20 : namespace {
21 : // current thread context
22 : thread_local aicpu::aicpuContext_t g_curCtx;
23 : // current thread prof context
24 : thread_local aicpu::aicpuProfContext_t g_curProfCtx;
25 : // task moniter context
26 : thread_local uint32_t g_threadIndex = UINT32_MAX;
27 : // aicpu run mode
28 : uint32_t g_runMode = aicpu::AicpuRunMode::THREAD_MODE;
29 : // cpu mode
30 : bool g_cpuMode = false;
31 : bool g_isCustAicpuSd = false;
32 : } // namespace
33 :
34 : namespace aicpu {
35 1 : __attribute__((visibility("default"))) status_t aicpuSetContext(aicpuContext_t* ctx)
36 : {
37 1 : aicpusd_info("Aicpu set ctx in stub func[%s].", __func__);
38 1 : g_curCtx = *ctx;
39 1 : return AICPU_ERROR_NONE;
40 : }
41 :
42 1 : __attribute__((visibility("default"))) status_t aicpuGetContext(aicpuContext_t* ctx)
43 : {
44 1 : aicpusd_info("Aicpu get ctx in stub func[%s].", __func__);
45 1 : *ctx = g_curCtx;
46 1 : return AICPU_ERROR_NONE;
47 : }
48 :
49 1 : status_t aicpuSetProfContext(const aicpuProfContext_t& ctx)
50 : {
51 1 : aicpusd_info("Aicpu set prof ctx in stub func[%s].", __func__);
52 1 : g_curProfCtx = ctx;
53 1 : return AICPU_ERROR_NONE;
54 : }
55 :
56 1 : const aicpuProfContext_t& aicpuGetProfContext()
57 : {
58 1 : aicpusd_info("Aicpu get prof ctx in stub func[%s].", __func__);
59 1 : return g_curProfCtx;
60 : }
61 :
62 1 : status_t InitTaskMonitorContext(uint32_t aicpuCoreCnt)
63 : {
64 : (void)aicpuCoreCnt;
65 1 : aicpusd_info("Init task monitor in stub func[%s].", __func__);
66 1 : return AICPU_ERROR_NONE;
67 : }
68 :
69 1 : status_t SetAicpuThreadIndex(uint32_t threadIndex)
70 : {
71 1 : aicpusd_info("Aicpu set thread index in stub func[%s].", __func__);
72 1 : g_threadIndex = threadIndex;
73 1 : return AICPU_ERROR_NONE;
74 : }
75 :
76 1 : uint32_t GetAicpuThreadIndex()
77 : {
78 1 : aicpusd_info("Aicpu get thread index in stub func[%s].", __func__);
79 1 : return g_threadIndex;
80 : }
81 :
82 1 : status_t SetOpname(const std::string& opname)
83 : {
84 : (void)opname;
85 1 : aicpusd_info("Set opname in stub func[%s].", __func__);
86 1 : return AICPU_ERROR_NONE;
87 : }
88 :
89 1 : status_t GetOpname(uint32_t threadIndex, std::string& opname)
90 : {
91 : (void)threadIndex;
92 : (void)opname;
93 1 : aicpusd_info("Get opname in stub func[%s].", __func__);
94 1 : return AICPU_ERROR_NONE;
95 : }
96 :
97 1 : status_t SetTaskAndStreamId(uint64_t taskId, uint32_t streamId)
98 : {
99 : (void)taskId;
100 : (void)streamId;
101 1 : aicpusd_info("Set task and streamId in stub func[%s].", __func__);
102 1 : return AICPU_ERROR_NONE;
103 : }
104 :
105 1 : status_t SetAicpuRunMode(uint32_t runMode)
106 : {
107 1 : aicpusd_info("Set aicpu run mode in stub func[%s].", __func__);
108 1 : g_runMode = runMode;
109 1 : return AICPU_ERROR_NONE;
110 : }
111 :
112 1 : status_t GetAicpuRunMode(uint32_t& runMode)
113 : {
114 1 : aicpusd_info("Get aicpu run mode in stub func[%s].", __func__);
115 1 : runMode = g_runMode;
116 1 : return AICPU_ERROR_NONE;
117 : }
118 :
119 1 : status_t SetThreadLocalCtx(const std::string& key, const std::string& value)
120 : {
121 : (void)key;
122 : (void)value;
123 1 : aicpusd_info("Set thread local ctx in stub func[%s].", __func__);
124 1 : return AICPU_ERROR_NONE;
125 : }
126 :
127 1 : status_t GetThreadLocalCtx(const std::string& key, std::string& value)
128 : {
129 : (void)key;
130 : (void)value;
131 1 : aicpusd_info("Get thread local ctx in stub func[%s].", __func__);
132 1 : return AICPU_ERROR_NONE;
133 : }
134 :
135 1 : uint32_t GetUniqueVfId()
136 : {
137 1 : aicpusd_info("Get unique vf id in stub func[%s].", __func__);
138 1 : return 0U;
139 : }
140 :
141 1 : void SetUniqueVfId(const uint32_t uniqueVfId)
142 : {
143 1 : aicpusd_info("Set unique vfid in stub func[%s].", __func__);
144 : (void)uniqueVfId;
145 1 : }
146 :
147 1 : void SetCustAicpuSdFlag(const bool isCustAicpuSdFlag)
148 : {
149 1 : aicpusd_info("Set cust aicpusd flag in stub func[%s].", __func__);
150 1 : g_isCustAicpuSd = isCustAicpuSdFlag;
151 1 : }
152 :
153 1 : bool IsCustAicpuSd()
154 : {
155 1 : aicpusd_info("Get cust aicpusd flag in stub func[%s].", __func__);
156 1 : return g_isCustAicpuSd;
157 : }
158 :
159 0 : void AicpuSetDfxInfo(const uint64_t dfxInfoAddr)
160 : {
161 0 : aicpusd_info("Set dfx info in stub func[%s].", __func__);
162 : (void)dfxInfoAddr;
163 0 : }
164 : } // namespace aicpu
165 :
166 : namespace AicpuSchedule {
167 0 : void SetCpuMode(bool cpuMode)
168 : {
169 0 : aicpusd_info("Set cpu mode in stub func[%s].", __func__);
170 0 : g_cpuMode = cpuMode;
171 0 : }
172 :
173 0 : bool GetCpuMode()
174 : {
175 0 : aicpusd_info("Get cpu mode in stub func[%s].", __func__);
176 0 : return g_cpuMode;
177 : }
178 : } // namespace AicpuSchedule
179 :
180 0 : void ClearPulseNotifyFunc() { aicpusd_info("call ClearPulseNotifyFunc stub func[%s].", __func__); }
|