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 : #ifndef INNER_INC_CLIENT_MANAGER_H
11 : #define INNER_INC_CLIENT_MANAGER_H
12 :
13 : #include <mmpa/mmpa_api.h>
14 : #include <vector>
15 : #include "tsd_util_func.h"
16 : #include "proto/tsd_message.pb.h"
17 : #include "tsd/status.h"
18 : #include "tsd/tsd_client.h"
19 : #include "basic_define.h"
20 : #include "package_env_info.h"
21 : #define TSD_PLAT_GET_CHIP(type) (((type) >> 8U) & 0xffU)
22 :
23 : namespace tsd {
24 : enum class ProfilingMode {
25 : PROFILING_CLOSE = 0,
26 : PROFILING_OPEN,
27 : };
28 :
29 : enum class RunningMode {
30 : UNSET_MODE = 0,
31 : PROCESS_MODE,
32 : THREAD_MODE,
33 : };
34 :
35 : typedef enum tagChipType {
36 : CHIP_BEGIN = 0,
37 : CHIP_MINI = CHIP_BEGIN,
38 : CHIP_ASCEND_910A = 1,
39 : CHIP_ADC = 2,
40 : CHIP_DC = 4,
41 : CHIP_ASCEND_910B = 5,
42 : CHIP_MINI_V3 = 7,
43 : CHIP_AS31XM1 = 11,
44 : CHIP_610LITE = 12,
45 : CHIP_ASCEND_950 = 15,
46 : CHIP_CLOUD_V5 = 16,
47 : CHIP_MC62CM12A = 17, /* MC62CM12A */
48 : CHIP_MC32DM11A = 18, /* CHIP_MC32DM11A */
49 : CHIP_ASCEND_350 = 19,
50 : CHIP_END
51 : } ChipType_t;
52 :
53 : // 返回给tsdclient的open/close确认码
54 : enum class ResponseCode { SUCCESS = 0, FAIL = 1 };
55 :
56 : class ClientManager {
57 : public:
58 : /**
59 : * @ingroup ClientManager
60 : * @brief 支持host侧单个APP进程,拉起多个device
61 : * @param [in] deviceId : 设备号
62 : * @return TsdClient对象的引用
63 : */
64 : static std::shared_ptr<ClientManager> GetInstance(
65 : const uint32_t& deviceId, const uint32_t deviceMode = DIE_MODE, const bool transDevIdFlag = true);
66 :
67 : static TSD_StatusT GetPlatformInfo(const uint32_t deviceId);
68 :
69 : static bool CheckDestructFlag(const uint32_t logicDevId);
70 :
71 : static void SetProfilingCallback(const MsprofReporterCallback& callback);
72 :
73 : static TSD_StatusT SetRunMode(const std::string& valueStr);
74 :
75 : static TSD_StatusT SetAicpuSchedMode(const uint32_t schedMode);
76 :
77 : /**
78 : * @ingroup ClientManager
79 : * @brief 构造函数
80 : */
81 : explicit ClientManager(const uint32_t& deviceId);
82 :
83 : /**
84 : * @ingroup ClientManager
85 : * @brief 析构函数
86 : */
87 : virtual ~ClientManager();
88 : /**
89 : * @ingroup ClientManager
90 : * @brief framework发送拉起hccp和computer process的命令
91 : * @param [in] logicDeviceId : FMK传入逻辑ID
92 : * @param [in] rankSize : FMK传入rankSize
93 : * @return TSD_OK:成功 或者其他错误码
94 : */
95 : virtual TSD_StatusT Open(const uint32_t rankSize) = 0;
96 :
97 : /**
98 : * @ingroup ClientManager
99 : * @brief framework发送拉起computer process的命令
100 : * @param [in] logicDeviceId : FMK传入逻辑ID
101 : * @param [in] rankSize : FMK传入rankSize
102 : * @return TSD_OK:成功 或者其他错误码
103 : */
104 : virtual TSD_StatusT OpenAicpuSd() = 0;
105 :
106 : /**
107 : * @ingroup ClientManager
108 : * @brief 通知ClientManager关闭相关资源
109 : * @param [in] flag: 关闭标志位
110 : * @return TSD_OK:成功 或者其他错误码
111 : */
112 : virtual TSD_StatusT Close(const uint32_t flag) = 0;
113 :
114 : /**
115 : * @ingroup ClientManager
116 : * @brief 通知ClientManager更新profiling状态
117 : * @param [in] flag: profiling 标志位
118 : * @return TSD_OK:成功 或者其他错误码
119 : */
120 : virtual TSD_StatusT UpdateProfilingConf(const uint32_t& flag) = 0;
121 :
122 : /**
123 : * @ingroup ClientManager
124 : * @brief 用于按需拉起QS的接口
125 : * @param [in] initInfo : QS初始化参数
126 : * @return TSD_OK:成功 或者其他错误码
127 : */
128 : virtual TSD_StatusT InitQs(const InitFlowGwInfo* const initInfo) = 0;
129 :
130 : /**
131 : * @ingroup ClientManager
132 : * @brief carry aicpu ops package to device
133 : * @return TSD_OK:成功 或者其他错误码
134 : */
135 : virtual void Destroy() = 0;
136 :
137 : /**
138 : * @ingroup ClientManager
139 : * @brief 通过tsd获取一些能力
140 : * @return TSD_OK:成功 或者其他错误码
141 : */
142 : virtual TSD_StatusT CapabilityGet(const int32_t type, const uint64_t ptr) = 0;
143 :
144 : /**
145 : * @ingroup ClientManager
146 : * @brief get hdc session status
147 : * @return TSD_OK:成功 或者其他错误码
148 : */
149 : virtual TSD_StatusT GetHdcConctStatus(int32_t& hdcSessStat);
150 :
151 : static RunningMode GetClientRunMode(const uint32_t logicDeviceId);
152 :
153 : virtual TSD_StatusT LoadFileToDevice(
154 : const char_t* const filePath, const uint64_t pathLen, const char_t* const fileName,
155 : const uint64_t fileNameLen) = 0;
156 :
157 : virtual TSD_StatusT ProcessOpenSubProc(ProcOpenArgs* openArgs) = 0;
158 :
159 : virtual TSD_StatusT ProcessCloseSubProc(const pid_t closePid) = 0;
160 :
161 : virtual TSD_StatusT GetSubProcStatus(ProcStatusInfo* pidInfo, const uint32_t arrayLen) = 0;
162 :
163 : virtual TSD_StatusT RemoveFileOnDevice(const char_t* const filePath, const uint64_t pathLen) = 0;
164 :
165 : virtual TSD_StatusT GetSubProcListStatus(ProcStatusParam* pidInfo, const uint32_t arrayLen) = 0;
166 :
167 : bool IsAdcEnv() const;
168 :
169 : static uint32_t GetPlatInfoChipType();
170 :
171 : virtual TSD_StatusT ProcessCloseSubProcList(const ProcStatusParam* closeList, const uint32_t listSize) = 0;
172 :
173 : static bool IsNumeric(const std::string& str);
174 :
175 : static bool IsSupportSetVisibleDevices();
176 :
177 : static void SplitString(const std::string& str, std::vector<std::string>& result);
178 :
179 : static bool GetVisibleDevices();
180 :
181 : static TSD_StatusT ChangeUserDeviceIdToLogicDeviceId(const uint32_t userDevId, uint32_t& logicDevId);
182 :
183 : virtual TSD_StatusT OpenNetService(const NetServiceOpenArgs* args) = 0;
184 :
185 : virtual TSD_StatusT CloseNetService() = 0;
186 :
187 : bool GetPackageTitle(std::string& packageTitle) const;
188 :
189 : uint32_t GetPlatInfoMode() const;
190 :
191 6 : bool CheckPackageExists(const bool loadAicpuKernelFlag = true)
192 :
193 : {
194 6 : return envInfo_.CheckPackageExists(loadAicpuKernelFlag);
195 : }
196 :
197 : protected:
198 : /**
199 : * @ingroup ClientManager
200 : * @brief GetProfilingMode获取pid
201 : */
202 : void GetProfilingMode();
203 :
204 : /**
205 : * @ingroup ClientManager
206 : * @brief SetPlatInfoMode set platinfo mode value
207 : * @param [in] platInfoMode : used to set g_platInfo.mode
208 : */
209 : void SetPlatInfoMode(const uint32_t platInfoMode) const;
210 :
211 : static void SetPlatInfoChipType(const ChipType_t curType);
212 :
213 : static void ResetPlatInfoFlag();
214 :
215 : uint32_t logicDeviceId_;
216 : ProfilingMode profilingMode_;
217 : static RunningMode g_runningMode;
218 : static std::mutex g_profilingCallbackMut;
219 : static MsprofReporterCallback g_profilingCallback;
220 : static SchedMode aicpuSchedMode_;
221 :
222 : protected:
223 : PackageEnvInfo envInfo_;
224 : std::string (&packagePath_)[static_cast<uint32_t>(TsdLoadPackageType::TSD_PKG_TYPE_MAX)];
225 : std::string (&packageName_)[static_cast<uint32_t>(TsdLoadPackageType::TSD_PKG_TYPE_MAX)];
226 :
227 : private:
228 : ClientManager(const ClientManager&) = delete;
229 : ClientManager(ClientManager&&) = delete;
230 : ClientManager& operator=(const ClientManager&) = delete;
231 : ClientManager& operator=(ClientManager&) = delete;
232 : ClientManager& operator=(ClientManager&&) = delete;
233 2 : bool GetPackagePath(std::string& packagePath, const uint32_t packageType) const
234 :
235 : {
236 2 : return envInfo_.GetPackagePath(packagePath, packageType);
237 : }
238 : bool CheckPackageExistsOnce(const uint32_t packageType) { return envInfo_.CheckPackageExistsOnce(packageType); }
239 : std::vector<std::string> ScanAndMatchPackages(const std::string& packagePath, const uint32_t packageType) const
240 :
241 : {
242 : return envInfo_.ScanAndMatchPackages(packagePath, packageType);
243 : }
244 : std::string (&packagePattern_)[static_cast<uint32_t>(TsdLoadPackageType::TSD_PKG_TYPE_MAX)];
245 : };
246 : } // namespace tsd
247 : #endif // INNER_INC_CLIENT_MANAGER_H
|