Merged
新增engram_fetch 核函数 && engram_fetch_wait算子 #7749
wuchenhao123Add on Jun 28
新增engram_fetch 核函数 && engram_fetch_wait算子 #7749
Merged
Total: 12 files changed+794-5
| @@ -492,6 +492,7 @@ function(add_ops_src_copy) | |||
| 492 | "quant_all_reduce;" | 492 | "quant_all_reduce;" |
| 493 | "quant_reduce_scatter;" | 493 | "quant_reduce_scatter;" |
| 494 | "engram_fetch;" | 494 | "engram_fetch;" |
| 495 | + "engram_fetch_wait;" | ||
| 495 | "allto_all_matmul;" | 496 | "allto_all_matmul;" |
| 496 | "matmul_allto_all;" | 497 | "matmul_allto_all;" |
| 497 | "attention_to_ffn;" | 498 | "attention_to_ffn;" |
| @@ -17,13 +17,11 @@ | |||
| 17 | #ifndef ENGRAM_FETCH_ARCH35_H | 17 | #ifndef ENGRAM_FETCH_ARCH35_H |
| 18 | #define ENGRAM_FETCH_ARCH35_H | 18 | #define ENGRAM_FETCH_ARCH35_H |
| 19 | 19 | ||
| 20 | -#if ASC_DEVKIT_MAJOR >= 9 | ||
| 21 | #include "basic_api/kernel_basic_intf.h" | 20 | #include "basic_api/kernel_basic_intf.h" |
| 22 | -#else | ||
| 23 | #include "kernel_operator.h" | 21 | #include "kernel_operator.h" |
| 24 | -#endif | ||
| 25 | #include "kernel_tiling/kernel_tiling.h" | 22 | #include "kernel_tiling/kernel_tiling.h" |
| 26 | #include "../engram_fetch_tiling_data.h" | 23 | #include "../engram_fetch_tiling_data.h" |
| 24 | +#include "../engram_fetch.h" | ||
| 27 | #include "adv_api/hccl/hccl.h" | 25 | #include "adv_api/hccl/hccl.h" |
| 28 | #include "adv_api/hcomm/hcomm.h" | 26 | #include "adv_api/hcomm/hcomm.h" |
| 29 | 27 | ||
| @@ -47,20 +45,301 @@ public: | |||
| 47 | TPipe *pipe, const EngramFetchTilingData *tilingData); | 45 | TPipe *pipe, const EngramFetchTilingData *tilingData); |
| 48 | 46 | ||
| 49 | __aicore__ inline void Process(); | 47 | __aicore__ inline void Process(); |
| 48 | + | ||
| 49 | +private: | ||
| 50 | + __aicore__ inline void LocalCopySlice(GM_ADDR dst, GM_ADDR src, uint64_t len); | ||
| 51 | + __aicore__ inline void CopyContextToUb(); | ||
| 52 | + __aicore__ inline void CopyIndicesToUb(uint32_t indicesBatchStart, uint32_t indicesBatchLen); | ||
| 53 | + __aicore__ inline void ScatterByRank(const LocalTensor<int32_t> &indicesLocal, | ||
| 54 | + const LocalTensor<uint32_t> &rankCounts, | ||
| 55 | + const LocalTensor<uint32_t> &rankOffsets, | ||
| 56 | + const LocalTensor<uint32_t> &tokenIdxInRank, | ||
| 57 | + uint32_t batchLen); | ||
| 58 | + | ||
| 59 | + TPipe *tpipe_{nullptr}; | ||
| 60 | + GM_ADDR indicesGM_{nullptr}; | ||
| 61 | + GM_ADDR fetchedGM_{nullptr}; | ||
| 62 | + __gm__ EngramCommContext *ctxPtr_{nullptr}; | ||
| 63 | + | ||
| 64 | + uint32_t aivId_{0}; | ||
| 65 | + uint32_t rankId_{0}; | ||
| 66 | + uint32_t numRanks_{0}; | ||
| 67 | + int32_t numEntriesPerRank_{0}; | ||
| 68 | + uint64_t ubSize_{0}; | ||
| 69 | + uint32_t indicesBatchSize_{0}; | ||
| 70 | + int64_t numTokens_{0}; | ||
| 71 | + int64_t hiddenBytes_{0}; | ||
| 72 | + | ||
| 73 | + TBuf<> pingBuf_; | ||
| 74 | + TBuf<> pongBuf_; | ||
| 75 | + int32_t ppEvtMte2ToMte3_[2] = {0, 0}; | ||
| 76 | + int32_t ppEvtMte3ToMte2_[2] = {0, 0}; | ||
| 77 | + TBuf<> indicesBuf_; | ||
| 78 | + TBuf<> hcommBuf_; | ||
| 79 | + TBuf<> rankCountsBuf_; | ||
| 80 | + TBuf<> rankOffsetsBuf_; | ||
| 81 | + TBuf<> tokenIdxInRankBuf_; | ||
| 82 | + TBuf<> commBufferBuf_; | ||
| 83 | + TBuf<> hcommHandleBuf_; | ||
| 84 | + TBuf<> rankIDsBuf_; | ||
| 85 | + TBuf<> positionsBuf_; | ||
| 86 | + TBuf<> divisorBuf_; | ||
| 87 | + TBuf<> maskBuf_; | ||
| 88 | + | ||
| 89 | + AscendC::Hcomm<COMM_PROTOCOL_UBC_CTP> hcomm_; | ||
| 50 | }; | 90 | }; |
| 51 | 91 | ||
| 52 | __aicore__ inline void EngramFetchArch35::Init( | 92 | __aicore__ inline void EngramFetchArch35::Init( |
| 53 | GM_ADDR commContext, GM_ADDR indices, GM_ADDR fetched, GM_ADDR workspaceGM, | 93 | GM_ADDR commContext, GM_ADDR indices, GM_ADDR fetched, GM_ADDR workspaceGM, |
| 54 | TPipe *pipe, const EngramFetchTilingData *tilingData) | 94 | TPipe *pipe, const EngramFetchTilingData *tilingData) |
| 55 | { | 95 | { |
| 56 | - printf("EngramFetchArch35::Init\n"); | 96 | + tpipe_ = pipe; |
| 97 | + indicesGM_ = indices; | ||
| 98 | + fetchedGM_ = fetched; | ||
| 99 | + aivId_ = GetBlockIdx(); | ||
| 100 | + (void)workspaceGM; | ||
| 101 | + | ||
| 102 | + ctxPtr_ = (__gm__ EngramCommContext *)commContext; | ||
| 103 | + rankId_ = ctxPtr_->rankId; | ||
| 104 | + numRanks_ = ctxPtr_->rankSize; | ||
| 105 | + | ||
| 106 | + numEntriesPerRank_ = tilingData->numEntriesPerRank; | ||
| 107 | + numTokens_ = tilingData->numTokens; | ||
| 108 | + hiddenBytes_ = tilingData->hiddenBytes; | ||
| 109 | + ubSize_ = tilingData->ubSize; | ||
| 110 | + | ||
| 111 | + tpipe_->InitBuffer(hcommBuf_, HCOMM_INIT_SIZE); | ||
| 112 | + LocalTensor<uint8_t> hcommTensor = hcommBuf_.Get<uint8_t>(); | ||
| 113 | + hcomm_.Init(hcommTensor, HCOMM_INIT_SIZE); | ||
| 114 | + | ||
| 115 | + tpipe_->InitBuffer(pingBuf_, TILE_BYTES); | ||
| 116 | + tpipe_->InitBuffer(pongBuf_, TILE_BYTES); | ||
| 117 | + ppEvtMte2ToMte3_[0] = static_cast<int32_t>(GetTPipePtr()->FetchEventID(HardEvent::MTE2_MTE3)); | ||
| 118 | + ppEvtMte2ToMte3_[1] = static_cast<int32_t>(GetTPipePtr()->FetchEventID(HardEvent::MTE2_MTE3)); | ||
| 119 | + ppEvtMte3ToMte2_[0] = static_cast<int32_t>(GetTPipePtr()->FetchEventID(HardEvent::MTE3_MTE2)); | ||
| 120 | + ppEvtMte3ToMte2_[1] = static_cast<int32_t>(GetTPipePtr()->FetchEventID(HardEvent::MTE3_MTE2)); | ||
| 121 | + | ||
| 122 | + uint32_t countsBufSize = Ceil(numRanks_ * sizeof(uint32_t), UB_ALIGN) * UB_ALIGN; | ||
| 123 | + tpipe_->InitBuffer(rankCountsBuf_, countsBufSize); | ||
| 124 | + uint32_t offsetsBufSize = Ceil(numRanks_ * sizeof(uint32_t), UB_ALIGN) * UB_ALIGN; | ||
| 125 | + tpipe_->InitBuffer(rankOffsetsBuf_, offsetsBufSize); | ||
| 126 | + uint32_t commBufferBufSize = Ceil(numRanks_ * sizeof(uint64_t), UB_ALIGN) * UB_ALIGN; | ||
| 127 | + tpipe_->InitBuffer(commBufferBuf_, commBufferBufSize); | ||
| 128 | + uint32_t hcommHandleBufSize = Ceil(numRanks_ * sizeof(uint64_t), UB_ALIGN) * UB_ALIGN; | ||
| 129 | + tpipe_->InitBuffer(hcommHandleBuf_, hcommHandleBufSize); | ||
| 130 | + | ||
| 131 | + constexpr uint64_t ubReserved = 8U * 1024U; | ||
| 132 | + // ScatterByRank 需要: indices + tokenIdxInRank + rankIDs + positions + divisor (各4字节) + mask(每元素1字节近似) | ||
| 133 | + uint32_t bytesPerIndice = sizeof(int32_t) + sizeof(uint32_t) + sizeof(int32_t) * 3U + 1U; | ||
| 134 | + uint64_t usedUb = HCOMM_INIT_SIZE + TILE_BYTES * 2U + countsBufSize + offsetsBufSize | ||
| 135 | + + commBufferBufSize + hcommHandleBufSize; | ||
| 136 | + uint64_t availableUb = (ubSize_ > usedUb + ubReserved) ? (ubSize_ - usedUb - ubReserved) : 0U; | ||
| 137 | + uint32_t maxBatchSize = static_cast<uint32_t>(availableUb / bytesPerIndice); | ||
| 138 | + uint32_t numTokens = static_cast<uint32_t>(numTokens_); | ||
| 139 | + indicesBatchSize_ = (numTokens <= maxBatchSize) ? numTokens : maxBatchSize; | ||
| 140 | + if (indicesBatchSize_ == 0U) { | ||
| 141 | + indicesBatchSize_ = 1U; | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + uint32_t indicesBufSize = Ceil(indicesBatchSize_ * sizeof(int32_t), UB_ALIGN) * UB_ALIGN; | ||
| 145 | + tpipe_->InitBuffer(indicesBuf_, indicesBufSize); | ||
| 146 | + uint32_t tokenIdxInRankBufSize = Ceil(indicesBatchSize_ * sizeof(uint32_t), UB_ALIGN) * UB_ALIGN; | ||
| 147 | + tpipe_->InitBuffer(tokenIdxInRankBuf_, tokenIdxInRankBufSize); | ||
| 148 | + | ||
| 149 | + uint32_t compareCntMax = Ceil(indicesBatchSize_ * sizeof(int32_t), ALIGNED_LEN_256) * | ||
| 150 | + ALIGNED_LEN_256 / sizeof(int32_t); | ||
| 151 | + uint32_t int32BufSize = compareCntMax * sizeof(int32_t); | ||
| 152 | + tpipe_->InitBuffer(rankIDsBuf_, int32BufSize); | ||
| 153 | + tpipe_->InitBuffer(positionsBuf_, int32BufSize); | ||
| 154 | + tpipe_->InitBuffer(divisorBuf_, int32BufSize); | ||
| 155 | + uint32_t maskBufSize = Ceil(Ceil(compareCntMax, BITS_PER_BYTE), UB_ALIGN) * UB_ALIGN; | ||
| 156 | + tpipe_->InitBuffer(maskBuf_, maskBufSize); | ||
| 157 | +} | ||
| 158 | + | ||
| 159 | +__aicore__ inline void EngramFetchArch35::CopyContextToUb() | ||
| 160 | +{ | ||
| 161 | + LocalTensor<uint64_t> commBufferLocal = commBufferBuf_.Get<uint64_t>(); | ||
| 162 | + GlobalTensor<uint64_t> commBufferGm; | ||
| 163 | + commBufferGm.SetGlobalBuffer((__gm__ uint64_t *)&ctxPtr_->commBuffer[0]); | ||
| 164 | + DataCopyExtParams cpComm{1U, numRanks_ * static_cast<uint32_t>(sizeof(uint64_t)), 0U, 0U, 0U}; | ||
| 165 | + DataCopyPadExtParams<uint64_t> padComm{false, 0, 0, 0}; | ||
| 166 | + DataCopyPad(commBufferLocal, commBufferGm, cpComm, padComm); | ||
| 167 | + | ||
| 168 | + LocalTensor<uint64_t> hcommHandleLocal = hcommHandleBuf_.Get<uint64_t>(); | ||
| 169 | + GlobalTensor<uint64_t> hcommHandleGm; | ||
| 170 | + hcommHandleGm.SetGlobalBuffer((__gm__ uint64_t *)&ctxPtr_->hcommHandle_[0]); | ||
| 171 | + DataCopyExtParams cpHandle{1U, numRanks_ * static_cast<uint32_t>(sizeof(uint64_t)), 0U, 0U, 0U}; | ||
| 172 | + DataCopyPadExtParams<uint64_t> padHandle{false, 0, 0, 0}; | ||
| 173 | + DataCopyPad(hcommHandleLocal, hcommHandleGm, cpHandle, padHandle); | ||
| 174 | +} | ||
| 175 | + | ||
| 176 | +__aicore__ inline void EngramFetchArch35::CopyIndicesToUb(uint32_t indicesBatchStart, uint32_t indicesBatchLen) | ||
| 177 | +{ | ||
| 178 | + GlobalTensor<int32_t> indicesGlobal; | ||
| 179 | + indicesGlobal.SetGlobalBuffer((__gm__ int32_t *)indicesGM_); | ||
| 180 | + LocalTensor<int32_t> indicesLocal = indicesBuf_.Get<int32_t>(); | ||
| 181 | + DataCopyExtParams params{1U, indicesBatchLen * static_cast<uint32_t>(sizeof(int32_t)), 0U, 0U, 0U}; | ||
| 182 | + DataCopyPadExtParams<int32_t> pad{false, 0, 0, 0}; | ||
| 183 | + DataCopyPad(indicesLocal, indicesGlobal[indicesBatchStart], params, pad); | ||
| 184 | +} | ||
| 185 | + | ||
| 186 | +__aicore__ inline void EngramFetchArch35::ScatterByRank( | ||
| 187 | + const LocalTensor<int32_t> &indicesLocal, | ||
| 188 | + const LocalTensor<uint32_t> &rankCounts, | ||
| 189 | + const LocalTensor<uint32_t> &rankOffsets, | ||
| 190 | + const LocalTensor<uint32_t> &tokenIdxInRank, | ||
| 191 | + uint32_t batchLen) | ||
| 192 | +{ | ||
| 193 | + uint32_t compareCntMax = Ceil(batchLen * sizeof(int32_t), ALIGNED_LEN_256) * ALIGNED_LEN_256 / sizeof(int32_t); | ||
| 194 | + | ||
| 195 | + LocalTensor<int32_t> rankIDs = rankIDsBuf_.Get<int32_t>(); | ||
| 196 | + LocalTensor<int32_t> positions = positionsBuf_.Get<int32_t>(); | ||
| 197 | + LocalTensor<int32_t> divisor = divisorBuf_.Get<int32_t>(); | ||
| 198 | + LocalTensor<uint8_t> mask = maskBuf_.Get<uint8_t>(); | ||
| 199 | + | ||
| 200 | + ArithProgression<int32_t>(positions, 0, 1, batchLen); | ||
| 201 | + Duplicate<int32_t>(divisor, numEntriesPerRank_, compareCntMax); | ||
| 202 | + | ||
| 203 | + Duplicate<int32_t>(rankIDs, static_cast<int32_t>(numRanks_), compareCntMax); | ||
| 204 | + PipeBarrier<PIPE_V>(); | ||
| 205 | + | ||
| 206 | + Div<int32_t>(rankIDs, indicesLocal, divisor, batchLen); | ||
| 207 | + PipeBarrier<PIPE_V>(); | ||
| 208 | + SyncFunc<HardEvent::V_S>(); | ||
| 209 | + | ||
| 210 | + uint32_t runningOffset = 0; | ||
| 211 | + uint32_t totalBlocks = GetBlockNum(); | ||
| 212 | + for (uint32_t ownerRank = aivId_; ownerRank < numRanks_; ownerRank += totalBlocks) { | ||
| 213 | + CompareScalar(mask, rankIDs, static_cast<int32_t>(ownerRank), AscendC::CMPMODE::EQ, compareCntMax); | ||
| 214 | + PipeBarrier<PIPE_V>(); | ||
| 215 | + | ||
| 216 | + LocalTensor<int32_t> dstRegion = tokenIdxInRank[runningOffset].ReinterpretCast<int32_t>(); | ||
| 217 | + uint64_t rsvdCnt = 0; | ||
| 218 | + GatherMask(dstRegion, positions, mask.ReinterpretCast<uint32_t>(), true, | ||
| 219 | + batchLen, {1, 1, 0, 0}, rsvdCnt); | ||
| 220 | + PipeBarrier<PIPE_V>(); | ||
| 221 | + | ||
| 222 | + uint32_t count = static_cast<uint32_t>(rsvdCnt); | ||
| 223 | + rankOffsets.SetValue(ownerRank, runningOffset); | ||
| 224 | + rankCounts.SetValue(ownerRank, count); | ||
| 225 | + runningOffset += count; | ||
| 226 | + } | ||
| 227 | + | ||
| 228 | + SyncFunc<HardEvent::V_S>(); | ||
| 57 | } | 229 | } |
| 58 | 230 | ||
| 59 | __aicore__ inline void EngramFetchArch35::Process() | 231 | __aicore__ inline void EngramFetchArch35::Process() |
超大函数,需要拆分一下 ![]() ![]() | |||
| 60 | { | 232 | { |
| 61 | - printf("EngramFetchArch35::Process\n"); | 233 | + if ASCEND_IS_AIV { |
| 234 | + if (numEntriesPerRank_ == 0 || numTokens_ == 0) { | ||
| 235 | + return; | ||
| 236 | + } | ||
| 237 | + | ||
| 238 | + uint32_t totalBlocks = GetBlockNum(); | ||
| 239 | + | ||
| 240 | + CopyContextToUb(); | ||
| 241 | + | ||
| 242 | + LocalTensor<uint64_t> commBufferLocal = commBufferBuf_.Get<uint64_t>(); | ||
| 243 | + LocalTensor<uint64_t> hcommHandleLocal = hcommHandleBuf_.Get<uint64_t>(); | ||
| 244 | + LocalTensor<int32_t> indicesLocal = indicesBuf_.Get<int32_t>(); | ||
| 245 | + LocalTensor<uint32_t> rankCounts = rankCountsBuf_.Get<uint32_t>(); | ||
| 246 | + LocalTensor<uint32_t> rankOffsets = rankOffsetsBuf_.Get<uint32_t>(); | ||
| 247 | + LocalTensor<uint32_t> tokenIdxInRank = tokenIdxInRankBuf_.Get<uint32_t>(); | ||
| 248 | + | ||
| 249 | + uint64_t hiddenBytes = static_cast<uint64_t>(hiddenBytes_); | ||
| 250 | + uint32_t numTokens = static_cast<uint32_t>(numTokens_); | ||
| 251 | + uint32_t numEntriesPerRank = static_cast<uint32_t>(numEntriesPerRank_); | ||
| 252 | + | ||
| 253 | + uint32_t indicesBatchStart = 0; | ||
| 254 | + while (indicesBatchStart < numTokens) { | ||
| 255 | + uint32_t indicesBatchLen = indicesBatchSize_; | ||
| 256 | + if (indicesBatchStart + indicesBatchLen > numTokens) { | ||
| 257 | + indicesBatchLen = numTokens - indicesBatchStart; | ||
| 258 | + } | ||
| 259 | + | ||
| 260 | + CopyIndicesToUb(indicesBatchStart, indicesBatchLen); | ||
| 261 | + SyncFunc<HardEvent::MTE2_S>(); | ||
| 262 | + | ||
| 263 | + ScatterByRank(indicesLocal, rankCounts, rankOffsets, tokenIdxInRank, indicesBatchLen); | ||
| 264 | + | ||
| 265 | + for (uint32_t ownerRank = aivId_; ownerRank < numRanks_; ownerRank += totalBlocks) { | ||
| 266 | + uint32_t idxStart = ownerRank * numEntriesPerRank; | ||
| 267 | + uint32_t rankStart = rankOffsets(ownerRank); | ||
| 268 | + uint32_t cnt = rankCounts(ownerRank); | ||
| 269 | + | ||
| 270 | + uint32_t channelIdx = ownerRank; | ||
| 271 | + uint32_t pendingReadCount = 0; | ||
| 272 | + for (uint32_t b = 0; b < cnt; b++) { | ||
| 273 | + uint32_t i = tokenIdxInRank(rankStart + b); | ||
| 274 | + int32_t globalIdx = indicesLocal(i); | ||
| 275 | + uint32_t localEntryIdx = static_cast<uint32_t>(globalIdx) - idxStart; | ||
| 276 | + uint64_t globalTokenIdx = indicesBatchStart + i; | ||
| 277 | + GM_ADDR dst = fetchedGM_ + globalTokenIdx * hiddenBytes; | ||
| 278 | + | ||
| 279 | + if (ownerRank == rankId_) { | ||
| 280 | + GM_ADDR src = (GM_ADDR)commBufferLocal(rankId_) | ||
| 281 | + + static_cast<uint64_t>(localEntryIdx) * hiddenBytes; | ||
| 282 | + LocalCopySlice(dst, src, hiddenBytes); | ||
| 283 | + } else { | ||
| 284 | + GM_ADDR remoteSrcAddr = (GM_ADDR)commBufferLocal(ownerRank) | ||
| 285 | + + static_cast<uint64_t>(localEntryIdx) * hiddenBytes; | ||
| 286 | + hcomm_.ReadNbi<false>(hcommHandleLocal(channelIdx), dst, remoteSrcAddr, hiddenBytes); | ||
| 287 | + pendingReadCount++; | ||
| 288 | + if (pendingReadCount >= READ_COMMIT_THRESHOLD) { | ||
| 289 | + hcomm_.Commit(hcommHandleLocal(channelIdx)); | ||
| 290 | + pendingReadCount = 0; | ||
| 291 | + } | ||
| 292 | + } | ||
| 293 | + } | ||
| 294 | + | ||
| 295 | + if (pendingReadCount > 0) { | ||
| 296 | + hcomm_.Commit(hcommHandleLocal(channelIdx)); | ||
| 297 | + } | ||
| 298 | + } | ||
| 299 | + | ||
| 300 | + indicesBatchStart += indicesBatchLen; | ||
| 301 | + } | ||
| 302 | + } | ||
| 62 | } | 303 | } |
| 63 | 304 | ||
| 305 | +__aicore__ inline void EngramFetchArch35::LocalCopySlice(GM_ADDR dst, GM_ADDR src, uint64_t len) | ||
| 306 | +{ | ||
| 307 | + LocalTensor<uint8_t> tmp0 = pingBuf_.Get<uint8_t>(); | ||
| 308 | + LocalTensor<uint8_t> tmp1 = pongBuf_.Get<uint8_t>(); | ||
| 309 | + GlobalTensor<uint8_t> srcGm; | ||
| 310 | + GlobalTensor<uint8_t> dstGm; | ||
| 311 | + srcGm.SetGlobalBuffer((__gm__ uint8_t *)src); | ||
| 312 | + dstGm.SetGlobalBuffer((__gm__ uint8_t *)dst); | ||
| 313 | + | ||
| 314 | + uint32_t tileLen = TILE_BYTES; | ||
| 315 | + uint64_t off = 0; | ||
| 316 | + uint32_t tileIdx = 0; | ||
| 317 | + while (off < len) { | ||
| 318 | + uint64_t thisLen = (len - off > TILE_BYTES) ? tileLen : (len - off); | ||
| 319 | + uint32_t bufIdx = tileIdx % 2U; | ||
| 320 | + LocalTensor<uint8_t> tmp = (bufIdx == 0U) ? tmp0 : tmp1; | ||
| 321 | + | ||
| 322 | + if (tileIdx >= 2U) { | ||
| 323 | + AscendC::WaitFlag<HardEvent::MTE3_MTE2>(ppEvtMte3ToMte2_[bufIdx]); | ||
| 324 | + } | ||
| 325 | + | ||
| 326 | + DataCopy(tmp, srcGm[off], thisLen); | ||
| 327 | + AscendC::SetFlag<HardEvent::MTE2_MTE3>(ppEvtMte2ToMte3_[bufIdx]); | ||
| 328 | + AscendC::WaitFlag<HardEvent::MTE2_MTE3>(ppEvtMte2ToMte3_[bufIdx]); | ||
| 329 | + DataCopy(dstGm[off], tmp, thisLen); | ||
| 330 | + AscendC::SetFlag<HardEvent::MTE3_MTE2>(ppEvtMte3ToMte2_[bufIdx]); | ||
| 331 | + | ||
| 332 | + off += thisLen; | ||
| 333 | + tileIdx++; | ||
| 334 | + } | ||
| 335 | + | ||
| 336 | + if (tileIdx >= 1U) { | ||
| 337 | + AscendC::WaitFlag<HardEvent::MTE3_MTE2>(ppEvtMte3ToMte2_[(tileIdx - 1U) % 2U]); | ||
| 338 | + } | ||
| 339 | + if (tileIdx >= 2U) { | ||
| 340 | + AscendC::WaitFlag<HardEvent::MTE3_MTE2>(ppEvtMte3ToMte2_[tileIdx % 2U]); | ||
| 341 | + } | ||
| 342 | +} | ||
| 64 | } // namespace Mc2Kernel | 343 | } // namespace Mc2Kernel |
| 65 | 344 | ||
| 66 | #endif | 345 | #endif |
| @@ -0,0 +1,44 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 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 | +/*! | ||
| 12 | + * \file engram_fetch.h | ||
文件名和算子名称完全一致,容易被误认为是算子kernel实现,但实际只放了结构体,建议加util这种后缀。 ![]() ![]() | |||
| 13 | + * \brief engram_fetch算子公共头文件 | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | +#ifndef ENGRAM_FETCH_H | ||
| 17 | +#define ENGRAM_FETCH_H | ||
| 18 | + | ||
| 19 | +#if ASC_DEVKIT_MAJOR >= 9 | ||
| 20 | +#include "basic_api/kernel_basic_intf.h" | ||
| 21 | +#else | ||
| 22 | +#include "kernel_operator.h" | ||
| 23 | +#endif | ||
| 24 | + | ||
| 25 | +constexpr uint32_t MAX_QP_SIZE = 1024; | ||
放到namespace Mc2Kernel 中 ![]() ![]() | |||
| 26 | +struct EngramCommContext { | ||
| 27 | + uint32_t rankId; | ||
| 28 | + uint32_t rankSize; | ||
| 29 | + uint64_t commBuffer[MAX_QP_SIZE]; | ||
| 30 | + uint64_t hcommHandle_[MAX_QP_SIZE]; | ||
下划线要统一一下 ![]() ![]() | |||
| 31 | +}; | ||
| 32 | + | ||
| 33 | +namespace Mc2Kernel { | ||
| 34 | +constexpr uint32_t UB_ALIGN = 32U; | ||
| 35 | +constexpr uint32_t TILE_BYTES = 32U * 1024U; | ||
| 36 | +constexpr uint32_t HCOMM_INIT_SIZE = 512U; | ||
| 37 | +constexpr uint32_t READ_COMMIT_THRESHOLD = 64U; | ||
| 38 | +constexpr int32_t BITS_PER_BYTE = 8; | ||
| 39 | +constexpr uint32_t ALIGNED_LEN_256 = 256U; | ||
| 40 | + | ||
| 41 | +using namespace AscendC; | ||
| 42 | +} // namespace Mc2Kernel | ||
| 43 | + | ||
| 44 | +#endif | ||
| @@ -0,0 +1,21 @@ | |||
| 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 | +file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | ||
| 12 | +if(NOT ENABLE_TEST) | ||
| 13 | + list(REMOVE_ITEM CURRENT_DIRS tests) | ||
| 14 | +endif() | ||
| 15 | +foreach(SUB_DIR ${CURRENT_DIRS}) | ||
| 16 | + if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | ||
| 17 | + add_subdirectory(${SUB_DIR}) | ||
| 18 | + endif() | ||
| 19 | +endforeach() | ||
| 20 | + | ||
| 21 | +set(MC2_COMPILE ${SUB_MC2_COMPILE} PARENT_SCOPE) | ||
| @@ -0,0 +1,60 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 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 | +/*! | ||
| 12 | + * \file aclnn_engram_fetch_wait.cpp | ||
| 13 | + * \brief engram_fetch_wait算子API实现 | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | +#include "aclnn/aclnn_base.h" | ||
| 17 | +#include "common/utils/op_mc2_def.h" | ||
| 18 | +#include "aclnn_kernels/common/op_error_check.h" | ||
| 19 | +#include "opdev/common_types.h" | ||
| 20 | +#include "opdev/op_log.h" | ||
| 21 | +#include "log/log.h" | ||
| 22 | +#include "aclnnInner_engram_fetch_wait.h" | ||
| 23 | + | ||
| 24 | +using namespace op; | ||
| 25 | + | ||
| 26 | +static bool CheckNotNull(const aclTensor *commContext, aclTensor *fetched) | ||
| 27 | +{ | ||
| 28 | + OP_CHECK_NULL(commContext, return false); | ||
| 29 | + OP_CHECK_NULL(fetched, return false); | ||
| 30 | + return true; | ||
| 31 | +} | ||
| 32 | + | ||
| 33 | +static aclnnStatus CheckParams(const aclTensor *commContext, aclTensor *fetched) | ||
| 34 | +{ | ||
| 35 | + CHECK_RET(CheckNotNull(commContext, fetched), ACLNN_ERR_PARAM_NULLPTR); | ||
| 36 | + return ACLNN_SUCCESS; | ||
| 37 | +} | ||
| 38 | + | ||
| 39 | +#ifdef __cplusplus | ||
| 40 | +extern "C" { | ||
| 41 | +#endif | ||
| 42 | + | ||
| 43 | +aclnnStatus aclnnEngramFetchWaitGetWorkspaceSize(const aclTensor *commContext, aclTensor *fetched, | ||
| 44 | + uint64_t *workspaceSize, aclOpExecutor **executor) | ||
| 45 | +{ | ||
| 46 | + auto retParam = CheckParams(commContext, fetched); | ||
| 47 | + CHECK_RET(retParam == ACLNN_SUCCESS, retParam); | ||
| 48 | + aclnnStatus ret = aclnnInnerEngramFetchWaitGetWorkspaceSize(commContext, fetched, workspaceSize, executor); | ||
| 49 | + return ret; | ||
| 50 | +} | ||
| 51 | + | ||
| 52 | +aclnnStatus aclnnEngramFetchWait(void *workspace, uint64_t workspaceSize, aclOpExecutor *executor, aclrtStream stream) | ||
| 53 | +{ | ||
| 54 | + aclnnStatus ret = aclnnInnerEngramFetchWait(workspace, workspaceSize, executor, stream); | ||
| 55 | + return ret; | ||
| 56 | +} | ||
| 57 | + | ||
| 58 | +#ifdef __cplusplus | ||
| 59 | +} | ||
| 60 | +#endif | ||
| @@ -0,0 +1,35 @@ | |||
| 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 | +if (BUILD_OPEN_PROJECT) # custom | ||
| 12 | + target_sources(op_host_aclnnInner PRIVATE | ||
| 13 | + engram_fetch_wait_def.cpp | ||
| 14 | + ) | ||
| 15 | + add_modules_sources_with_soc( | ||
| 16 | + OP_API_INDEPENDENT ON | ||
| 17 | + OP_API_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../op_api | ||
| 18 | + OP_MC2_ENABLE ON | ||
| 19 | + OPTYPE engram_fetch_wait engram_fetch_wait ACLNNTYPE aclnn aclnn_inner) | ||
| 20 | + set(SUB_MC2_COMPILE TRUE PARENT_SCOPE) | ||
| 21 | + set(MC2_OPT ON PARENT_SCOPE) | ||
| 22 | + set(engram_fetch_wait_depends mc2/common mc2/3rd mc2/engram_fetch PARENT_SCOPE) | ||
| 23 | + | ||
| 24 | + set(CONDITION_UNIT ${ASCEND_COMPUTE_UNIT}) | ||
| 25 | + if("${CONDITION_UNIT}" STREQUAL "ascend950") | ||
| 26 | + add_ops_compile_options( | ||
| 27 | + OP_NAME EngramFetchWait | ||
| 28 | + COMPUTE_UNIT Ascend950PR_9599 | ||
| 29 | + OPTIONS --cce-auto-sync=off | ||
| 30 | + ) | ||
| 31 | + endif() | ||
| 32 | +else() | ||
| 33 | + add_mc2_modules_sources(OPTYPE engram_fetch_wait engram_fetch_wait ACLNNTYPE aclnn aclnn_inner) | ||
| 34 | + set(SUB_MC2_COMPILE TRUE PARENT_SCOPE) | ||
| 35 | +endif() | ||
| @@ -0,0 +1,50 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 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 | +/*! | ||
| 12 | + * \file engram_fetch_wait_def.cpp | ||
| 13 | + * \brief 算子信息库定义 | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | +#include "register/op_def_registry.h" | ||
| 17 | + | ||
| 18 | +namespace ops { | ||
| 19 | +class EngramFetchWait : public OpDef { | ||
| 20 | +public: | ||
| 21 | + explicit EngramFetchWait(const char *name) : OpDef(name) | ||
| 22 | + { | ||
| 23 | + this->Input("commContext").ParamType(REQUIRED).DataTypeList({ge::DT_INT32}).FormatList({ge::FORMAT_ND}); | ||
| 24 | + | ||
| 25 | + this->Input("fetched") | ||
| 26 | + .ParamType(REQUIRED) | ||
| 27 | + .DataType({ge::DT_BF16, ge::DT_FLOAT16, ge::DT_FLOAT}) | ||
| 28 | + .FormatList({ge::FORMAT_ND}) | ||
| 29 | + .AutoContiguous(); | ||
| 30 | + | ||
| 31 | + this->Output("fetched") | ||
| 32 | + .ParamType(REQUIRED) | ||
| 33 | + .DataType({ge::DT_BF16, ge::DT_FLOAT16, ge::DT_FLOAT}) | ||
| 34 | + .FormatList({ge::FORMAT_ND}); | ||
| 35 | + | ||
| 36 | + OpAICoreConfig aicore_config_950; | ||
| 37 | + aicore_config_950.DynamicCompileStaticFlag(true) | ||
| 38 | + .DynamicFormatFlag(true) | ||
| 39 | + .DynamicRankSupportFlag(true) | ||
| 40 | + .DynamicShapeSupportFlag(true) | ||
| 41 | + .NeedCheckSupportFlag(false) | ||
| 42 | + .PrecisionReduceFlag(true) | ||
| 43 | + .ExtendCfgInfo("aclnnSupport.value", "support_aclnn") | ||
| 44 | + .ExtendCfgInfo("jitCompile.flag", "static_false") | ||
| 45 | + .ExtendCfgInfo("multiKernelSupportDynamicGraph.value", "multi_kernel"); | ||
| 46 | + this->AICore().AddConfig("ascend950", aicore_config_950); | ||
| 47 | + } | ||
| 48 | +}; | ||
| 49 | +OP_ADD(EngramFetchWait); | ||
| 50 | +} // namespace ops | ||
| @@ -0,0 +1,52 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 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 | +/*! | ||
| 12 | + * \file engram_fetch_wait_infershape.cpp | ||
| 13 | + * \brief engram_fetch_wait算子infershape实现 | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | +#include "mc2_log.h" | ||
| 17 | +#include "platform/platform_info.h" | ||
| 18 | +#include "register/op_impl_registry.h" | ||
| 19 | +using namespace ge; | ||
| 20 | +namespace ops { | ||
| 21 | + | ||
| 22 | +static constexpr size_t FETCH_WAIT_INPUT_FETCHED_INDEX = 1UL; | ||
| 23 | +static constexpr size_t FETCH_WAIT_OUTPUT_FETCHED_INDEX = 0UL; | ||
| 24 | + | ||
| 25 | +static ge::graphStatus InferShapeEngramFetchWait(gert::InferShapeContext *context) | ||
| 26 | +{ | ||
| 27 | + OPS_LOG_D(context->GetNodeName(), "Begin to do InferShapeEngramFetchWait."); | ||
| 28 | + const gert::Shape *fetchedInputShape = context->GetInputShape(FETCH_WAIT_INPUT_FETCHED_INDEX); | ||
| 29 | + OPS_CHECK_NULL_WITH_CONTEXT(context, fetchedInputShape); | ||
| 30 | + gert::Shape *fetchedOutputShape = context->GetOutputShape(FETCH_WAIT_OUTPUT_FETCHED_INDEX); | ||
| 31 | + OPS_CHECK_NULL_WITH_CONTEXT(context, fetchedOutputShape); | ||
| 32 | + | ||
| 33 | + *fetchedOutputShape = *fetchedInputShape; | ||
| 34 | + OPS_LOG_D(context->GetNodeName(), "fetched shape is :%s after infershape.", | ||
| 35 | + Ops::Base::ToString(*fetchedOutputShape).c_str()); | ||
| 36 | + OPS_LOG_D(context->GetNodeName(), "End to do InferShapeEngramFetchWait."); | ||
| 37 | + return ge::GRAPH_SUCCESS; | ||
| 38 | +} | ||
| 39 | + | ||
| 40 | +static ge::graphStatus InferDataTypeEngramFetchWait(gert::InferDataTypeContext *context) | ||
| 41 | +{ | ||
| 42 | + OPS_LOG_D(context->GetNodeName(), "Begin to do InferDataTypeEngramFetchWait."); | ||
| 43 | + auto fetchedDtype = context->GetInputDataType(FETCH_WAIT_INPUT_FETCHED_INDEX); | ||
| 44 | + context->SetOutputDataType(FETCH_WAIT_OUTPUT_FETCHED_INDEX, fetchedDtype); | ||
| 45 | + OPS_LOG_D(context->GetNodeName(), "End to do InferDataTypeEngramFetchWait."); | ||
| 46 | + return ge::GRAPH_SUCCESS; | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +IMPL_OP_INFERSHAPE(EngramFetchWait) | ||
| 50 | + .InferShape(InferShapeEngramFetchWait) | ||
| 51 | + .InferDataType(InferDataTypeEngramFetchWait); | ||
| 52 | +} // namespace ops | ||
| @@ -0,0 +1,102 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 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 | +/*! | ||
| 12 | + * \file engram_fetch_wait_tiling.cpp | ||
| 13 | + * \brief host侧tiling实现 | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | +#include <string> | ||
| 17 | +#include "mc2_log.h" | ||
| 18 | +#include "graph/utils/type_utils.h" | ||
| 19 | +#include "register/op_def_registry.h" | ||
| 20 | +#include "../../op_kernel/engram_fetch_wait_tiling_data.h" | ||
| 21 | + | ||
| 22 | +using namespace AscendC; | ||
| 23 | +using namespace ge; | ||
| 24 | +using namespace Mc2Tiling; | ||
| 25 | + | ||
| 26 | +namespace optiling { | ||
| 27 | +constexpr uint32_t COMM_CONTEXT_INDEX = 0U; | ||
| 28 | +constexpr uint32_t SYSTEM_NEED_WORKSPACE = 16U * 1024 * 1024; | ||
| 29 | + | ||
| 30 | +static ge::graphStatus CheckInputDataType(const gert::TilingContext *context) | ||
| 31 | +{ | ||
| 32 | + const char *nodeName = context->GetNodeName(); | ||
| 33 | + | ||
| 34 | + auto commContextDesc = context->GetInputDesc(COMM_CONTEXT_INDEX); | ||
| 35 | + OP_TILING_CHECK(commContextDesc == nullptr, OP_LOGE_WITH_INVALID_INPUT(nodeName, "commContext"), | ||
| 36 | + return ge::GRAPH_FAILED); | ||
| 37 | + OP_TILING_CHECK(commContextDesc->GetDataType() != ge::DT_INT32, | ||
| 38 | + OP_LOGE_FOR_INVALID_DTYPE(nodeName, "commContext", | ||
| 39 | + Ops::Base::ToString(commContextDesc->GetDataType()).c_str(), "INT32"), | ||
| 40 | + return ge::GRAPH_FAILED); | ||
| 41 | + | ||
| 42 | + return ge::GRAPH_SUCCESS; | ||
| 43 | +} | ||
| 44 | + | ||
| 45 | +static void SetTilingKey(gert::TilingContext *context) | ||
| 46 | +{ | ||
| 47 | + context->SetTilingKey(0); | ||
| 48 | +} | ||
| 49 | + | ||
| 50 | +static ge::graphStatus SetWorkSpace(gert::TilingContext *context) | ||
| 51 | +{ | ||
| 52 | + const char *nodeName = context->GetNodeName(); | ||
| 53 | + size_t *workSpaces = context->GetWorkspaceSizes(1); | ||
| 54 | + OP_TILING_CHECK(workSpaces == nullptr, OP_LOGE(nodeName, "workSpaces is nullptr."), return ge::GRAPH_FAILED); | ||
| 55 | + workSpaces[0] = SYSTEM_NEED_WORKSPACE; | ||
| 56 | + return ge::GRAPH_SUCCESS; | ||
| 57 | +} | ||
| 58 | + | ||
| 59 | +static ge::graphStatus EngramFetchWaitTilingFunc(gert::TilingContext *context) | ||
| 60 | +{ | ||
| 61 | + OP_LOGD("EngramFetchWait", "tiling start."); | ||
| 62 | + OP_TILING_CHECK(context == nullptr, OP_LOGE("engram_fetch_wait_tiling", "failed to get tiling context."), | ||
| 63 | + return ge::GRAPH_FAILED); | ||
| 64 | + const char *nodeName = context->GetNodeName(); | ||
| 65 | + OP_TILING_CHECK(nodeName == nullptr, OP_LOGE("engram_fetch_wait_tiling", "failed to get nodeName."), | ||
| 66 | + return ge::GRAPH_FAILED); | ||
| 67 | + | ||
| 68 | + EngramFetchWaitTilingData *tilingData = context->GetTilingData<EngramFetchWaitTilingData>(); | ||
| 69 | + OP_TILING_CHECK(tilingData == nullptr, OP_LOGE(nodeName, "tilingData is nullptr."), return ge::GRAPH_FAILED); | ||
| 70 | + | ||
| 71 | + OP_TILING_CHECK(CheckInputDataType(context) != ge::GRAPH_SUCCESS, OP_LOGE(nodeName, "Check input dtype failed."), | ||
| 72 | + return ge::GRAPH_FAILED); | ||
| 73 | + | ||
| 74 | + auto platformInfo = context->GetPlatformInfo(); | ||
| 75 | + OPS_CHECK_NULL_WITH_CONTEXT(context, platformInfo); | ||
| 76 | + auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfo); | ||
| 77 | + uint32_t aivNum = ascendcPlatform.GetCoreNumAiv(); | ||
| 78 | + uint32_t aicNum = ascendcPlatform.GetCoreNumAic(); | ||
| 79 | + uint32_t numBlocks = ascendcPlatform.CalcTschNumBlocks(aivNum, 0, aivNum); | ||
| 80 | + context->SetBlockDim(numBlocks); | ||
| 81 | + OP_LOGD(nodeName, "aicNum=%u, aivNum=%u, numBlocks=%u", aicNum, aivNum, numBlocks); | ||
| 82 | + | ||
| 83 | + OP_TILING_CHECK(SetWorkSpace(context) != ge::GRAPH_SUCCESS, OP_LOGE(nodeName, "SetWorkSpace failed."), | ||
| 84 | + return ge::GRAPH_FAILED); | ||
| 85 | + SetTilingKey(context); | ||
| 86 | + | ||
| 87 | + OP_LOGD(nodeName, "EngramFetchWait tiling end."); | ||
| 88 | + return ge::GRAPH_SUCCESS; | ||
| 89 | +} | ||
| 90 | + | ||
| 91 | +struct EngramFetchWaitCompileInfo {}; | ||
91~97行不用的代码直接删除 ![]() ![]() | |||
| 92 | + | ||
| 93 | +ge::graphStatus TilingParseForEngramFetchWait(gert::TilingParseContext *context) | ||
| 94 | +{ | ||
| 95 | + (void)context; | ||
| 96 | + return ge::GRAPH_SUCCESS; | ||
| 97 | +} | ||
| 98 | + | ||
| 99 | +IMPL_OP_OPTILING(EngramFetchWait) | ||
| 100 | + .Tiling(EngramFetchWaitTilingFunc); | ||
| 101 | + | ||
| 102 | +} // namespace optiling | ||
| @@ -0,0 +1,89 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 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 | +/*! | ||
| 12 | + * \file engram_fetch_wait_arch35.h | ||
| 13 | + * \brief engram_fetch_wait算子arch35 kernel实现 | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | +#ifndef ENGRAM_FETCH_WAIT_ARCH35_H | ||
| 18 | +#define ENGRAM_FETCH_WAIT_ARCH35_H | ||
| 19 | + | ||
| 20 | +#if ASC_DEVKIT_MAJOR >= 9 | ||
| 21 | +#include "basic_api/kernel_basic_intf.h" | ||
| 22 | +#else | ||
| 23 | +#include "kernel_operator.h" | ||
| 24 | +#endif | ||
| 25 | +#include "kernel_tiling/kernel_tiling.h" | ||
| 26 | +#include "../engram_fetch_wait_tiling_data.h" | ||
| 27 | +#if __has_include("../../engram_fetch/engram_fetch.h") | ||
| 28 | +#include "../../engram_fetch/engram_fetch.h" | ||
| 29 | +#else | ||
| 30 | +#include "../../../engram_fetch/op_kernel/engram_fetch.h" | ||
| 31 | +#endif | ||
| 32 | +#include "adv_api/hccl/hccl.h" | ||
| 33 | +#include "adv_api/hcomm/hcomm.h" | ||
| 34 | + | ||
| 35 | +namespace Mc2Kernel { | ||
| 36 | + | ||
| 37 | +using namespace AscendC; | ||
不要在头文件中using namespace ![]() ![]() | |||
| 38 | + | ||
| 39 | +class EngramFetchWaitArch35 { | ||
| 40 | +public: | ||
| 41 | + __aicore__ inline EngramFetchWaitArch35() = default; | ||
| 42 | + | ||
| 43 | + __aicore__ inline void Init(GM_ADDR commContext, GM_ADDR workspaceGM, TPipe *pipe); | ||
| 44 | + | ||
| 45 | + __aicore__ inline void Process(); | ||
| 46 | + | ||
| 47 | +private: | ||
| 48 | + TPipe *tpipe_{nullptr}; | ||
| 49 | + __gm__ EngramCommContext *ctxPtr_{nullptr}; | ||
| 50 | + | ||
| 51 | + uint32_t aivId_{0}; | ||
| 52 | + uint32_t rankId_{0}; | ||
| 53 | + uint32_t numRanks_{0}; | ||
| 54 | + | ||
多余的空行需要删除 ![]() ![]() | |||
| 55 | + TBuf<> hcommBuf_; | ||
| 56 | + | ||
| 57 | + AscendC::Hcomm<COMM_PROTOCOL_UBC_CTP> hcomm_; | ||
| 58 | +}; | ||
| 59 | + | ||
| 60 | +__aicore__ inline void EngramFetchWaitArch35::Init(GM_ADDR commContext, GM_ADDR workspaceGM, TPipe *pipe) | ||
| 61 | +{ | ||
| 62 | + tpipe_ = pipe; | ||
| 63 | + aivId_ = GetBlockIdx(); | ||
| 64 | + | ||
| 65 | + ctxPtr_ = (__gm__ EngramCommContext *)commContext; | ||
| 66 | + rankId_ = ctxPtr_->rankId; | ||
| 67 | + numRanks_ = ctxPtr_->rankSize; | ||
| 68 | + | ||
| 69 | + tpipe_->InitBuffer(hcommBuf_, Mc2Kernel::HCOMM_INIT_SIZE); | ||
| 70 | + LocalTensor<uint8_t> hcommTensor = hcommBuf_.Get<uint8_t>(); | ||
| 71 | + hcomm_.Init(hcommTensor, Mc2Kernel::HCOMM_INIT_SIZE); | ||
| 72 | +} | ||
| 73 | + | ||
| 74 | +__aicore__ inline void EngramFetchWaitArch35::Process() | ||
| 75 | +{ | ||
| 76 | + if ASCEND_IS_AIV { | ||
| 77 | + uint32_t totalBlocks = GetBlockNum(); | ||
| 78 | + for (uint32_t channelIdx = aivId_; channelIdx < numRanks_; channelIdx += totalBlocks) { | ||
| 79 | + if (channelIdx == rankId_) { | ||
| 80 | + continue; | ||
| 81 | + } | ||
| 82 | + hcomm_.Drain(ctxPtr_->hcommHandle_[channelIdx]); | ||
| 83 | + } | ||
| 84 | + } | ||
| 85 | +} | ||
| 86 | + | ||
| 87 | +} // namespace Mc2Kernel | ||
| 88 | + | ||
| 89 | +#endif | ||
| @@ -0,0 +1,32 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 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 | +/*! | ||
| 12 | + * \file engram_fetch_wait.cpp | ||
| 13 | + * \brief engram_fetch_wait算子kernel入口 | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | +#include "arch35/engram_fetch_wait_arch35.h" | ||
| 18 | + | ||
| 19 | +using namespace AscendC; | ||
| 20 | +using namespace Mc2Kernel; | ||
| 21 | + | ||
| 22 | +__global__ __aicore__ void engram_fetch_wait(GM_ADDR commContext, GM_ADDR fetched, GM_ADDR fetchedOut, | ||
| 23 | + GM_ADDR workspaceGM, GM_ADDR tilingGM) | ||
| 24 | +{ | ||
| 25 | + REGISTER_TILING_DEFAULT(EngramFetchWaitTilingData); | ||
| 26 | + GET_TILING_DATA_WITH_STRUCT(EngramFetchWaitTilingData, tilingData, tilingGM); | ||
| 27 | + KERNEL_TASK_TYPE_DEFAULT(KERNEL_TYPE_AIV_ONLY); | ||
| 28 | + TPipe pipe; | ||
| 29 | + EngramFetchWaitArch35 op; | ||
| 30 | + op.Init(commContext, workspaceGM, &pipe); | ||
| 31 | + op.Process(); | ||
| 32 | +} | ||
| @@ -0,0 +1,24 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 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 | +/*! | ||
| 12 | + * \file engram_fetch_wait_tiling_data.h | ||
| 13 | + * \brief engram_fetch_wait算子tiling数据结构定义 | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | +#ifndef ASCENDC_ENGRAM_FETCH_WAIT_TILING_H | ||
| 18 | +#define ASCENDC_ENGRAM_FETCH_WAIT_TILING_H | ||
| 19 | + | ||
| 20 | +#include "kernel_tiling/kernel_tiling.h" | ||
| 21 | + | ||
| 22 | +struct EngramFetchWaitTilingData { | ||
| 23 | +}; | ||
| 24 | +#endif | ||


其他文件都加了 #if ASC_DEVKIT_MAJOR >= 9 分支,这里为啥删除了