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 : #include "common/aicpu_sqe_context.h"
12 :
13 : #include <sstream>
14 : #include <unordered_map>
15 :
16 : #include "common/aicpu_hccl_common.h"
17 : #include "utils/hccl_aicpu_utils.h"
18 : #include "securec.h"
19 :
20 : namespace {
21 157 : void ParseNotifySqe(const uint8_t *sqeLocal, uint32_t addInfo, SqeInfo *info)
22 : {
23 157 : auto sqe = reinterpret_cast<const rtStarsNotifySqeV1_t *>(sqeLocal);
24 157 : info->type = sqe->header.type;
25 157 : info->streamId = sqe->header.rtStreamId;
26 157 : info->taskId = sqe->header.taskId;
27 157 : info->notifyId = sqe->notify_id;
28 157 : info->remoteRank = addInfo;
29 157 : }
30 28 : void ParseWriteValueSqe(const uint8_t *sqeLocal, uint32_t addInfo, SqeInfo *info)
31 : {
32 28 : auto sqe = reinterpret_cast<const rtStarsWriteValueSqe_t *>(sqeLocal);
33 28 : info->type = sqe->header.type;
34 28 : info->streamId = sqe->header.rtStreamId;
35 28 : info->taskId = sqe->header.taskId;
36 28 : info->subType = sqe->sub_type;
37 28 : info->eventId = sqe->res7;
38 28 : info->addr1High = sqe->write_addr_high;
39 28 : info->addr1Low = sqe->write_addr_low;
40 28 : info->remoteRank = addInfo;
41 28 : info->length = sqe->rdmaWrLenth; // rdma wr len
42 28 : info->taskRelated.rdmaType = sqe->rdmaType; // rdma type
43 28 : }
44 0 : void ParseFlipPlaceHolderSqe(const uint8_t *sqeLocal, uint32_t addInfo, SqeInfo *info)
45 : {
46 0 : auto sqe = reinterpret_cast<const rtStarsPlaceHolderSqe_t *>(sqeLocal);
47 0 : info->type = sqe->header.type;
48 0 : info->streamId = sqe->header.rtStreamId;
49 0 : info->taskId = sqe->header.taskId;
50 0 : info->length = sqe->u.flip_task_info.flipNumReport;
51 0 : info->remoteRank = addInfo;
52 0 : }
53 0 : void ParseCacheMemcpyPlaceholderSqe(const uint8_t *sqeLocal, uint32_t addInfo, SqeInfo *info)
54 : {
55 0 : auto sqe = reinterpret_cast<const rtStarsPlaceHolderSqe_t *>(sqeLocal);
56 0 : info->type = sqe->header.type;
57 0 : info->streamId = sqe->header.rtStreamId;
58 0 : info->taskId = sqe->header.taskId;
59 : // 注意: cache hit后重新生成的placeholder SQE中的src/dst addr为0 (无需刷新, 因为addr字段只在第一次cache miss时使用, 用于确定memory type和target rank)
60 0 : info->addr1High = sqe->u.cache_memcpy_task_info.src_addr_high;
61 0 : info->addr1Low = sqe->u.cache_memcpy_task_info.src_addr_low;
62 0 : info->addr2High = sqe->u.cache_memcpy_task_info.dst_addr_high;
63 0 : info->addr2Low = sqe->u.cache_memcpy_task_info.dst_addr_low;
64 0 : info->remoteRank = addInfo >> 16; // 16 bit
65 0 : info->dataType = static_cast<uint16_t>(addInfo);
66 0 : info->taskRelated.linkType = static_cast<uint8_t>(sqe->u.cache_memcpy_task_info.linkType); // linkType
67 0 : }
68 0 : void ParseCacheNotifyPlaceholderSqe(const uint8_t *sqeLocal, uint32_t addInfo, SqeInfo *info)
69 : {
70 0 : auto sqe = reinterpret_cast<const rtStarsPlaceHolderSqe_t *>(sqeLocal);
71 0 : info->type = sqe->header.type;
72 0 : info->streamId = sqe->header.rtStreamId;
73 0 : info->taskId = sqe->header.taskId;
74 0 : info->notifyId = sqe->u.cache_notify_task_info.notify_id;
75 0 : info->remoteRank = addInfo;
76 0 : }
77 0 : void ParseCacheWriteValuePlaceholderSqe(const uint8_t *sqeLocal, uint32_t addInfo, SqeInfo *info)
78 : {
79 0 : auto sqe = reinterpret_cast<const rtStarsPlaceHolderSqe_t *>(sqeLocal);
80 0 : info->type = sqe->header.type;
81 0 : info->streamId = sqe->header.rtStreamId;
82 0 : info->taskId = sqe->header.taskId;
83 0 : info->subType = RT_STARS_WRITE_VALUE_SUB_TYPE_NOTIFY_RECORD_IPC_NO_PCIE;
84 0 : info->addr1High = sqe->u.cache_write_value_task_info.write_addr_high;
85 0 : info->addr1Low = sqe->u.cache_write_value_task_info.write_addr_low;
86 0 : info->remoteRank = addInfo;
87 0 : }
88 0 : void ParseCacheMemcpyRecordPlaceholderSqe(const uint8_t *sqeLocal, uint32_t addInfo, SqeInfo *info)
89 : {
90 0 : auto sqe = reinterpret_cast<const rtStarsPlaceHolderSqe_t *>(sqeLocal);
91 0 : info->type = sqe->header.type;
92 0 : info->streamId = sqe->header.rtStreamId;
93 0 : info->taskId = sqe->header.taskId;
94 0 : info->opCode = sqe->u.cache_memcpy_record_task_info.opcode;
95 0 : info->length = sqe->u.cache_memcpy_record_task_info.length;
96 0 : info->addr1High = sqe->u.cache_memcpy_record_task_info.src_addr_high;
97 0 : info->addr1Low = sqe->u.cache_memcpy_record_task_info.src_addr_low;
98 0 : info->addr2High = sqe->u.cache_memcpy_record_task_info.dst_addr_high;
99 0 : info->addr2Low = sqe->u.cache_memcpy_record_task_info.dst_addr_low;
100 0 : info->partId = sqe->u.cache_memcpy_record_task_info.partid;
101 0 : info->remoteRank = addInfo >> 16; // 16 bit
102 0 : info->dataType = static_cast<uint16_t>(addInfo);
103 0 : info->taskRelated.linkType = static_cast<uint8_t>(sqe->u.cache_memcpy_record_task_info.linkType); // linkType
104 0 : }
105 0 : void ParseEventSqe(const uint8_t *sqeLocal, uint32_t /* addInfo */, SqeInfo *info)
106 : {
107 0 : auto sqe = reinterpret_cast<const rtStarsEventSqe_t *>(sqeLocal);
108 0 : info->type = sqe->header.type;
109 0 : info->streamId = sqe->header.rtStreamId;
110 0 : info->taskId = sqe->header.taskId;
111 0 : info->eventId = sqe->eventId;
112 0 : }
113 16 : void ParseMemcpyAsyncSqe(const uint8_t *sqeLocal, uint32_t addInfo, SqeInfo *info)
114 : {
115 16 : auto sqe = reinterpret_cast<const rtStarsMemcpyAsyncSqe_t *>(sqeLocal);
116 16 : info->type = sqe->header.type;
117 16 : info->streamId = sqe->header.rtStreamId;
118 16 : info->taskId = sqe->header.taskId;
119 16 : info->opCode = sqe->opcode;
120 16 : info->length = sqe->length;
121 16 : info->addr1High = sqe->src_addr_high;
122 16 : info->addr1Low = sqe->src_addr_low;
123 16 : info->addr2High = sqe->dst_addr_high;
124 16 : info->addr2Low = sqe->dst_addr_low;
125 16 : info->partId = sqe->partid;
126 16 : info->remoteRank = addInfo >> 16; // 16 bit
127 16 : info->dataType = static_cast<uint16_t>(addInfo);
128 16 : info->taskRelated.linkType = static_cast<uint8_t>(sqe->linkType); // linkType
129 16 : }
130 4 : void ParseCcoreWaitStartSqe(const uint8_t *sqeLocal, uint32_t addInfo, SqeInfo *info)
131 : {
132 4 : auto sqe = reinterpret_cast<const rtStarsCcoreWaitStartSqe_t *>(sqeLocal);
133 4 : info->type = sqe->sqeHeader.type;
134 4 : info->streamId = sqe->sqeHeader.rtStreamId;
135 4 : info->taskId = sqe->sqeHeader.taskId;
136 4 : info->addr1High = sqe->ldrImm2.immdAddrHigh;
137 4 : info->addr1Low = sqe->ldrImm2.immdAddrLow;
138 4 : info->condValue = addInfo >> 16; // 16 bit
139 4 : info->isLast = addInfo & 1;
140 4 : }
141 2 : void ParseCcoreWriteValueSqe(const uint8_t *sqeLocal, uint32_t addInfo, SqeInfo *info)
142 : {
143 2 : auto sqe = reinterpret_cast<const rtStarsCcoreWriteValueSqe_t *>(sqeLocal);
144 2 : info->type = sqe->sqeHeader.type;
145 2 : info->streamId = sqe->sqeHeader.rtStreamId;
146 2 : info->taskId = sqe->sqeHeader.taskId;
147 2 : info->addr1High = sqe->lhwi1.immd;
148 2 : info->addr1Low = sqe->llwi1.immdHigh;
149 2 : info->addr2High = sqe->llwi1.immdLow;
150 2 : info->condValue = addInfo;
151 2 : }
152 0 : void ParseNotifySqeV2(const uint8_t *sqeLocal, uint32_t /* addInfo */, SqeInfo *info)
153 : {
154 0 : auto sqe = reinterpret_cast<const rtStarsNotifySqeV2_t *>(sqeLocal);
155 0 : info->type = sqe->header.type;
156 0 : info->streamId = sqe->header.rt_stream_id;
157 0 : info->taskId = sqe->header.task_id;
158 0 : info->notifyId = sqe->notify_id;
159 0 : }
160 0 : void ParseWriteValueSqeV2(const uint8_t *sqeLocal, uint32_t /* addInfo */, SqeInfo *info)
161 : {
162 0 : auto sqe = reinterpret_cast<const rtStarsWriteValueSqeV2_t *>(sqeLocal);
163 0 : info->type = sqe->header.type;
164 0 : info->streamId = sqe->header.rt_stream_id;
165 0 : info->taskId = sqe->header.task_id;
166 0 : info->addr1High = sqe->reg_addr_high;
167 0 : info->addr1Low = sqe->reg_addr_low;
168 0 : }
169 0 : void ParseEventSqeV2(const uint8_t *sqeLocal, uint32_t /* addInfo */, SqeInfo *info)
170 : {
171 0 : auto sqe = reinterpret_cast<const rtStarsEventSqeV2_t *>(sqeLocal);
172 0 : info->type = sqe->type;
173 0 : info->streamId = sqe->rt_stream_id;
174 0 : info->taskId = sqe->task_id;
175 0 : info->eventId = sqe->event_id;
176 0 : }
177 0 : void ParseMemcpyAsyncSqeV2(const uint8_t *sqeLocal, uint32_t /* addInfo */, SqeInfo *info)
178 : {
179 0 : auto sqe = reinterpret_cast<const rtStarsMemcpyAsyncSqeV2_t *>(sqeLocal);
180 0 : info->type = sqe->type;
181 0 : info->streamId = sqe->rt_stream_id;
182 0 : info->taskId = sqe->task_id;
183 0 : info->opCode = sqe->opcode;
184 0 : info->length = sqe->length;
185 0 : info->addr1High = sqe->src_addr_high;
186 0 : info->addr1Low = sqe->src_addr_low;
187 0 : info->addr2High = sqe->dst_addr_high;
188 0 : info->addr2Low = sqe->dst_addr_low;
189 0 : }
190 : }
191 :
192 2304 : HcclResult SqeContextUtils::QuerySqeInfo(const uint8_t *sqeLocal, uint8_t sqeType, uint32_t addInfo, SqeInfo *info)
193 : {
194 : static const std::unordered_map<uint8_t, void (*)(const uint8_t *, uint32_t, SqeInfo *)> funcMap = {
195 : { SqeType::NOTIFY_SQE, ParseNotifySqe },
196 : { SqeType::WRITE_VALUE_SQE, ParseWriteValueSqe },
197 : { SqeType::EVENT_SQE, ParseEventSqe },
198 : { SqeType::MEMCPY_ASYNC_SQE, ParseMemcpyAsyncSqe },
199 : { SqeType::CCORE_WAIT_START_SQE, ParseCcoreWaitStartSqe },
200 : { SqeType::CCORE_WRITE_VALUE_SQE, ParseCcoreWriteValueSqe },
201 : { SqeType::NOTIFY_SQE_V2, ParseNotifySqeV2 },
202 : { SqeType::WRITE_VALUE_SQE_V2, ParseWriteValueSqeV2 },
203 : { SqeType::EVENT_SQE_V2, ParseEventSqeV2 },
204 : { SqeType::MEMCPY_ASYNC_SQE_V2, ParseMemcpyAsyncSqeV2 },
205 : { SqeType::RDMA_DB_SEND_SQE, ParseWriteValueSqe },
206 : { SqeType::FLIP_PLACEHOLDER_SQE, ParseFlipPlaceHolderSqe},
207 : { SqeType::CACHE_MEMCPY_PLACEHOLDER_SQE, ParseCacheMemcpyPlaceholderSqe},
208 : { SqeType::CACHE_NOTIFY_PLACEHOLDER_SQE, ParseCacheNotifyPlaceholderSqe},
209 : { SqeType::CACHE_WRITE_VALUE_PLACEHOLDER_SQE, ParseCacheWriteValuePlaceholderSqe},
210 : { SqeType::CACHE_MEMCPY_RECORD_PLACEHOLDER_SQE, ParseCacheMemcpyRecordPlaceholderSqe}
211 2308 : };
212 2304 : auto it = funcMap.find(sqeType);
213 2304 : if (it == funcMap.cend()) {
214 2097 : HCCL_WARNING("sqetype:%u is unsupported", sqeType);
215 2097 : return HCCL_E_NOT_SUPPORT;
216 : }
217 207 : CHK_PTR_NULL(info);
218 207 : (it->second)(sqeLocal, addInfo, info);
219 207 : info->valid = 1;
220 207 : return HCCL_SUCCESS;
221 : }
222 :
223 25 : std::string SqeContextUtils::RtsqTaskTypeToStr(uint8_t type)
224 : {
225 25 : switch(type) {
226 14 : case RT_STARS_SQE_TYPE_NOTIFY_WAIT:
227 28 : return "NOTIFY WAIT";
228 0 : case RT_STARS_SQE_TYPE_NOTIFY_RECORD:
229 0 : return "NOTIFY RECORD";
230 0 : case RT_STARS_SQE_TYPE_WRITE_VALUE:
231 0 : return "WRITE VALUE";
232 0 : case RT_STARS_SQE_TYPE_SDMA:
233 0 : return "SDMA";
234 2 : case RT_STARS_SQE_TYPE_COND:
235 4 : return "COND";
236 9 : default:
237 9 : return std::to_string(type);
238 : }
239 : }
|