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 : #ifndef AICPUSD_AICPUSD_INFO_H
12 : #define AICPUSD_AICPUSD_INFO_H
13 :
14 : #include <cstdint>
15 : #include <sched.h>
16 : #include <sys/types.h>
17 : #include "../common/type_def.h"
18 :
19 : extern "C" {
20 : struct __attribute__((visibility("default"))) AICPUActiveStream {
21 : uint32_t streamId;
22 : };
23 :
24 : static const uint32_t MAX_CUST_SO_NAME_LEN = 128U;
25 : static const uint32_t OP_NAME_MAX_LEN = 50U;
26 : static const uint32_t FUN_NAME_MAX_LEN = 30U;
27 : static const uint32_t ERROR_KEY_INFO_MAX_LEN = 30U;
28 : static const uint32_t MODULE_NAME_MAX_LEN = 10U;
29 : static const uint32_t FILE_NAME_MAX_LEN = 30U;
30 : static const uint16_t PRIORITY_MSG_CHECKCODE = 0xABCD;
31 : static const int32_t INVALID_ESCAPE_PRI_VALUE = -1;
32 : // loadOpFromBuf task args
33 : struct __attribute__((visibility("default"))) LoadOpFromBufArgs {
34 : uint64_t kernelSoBuf; // the starting address of custom operator so buf
35 : uint32_t kernelSoBufLen; // the length of custom operator so buf
36 : uint64_t kernelSoName; // the starting address of custom operator so name
37 : uint32_t kernelSoNameLen; // the length of custom operator so name
38 : } __attribute__((packed));
39 :
40 : // batchLoadOpFromBuf task args
41 : struct __attribute__((visibility("default"))) BatchLoadOpFromBufArgs {
42 : uint32_t soNum; // the number of so
43 : uint64_t opInfoArgs;
44 : } __attribute__((packed));
45 :
46 : /**
47 : * The mode of profiling
48 : */
49 : enum __attribute__((visibility("default"))) ProfilingMode {
50 : PROFILING_CLOSE = 0,
51 : PROFILING_OPEN,
52 : };
53 :
54 : enum __attribute__((visibility("default"))) AicpuSchedMode {
55 : SCHED_MODE_INTERRUPT = 0,
56 : SCHED_MODE_MSGQ,
57 : SCHED_MODE_INVALID
58 : };
59 :
60 : enum __attribute__((visibility("default"))) AICPUSubEvent {
61 : AICPU_SUB_EVENT_ACTIVE_STREAM = 0,
62 : AICPU_SUB_EVENT_EXECUTE_MODEL,
63 : AICPU_SUB_EVENT_REPEAT_MODEL,
64 : AICPU_SUB_EVENT_RECOVERY_STREAM,
65 : AICPU_SUB_EVENT_UPDATE_PROFILING_MODE,
66 : AICPU_SUB_EVENT_LOAD_SO,
67 : AICPU_SUB_EVENT_END_GRAPH,
68 : AICPU_SUB_EVENT_ACTIVE_MODEL,
69 : AICPU_SUB_EVENT_PREPARE_MEM,
70 : AICPU_SUB_EVENT_TABLE_UNLOCK,
71 : AICPU_SUB_EVENT_SUPPLY_ENQUEUE,
72 : AICPU_SUB_EVENT_MAX_NUM,
73 : };
74 :
75 : enum __attribute__((visibility("default"))) AICPUCustSubEvent {
76 : // sub type begin with 10 for interface event
77 : AICPU_SUB_EVENT_BIND_SD_PID = 10, // cust-sd bind sd pid, Implemented by cust-sd
78 : AICPU_SUB_EVENT_OPEN_CUSTOM_SO, // open costom so file, Implemented by cust-sd
79 : AICPU_SUB_EVENT_CUST_UPDATE_PROFILING_MODE, // update profiling mode, Implemented by cust-sd
80 : AICPU_SUB_EVENT_ABNORMAL_LOG, // print aicpu cust schedule's error log
81 : AICPU_SUB_EVENT_REPORT_CUST_DUMPDATA, // aicpusd do cust datadump
82 : AICPU_SUB_EVENT_REPORT_UDF_DUMPDATA, // aicpusd do udf datadump
83 : AICPU_SUB_EVENT_CUST_LOAD_PLATFORM, // custom scheduler process load platform info event
84 : AICPU_SUB_EVENT_CUST_CLOSE_MONITOR, // notify cust-sd to close aicpu kernel timeout monitor
85 : AICPU_SUB_EVENT_SET_DFX_INFO, // custom scheduler process set dfx event
86 : };
87 :
88 : struct __attribute__((visibility("default"))) AICPUSubEventStreamInfo {
89 : uint32_t streamId;
90 : };
91 :
92 : struct __attribute__((visibility("default"))) AICPUProfilingModeInfo {
93 : uint32_t deviceId;
94 : pid_t hostpId;
95 : uint32_t flag;
96 : };
97 :
98 : struct __attribute__((visibility("default"))) AICPULoadSoInfo {
99 : uint32_t kernelSoIndex;
100 : };
101 :
102 : struct __attribute__((visibility("default"))) AICPUEndGraphInfo {
103 : uint32_t result;
104 : };
105 :
106 : struct __attribute__((visibility("default"))) AICPUSharderTaskInfo {
107 : uint32_t parallelId;
108 : int64_t shardNum;
109 :
110 185 : bool operator==(const AICPUSharderTaskInfo& sharderInfo) const noexcept
111 : {
112 185 : return (parallelId == sharderInfo.parallelId);
113 : }
114 : };
115 :
116 : struct __attribute__((visibility("default"))) AICPUUnLockTableInfo {
117 : uint32_t tableId;
118 : };
119 :
120 : struct __attribute__((visibility("default"))) AICPUDumpCustInfo {
121 : uint32_t threadIndex; // dump任务的线程号
122 : int32_t retCode; // dump result
123 : uint32_t streamId; // dump key streamId
124 : uint32_t taskId; // dump key taskId
125 : };
126 :
127 : struct __attribute__((visibility("default"))) AICPUDumpUdfInfo {
128 : uint64_t length;
129 : uint64_t udfInfo;
130 : uint32_t udfPid;
131 : char_t rsv[20];
132 : };
133 :
134 : struct __attribute__((visibility("default"))) AICPULoadPlatformCustInfo {
135 : uint64_t length;
136 : uint64_t platformInfo;
137 : uint32_t aicpuPid;
138 : char_t rsv[20];
139 : };
140 :
141 : struct __attribute__((visibility("default"))) AICPUSubEventInfo {
142 : uint32_t modelId;
143 : union {
144 : AICPUSubEventStreamInfo streamInfo;
145 : AICPUProfilingModeInfo modeInfo;
146 : AICPULoadSoInfo loadSoInfo;
147 : AICPUEndGraphInfo endGraphInfo;
148 : AICPUSharderTaskInfo sharderTaskInfo;
149 : AICPUUnLockTableInfo unlockTableInfo;
150 : } para;
151 : };
152 :
153 : struct __attribute__((visibility("default"))) AICPUBindSdPidEventMsg {
154 : int32_t pid;
155 : } __attribute__((packed));
156 :
157 : struct __attribute__((visibility("default"))) AICPUOpenCustomSoEventMsg {
158 : char_t kernelSoName[MAX_CUST_SO_NAME_LEN];
159 : } __attribute__((packed));
160 :
161 : struct __attribute__((visibility("default"))) AICPUCloseMonitorEventMsg {
162 : uint8_t closeFlag;
163 : } __attribute__((packed));
164 :
165 : struct __attribute__((visibility("default"))) CpuSchedInitParam {
166 : uint32_t deviceId;
167 : pid_t hostPid;
168 : ProfilingMode profilingMode;
169 : char_t rsv[128];
170 : } __attribute__((packed));
171 :
172 : struct __attribute__((visibility("default"))) ModelQueueInfo {
173 : uint32_t queueId;
174 : uint32_t flag;
175 : } __attribute__((packed));
176 :
177 : struct __attribute__((visibility("default"))) ModelTaskInfo {
178 : uint32_t taskId;
179 : uint64_t kernelName;
180 : uint64_t paraBase; // param地址
181 : } __attribute__((packed));
182 :
183 : struct __attribute__((visibility("default"))) ModelStreamInfo {
184 : uint32_t streamId;
185 : uint32_t streamFlag;
186 : uint16_t taskNum;
187 : ModelTaskInfo* tasks;
188 : } __attribute__((packed));
189 :
190 : struct __attribute__((visibility("default"))) AicpuPriInfo {
191 : uint16_t checkHead;
192 : int32_t pidPriority;
193 : int32_t eventPriority;
194 : } __attribute__((packed));
195 :
196 : struct __attribute__((visibility("default"))) ModelCommOpList {
197 : uint64_t commOpDescsListAddr;
198 : uint32_t opNum;
199 : } __attribute__((packed));
200 :
201 : // 配置类型,用于给AICPU控制不同的加载流程
202 : enum __attribute__((visibility("default"))) ModelType {
203 : kModelWithEmbedding = 0,
204 : kModelWithSyncEvent = 1,
205 : kModelTypeNum
206 : };
207 :
208 : struct __attribute__((visibility("default"))) CommGroup {
209 : const char* groupName;
210 : uint32_t rankNum;
211 : uint32_t* rankIds;
212 : } __attribute__((packed));
213 :
214 : struct __attribute__((visibility("default"))) CommGroups {
215 : uint32_t groupNum;
216 : CommGroup* groups;
217 : } __attribute__((packed));
218 :
219 : struct __attribute__((visibility("default"))) ModelCfgInfo {
220 : uint64_t inBuffPoolSizeAddr; // input buffer block num array's address, the array is uint16_t[]
221 : uint64_t outBuffPoolSizeAddr; // output buffer block num array's address, the array is uint16_t[]
222 : uint64_t inBuffSizeAddr; // input block size array's address, the array is uint64_t[]
223 : uint64_t outBuffSizeAddr; // output block size array's address, the array is uint64_t[]
224 : uint32_t inputNum;
225 : uint32_t outputNum;
226 : int32_t tagId; // tag id for hccl
227 : int32_t rankId; // rank id for hccl
228 : uint64_t rankTableLen; // rank table length
229 : uint64_t rankTableAddr; // rank table ptr
230 : uint64_t roleTableLen; // cluster spec length
231 : uint64_t roleTableAddr; // role table ptr
232 : uint64_t modelCommOpListAddr; // ModelCommOpList ptr
233 : uint32_t modelType;
234 : uint64_t commGroupsAddr; // communication groups ptr
235 : int32_t psId; // ps id
236 : bool supportCounterFilter; // counter filter flag
237 : bool memoryRegister;
238 : uint64_t clientRankNum; // clientRank array's length
239 : uint64_t clientRankAddr; // clientRank array's address, the array is uint32_t[]
240 : uint64_t hcclCommNameAddr; // hcclComm name's addr, the name is char*
241 : int32_t hcclTimeOut; // 0 means default, -1 means never timeout
242 : bool associateWorker; // true means we need to associate worker when load model, default false
243 : char rsv[53UL];
244 : } __attribute__((packed));
245 :
246 : struct __attribute__((visibility("default"))) ModelInfo {
247 : uint32_t modelId;
248 : uint16_t aicpuStreamNum;
249 : ModelStreamInfo* streams;
250 : uint16_t queueNum;
251 : ModelQueueInfo* queues;
252 : int32_t abnormalBreak;
253 : int32_t abnormalEnqueue;
254 : AicpuPriInfo aicpuPriInfo;
255 : uint64_t cfgInfoPtr = 0;
256 : int32_t abnormalEnable = 1;
257 : char rsv[98];
258 : } __attribute__((packed));
259 :
260 : struct __attribute__((visibility("default"))) ReDeployConfig {
261 : uint64_t modelIdsAddr; // ptr which point to modelIds(uint32_t)
262 : uint32_t modelIdNum; // modelIdNum
263 : char rsv[4];
264 : } __attribute__((packed));
265 :
266 : struct __attribute__((visibility("default"))) CheckKernelSupportedConfig {
267 : uint64_t kernelNameAddr; // ptr which point to kernelName
268 : uint32_t kernelNameLen;
269 : uint64_t checkResultAddr; // int32: 0 is supported, others are not supported
270 : uint32_t checkResultLen;
271 : } __attribute__((packed));
272 :
273 : struct __attribute__((visibility("default"))) DataFlowExceptionNotify {
274 : uint64_t transId;
275 : uint32_t type; // 0:Exception occured, 1:Exception expired
276 : uint32_t modelIdNum;
277 : uint64_t modelIdsAddr; // ptr which point to modelIds(uint32_t)
278 : char rsv[40];
279 : } __attribute__((packed));
280 :
281 : struct __attribute__((visibility("default"))) SomaMemMng {
282 : uint64_t size;
283 : uint64_t va; // Virtual address
284 : uint64_t mempoolId; // Id of memory pool
285 : uint32_t deviceId;
286 : int32_t memAsyncOpType; // Malloc(0) Free(1)
287 : int32_t memAsyncSubCMD; // Distinguish between Malloc reuse strategies and Free explicit/implicit reuse methods
288 : char rsv[4];
289 : } __attribute__((packed));
290 :
291 : struct AicpuDfxInfoReq {
292 : uint64_t syncEventHead;
293 : uint64_t infoAddr;
294 : } __attribute__((packed));
295 : }
296 : #endif // AICPUSD_AICPUSD_INFO_H
|