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 : }
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 :
83 1 : status_t SetOpname(const std::string &opname)
84 : {
85 : (void)opname;
86 1 : aicpusd_info("Set opname in stub func[%s].", __func__);
87 1 : return AICPU_ERROR_NONE;
88 : }
89 :
90 :
91 1 : status_t GetOpname(uint32_t threadIndex, std::string &opname)
92 : {
93 : (void)threadIndex;
94 : (void)opname;
95 1 : aicpusd_info("Get opname in stub func[%s].", __func__);
96 1 : return AICPU_ERROR_NONE;
97 : }
98 :
99 1 : status_t SetTaskAndStreamId(uint64_t taskId, uint32_t streamId)
100 : {
101 : (void)taskId;
102 : (void)streamId;
103 1 : aicpusd_info("Set task and streamId in stub func[%s].", __func__);
104 1 : return AICPU_ERROR_NONE;
105 : }
106 :
107 1 : status_t SetAicpuRunMode(uint32_t runMode)
108 : {
109 1 : aicpusd_info("Set aicpu run mode in stub func[%s].", __func__);
110 1 : g_runMode = runMode;
111 1 : return AICPU_ERROR_NONE;
112 : }
113 :
114 1 : status_t GetAicpuRunMode(uint32_t &runMode)
115 : {
116 1 : aicpusd_info("Get aicpu run mode in stub func[%s].", __func__);
117 1 : runMode = g_runMode;
118 1 : return AICPU_ERROR_NONE;
119 : }
120 :
121 1 : status_t SetThreadLocalCtx(const std::string &key, const std::string &value)
122 : {
123 : (void)key;
124 : (void)value;
125 1 : aicpusd_info("Set thread local ctx in stub func[%s].", __func__);
126 1 : return AICPU_ERROR_NONE;
127 : }
128 :
129 1 : status_t GetThreadLocalCtx(const std::string &key, std::string &value)
130 : {
131 : (void)key;
132 : (void)value;
133 1 : aicpusd_info("Get thread local ctx in stub func[%s].", __func__);
134 1 : return AICPU_ERROR_NONE;
135 : }
136 :
137 1 : uint32_t GetUniqueVfId()
138 : {
139 1 : aicpusd_info("Get unique vf id in stub func[%s].", __func__);
140 1 : return 0U;
141 : }
142 :
143 1 : void SetUniqueVfId(const uint32_t uniqueVfId)
144 : {
145 1 : aicpusd_info("Set unique vfid in stub func[%s].", __func__);
146 : (void)uniqueVfId;
147 1 : }
148 :
149 1 : void SetCustAicpuSdFlag(const bool isCustAicpuSdFlag)
150 : {
151 1 : aicpusd_info("Set cust aicpusd flag in stub func[%s].", __func__);
152 1 : g_isCustAicpuSd = isCustAicpuSdFlag;
153 1 : }
154 :
155 1 : bool IsCustAicpuSd()
156 : {
157 1 : aicpusd_info("Get cust aicpusd flag in stub func[%s].", __func__);
158 1 : return g_isCustAicpuSd;
159 : }
160 : } // namespace aicpu
161 :
162 : namespace AicpuSchedule {
163 0 : void SetCpuMode(bool cpuMode)
164 : {
165 0 : aicpusd_info("Set cpu mode in stub func[%s].", __func__);
166 0 : g_cpuMode = cpuMode;
167 0 : }
168 :
169 0 : bool GetCpuMode()
170 : {
171 0 : aicpusd_info("Get cpu mode in stub func[%s].", __func__);
172 0 : return g_cpuMode;
173 : }
174 : } // namespace AicpuSchedule
175 :
176 0 : void ClearPulseNotifyFunc()
177 : {
178 0 : aicpusd_info("call ClearPulseNotifyFunc stub func[%s].", __func__);
179 0 : }
|