LCOV - code coverage report
Current view: top level - base_comm/resources/ccu/ccu_representation/reps/translator - ccu_ins_generator_v1.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 70.1 % 509 357
Test Date: 2026-08-04 10:52:23 Functions: 58.9 % 56 33

            Line data    Source code
       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              : #include "ccu_ins_generator_v1.h"
      11              : #include "hcomm_c_adpt.h"
      12              : #include "ccu_rep_base_v1.h"
      13              : #include "../../../../endpoint_pairs/channels/ccu/ccu_urma_channel.h"
      14              : #include "ccu_api_exception.h"
      15              : #include "ccu_assist_v1.h"
      16              : #include "ccu_log.h"
      17              : 
      18              : namespace hcomm {
      19              : namespace CcuRep {
      20              : 
      21              : #define UNUSED(x) (void)(x)
      22              : 
      23              : namespace {
      24              : template <typename T>
      25            0 : void LoadAddrArg(CcuInstr*& instr, const T& dst, const T& src, const TransDep& dep)
      26              : {
      27            0 :     LoadGSAGSAInstr(instr++, dst.addr.Id(), src.addr.Id(), dep.reserveGsaId);
      28            0 :     LoadXXInstr(instr++, dst.token.Id(), src.token.Id(), dep.reserveXnId);
      29            0 : }
      30              : 
      31              : template <typename T>
      32            0 : HcclResult LoadAddrListArg(CcuInstr*& instr, const std::vector<T>& dst, const std::vector<T>& src, const TransDep& dep)
      33              : {
      34            0 :     if (src.size() != dst.size()) {
      35            0 :         HCCL_ERROR("Mismatched Arg Size: srcSize[%u], dstSize[%u]", src.size(), dst.size());
      36            0 :         return HCCL_E_PARA;
      37              :     }
      38            0 :     for (uint32_t j = 0; j < src.size(); j++) {
      39            0 :         LoadAddrArg(instr, dst[j], src[j], dep);
      40              :     }
      41            0 :     return HcclResult::HCCL_SUCCESS;
      42              : }
      43              : } // namespace
      44              : 
      45            7 : HcclResult CcuInsGeneratorV1::CcuRepBufLocReadTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepBufLocRead* repBufLocRead, const TransDep &dep)
      46              : {
      47              :     UNUSED(ccuKernel);
      48            7 :     CHK_PTR_NULL(repBufLocRead);
      49            7 :     TransLocMemToLocMSInstr(instr++, repBufLocRead->GetDst().Id(), repBufLocRead->GetSrc().addr.Id(), repBufLocRead->GetSrc().token.Id(), repBufLocRead->GetLen().Id(), dep.reserveChannalId[0],
      50           14 :                             repBufLocRead->GetSem().Id(), repBufLocRead->GetMask(), 0, 0, 1, 1);
      51              : 
      52            7 :     return HcclResult::HCCL_SUCCESS;
      53              : }
      54              : 
      55            5 : HcclResult CcuInsGeneratorV1::CcuRepBufLocWriteTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepBufLocWrite* repBufLocWrite, const TransDep &dep)
      56              : {
      57              :     UNUSED(ccuKernel);
      58            5 :     CHK_PTR_NULL(repBufLocWrite);
      59            5 :     TransLocMSToLocMemInstr(instr++, repBufLocWrite->GetDst().addr.Id(), repBufLocWrite->GetDst().token.Id(), repBufLocWrite->GetSrc().Id(), repBufLocWrite->GetLen().Id(), dep.reserveChannalId[0],
      60           10 :                             repBufLocWrite->GetSem().Id(), repBufLocWrite->GetMask(), 0, 0, 1, 1);
      61              : 
      62            5 :     return HcclResult::HCCL_SUCCESS;
      63              : }
      64              : 
      65            1 : HcclResult CcuInsGeneratorV1::CcuRepBufReadTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepBufRead* repBufRead, const TransDep &dep)
      66              : {
      67              :     UNUSED(ccuKernel);
      68              :     UNUSED(dep);
      69            1 :     CHK_PTR_NULL(repBufRead);
      70            1 :     void *channelPtr{nullptr};
      71            1 :     CHK_PRT_RET(static_cast<HcclResult>(HcommChannelGet(repBufRead->GetChannel(), &channelPtr)) != HcclResult::HCCL_SUCCESS,
      72              :         HCCL_ERROR("failed to get ccu channel, type[%d]", repBufRead->Type()), HCCL_E_INTERNAL);
      73              : 
      74            1 :     auto *channelImpl = dynamic_cast<CcuUrmaChannel *>(static_cast<Channel *>(channelPtr));
      75            1 :     CHK_PTR_NULL(channelImpl);
      76              : 
      77            1 :     TransRmtMemToLocMSInstr(instr++, repBufRead->GetDst().Id(), repBufRead->GetSrc().addr.Id(), repBufRead->GetSrc().token.Id(), repBufRead->GetLen().Id(), channelImpl->GetChannelId(),
      78            2 :                             repBufRead->GetSem().Id(), repBufRead->GetMask(), 0, 0, 1, 1);
      79              : 
      80            1 :     return HcclResult::HCCL_SUCCESS;
      81              : }
      82              : 
      83            3 : HcclResult CcuInsGeneratorV1::CcuRepWriteTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepWrite* repWrite)
      84              : {
      85              :     UNUSED(ccuKernel);
      86            3 :     CHK_PTR_NULL(repWrite);
      87            3 :     void *channelPtr{nullptr};
      88            3 :     CHK_PRT_RET(static_cast<HcclResult>(HcommChannelGet(repWrite->GetChannel(), &channelPtr)) != HcclResult::HCCL_SUCCESS,
      89              :         HCCL_ERROR("failed to get ccu channel, type[%d]", repWrite->Type()), HCCL_E_INTERNAL);
      90              : 
      91            3 :     auto *channelImpl = dynamic_cast<CcuUrmaChannel *>(static_cast<Channel *>(channelPtr));
      92            3 :     CHK_PTR_NULL(channelImpl);
      93            3 :     TransLocMemToRmtMemInstr(instr++, repWrite->GetRem().addr.Id(), repWrite->GetRem().token.Id(), repWrite->GetLoc().addr.Id(), repWrite->GetLoc().token.Id(), repWrite->GetLen().Id(),
      94            6 :                              channelImpl->GetChannelId(), repWrite->GetDataType(), repWrite->GetOpType(), repWrite->GetSem().Id(), repWrite->GetMask(), 0, 0, 1, 1, repWrite->GetReduceFlag());
      95              : 
      96            3 :     return HcclResult::HCCL_SUCCESS;
      97              : }
      98              : 
      99            3 : HcclResult CcuInsGeneratorV1::CcuRepReadTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepRead* repRead)
     100              : {
     101              :     UNUSED(ccuKernel);
     102            3 :     CHK_PTR_NULL(repRead);
     103            3 :     void *channelPtr{nullptr};
     104            3 :     CHK_PRT_RET(static_cast<HcclResult>(HcommChannelGet(repRead->GetChannel(), &channelPtr)) != HcclResult::HCCL_SUCCESS,
     105              :         HCCL_ERROR("failed to get ccu channel, type[%d]", repRead->Type()), HCCL_E_INTERNAL);
     106              : 
     107            3 :     auto *channelImpl = dynamic_cast<CcuUrmaChannel *>(static_cast<Channel *>(channelPtr));
     108            3 :     CHK_PTR_NULL(channelImpl);
     109            3 :     TransRmtMemToLocMemInstr(instr++, repRead->GetLoc().addr.Id(), repRead->GetLoc().token.Id(), repRead->GetRem().addr.Id(), repRead->GetRem().token.Id(), repRead->GetLen().Id(),
     110            6 :                              channelImpl->GetChannelId(), repRead->GetDataType(), repRead->GetOpType(), repRead->GetSem().Id(), repRead->GetMask(), 0, 0, 1, 1, repRead->GetReduceFlag());
     111              : 
     112            3 :     return HcclResult::HCCL_SUCCESS;
     113              : }
     114              : 
     115            0 : HcclResult CcuInsGeneratorV1::CcuRepRemMemTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepRemMem* repRemMem)
     116              : {
     117              :     UNUSED(ccuKernel);
     118            0 :     CHK_PTR_NULL(repRemMem);
     119            0 :     void *channelPtr{nullptr};
     120            0 :     CHK_PRT_RET(static_cast<HcclResult>(HcommChannelGet(repRemMem->GetChannel(), &channelPtr)) != HcclResult::HCCL_SUCCESS,
     121              :         HCCL_ERROR("failed to get ccu channel, type[%d]", repRemMem->Type()), HCCL_E_INTERNAL);
     122              : 
     123            0 :     auto *channelImpl = dynamic_cast<CcuUrmaChannel *>(static_cast<Channel *>(channelPtr));
     124            0 :     uint32_t size{0}, tokenId{0}, tokenValue{0};
     125            0 :     uint64_t addr{0};
     126            0 :     CHK_PTR_NULL(channelImpl);
     127            0 :     CHK_PRT_RET(channelImpl->GetRmtBuffer(addr, size, tokenId, tokenValue) != HcclResult::HCCL_SUCCESS,
     128              :         HCCL_ERROR("[CcuRepRemMem][%s] failed to get remote buffer, channelHandle[0x%llx].",
     129              :             __func__, repRemMem->GetChannel()), HCCL_E_UNAVAIL);// 当前认为channel只持有一个buffer
     130              : 
     131            0 :     auto tokenInfo = GetToken(tokenId, tokenValue, 1);
     132              : 
     133            0 :     LoadImdToGSAInstr(instr++, repRemMem->GetRem().addr.Id(), addr);
     134            0 :     LoadImdToXnInstr(instr++, repRemMem->GetRem().token.Id(), tokenInfo, CCU_LOAD_TO_XN_SEC_INFO);
     135              : 
     136            0 :     return HcclResult::HCCL_SUCCESS;
     137              : }
     138              : 
     139            2 : HcclResult CcuInsGeneratorV1::CcuRepLocCpyTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepLocCpy* ccuRepLocCpy, const TransDep &dep)
     140              : {
     141              :     UNUSED(ccuKernel);
     142            2 :     CHK_PTR_NULL(ccuRepLocCpy);
     143            2 :     if (ccuRepLocCpy->GetReduceFlag() == 0) {
     144            1 :         TransLocMemToLocMemInstr(instr++, ccuRepLocCpy->GetDst().addr.Id(), ccuRepLocCpy->GetDst().token.Id(), ccuRepLocCpy->GetSrc().addr.Id(), ccuRepLocCpy->GetSrc().token.Id(), ccuRepLocCpy->GetLen().Id(),
     145            2 :                                 dep.reserveChannalId[0], ccuRepLocCpy->GetSem().Id(), ccuRepLocCpy->GetMask(), 0, 0, 1, 1);
     146              :     } else {
     147              :         // 这个翻译需要验证
     148            1 :         TransLocMemToRmtMemInstr(instr++, ccuRepLocCpy->GetDst().addr.Id(), ccuRepLocCpy->GetDst().token.Id(), ccuRepLocCpy->GetSrc().addr.Id(), ccuRepLocCpy->GetSrc().token.Id(), ccuRepLocCpy->GetLen().Id(),
     149            2 :                                  dep.reserveChannalId[0], ccuRepLocCpy->GetDataType(), ccuRepLocCpy->GetOpType(), ccuRepLocCpy->GetSem().Id(), ccuRepLocCpy->GetMask(), 0, 0, 1, 1, ccuRepLocCpy->GetReduceFlag());
     150              :     }
     151              : 
     152            2 :     return HcclResult::HCCL_SUCCESS;
     153              : }
     154              : 
     155            1 : HcclResult CcuInsGeneratorV1::CcuRepBufWriteTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepBufWrite* ccuRepBufWrite, const TransDep &dep)
     156              : {
     157              :     UNUSED(ccuKernel);
     158              :     UNUSED(dep);
     159            1 :     CHK_PTR_NULL(ccuRepBufWrite);
     160            1 :     void *channelPtr{nullptr};
     161            1 :     CHK_PRT_RET(static_cast<HcclResult>(HcommChannelGet(ccuRepBufWrite->GetChannel(), &channelPtr)) != HcclResult::HCCL_SUCCESS,
     162              :         HCCL_ERROR("failed to get ccu channel, type[%d]", ccuRepBufWrite->Type()), HCCL_E_INTERNAL);
     163              : 
     164            1 :     auto *channelImpl = dynamic_cast<CcuUrmaChannel *>(static_cast<Channel *>(channelPtr));
     165            1 :     CHK_PTR_NULL(channelImpl);
     166            1 :     TransLocMSToRmtMemInstr(instr++, ccuRepBufWrite->GetDst().addr.Id(), ccuRepBufWrite->GetDst().token.Id(), ccuRepBufWrite->GetSrc().Id(), ccuRepBufWrite->GetLen().Id(), channelImpl->GetChannelId(),
     167            2 :                             ccuRepBufWrite->GetSem().Id(), ccuRepBufWrite->GetMask(), 0, 0, 1, 1);
     168              : 
     169            1 :     return HcclResult::HCCL_SUCCESS;
     170              : }
     171              : 
     172            6 : HcclResult CcuInsGeneratorV1::CcuRepBufReduceTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepBufReduce* ccuRepBufReduce)
     173              : {
     174              :     UNUSED(ccuKernel);
     175            6 :     CHK_PTR_NULL(ccuRepBufReduce);
     176            6 :     if (ccuRepBufReduce->GetCount() < CCU_REDUCE_MIN_MS) {
     177            1 :         HCCL_ERROR("count must be at least %u", CCU_REDUCE_MIN_MS);
     178            1 :         return HCCL_E_PARA;
     179              :     }
     180            5 :     if (ccuRepBufReduce->GetCount() > CCU_REDUCE_MAX_MS || ccuRepBufReduce->GetMem().size() > CCU_REDUCE_MAX_MS) {
     181            0 :         HCCL_ERROR("count and mem size must less than %u", CCU_REDUCE_MAX_MS);
     182            0 :         return HCCL_E_PARA;
     183              :     }
     184              : 
     185              :     // 这里需要注意,在数据格式膨胀的情况下,需要传入用来存放输出的MSId
     186              :     // 特别是2P场景,输入MS的数目为2,但是在8bit进,32bit出的场景,输出MS的数目为4
     187              :     // 传入的MS中已经包含了需要使用的输入输出的最大量,因此,这里应该直接去MS的size
     188            5 :     auto mem = ccuRepBufReduce->GetMem();
     189            5 :     uint16_t msId[CCU_REDUCE_MAX_MS] = {0};
     190           21 :     for (uint16_t i = 0; i < mem.size(); i++) {
     191           16 :         msId[i] = mem[i].Id();
     192              :     }
     193              : 
     194            5 :     if (ccuRepBufReduce->GetOpType() == CCU_REDUCE_SUM) {
     195            3 :         if (ccuRepBufReduce->GetOutputDataType() == 1) { // 1是fp16
     196            3 :             AddInstr(instr++, msId, ccuRepBufReduce->GetCount(), ccuRepBufReduce->GetOutputDataType(), ccuRepBufReduce->GetDataType(), ccuRepBufReduce->GetSem().Id(), ccuRepBufReduce->GetMask(), 0, 0, 1, ccuRepBufReduce->GetXnIdLength().Id());
     197            0 :         } else if (ccuRepBufReduce->GetOutputDataType() == 2) { // 2是bf16
     198            0 :             AddInstr(instr++, msId, ccuRepBufReduce->GetCount(), ccuRepBufReduce->GetOutputDataType(), ccuRepBufReduce->GetDataType(), ccuRepBufReduce->GetSem().Id(), ccuRepBufReduce->GetMask(), 0, 0, 1, ccuRepBufReduce->GetXnIdLength().Id());
     199              :         } else {
     200            0 :             AddInstr(instr++, msId, ccuRepBufReduce->GetCount(), 0, ccuRepBufReduce->GetDataType(), ccuRepBufReduce->GetSem().Id(), ccuRepBufReduce->GetMask(), 0, 0, 1, ccuRepBufReduce->GetXnIdLength().Id());
     201              :         }
     202            2 :     } else if (ccuRepBufReduce->GetOpType() == CCU_REDUCE_MAX) {
     203            1 :         MaxInstr(instr++, msId, ccuRepBufReduce->GetCount(), ccuRepBufReduce->GetDataType(), ccuRepBufReduce->GetSem().Id(), ccuRepBufReduce->GetMask(), 0, 0, 1, ccuRepBufReduce->GetXnIdLength().Id());
     204            1 :     } else if (ccuRepBufReduce->GetOpType() == CCU_REDUCE_MIN) {
     205            1 :         MinInstr(instr++, msId, ccuRepBufReduce->GetCount(), ccuRepBufReduce->GetDataType(), ccuRepBufReduce->GetSem().Id(), ccuRepBufReduce->GetMask(), 0, 0, 1, ccuRepBufReduce->GetXnIdLength().Id());
     206              :     }
     207              : 
     208            5 :     return HcclResult::HCCL_SUCCESS;
     209            5 : }
     210              : 
     211          717 : uint32_t CcuInsGeneratorV1::GetInstrCount(CcuRepType repType)
     212              : {
     213          717 :     if (repTypeInstrCount.find(repType) == repTypeInstrCount.end()) {
     214            4 :         Hccl::THROW<Hccl::CcuApiException>("[%s] Unsupported repType[%d]", __func__, repType);
     215              :     }
     216          713 :     return repTypeInstrCount[repType];
     217              : }
     218              : 
     219            6 : HcclResult CcuInsGeneratorV1::CcuRepLocRecordEventTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepLocRecordEvent* ccuRepLocRecordEvent)
     220              : {
     221              :     UNUSED(ccuKernel);
     222            6 :     CHK_PTR_NULL(ccuRepLocRecordEvent);
     223            6 :     SetCKEInstr(instr++, ccuRepLocRecordEvent->GetEvent().Id(), ccuRepLocRecordEvent->GetMask(), 0, 0, 1);
     224              : 
     225            6 :     return HcclResult::HCCL_SUCCESS;
     226              : }
     227              : 
     228           23 : HcclResult CcuInsGeneratorV1::CcuRepLocWaitEventTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepLocWaitEvent* ccuRepLocWaitEvent)
     229              : {
     230              :     UNUSED(ccuKernel);
     231           23 :     CHK_PTR_NULL(ccuRepLocWaitEvent);
     232              :     // SetCKEInstr支持硬件profiling功能
     233           23 :     if (ccuRepLocWaitEvent->GetIsProfiling()) {
     234           12 :         SetCKEInstr(instr++, 0, 0, ccuRepLocWaitEvent->GetEvent().Id(), ccuRepLocWaitEvent->GetMask(), 1);
     235              :     } else {
     236           11 :         ClearCKEInstr(instr++, 0, 0, ccuRepLocWaitEvent->GetEvent().Id(), ccuRepLocWaitEvent->GetMask(), 1);
     237              :     }
     238              : 
     239           23 :     return HcclResult::HCCL_SUCCESS;
     240              : }
     241              : 
     242            2 : HcclResult CcuInsGeneratorV1::CcuRepLocWaitNotifyTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepLocWaitNotify* ccuRepLocWaitNotify)
     243              : {
     244              :     UNUSED(ccuKernel);
     245            2 :     CHK_PTR_NULL(ccuRepLocWaitNotify);
     246              :     // SetCKEInstr支持硬件profiling功能
     247            2 :     if (ccuRepLocWaitNotify->GetIsProfiling()) {
     248            1 :         SetCKEInstr(instr++, 0, 0, ccuRepLocWaitNotify->GetNotify().Id(), ccuRepLocWaitNotify->GetMask(), 1);
     249              :     } else {
     250            1 :         ClearCKEInstr(instr++, 0, 0, ccuRepLocWaitNotify->GetNotify().Id(), ccuRepLocWaitNotify->GetMask(), 1);
     251              :     }
     252              : 
     253            2 :     return HcclResult::HCCL_SUCCESS;
     254              : }
     255              : 
     256            4 : HcclResult CcuInsGeneratorV1::CcuRepRemWaitSemTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepRemWaitSem* cuRepRemWaitSem)
     257              : {
     258              :     UNUSED(ccuKernel);
     259            4 :     CHK_PTR_NULL(cuRepRemWaitSem);
     260            4 :     void *channelPtr{nullptr};
     261            4 :     CHK_PRT_RET(static_cast<HcclResult>(HcommChannelGet(cuRepRemWaitSem->GetChannel(), &channelPtr)) != HcclResult::HCCL_SUCCESS,
     262              :         HCCL_ERROR("failed to get ccu channel, type[%d]", cuRepRemWaitSem->Type()), HCCL_E_INTERNAL);
     263              : 
     264            4 :     auto *channelImpl = dynamic_cast<CcuUrmaChannel *>(static_cast<Channel *>(channelPtr));
     265            4 :     CHK_PTR_NULL(channelImpl);
     266            4 :     uint32_t locCkeId{0};
     267            4 :     CHK_PRT_RET(channelImpl->GetLocCkeByIndex(cuRepRemWaitSem->GetSemIndex(), locCkeId) != HcclResult::HCCL_SUCCESS,
     268              :         HCCL_ERROR("[CcuRepRemWaitSem][%s] failed to get to loc cke id.", __func__), HCCL_E_UNAVAIL);
     269              : 
     270              :     // 需要profiling的使用SetCKEInstr, 否则使用ClearCKEInstr
     271            4 :     if (cuRepRemWaitSem->GetIsProfiling()) {
     272            4 :         SetCKEInstr(instr++, 0, 0, locCkeId, cuRepRemWaitSem->GetMask(), 1);
     273              :     } else {
     274            0 :         ClearCKEInstr(instr++, 0, 0, locCkeId, cuRepRemWaitSem->GetMask(), 1);
     275              :     }
     276              : 
     277            4 :     return HcclResult::HCCL_SUCCESS;
     278              : }
     279              : 
     280            5 : HcclResult CcuInsGeneratorV1::CcuRepRemPostVarTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepRemPostVar* ccuRepRemPostVar)
     281              : {
     282              :     UNUSED(ccuKernel);
     283            5 :     CHK_PTR_NULL(ccuRepRemPostVar);
     284            5 :     void *channelPtr{nullptr};
     285            5 :     CHK_PRT_RET(static_cast<HcclResult>(HcommChannelGet(ccuRepRemPostVar->GetChannel(), &channelPtr)) != HcclResult::HCCL_SUCCESS,
     286              :         HCCL_ERROR("failed to get ccu channel, type[%d]", ccuRepRemPostVar->Type()), HCCL_E_INTERNAL);
     287              : 
     288            5 :     auto *channelImpl = dynamic_cast<CcuUrmaChannel *>(static_cast<Channel *>(channelPtr));
     289            5 :     CHK_PTR_NULL(channelImpl);
     290            5 :     uint32_t rmtXnId{0};
     291            5 :     CHK_PRT_RET(channelImpl->GetRmtXnByIndex(ccuRepRemPostVar->GetParamIndex(), rmtXnId) != HcclResult::HCCL_SUCCESS,
     292              :         HCCL_ERROR("[CcuRepRemPostSem][%s] failed to get remote xn id, channelHandle[0x%llx].",
     293              :             __func__, ccuRepRemPostVar->GetChannel()), HCCL_E_UNAVAIL);
     294              : 
     295            5 :     uint32_t rmtCkeId{0};
     296            5 :     CHK_PRT_RET(channelImpl->GetRmtCkeByIndex(ccuRepRemPostVar->GetSemIndex(), rmtCkeId) != HcclResult::HCCL_SUCCESS,
     297              :         HCCL_ERROR("[CcuRepRemPostSem][%s] failed to get remote cke id, channelHandle[0x%llx].",
     298              :             __func__, ccuRepRemPostVar->GetChannel()), HCCL_E_UNAVAIL);
     299              : 
     300            5 :     SyncXnInstr(instr++, rmtXnId, ccuRepRemPostVar->GetParam().Id(), channelImpl->GetChannelId(),
     301            5 :                 rmtCkeId, ccuRepRemPostVar->GetMask(), 0, 0, 0, 0, 1);
     302              : 
     303            5 :     return HcclResult::HCCL_SUCCESS;
     304              : }
     305              : 
     306            2 : HcclResult CcuInsGeneratorV1::CcuRepRemPostSemTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepRemPostSem* ccuRepRemPostSem, const TransDep &dep)
     307              : {
     308              :     UNUSED(ccuKernel);
     309            2 :     CHK_PTR_NULL(ccuRepRemPostSem);
     310            2 :     void *channelPtr{nullptr};
     311            2 :     CHK_PRT_RET(static_cast<HcclResult>(HcommChannelGet(ccuRepRemPostSem->GetChannel(), &channelPtr)) != HcclResult::HCCL_SUCCESS,
     312              :         HCCL_ERROR("failed to get ccu channel, type[%d]", ccuRepRemPostSem->Type()), HCCL_E_INTERNAL);
     313              : 
     314            2 :     auto *channelImpl = dynamic_cast<CcuUrmaChannel *>(static_cast<Channel *>(channelPtr));
     315            2 :     CHK_PTR_NULL(channelImpl);
     316            2 :     uint32_t rmtCkeId{0};
     317            2 :     CHK_PRT_RET(channelImpl->GetRmtCkeByIndex(ccuRepRemPostSem->GetSemIndex(), rmtCkeId) != HcclResult::HCCL_SUCCESS,
     318              :         HCCL_ERROR("[CcuRepRemPostSem][%s] failed to get remote cke id, channelHandle[0x%llx].",
     319              :             __func__, ccuRepRemPostSem->GetChannel()), HCCL_E_UNAVAIL);
     320              : 
     321            2 :     SyncCKEInstr(instr++, rmtCkeId, dep.reserveCkeId, ccuRepRemPostSem->GetMask(), channelImpl->GetChannelId(), 0,
     322              :                  0, 0, 0, 1);
     323              : 
     324            2 :     return HcclResult::HCCL_SUCCESS;
     325              : }
     326              : 
     327            2 : HcclResult CcuInsGeneratorV1::CcuRepRecordSharedNotifyTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepRecordSharedNotify* ccuRepRecordSharedNotify, const TransDep &dep)
     328              : {
     329              :     UNUSED(ccuKernel);
     330            2 :     CHK_PTR_NULL(ccuRepRecordSharedNotify);
     331              :     // 非本die时利用环回访问
     332            2 :     if (ccuRepRecordSharedNotify->GetNotify().DieId() != dep.dieId) {
     333            1 :         SyncCKEInstr(instr++, ccuRepRecordSharedNotify->GetNotify().Id(), dep.reserveCkeId, ccuRepRecordSharedNotify->GetMask(),
     334            1 :             dep.reserveChannalId[1], 0, 0, 0, 0, 1);
     335              :     } else {
     336            1 :         SetCKEInstr(instr++, ccuRepRecordSharedNotify->GetNotify().Id(), ccuRepRecordSharedNotify->GetMask(), 0, 0, 1);
     337              :     }
     338              : 
     339            2 :     return HcclResult::HCCL_SUCCESS;
     340              : }
     341              : 
     342           84 : HcclResult CcuInsGeneratorV1::CcuRepAddTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepAdd* ccuRepAdd, const TransDep &dep)
     343              : {
     344              :     UNUSED(ccuKernel);
     345           84 :     CHK_PTR_NULL(ccuRepAdd);
     346           84 :     switch (ccuRepAdd->GetSubType()) {
     347            1 :         case AddSubType::ADDR_PLUS_VAR_TO_ADDR: {
     348            1 :             LoadGSAXnInstr(instr++, ccuRepAdd->GetAddrC().Id(), ccuRepAdd->GetAddrA().Id(), ccuRepAdd->GetVarB().Id());
     349            1 :             break;
     350              :         }
     351            2 :         case AddSubType::ADDR_PLUS_ADDR_TO_ADDR: {
     352            2 :             LoadGSAGSAInstr(instr++, ccuRepAdd->GetAddrC().Id(), ccuRepAdd->GetAddrA().Id(), ccuRepAdd->GetAddrB().Id());
     353            2 :             break;
     354              :         }
     355           53 :         case AddSubType::VAR_PLUS_VAR_TO_VAR: {
     356           53 :             LoadXXInstr(instr++, ccuRepAdd->GetVarC().Id(), ccuRepAdd->GetVarA().Id(), ccuRepAdd->GetVarB().Id());
     357           53 :             break;
     358              :         }
     359           27 :         case AddSubType::SELF_ADD_ADDRESS: {
     360           27 :             LoadGSAXnInstr(instr++, ccuRepAdd->GetAddrA().Id(), ccuRepAdd->GetAddrA().Id(), ccuRepAdd->GetVarB().Id());
     361           27 :             break;
     362              :         }
     363            1 :         case AddSubType::SELF_ADD_VARIABLE: {
     364            1 :             LoadXXInstr(instr++, ccuRepAdd->GetVarA().Id(), ccuRepAdd->GetVarA().Id(), ccuRepAdd->GetVarB().Id());
     365            1 :             break;
     366              :         }
     367            0 :         default: {
     368            0 :             HCCL_ERROR("Invalid Add");
     369            0 :             return HCCL_E_PARA;
     370              :         }
     371              :     }
     372              : 
     373           84 :     return HcclResult::HCCL_SUCCESS;
     374              : }
     375              : 
     376          184 : HcclResult CcuInsGeneratorV1::CcuRepAssignTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepAssign* ccuRepAssign, const TransDep &dep)
     377              : {
     378              :     UNUSED(ccuKernel);
     379          184 :     CHK_PTR_NULL(ccuRepAssign);
     380          184 :     switch (ccuRepAssign->GetSubType()) {
     381           96 :         case AssignSubType::IMD_TO_VARIABLE: {
     382           96 :             LoadImdToXnInstr(instr++, ccuRepAssign->GetVarA().Id(), ccuRepAssign->GetImmed());
     383           96 :             break;
     384              :         }
     385            7 :         case AssignSubType::IMD_TO_ADDR: {
     386            7 :             LoadImdToGSAInstr(instr++, ccuRepAssign->GetAddrA().Id(), ccuRepAssign->GetImmed());
     387            7 :             break;
     388              :         }
     389           10 :         case AssignSubType::VAR_TO_ADDR: {
     390           10 :             LoadGSAXnInstr(instr++, ccuRepAssign->GetAddrA().Id(), dep.reserveGsaId, ccuRepAssign->GetVarA().Id());
     391           10 :             break;
     392              :         }
     393           23 :         case AssignSubType::ADDR_TO_ADDR: {
     394           23 :             LoadGSAGSAInstr(instr++, ccuRepAssign->GetAddrB().Id(), ccuRepAssign->GetAddrA().Id(), dep.reserveGsaId);
     395           23 :             break;
     396              :         }
     397           48 :         case AssignSubType::VAR_TO_VAR: {
     398           48 :             LoadXXInstr(instr++, ccuRepAssign->GetVarB().Id(), ccuRepAssign->GetVarA().Id(), dep.reserveXnId);
     399           48 :             break;
     400              :         }
     401            0 :         default: {
     402            0 :             HCCL_ERROR("Invalid Assign");
     403            0 :             return HCCL_E_PARA;
     404              :         }
     405              :     }
     406              : 
     407          184 :     return HcclResult::HCCL_SUCCESS;
     408              : }
     409              : 
     410            0 : HcclResult CcuInsGeneratorV1::CcuRepMulTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepMul* ccuRepMul)
     411              : {
     412              :     UNUSED(ccuKernel);
     413              :     UNUSED(instr);
     414              :     UNUSED(ccuRepMul);
     415            0 :     return HCCL_E_NOT_SUPPORT;
     416              : }
     417              : 
     418            0 : HcclResult CcuInsGeneratorV1::CcuRepSubTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepSub* ccuRepSub)
     419              : {
     420              :     UNUSED(ccuKernel);
     421              :     UNUSED(instr);
     422              :     UNUSED(ccuRepSub);
     423            0 :     return HCCL_E_NOT_SUPPORT;
     424              : }
     425              : 
     426            0 : HcclResult CcuInsGeneratorV1::CcuRepAndTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepAnd* ccuRepAnd, const TransDep &dep)
     427              : {
     428              :     UNUSED(ccuKernel);
     429              :     UNUSED(instr);
     430              :     UNUSED(ccuRepAnd);
     431              :     UNUSED(dep);
     432            0 :     return HCCL_E_NOT_SUPPORT;
     433              : }
     434              : 
     435            0 : HcclResult CcuInsGeneratorV1::CcuRepNotTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepNot* ccuRepNot, const TransDep &dep)
     436              : {
     437              :     UNUSED(ccuKernel);
     438              :     UNUSED(instr);
     439              :     UNUSED(ccuRepNot);
     440              :     UNUSED(dep);
     441            0 :     return HCCL_E_NOT_SUPPORT;
     442              : }
     443              : 
     444            0 : HcclResult CcuInsGeneratorV1::CcuRepOrTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepOr* ccuRepOr, const TransDep &dep)
     445              : {
     446              :     UNUSED(ccuKernel);
     447              :     UNUSED(instr);
     448              :     UNUSED(ccuRepOr);
     449              :     UNUSED(dep);
     450            0 :     return HCCL_E_NOT_SUPPORT;
     451              : }
     452              : 
     453            0 : HcclResult CcuInsGeneratorV1::CcuRepXorTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepXor* ccuRepXor, const TransDep &dep)
     454              : {
     455              :     UNUSED(ccuKernel);
     456              :     UNUSED(instr);
     457              :     UNUSED(ccuRepXor);
     458              :     UNUSED(dep);
     459            0 :     return HCCL_E_NOT_SUPPORT;
     460              : }
     461              : 
     462            0 : HcclResult CcuInsGeneratorV1::CcuRepShLTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepShL* ccuRepShL, const TransDep &dep)
     463              : {
     464              :     UNUSED(ccuKernel);
     465              :     UNUSED(instr);
     466              :     UNUSED(ccuRepShL);
     467              :     UNUSED(dep);
     468            0 :     return HCCL_E_NOT_SUPPORT;
     469              : }
     470              : 
     471            0 : HcclResult CcuInsGeneratorV1::CcuRepShRTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepShR* ccuRepShR, const TransDep &dep)
     472              : {
     473              :     UNUSED(ccuKernel);
     474              :     UNUSED(instr);
     475              :     UNUSED(ccuRepShR);
     476              :     UNUSED(dep);
     477            0 :     return HCCL_E_NOT_SUPPORT;
     478              : }
     479              : 
     480            8 : HcclResult CcuInsGeneratorV1::CcuRepFuncBlockTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId,
     481              :     CcuRepFuncBlock* funcBlockPtr, const TransDep &dep, uint32_t step)
     482              : {
     483              :     UNUSED(ccuKernel);
     484            8 :     CHK_PTR_NULL(funcBlockPtr);
     485            8 :     std::vector<CcuRepArg>& outArgs = funcBlockPtr->GetOutArgs();
     486            8 :     CcuRepReferenceManager* funcManager = funcBlockPtr->GetFuncManager();
     487            8 :     CHK_PTR_NULL(funcManager);
     488            8 :     if (step == 0) {
     489              :         // 函数入口为nop
     490            4 :         LoadImdToXnInstr(instr++, dep.reserveXnId, 0);  // 向记录常量0的Xn再次赋值0作为nop操作
     491            4 :         curInstrId++;
     492            4 :     } else if (step == 1) {
     493              :         // 处理输出的参数
     494            4 :         uint32_t iOutArg = 0;
     495            4 :         for (uint32_t i = 0; i < outArgs.size(); i++) {
     496            0 :             if (outArgs[i].type == CcuArgType::VARIABLE) {
     497            0 :                 LoadXXInstr(instr++, funcManager->GetFuncOut()[iOutArg++].Id(), outArgs[i].var.Id(), dep.reserveXnId);
     498            0 :                 curInstrId++;
     499            0 :             } else if (outArgs[i].type == CcuArgType::VARIABLE_LIST) {
     500            0 :                 for (uint32_t j = 0; j < outArgs[i].varList.size(); j++) {
     501            0 :                     LoadXXInstr(instr++, funcManager->GetFuncOut()[iOutArg++].Id(),
     502            0 :                                 outArgs[i].varList[j].Id(), dep.reserveXnId);
     503            0 :                     curInstrId++;
     504              :                 }
     505              :             }
     506              :         }
     507              :         
     508              :         // 返回调用处
     509            4 :         JumpInstr(instr++, funcManager->GetFuncRet(funcBlockPtr->GetCallLayer()).Id(), dep.reserveXnId, 1);
     510            4 :         curInstrId++;
     511              :     } else {
     512            0 :         HCCL_ERROR("Unsupported step[%d] for CcuRepFuncBlockTranslate", step);
     513            0 :         return HCCL_E_PARA;
     514              :     }
     515            8 :     return HcclResult::HCCL_SUCCESS;
     516              : }
     517              :  
     518            5 : void CcuInsGeneratorV1::LoadFuncCallInArgs(CcuInstr* instr, std::vector<CcuRepArg>& inArgs,
     519              :                                            std::vector<Variable>& formalIns, uint16_t reserveXnId)
     520              : {
     521            5 :     uint32_t idx = 0;
     522           12 :     for (uint32_t i = 0; i < inArgs.size(); i++) {
     523            7 :         if (inArgs[i].type == CcuArgType::VARIABLE) {
     524            7 :             LoadXXInstr(instr + idx, formalIns[idx].Id(), inArgs[i].var.Id(), reserveXnId);
     525            7 :             idx++;
     526            0 :         } else if (inArgs[i].type == CcuArgType::VARIABLE_LIST) {
     527            0 :             for (uint32_t j = 0; j < inArgs[i].varList.size(); j++) {
     528            0 :                 LoadXXInstr(instr + idx, formalIns[idx].Id(), inArgs[i].varList[j].Id(), reserveXnId);
     529            0 :                 idx++;
     530              :             }
     531              :         }
     532              :     }
     533            5 : }
     534              : 
     535            5 : void CcuInsGeneratorV1::LoadFuncCallOutArgs(CcuInstr* instr, uint32_t offset, std::vector<CcuRepArg>& outArgs,
     536              :                                             CcuRepReferenceManager* funcManager, uint16_t reserveXnId)
     537              : {
     538            5 :     uint32_t idx = 0;
     539            5 :     for (uint32_t i = 0; i < outArgs.size(); i++) {
     540            0 :         if (outArgs[i].type == CcuArgType::VARIABLE) {
     541            0 :             LoadXXInstr(instr + offset + idx, outArgs[i].var.Id(), funcManager->GetFuncOut()[idx].Id(), reserveXnId);
     542            0 :             idx++;
     543            0 :         } else if (outArgs[i].type == CcuArgType::VARIABLE_LIST) {
     544            0 :             for (uint32_t j = 0; j < outArgs[i].varList.size(); j++) {
     545            0 :                 LoadXXInstr(instr + offset + idx, outArgs[i].varList[j].Id(), funcManager->GetFuncOut()[idx].Id(),
     546              :                             reserveXnId);
     547            0 :                 idx++;
     548              :             }
     549              :         }
     550              :     }
     551            5 : }
     552              : 
     553            5 : HcclResult CcuInsGeneratorV1::CcuRepFuncCallTranslate(CcuKernel* ccuKernel, CcuInstr *&curInstr, uint16_t &curInstrId,
     554              :     CcuRepFuncCall* funcCallPtr, const TransDep &dep)
     555              : {
     556              :     UNUSED(ccuKernel);
     557              :     (void)curInstrId;
     558              :     (void)curInstr;
     559              : 
     560            5 :     FuncCallContext ctx;
     561            5 :     CHK_RET(PrepareFuncCallContext(funcCallPtr, ctx));
     562              : 
     563            5 :     std::vector<CcuRepArg>& outArgs = funcCallPtr->GetOutArgs();
     564            5 :     std::vector<CcuRepArg>& inArgs = funcCallPtr->GetInArgs();
     565            5 :     uint32_t inArgCount = ctx.inArgCount;
     566            5 :     CcuInstr* instr = ctx.instr;
     567            5 :     CcuRepReferenceManager* funcManager = ctx.funcManager;
     568            5 :     std::vector<Variable>& formalIns = ctx.formalIns;
     569            5 :     std::shared_ptr<CcuRepFuncBlock>& funcBlock = ctx.funcBlock;
     570            5 :     LoadFuncCallInArgs(instr, inArgs, formalIns, dep.reserveXnId);
     571              :  
     572            5 :     uint32_t locId = 0;
     573            5 :     if (funcBlock != nullptr) {
     574            5 :         LoadImdToXnInstr(instr + inArgCount + locId++, funcManager->GetFuncCall().Id(), funcBlock->StartInstrId());
     575              :     } else {
     576            0 :         LoadXXInstr(instr + inArgCount + locId++,
     577            0 :                     funcManager->GetFuncCall().Id(), funcCallPtr->GetFuncAddrVar().Id(), dep.reserveXnId);
     578              :     }
     579              :  
     580            5 :     LoadImdToXnInstr(instr + inArgCount + locId++, funcManager->GetFuncRet(funcCallPtr->GetCallLayer()).Id(),
     581            5 :                      funcCallPtr->StartInstrId() + inArgCount + 3); // 需要指向函数返回位置,为输入指令Id + 3
     582            5 :     JumpInstr(instr + inArgCount + locId++, funcManager->GetFuncCall().Id(), dep.reserveXnId, 1);
     583            5 :     LoadImdToXnInstr(instr + inArgCount + locId++, dep.reserveXnId, 0);
     584              :  
     585            5 :     uint32_t extraInstrNum = GetInstrCount(funcCallPtr->Type());
     586            5 :     LoadFuncCallOutArgs(instr, inArgCount + extraInstrNum, outArgs, funcManager, dep.reserveXnId);
     587            5 :     return HcclResult::HCCL_SUCCESS;
     588            5 : }
     589              :  
     590            6 : HcclResult CcuInsGeneratorV1::CcuRepJumpTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId,
     591              :     CcuRepJump* jumpPtr, const TransDep &dep)
     592              : {
     593              :     UNUSED(ccuKernel);
     594              :     (void)instr;
     595              :     (void)curInstrId;
     596              : 
     597              :     // 翻译直接跳转指令
     598            6 :     CHK_PTR_NULL(jumpPtr);
     599            6 :     std::shared_ptr<CcuRepJumpLabel> jumpLabel = jumpPtr->GetJumpLabel();
     600            6 :     CHK_PTR_NULL(jumpLabel);
     601            6 :     LoadImdToXnInstr(jumpPtr->GetInstr() + 0, jumpPtr->GetTargetInstrId().Id(), jumpLabel->StartInstrId());
     602            6 :     JumpInstr(jumpPtr->GetInstr() + 1, jumpPtr->GetTargetInstrId().Id(), dep.reserveXnId, 1);
     603              :  
     604            6 :     return HcclResult::HCCL_SUCCESS;
     605            6 : }
     606              :  
     607           13 : HcclResult CcuInsGeneratorV1::CcuRepJumpNETranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId,
     608              :     CcuRepJumpNE* jumpNEPtr, const TransDep &dep)
     609              : {
     610              :     UNUSED(ccuKernel);
     611              :     UNUSED(instr);
     612              :     UNUSED(curInstrId);
     613           13 :     CHK_PTR_NULL(jumpNEPtr);
     614           13 :     std::shared_ptr<CcuRepJumpLabel> jumpLabel = jumpNEPtr->GetJumpLabel();
     615           13 :     CHK_PTR_NULL(jumpLabel);
     616           13 :     LoadImdToXnInstr(jumpNEPtr->GetInstr() + 0, jumpNEPtr->GetTargetInstrId().Id(), jumpLabel->StartInstrId());
     617           13 :     JumpInstr(jumpNEPtr->GetInstr() + 1, jumpNEPtr->GetTargetInstrId().Id(), jumpNEPtr->GetCondition().Id(),
     618              :                 jumpNEPtr->GetExpectedNum());
     619              :  
     620           13 :     return HcclResult::HCCL_SUCCESS;
     621           13 : }
     622              :  
     623           10 : HcclResult CcuInsGeneratorV1::CcuRepJumpEQTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId,
     624              :     CcuRepJumpEQ* jumpEQPtr, const TransDep &dep)
     625              : {
     626              :     UNUSED(ccuKernel);
     627              :     UNUSED(instr);
     628              :     UNUSED(curInstrId);
     629              :     
     630           10 :     CHK_PTR_NULL(jumpEQPtr);
     631           10 :     std::shared_ptr<CcuRepJumpLabel> jumpLabel = jumpEQPtr->GetJumpLabel();
     632           10 :     CHK_PTR_NULL(jumpLabel);
     633           10 :     uint32_t localInstrIndex = 0;
     634           10 :     CcuInstr* startInstr = jumpEQPtr->GetInstr();
     635           10 :     Variable& targetInstrId = jumpEQPtr->GetTargetInstrId();
     636           10 :     LoadImdToXnInstr(startInstr + localInstrIndex++, targetInstrId.Id(), jumpEQPtr->StartInstrId() + 4); // 需要指向NOP位置,为输入指令Id + 4
     637           10 :     JumpInstr(startInstr + localInstrIndex++, targetInstrId.Id(), jumpEQPtr->GetCondition().Id(), jumpEQPtr->GetExpectedNum());
     638           10 :     LoadImdToXnInstr(startInstr + localInstrIndex++, targetInstrId.Id(), jumpLabel->StartInstrId());
     639           10 :     JumpInstr(startInstr + localInstrIndex++, targetInstrId.Id(), dep.reserveXnId, 1);
     640           10 :     LoadImdToXnInstr(startInstr + localInstrIndex++, dep.reserveXnId, 0);
     641              :  
     642           10 :     return HcclResult::HCCL_SUCCESS;
     643           10 : }
     644              :  
     645            0 : HcclResult CcuInsGeneratorV1::CcuRepJumpLETranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId,
     646              :     CcuRepJumpLE* jumpLEPtr, const TransDep &dep)
     647              : {
     648              :     UNUSED(ccuKernel);
     649              :     (void)instr;
     650              :     (void)curInstrId;
     651            0 :     CHK_PTR_NULL(jumpLEPtr);
     652            0 :     HCCL_ERROR("Unsupported Jump type for CcuV1: %s", jumpLEPtr->Describe().c_str());
     653            0 :     return HCCL_E_NOT_SUPPORT;
     654              : }
     655              :  
     656            0 : HcclResult CcuInsGeneratorV1::CcuRepJumpGETranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId,
     657              :     CcuRepJumpGE* jumpGEPtr, const TransDep &dep)
     658              : {
     659              :     UNUSED(ccuKernel);
     660              :     (void)instr;
     661              :     (void)curInstrId;
     662            0 :     CHK_PTR_NULL(jumpGEPtr);
     663            0 :     HCCL_ERROR("Unsupported Jump type for CcuV1: %s", jumpGEPtr->Describe().c_str());
     664            0 :     return HCCL_E_NOT_SUPPORT;
     665              : }
     666              :  
     667            0 : HcclResult CcuInsGeneratorV1::CcuRepJumpGTTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId,
     668              :     CcuRepJumpGT* jumpGTPtr, const TransDep &dep)
     669              : {
     670              :     UNUSED(ccuKernel);
     671              :     (void)instr;
     672              :     (void)curInstrId;
     673            0 :     CHK_PTR_NULL(jumpGTPtr);
     674            0 :     HCCL_ERROR("Unsupported Jump type for CcuV1: %s", jumpGTPtr->Describe().c_str());
     675            0 :     return HCCL_E_NOT_SUPPORT;
     676              : }
     677              :  
     678            0 : HcclResult CcuInsGeneratorV1::CcuRepJumpLTTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId,
     679              :     CcuRepJumpLT* jumpLTPtr, const TransDep &dep)
     680              : {
     681              :     UNUSED(ccuKernel);
     682              :     (void)instr;
     683              :     (void)curInstrId;
     684            0 :     CHK_PTR_NULL(jumpLTPtr);
     685            0 :     HCCL_ERROR("Unsupported Jump type for CcuV1: %s", jumpLTPtr->Describe().c_str());
     686            0 :     return HCCL_E_NOT_SUPPORT;
     687              : }
     688              : 
     689              : 
     690            0 : HcclResult CcuInsGeneratorV1::CcuRepLoopTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId, CcuRepLoop* loopPtr)
     691              : {
     692              :     UNUSED(ccuKernel);
     693              :     UNUSED(curInstrId);
     694            0 :     CHK_PTR_NULL(loopPtr);
     695            0 :     auto loopBlock = loopPtr->GetLoopBlock();
     696            0 :     CHK_PTR_NULL(loopBlock);
     697              : 
     698            0 :     LoopInstr(instr++, loopBlock->StartInstrId(),
     699            0 :                 loopBlock->StartInstrId() + loopBlock->InstrCount() - 1, loopPtr->GetLoopParam()->Id());
     700            0 :     return HcclResult::HCCL_SUCCESS;
     701              : }
     702              :  
     703            0 : HcclResult CcuInsGeneratorV1::LoadLoopCallArg(CcuInstr*& instr, const CcuRepArg& inArg, const CcuRepArg& blkArg,
     704              :                                               const TransDep& dep)
     705              : {
     706            0 :     switch (inArg.type) {
     707            0 :         case CcuArgType::VARIABLE:
     708            0 :             LoadXXInstr(instr++, blkArg.var.Id(), inArg.var.Id(), dep.reserveXnId);
     709            0 :             break;
     710            0 :         case CcuArgType::VARIABLE_LIST:
     711            0 :             if (inArg.varList.size() != blkArg.varList.size()) {
     712            0 :                 HCCL_ERROR("Mismatched Arg Size");
     713            0 :                 return HCCL_E_PARA;
     714              :             }
     715            0 :             for (uint32_t j = 0; j < inArg.varList.size(); j++) {
     716            0 :                 LoadXXInstr(instr++, blkArg.varList[j].Id(), inArg.varList[j].Id(), dep.reserveXnId);
     717              :             }
     718            0 :             break;
     719            0 :         case CcuArgType::MEMORY:
     720            0 :             LoadAddrArg(instr, blkArg.mem, inArg.mem, dep);
     721            0 :             break;
     722            0 :         case CcuArgType::LOCAL_ADDR:
     723            0 :             LoadAddrArg(instr, blkArg.localAddr, inArg.localAddr, dep);
     724            0 :             break;
     725            0 :         case CcuArgType::REMOTE_ADDR:
     726            0 :             LoadAddrArg(instr, blkArg.remoteAddr, inArg.remoteAddr, dep);
     727            0 :             break;
     728            0 :         case CcuArgType::MEMORY_LIST:
     729            0 :             CHK_RET(LoadAddrListArg(instr, blkArg.memList, inArg.memList, dep));
     730            0 :             break;
     731            0 :         case CcuArgType::LOCAL_ADDR_LIST:
     732            0 :             CHK_RET(LoadAddrListArg(instr, blkArg.localAddrList, inArg.localAddrList, dep));
     733            0 :             break;
     734            0 :         case CcuArgType::REMOTE_ADDR_LIST:
     735            0 :             CHK_RET(LoadAddrListArg(instr, blkArg.remoteAddrList, inArg.remoteAddrList, dep));
     736            0 :             break;
     737            0 :         default:
     738            0 :             HCCL_ERROR("Mismatched Arg Type");
     739            0 :             return HCCL_E_PARA;
     740              :     }
     741            0 :     return HcclResult::HCCL_SUCCESS;
     742              : }
     743              : 
     744            0 : HcclResult CcuInsGeneratorV1::CcuRepLoopCallTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId,
     745              :     CcuRepLoopCall* loopCallPtr, const TransDep &dep)
     746              : {
     747              :     UNUSED(ccuKernel);
     748              :     UNUSED(curInstrId);
     749            0 :     CHK_PTR_NULL(loopCallPtr);
     750            0 :     auto loopBlock = loopCallPtr->GetLoopBlock();
     751            0 :     CHK_PTR_NULL(loopBlock);
     752            0 :     std::vector<CcuRepArg> &inArgs = loopCallPtr->GetInArgs();
     753              :  
     754            0 :     for (uint32_t i = 0; i < inArgs.size(); i++) {
     755            0 :         const CcuRepArg& blkArg = loopBlock->GetArg(i);
     756            0 :         const CcuRepArg& inArg = inArgs[i];
     757            0 :         if (inArg.type != blkArg.type) {
     758            0 :             HCCL_ERROR("Mismatched Arg Type");
     759            0 :             return HCCL_E_PARA;
     760              :         }
     761            0 :         CHK_RET(LoadLoopCallArg(instr, inArg, blkArg, dep));
     762              :     }
     763              :  
     764            0 :     return HcclResult::HCCL_SUCCESS;
     765            0 : }
     766              :  
     767            0 : HcclResult CcuInsGeneratorV1::CcuRepSetLoopTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId, CcuRepSetLoop* setLoopPtr)
     768              : {
     769              :     UNUSED(ccuKernel);
     770              :     (void)curInstrId;
     771            0 :     CHK_PTR_NULL(setLoopPtr);
     772            0 :     LoadImdToXnInstr(instr++, setLoopPtr->loopParam.Id(), GetLoopParam(setLoopPtr->executor.Id(), 0, 0));
     773            0 :     LoadXXInstr(instr++, setLoopPtr->loopParam.Id(), setLoopPtr->loopParam.Id(), setLoopPtr->var.Id());
     774            0 :     return HcclResult::HCCL_SUCCESS;
     775              : }
     776              :  
     777            3 : HcclResult CcuInsGeneratorV1::CcuRepLoadTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId,
     778              :     CcuRepLoad* loadPtr, const TransDep &dep)
     779              : {
     780              :     UNUSED(ccuKernel);
     781              :     (void)curInstrId;
     782            3 :     CHK_PTR_NULL(loadPtr);
     783            3 :     uint64_t varAddr = dep.xnBaseAddr[dep.dieId] + CCU_RESOURCE_XN_PER_SIZE * loadPtr->GetVar().Id();
     784              :  
     785            3 :     LoadImdToGSAInstr(instr++, dep.commGsa[0], varAddr);
     786            3 :     LoadImdToGSAInstr(instr++, dep.commGsa[1], loadPtr->GetAddr());
     787            3 :     LoadImdToXnInstr(instr++, dep.commXn[0], dep.ccuResSpaceTokenInfo, CCU_LOAD_TO_XN_SEC_INFO);
     788            3 :     LoadImdToXnInstr(instr++, dep.commXn[1], dep.memTokenInfo, CCU_LOAD_TO_XN_SEC_INFO);
     789            3 :     LoadImdToXnInstr(instr++, dep.commXn[2], CCU_RESOURCE_XN_PER_SIZE * loadPtr->GetNum());
     790            3 :     TransLocMemToLocMemInstr(instr++, dep.commGsa[0], dep.commXn[0], dep.commGsa[1], dep.commXn[1], dep.commXn[2],
     791            3 :                              dep.reserveChannalId[0], dep.commSignal, loadPtr->GetMask(), 0, 0, 1, 1);
     792            3 :     SetCKEInstr(instr++, 0, 0, dep.commSignal, loadPtr->GetMask(), 1);
     793              :  
     794            3 :     return HcclResult::HCCL_SUCCESS;
     795              : }
     796              :  
     797            3 : HcclResult CcuInsGeneratorV1::CcuRepLoadVarTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId,
     798              :     CcuRepLoadVar* loadVarPtr, const TransDep &dep)
     799              : {
     800              :     UNUSED(ccuKernel);
     801              :     (void)curInstrId;
     802            3 :     CHK_PTR_NULL(loadVarPtr);
     803            3 :     uint64_t varAddr = dep.xnBaseAddr[dep.dieId] + CCU_RESOURCE_XN_PER_SIZE * loadVarPtr->GetVar().Id();
     804            3 :     LoadImdToGSAInstr(instr++, dep.commGsa[0], varAddr);
     805            3 :     LoadGSAXnInstr(instr++, dep.commGsa[1], dep.reserveGsaId, loadVarPtr->GetSrc().Id());
     806            3 :     LoadImdToXnInstr(instr++, dep.commXn[0], dep.ccuResSpaceTokenInfo, CCU_LOAD_TO_XN_SEC_INFO);
     807            3 :     LoadImdToXnInstr(instr++, dep.commXn[1], dep.memTokenInfo, CCU_LOAD_TO_XN_SEC_INFO);
     808            3 :     LoadImdToXnInstr(instr++, dep.commXn[2], CCU_RESOURCE_XN_PER_SIZE * loadVarPtr->GetNum());
     809            3 :     TransLocMemToLocMemInstr(instr++, dep.commGsa[0], dep.commXn[0], dep.commGsa[1], dep.commXn[1], dep.commXn[2],
     810            3 :                              dep.reserveChannalId[0], dep.commSignal, loadVarPtr->GetMask(), 0, 0, 1, 1);
     811            3 :     SetCKEInstr(instr++, 0, 0, dep.commSignal, loadVarPtr->GetMask(), 1);
     812              :  
     813            3 :     return HcclResult::HCCL_SUCCESS;
     814              : }
     815              :  
     816           34 : HcclResult CcuInsGeneratorV1::CcuRepLoadArgTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId,
     817              :     CcuRepLoadArg* loadArgPtr, const TransDep &dep)
     818              : {
     819              :     UNUSED(ccuKernel);
     820              :     (void)curInstrId;
     821           34 :     CHK_PTR_NULL(loadArgPtr);
     822           34 :     if (dep.isFuncBlock) {
     823              :         // Xn(var) = Xn(loadXnId) + 0
     824            1 :         LoadXXInstr(instr++, loadArgPtr->GetVar().Id(), dep.loadXnId, dep.reserveXnId);
     825              :     } else {
     826           33 :         LoadSqeArgsToXnInstr(instr++, loadArgPtr->GetVar().Id(), loadArgPtr->GetArgId());
     827              :     }
     828              :  
     829           34 :     return HcclResult::HCCL_SUCCESS;
     830              : }
     831              :  
     832           35 : HcclResult CcuInsGeneratorV1::CcuRepNopTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId, CcuRepNop* nopPtr, const TransDep &dep)
     833              : {
     834              :     UNUSED(ccuKernel);
     835              :     (void)curInstrId;
     836              :     (void)nopPtr;
     837           35 :     LoadImdToXnInstr(instr++, dep.reserveXnId, 0);
     838              :  
     839           35 :     return HcclResult::HCCL_SUCCESS;
     840              : }
     841              :  
     842            3 : HcclResult CcuInsGeneratorV1::CcuRepStoreTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId,
     843              :     CcuRepStore* storePtr, const TransDep &dep)
     844              : {
     845              :     UNUSED(ccuKernel);
     846              :     (void)curInstrId;
     847            3 :     CHK_PTR_NULL(storePtr);
     848            3 :     uint64_t varAddr = dep.xnBaseAddr[dep.dieId] + CCU_RESOURCE_XN_PER_SIZE * storePtr->GetVar().Id();
     849              :  
     850            3 :     LoadImdToGSAInstr(instr++, dep.commGsa[0], storePtr->GetAddr());
     851            3 :     LoadImdToGSAInstr(instr++, dep.commGsa[1], varAddr);
     852            3 :     LoadImdToXnInstr(instr++, dep.commXn[0], dep.memTokenInfo, CCU_LOAD_TO_XN_SEC_INFO);
     853            3 :     LoadImdToXnInstr(instr++, dep.commXn[1], dep.ccuResSpaceTokenInfo, CCU_LOAD_TO_XN_SEC_INFO);
     854            3 :     LoadImdToXnInstr(instr++, dep.commXn[2], CCU_RESOURCE_XN_PER_SIZE * storePtr->GetNum());
     855            3 :     TransLocMemToLocMemInstr(instr++, dep.commGsa[0], dep.commXn[0], dep.commGsa[1], dep.commXn[1], dep.commXn[2],
     856            3 :                              dep.reserveChannalId[0], dep.commSignal, storePtr->GetMask(), 0, 0, 1, 1);
     857            3 :     SetCKEInstr(instr++, 0, 0, dep.commSignal, storePtr->GetMask(), 1);
     858              :  
     859            3 :     return HcclResult::HCCL_SUCCESS;
     860              : }
     861              :  
     862            3 : HcclResult CcuInsGeneratorV1::CcuRepStoreVarTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId,
     863              :     CcuRepStoreVar* storeVarPtr, const TransDep &dep)
     864              : {
     865              :     UNUSED(ccuKernel);
     866              :     (void)curInstrId;
     867            3 :     CHK_PTR_NULL(storeVarPtr);
     868            3 :     uint64_t varAddr = dep.xnBaseAddr[dep.dieId] + CCU_RESOURCE_XN_PER_SIZE * storeVarPtr->GetVar().Id();
     869              : 
     870            3 :     LoadImdToGSAInstr(instr++, dep.commGsa[0], varAddr);
     871            3 :     LoadGSAXnInstr(instr++, dep.commGsa[1], dep.reserveGsaId, storeVarPtr->GetDst().Id());
     872            3 :     LoadImdToXnInstr(instr++, dep.commXn[0], dep.memTokenInfo, CCU_LOAD_TO_XN_SEC_INFO);
     873            3 :     LoadImdToXnInstr(instr++, dep.commXn[1], dep.ccuResSpaceTokenInfo, CCU_LOAD_TO_XN_SEC_INFO);
     874            3 :     LoadImdToXnInstr(instr++, dep.commXn[2], CCU_RESOURCE_XN_PER_SIZE * storeVarPtr->GetNum());
     875            3 :     TransLocMemToLocMemInstr(instr++, dep.commGsa[1], dep.commXn[1], dep.commGsa[0], dep.commXn[0], dep.commXn[2],
     876            3 :                              dep.reserveChannalId[0], dep.commSignal, storeVarPtr->GetMask(), 0, 0, 1, 1);
     877            3 :     SetCKEInstr(instr++, 0, 0, dep.commSignal, storeVarPtr->GetMask(), 1);
     878              : 
     879            3 :     return HcclResult::HCCL_SUCCESS;
     880              : }
     881              : 
     882           20 : HcclResult CcuInsGeneratorV1::CcuRepLoopGroupBundleTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId,
     883              :     CcuRepLoopGroupBundle* bundlePtr, const TransDep &dep)
     884              : {
     885              :     UNUSED(ccuKernel);
     886           20 :     CHK_PTR_NULL(bundlePtr);
     887           20 :     const auto &loops = bundlePtr->GetLoops();
     888              : 
     889           58 :     for (const auto &loop : loops) {
     890           38 :         if (loop.layout == CcuRepLoopGroupBundle::Layout::Config) {
     891           19 :             uint64_t lpImm = GetLoopParam(loop.executor.Id(), loop.config.addrOffset, loop.config.iterNum);
     892           19 :             LoadImdToXnInstr(instr++, loop.loopParamVar.Id(), lpImm);
     893           19 :             curInstrId++;
     894              :         } else {
     895           19 :             uint64_t ctxImm = static_cast<uint64_t>(loop.executor.Id()) << 45;  // 左移45位到对应字段然后相加
     896           19 :             LoadImdToXnInstr(instr++, dep.reserveXnId, ctxImm);
     897           19 :             curInstrId++;
     898           19 :             LoadXXInstr(instr++, loop.loopParamVar.Id(), loop.loopParamVar.Id(), dep.reserveXnId);
     899           19 :             curInstrId++;
     900              :         }
     901              :     }
     902              : 
     903           20 :     if (bundlePtr->GetLayout() == CcuRepLoopGroupBundle::Layout::Config) {
     904           10 :         uint64_t parallelImm = GetParallelParam(bundlePtr->GetConfig().cloneNum, bundlePtr->GetRepeatLoopIdx(),
     905              :                                                 bundlePtr->GetTotalLoopNum());
     906           10 :         LoadImdToXnInstr(instr++, bundlePtr->GetParallelVar().Id(), parallelImm);
     907           10 :         curInstrId++;
     908              : 
     909           10 :         uint64_t offsetImm = ::hcomm::CcuRep::GetOffsetParam(bundlePtr->GetConfig().addrOffset,
     910           10 :                                                              bundlePtr->GetConfig().ccuBufferOffset,
     911           10 :                                                              bundlePtr->GetConfig().eventOffset);
     912           10 :         LoadImdToXnInstr(instr++, bundlePtr->GetOffsetParam().Id(), offsetImm);
     913           10 :         curInstrId++;
     914              :     }
     915              : 
     916           20 :     LoopGroupInstr(instr++, curInstrId + 3, bundlePtr->GetParallelVar().Id(), bundlePtr->GetOffsetParam().Id(), 0);  // 向后3条为loop指令
     917           20 :     curInstrId++;
     918              : 
     919           20 :     uint16_t loopCount = static_cast<uint16_t>(loops.size());
     920           20 :     uint16_t jumpTargetInstrId = curInstrId + 2 + loopCount + 1;  // 跳转目标为向后2条+loop指令条数+额外1条
     921           20 :     LoadImdToXnInstr(instr++, dep.reserveXnId, jumpTargetInstrId);
     922           20 :     curInstrId++;
     923           20 :     JumpInstr(instr++, dep.reserveXnId, dep.reserveXnId, 1);
     924           20 :     curInstrId++;
     925              : 
     926           58 :     for (const auto &loop : loops) {
     927           38 :         const auto &block = loop.repLoopBlock;
     928           38 :         CHK_PTR_NULL(block);
     929           38 :         LoopInstr(instr++, block->StartInstrId(),
     930           38 :                   block->StartInstrId() + block->InstrCount() - 1,
     931           38 :                   loop.loopParamVar.Id());
     932           38 :         curInstrId++;
     933              :     }
     934              : 
     935           20 :     LoadImdToXnInstr(instr++, dep.reserveXnId, 0);
     936           20 :     curInstrId++;
     937              : 
     938           20 :     return HcclResult::HCCL_SUCCESS;
     939              : }
     940              : 
     941           55 : uint16_t CcuInsGeneratorV1::CcuRepLoopGroupBundleInstrCount(CcuRepLoopGroupBundle* bundlePtr)
     942              : {
     943           55 :     if (bundlePtr == nullptr) {
     944            0 :         Hccl::THROW<Hccl::CcuApiException>("[%s] bundlePtr is nullptr", __func__);
     945              :     }
     946           55 :     const auto &loops = bundlePtr->GetLoops();
     947           55 :     const uint16_t loopCount = static_cast<uint16_t>(loops.size());
     948           55 :     uint16_t varBasedLoopCount = 0;
     949          164 :     for (const auto &loop : loops) {
     950          109 :         if (loop.layout != CcuRepLoopGroupBundle::Layout::Config) {
     951           57 :             varBasedLoopCount++;
     952              :         }
     953              :     }
     954              :     // 每 loop:config 1 条载入 / var 2 条;config bundle 额外 2 条(parallel+offset);+loopgroup1 +跳过2 +每loop Loop1 +收尾1
     955           55 :     const uint16_t groupOffset = (loopCount - varBasedLoopCount) + (varBasedLoopCount * 2)
     956           55 :         + (bundlePtr->GetLayout() == CcuRepLoopGroupBundle::Layout::Config ? 2 : 0);
     957           55 :     return groupOffset + 1 + 2 + loopCount + 1;  // 跳过2条
     958              : }
     959              : 
     960              : }
     961              : }  // namespace hcomm
        

Generated by: LCOV version 2.0-1