LCOV - code coverage report
Current view: top level - base_comm/primitives/api_c_adpt/ccu - ccu_primitives_impl.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 85.7 % 560 480
Test Date: 2026-08-04 10:52:23 Functions: 92.9 % 85 79

            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              : 
      11              : #include "ccu_primitives_impl.h"
      12              : 
      13              : #include "ccu_log.h"
      14              : #include "hcom_common.h"
      15              : 
      16              : #include "ccu_kernel_mgr.h"
      17              : 
      18              : namespace {
      19              : // strict 校验:magic 不符 / version 越界 / size 不匹配当前版本一律拒绝。
      20           40 : CcuResult ValidateCcuCfgHeader(const CcuCfgHeader *header, uint32_t expectSize, uint32_t maxVersion)
      21              : {
      22           40 :     if (header == nullptr) {
      23            0 :         return CcuResult::CCU_E_PTR;
      24              :     }
      25           40 :     if (header->magic != CCU_CFG_MAGIC_WORD) {
      26            2 :         HCCL_ERROR("[ValidateCcuCfgHeader] bad magic 0x%x", header->magic);
      27            2 :         return CcuResult::CCU_E_PARA;
      28              :     }
      29           38 :     if (header->version == 0 || header->version > maxVersion) {
      30            0 :         HCCL_ERROR("[ValidateCcuCfgHeader] bad version %u (max %u)", header->version, maxVersion);
      31            0 :         return CcuResult::CCU_E_PARA;
      32              :     }
      33           38 :     if (header->size != expectSize) {
      34            0 :         HCCL_ERROR("[ValidateCcuCfgHeader] bad size %u (expect %u)", header->size, expectSize);
      35            0 :         return CcuResult::CCU_E_PARA;
      36              :     }
      37           38 :     return CcuResult::CCU_SUCCESS;
      38              : }
      39              : }  // namespace
      40              : 
      41              : //Alloc 相关接口
      42          431 : CcuResult CcuVariableAlloc(CcuVariableHandle *varHandle)
      43              : {
      44          431 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
      45          431 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
      46          431 :     CCU_CHK_PTR_NULL(kernel);
      47          431 :     CCU_CHK_RET(kernel->VariableAlloc(varHandle));
      48          431 :     return CcuResult::CCU_SUCCESS;
      49              : }
      50              : 
      51           10 : CcuResult CcuAddressAlloc(CcuAddressHandle *addrHandle)
      52              : {
      53           10 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
      54           10 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
      55           10 :     CCU_CHK_PTR_NULL(kernel);
      56           10 :     CCU_CHK_RET(kernel->AddressAlloc(addrHandle));
      57           10 :     return CcuResult::CCU_SUCCESS;
      58              : }
      59              : 
      60            9 : CcuResult CcuEventAlloc(CcuEventHandle *eventHandle)
      61              : {
      62            9 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
      63            9 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
      64            9 :     CCU_CHK_PTR_NULL(kernel);
      65            9 :     CCU_CHK_RET(kernel->EventAlloc(eventHandle));
      66            9 :     return CcuResult::CCU_SUCCESS;
      67              : }
      68              : 
      69            1 : CcuResult CcuBufferAlloc(CcuBufferHandle *bufHandle)
      70              : {
      71            1 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
      72            1 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
      73            1 :     CCU_CHK_PTR_NULL(kernel);
      74            1 :     CCU_CHK_RET(kernel->BufferAlloc(bufHandle));
      75            1 :     return CcuResult::CCU_SUCCESS;
      76              : }
      77              : 
      78          154 : CcuResult CcuLocalAddrAlloc(CcuLocalAddrHandle *localAddrHandle, CcuAddressHandle *addrHandle, CcuVariableHandle *tokenHandle)
      79              : {
      80          154 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
      81          154 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
      82          154 :     CCU_CHK_PTR_NULL(kernel);
      83          154 :     CCU_CHK_RET(kernel->LocalAddrAlloc(localAddrHandle, addrHandle, tokenHandle));
      84          154 :     return CcuResult::CCU_SUCCESS;
      85              : }
      86              : 
      87           37 : CcuResult CcuRemoteAddrAlloc(CcuRemoteAddrHandle *remoteAddrHandle, CcuAddressHandle *addrHandle, CcuVariableHandle *tokenHandle)
      88              : {
      89           37 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
      90           37 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
      91           37 :     CCU_CHK_PTR_NULL(kernel);
      92           37 :     CCU_CHK_RET(kernel->RemoteAddrAlloc(remoteAddrHandle, addrHandle, tokenHandle));
      93           37 :     return CcuResult::CCU_SUCCESS;
      94              : }
      95              : 
      96            6 : CcuResult CcuBlockVariableAlloc(CcuVariableHandle *varHandles, uint32_t count)
      97              : {
      98            6 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
      99            6 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     100            6 :     CCU_CHK_PTR_NULL(kernel);
     101            6 :     CCU_CHK_RET(kernel->BlockVariableAlloc(varHandles, count));
     102            6 :     return CcuResult::CCU_SUCCESS;
     103              : }
     104              : 
     105            6 : CcuResult CcuBlockEventAlloc(CcuEventHandle *eventHandles, uint32_t count)
     106              : {
     107            6 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     108            6 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     109            6 :     CCU_CHK_PTR_NULL(kernel);
     110            6 :     CCU_CHK_RET(kernel->BlockEventAlloc(eventHandles, count));
     111            6 :     return CcuResult::CCU_SUCCESS;
     112              : }
     113            6 : CcuResult CcuBlockBufferAlloc(CcuBufferHandle *bufHandles, uint32_t count)
     114              : {
     115            6 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     116            6 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     117            6 :     CCU_CHK_PTR_NULL(kernel);
     118            6 :     CCU_CHK_RET(kernel->BlockBufferAlloc(bufHandles, count));
     119            6 :     return CcuResult::CCU_SUCCESS;
     120              : }
     121           14 : CcuResult CcuVariableCreateByChannel(ChannelHandle channel, uint32_t varIndex, CcuVariableHandle *varHandle)
     122              : {
     123           14 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     124           14 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     125           14 :     CCU_CHK_PTR_NULL(kernel);
     126           14 :     CCU_CHK_RET(kernel->VariableCreateByChannel(channel, varIndex, varHandle));
     127           14 :     return CcuResult::CCU_SUCCESS;
     128              : }
     129              : 
     130              : //Variable操作类 相关接口
     131          206 : CcuResult CcuVariableAssignImm(CcuVariableHandle resVar, uint64_t immediate)
     132              : {
     133          206 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     134          206 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     135          206 :     CCU_CHK_PTR_NULL(kernel);
     136          206 :     CCU_CHK_RET(kernel->VariableAssignImm(resVar, immediate));
     137              :     
     138          206 :     return CcuResult::CCU_SUCCESS;
     139              : }
     140           77 : CcuResult CcuVariableAssignVar(CcuVariableHandle dstVarHandle, CcuVariableHandle srcVarHandle)
     141              : {
     142           77 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     143           77 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     144           77 :     CCU_CHK_PTR_NULL(kernel);
     145           77 :     CCU_CHK_RET(kernel->VariableAssignVar(dstVarHandle, srcVarHandle));
     146              :     
     147           77 :     return CcuResult::CCU_SUCCESS;
     148              : }
     149              : 
     150           99 : CcuResult CcuVariableAddVarToVar(CcuVariableHandle resVar, CcuVariableHandle varA, CcuVariableHandle varB)
     151              : {
     152           99 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     153           99 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     154           99 :     CCU_CHK_PTR_NULL(kernel);
     155           99 :     CCU_CHK_RET(kernel->VariableAddVarToVar(resVar, varA, varB));
     156              :     
     157           99 :     return CcuResult::CCU_SUCCESS;
     158              : }
     159              : 
     160            2 : CcuResult CcuVariableSubVarToVar(CcuVariableHandle resVar, CcuVariableHandle varA, CcuVariableHandle varB)
     161              : {
     162            2 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     163            2 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     164            2 :     CCU_CHK_PTR_NULL(kernel);
     165            2 :     CCU_CHK_RET(kernel->VariableSubVarToVar(resVar, varA, varB));
     166              : 
     167            2 :     return CcuResult::CCU_SUCCESS;
     168              : }
     169              : 
     170            2 : CcuResult CcuVariableMulVarToVar(CcuVariableHandle resVar, CcuVariableHandle varA, CcuVariableHandle varB)
     171              : {
     172            2 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     173            2 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     174            2 :     CCU_CHK_PTR_NULL(kernel);
     175            2 :     CCU_CHK_RET(kernel->VariableMulVarToVar(resVar, varA, varB));
     176              : 
     177            2 :     return CcuResult::CCU_SUCCESS;
     178              : }
     179              : 
     180            1 : CcuResult CcuVariableAddImmToVar(CcuVariableHandle resVar, CcuVariableHandle varA, uint16_t immediate)
     181              : {
     182            1 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     183            1 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     184            1 :     CCU_CHK_PTR_NULL(kernel);
     185            1 :     CCU_CHK_RET(kernel->VariableAddImmToVar(resVar, varA, immediate));
     186              : 
     187            1 :     return CcuResult::CCU_SUCCESS;
     188              : }
     189              : 
     190            2 : CcuResult CcuVariableSubImmToVar(CcuVariableHandle resVar, CcuVariableHandle varA, uint16_t immediate)
     191              : {
     192            2 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     193            2 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     194            2 :     CCU_CHK_PTR_NULL(kernel);
     195            2 :     CCU_CHK_RET(kernel->VariableSubImmToVar(resVar, varA, immediate));
     196              : 
     197            2 :     return CcuResult::CCU_SUCCESS;
     198              : }
     199              : 
     200            2 : CcuResult CcuVariableMulImmToVar(CcuVariableHandle resVar, CcuVariableHandle varA, uint16_t immediate)
     201              : {
     202            2 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     203            2 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     204            2 :     CCU_CHK_PTR_NULL(kernel);
     205            2 :     CCU_CHK_RET(kernel->VariableMulImmToVar(resVar, varA, immediate));
     206              : 
     207            2 :     return CcuResult::CCU_SUCCESS;
     208              : }
     209              : 
     210            2 : CcuResult CcuVariableAndVarToVar(CcuVariableHandle resVar, CcuVariableHandle varA, CcuVariableHandle varB)
     211              : {
     212            2 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     213            2 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     214            2 :     CCU_CHK_PTR_NULL(kernel);
     215            2 :     CCU_CHK_RET(kernel->VariableAndVarToVar(resVar, varA, varB));
     216              : 
     217            2 :     return CcuResult::CCU_SUCCESS;
     218              : }
     219              : 
     220            2 : CcuResult CcuVariableOrVarToVar(CcuVariableHandle resVar, CcuVariableHandle varA, CcuVariableHandle varB)
     221              : {
     222            2 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     223            2 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     224            2 :     CCU_CHK_PTR_NULL(kernel);
     225            2 :     CCU_CHK_RET(kernel->VariableOrVarToVar(resVar, varA, varB));
     226              : 
     227            2 :     return CcuResult::CCU_SUCCESS;
     228              : }
     229              : 
     230            2 : CcuResult CcuVariableXorVarToVar(CcuVariableHandle resVar, CcuVariableHandle varA, CcuVariableHandle varB)
     231              : {
     232            2 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     233            2 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     234            2 :     CCU_CHK_PTR_NULL(kernel);
     235            2 :     CCU_CHK_RET(kernel->VariableXorVarToVar(resVar, varA, varB));
     236              : 
     237            2 :     return CcuResult::CCU_SUCCESS;
     238              : }
     239              : 
     240            1 : CcuResult CcuVariableNotVar(CcuVariableHandle resVar, CcuVariableHandle varA)
     241              : {
     242            1 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     243            1 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     244            1 :     CCU_CHK_PTR_NULL(kernel);
     245            1 :     CCU_CHK_RET(kernel->VariableNotVar(resVar, varA));
     246              : 
     247            1 :     return CcuResult::CCU_SUCCESS;
     248              : }
     249              : 
     250              : /*
     251              : Address 相关接口
     252              : */
     253           11 : CcuResult CcuAddressAssignImm(CcuAddressHandle addr, uint64_t immediate)
     254              : {
     255           11 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     256           11 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     257           11 :     CCU_CHK_PTR_NULL(kernel);
     258           11 :     CCU_CHK_RET(kernel->AddressAssignImm(addr, immediate));
     259           11 :     return CcuResult::CCU_SUCCESS;
     260              : }
     261              : 
     262           38 : CcuResult CcuAddressAssignAddr(CcuAddressHandle dstAddrHandle, CcuAddressHandle srcAddrHandle)
     263              : {
     264           38 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     265           38 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     266           38 :     CCU_CHK_PTR_NULL(kernel);
     267           38 :     CCU_CHK_RET(kernel->AddressAssignAddr(dstAddrHandle, srcAddrHandle));
     268           38 :     return CcuResult::CCU_SUCCESS;
     269              : }
     270              : 
     271           14 : CcuResult CcuAddressAssignVar(CcuAddressHandle addr, CcuVariableHandle var)
     272              : {
     273           14 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     274           14 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     275           14 :     CCU_CHK_PTR_NULL(kernel);
     276           14 :     CCU_CHK_RET(kernel->AddressAssignVar(addr, var));
     277           14 :     return CcuResult::CCU_SUCCESS;
     278              : }
     279              : 
     280            0 : CcuResult CcuAddressAddVarToAddr(CcuAddressHandle resAddr, CcuAddressHandle lhsAddr, CcuVariableHandle rhsVar)
     281              : {
     282            0 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     283            0 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     284            0 :     CCU_CHK_PTR_NULL(kernel);
     285            0 :     CCU_CHK_RET(kernel->AddressAddVarToAddr(resAddr, lhsAddr, rhsVar));
     286            0 :     return CcuResult::CCU_SUCCESS;
     287              : }
     288              : 
     289            2 : CcuResult CcuAddressAddAddrToAddr(CcuAddressHandle resAddr, CcuAddressHandle addrA, CcuAddressHandle addrB)
     290              : {
     291            2 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     292            2 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     293            2 :     CCU_CHK_PTR_NULL(kernel);
     294            2 :     CCU_CHK_RET(kernel->AddressAddAddrToAddr(resAddr, addrA, addrB));
     295            2 :     return CcuResult::CCU_SUCCESS;
     296              : }
     297              : 
     298           41 : CcuResult CcuAddressAddAssignVar(CcuAddressHandle addr, CcuVariableHandle var)
     299              : {
     300           41 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     301           41 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     302           41 :     CCU_CHK_PTR_NULL(kernel);
     303           41 :     CCU_CHK_RET(kernel->AddressAddAssignVar(addr, var));
     304           41 :     return CcuResult::CCU_SUCCESS;
     305              : }
     306              : 
     307            1 : CcuResult CcuAddressAddImmToAddr(CcuAddressHandle resAddr, CcuAddressHandle addrA, uint16_t imm)
     308              : {
     309            1 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     310            1 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     311            1 :     CCU_CHK_PTR_NULL(kernel);
     312            1 :     CCU_CHK_RET(kernel->AddressAddImmToAddr(resAddr, addrA, imm));
     313            1 :     return CcuResult::CCU_SUCCESS;
     314              : }
     315              : 
     316              : //参数加载类 相关接口
     317           49 : CcuResult CcuLoadArg(CcuVariableHandle varHandle, uint32_t argId)
     318              : {
     319           49 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     320           49 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     321           49 :     CCU_CHK_PTR_NULL(kernel);
     322           49 :     CCU_CHK_RET(kernel->LoadArg(varHandle, argId));
     323           49 :     return CcuResult::CCU_SUCCESS;
     324              : }
     325              : 
     326            6 : CcuResult CcuLoadVar(uint64_t addr, CcuVariableHandle varHandle, uint32_t num)
     327              : {
     328            6 :     if (num == 0) {
     329            0 :         HCCL_ERROR("[CcuLoadVar] invalid args, num[%u]", num);
     330            0 :         return CcuResult::CCU_E_PARA;
     331              :     }
     332            6 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     333            6 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     334            6 :     CCU_CHK_PTR_NULL(kernel);
     335            6 :     CCU_CHK_RET(kernel->LoadVar(addr, varHandle, num));
     336            6 :     return CcuResult::CCU_SUCCESS;
     337              : }
     338              : 
     339            2 : CcuResult CcuLoadVarFromVarAddr(CcuVariableHandle addrHandle, CcuVariableHandle varHandle, uint32_t num)
     340              : {
     341            2 :     if (num == 0) {
     342            0 :         HCCL_ERROR("[CcuLoadVarFromVarAddr] invalid args, num[%u]", num);
     343            0 :         return CcuResult::CCU_E_PARA;
     344              :     }
     345            2 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     346            2 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     347            2 :     CCU_CHK_PTR_NULL(kernel);
     348            2 :     CCU_CHK_RET(kernel->CcuLoadVarFromVarAddr(addrHandle, varHandle, num));
     349            2 :     return CcuResult::CCU_SUCCESS;
     350              : }
     351              : 
     352            3 : CcuResult CcuStoreVar(uint64_t addr, CcuVariableHandle varHandle, uint32_t num)
     353              : {
     354            3 :     if (num == 0) {
     355            0 :         HCCL_ERROR("[CcuStoreVar] invalid args, num[%u]", num);
     356            0 :         return CcuResult::CCU_E_PARA;
     357              :     }
     358            3 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     359            3 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     360            3 :     CCU_CHK_PTR_NULL(kernel);
     361            3 :     CCU_CHK_RET(kernel->StoreVar(addr, varHandle, num));
     362            3 :     return CcuResult::CCU_SUCCESS;
     363              : }
     364              : 
     365            2 : CcuResult CcuStoreVarToVarAddr(CcuVariableHandle addrHandle, CcuVariableHandle varHandle, uint32_t num)
     366              : {
     367            2 :     if (num == 0) {
     368            0 :         HCCL_ERROR("[CcuStoreVarToVarAddr] invalid args, num[%u]", num);
     369            0 :         return CcuResult::CCU_E_PARA;
     370              :     }
     371            2 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     372            2 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     373            2 :     CCU_CHK_PTR_NULL(kernel);
     374            2 :     CCU_CHK_RET(kernel->CcuStoreVarToVarAddr(addrHandle, varHandle, num));
     375            2 :     return CcuResult::CCU_SUCCESS;
     376              : }
     377              : 
     378              : //Event信号同步类 相关接口
     379           11 : CcuResult CcuEventRecord(CcuEventHandle eventHandle, uint16_t mask)
     380              : {
     381           11 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     382           11 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     383           11 :     CCU_CHK_PTR_NULL(kernel);
     384           11 :     CCU_CHK_RET(kernel->EventRecord(eventHandle, mask));
     385           10 :     return CcuResult::CCU_SUCCESS;
     386              : }
     387           32 : CcuResult CcuEventWait(CcuEventHandle eventHandle, uint16_t mask)
     388              : {
     389           32 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     390           32 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     391           32 :     CCU_CHK_PTR_NULL(kernel);
     392           32 :     CCU_CHK_RET(kernel->EventWait(eventHandle, mask));
     393           32 :     return CcuResult::CCU_SUCCESS;
     394              : }
     395            6 : CcuResult CcuNotifyRecord(ChannelHandle channel, uint32_t remoteNotifyIdx, uint16_t mask)
     396              : {
     397            6 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     398            6 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     399            6 :     CCU_CHK_PTR_NULL(kernel);
     400            6 :     CCU_CHK_RET(kernel->NotifyRecord(channel, remoteNotifyIdx, mask));
     401            5 :     return CcuResult::CCU_SUCCESS;
     402              : }
     403           11 : CcuResult CcuNotifyWait(ChannelHandle channel, uint32_t localNotifyIdx, uint16_t mask)  
     404              : {
     405           11 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     406           11 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     407           11 :     CCU_CHK_PTR_NULL(kernel);
     408           11 :     CCU_CHK_RET(kernel->NotifyWait(channel, localNotifyIdx, mask));
     409           10 :     return CcuResult::CCU_SUCCESS;
     410              : }
     411           10 : CcuResult CcuWriteVariableWithNotify(ChannelHandle channel, CcuVariableHandle varHandle,uint32_t remoteVarIdx, uint32_t remoteNotifyIdx, uint16_t mask)
     412              : {
     413           10 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     414           10 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     415           10 :     CCU_CHK_PTR_NULL(kernel);
     416           10 :     CCU_CHK_RET(kernel->WriteVariableWithNotify(channel, varHandle, remoteVarIdx, remoteNotifyIdx, mask));
     417            9 :     return CcuResult::CCU_SUCCESS;
     418              : }
     419            1 : CcuResult CcuLocalNotifyRecord(const char *notifyTag, uint16_t mask)
     420              : {
     421            1 :     CCU_CHK_PTR_NULL(notifyTag);
     422            1 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     423            1 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     424            1 :     CCU_CHK_PTR_NULL(kernel);
     425            1 :     CCU_CHK_RET(kernel->LocalNotifyRecord(notifyTag, mask));
     426            0 :     return CcuResult::CCU_SUCCESS;
     427              : }
     428            0 : CcuResult CcuLocalNotifyWait(const char *notifyTag, uint16_t mask)
     429              : {
     430            0 :     CCU_CHK_PTR_NULL(notifyTag);
     431            0 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     432            0 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     433            0 :     CCU_CHK_PTR_NULL(kernel);
     434            0 :     CCU_CHK_RET(kernel->LocalNotifyWait(notifyTag, mask));
     435            0 :     return CcuResult::CCU_SUCCESS;
     436              : }
     437              : 
     438              : //本地数据拷贝 相关接口
     439            0 : CcuResult CcuLocalCopyMemToMem(
     440              :     CcuLocalAddrHandle dst, CcuLocalAddrHandle src,
     441              :     CcuVariableHandle len, CcuEventHandle event, uint16_t mask)
     442              : {
     443            0 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     444            0 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     445            0 :     CCU_CHK_PTR_NULL(kernel);
     446            0 :     CCU_CHK_RET(kernel->LocalCopyMemToMem(dst, src, len, event, mask));
     447            0 :     return CcuResult::CCU_SUCCESS;
     448              : }
     449              : 
     450           10 : CcuResult CcuLocalCopyMemToBuffer(
     451              :     CcuBufferHandle dst, CcuLocalAddrHandle src,
     452              :     CcuVariableHandle len, CcuEventHandle event, uint16_t mask)
     453              : {
     454           10 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     455           10 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     456           10 :     CCU_CHK_PTR_NULL(kernel);
     457           10 :     CCU_CHK_RET(kernel->LocalCopyMemToBuffer(dst, src, len, event, mask));
     458           10 :     return CcuResult::CCU_SUCCESS;
     459              : }
     460              : 
     461            6 : CcuResult CcuLocalCopyBufferToMem(
     462              :     CcuLocalAddrHandle dst, CcuBufferHandle src,
     463              :     CcuVariableHandle len, CcuEventHandle event, uint16_t mask)
     464              : {
     465            6 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     466            6 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     467            6 :     CCU_CHK_PTR_NULL(kernel);
     468            6 :     CCU_CHK_RET(kernel->LocalCopyBufferToMem(dst, src, len, event, mask));
     469            6 :     return CcuResult::CCU_SUCCESS;
     470              : }
     471              : //本地reduce 相关接口
     472            0 : CcuResult CcuLocalMemReduce(CcuLocalAddrHandle dst, CcuLocalAddrHandle src, CcuVariableHandle len, HcclDataType dataType, HcclReduceOp opType, CcuEventHandle event, uint16_t mask)
     473              : {
     474            0 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     475            0 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     476            0 :     CCU_CHK_PTR_NULL(kernel);
     477            0 :     CCU_CHK_RET(kernel->LocalMemReduce(dst, src, len, dataType, opType, event, mask));
     478            0 :     return CcuResult::CCU_SUCCESS;
     479              : }
     480              : 
     481            4 : CcuResult CcuLocalBufferReduce(CcuBufferHandle* buffers, uint32_t count, HcclDataType dataType, HcclDataType outputDataType, HcclReduceOp opType, CcuVariableHandle len, CcuEventHandle event, uint16_t mask)
     482              : {
     483            4 :     if (buffers == nullptr || count == 0) {
     484            0 :         HCCL_ERROR("[CcuLocalBufferReduce] invalid args, buffers[%p] count[%u]", buffers, count);
     485            0 :         return CcuResult::CCU_E_PARA;
     486              :     }
     487            4 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     488            4 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     489            4 :     CCU_CHK_PTR_NULL(kernel);
     490            4 :     CCU_CHK_RET(kernel->LocalBufferReduce(buffers, count, dataType, outputDataType, opType, len, event, mask));
     491            4 :     return CcuResult::CCU_SUCCESS;
     492              : }
     493              : 
     494              : /*========== 远端数据传输操作 ==========*/
     495            4 : CcuResult CcuReadMemToMem(
     496              :     ChannelHandle channel, CcuLocalAddrHandle localHandle, CcuRemoteAddrHandle remoteHandle,
     497              :     CcuVariableHandle len, CcuEventHandle event, uint16_t mask)
     498              : {
     499            4 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     500            4 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     501            4 :     CCU_CHK_PTR_NULL(kernel);
     502            4 :     CCU_CHK_RET(kernel->ReadMemToMem(channel, localHandle, remoteHandle, len, event, mask));
     503            4 :     return CcuResult::CCU_SUCCESS;
     504              : }
     505              : 
     506            2 : CcuResult CcuReadMemToBuffer(
     507              :     ChannelHandle channel, CcuBufferHandle localHandle, CcuRemoteAddrHandle remoteHandle,
     508              :     CcuVariableHandle len, CcuEventHandle event, uint16_t mask)
     509              : {
     510            2 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     511            2 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     512            2 :     CCU_CHK_PTR_NULL(kernel);
     513            2 :     CCU_CHK_RET(kernel->ReadMemToBuffer(channel, localHandle, remoteHandle, len, event, mask));
     514            2 :     return CcuResult::CCU_SUCCESS;
     515              : }
     516              : 
     517            2 : CcuResult CcuReadMemToMemReduce(
     518              :     ChannelHandle channel, CcuLocalAddrHandle localHandle, CcuRemoteAddrHandle remoteHandle,
     519              :     CcuVariableHandle len, HcclDataType dataType,
     520              :     HcclReduceOp opType, CcuEventHandle event, uint16_t mask)
     521              : {
     522            2 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     523            2 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     524            2 :     CCU_CHK_PTR_NULL(kernel);
     525            2 :     CCU_CHK_RET(kernel->ReadMemToMemReduce(channel, localHandle, remoteHandle, len, dataType, opType, event, mask));
     526            2 :     return CcuResult::CCU_SUCCESS;
     527              : }
     528              : 
     529            3 : CcuResult CcuWriteMemToMem(
     530              :     ChannelHandle channel, CcuRemoteAddrHandle remoteHandle, CcuLocalAddrHandle localHandle, 
     531              :     CcuVariableHandle len, CcuEventHandle event, uint16_t mask)
     532              : {
     533            3 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     534            3 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     535            3 :     CCU_CHK_PTR_NULL(kernel);
     536            3 :     CCU_CHK_RET(kernel->WriteMemToMem(channel, remoteHandle, localHandle, len, event, mask));
     537            3 :     return CcuResult::CCU_SUCCESS;
     538              : }
     539              : 
     540            2 : CcuResult CcuWriteBufferToMem(
     541              :     ChannelHandle channel, CcuRemoteAddrHandle remote, CcuBufferHandle local, 
     542              :     CcuVariableHandle len, CcuEventHandle event, uint16_t mask)
     543              : {
     544            2 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     545            2 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     546            2 :     CCU_CHK_PTR_NULL(kernel);
     547            2 :     CCU_CHK_RET(kernel->WriteBufferToMem(channel, remote, local, len, event, mask));
     548            2 :     return CcuResult::CCU_SUCCESS;
     549              : }
     550              : 
     551            2 : CcuResult CcuWriteMemToMemReduce(
     552              :     ChannelHandle channel, CcuRemoteAddrHandle remote, CcuLocalAddrHandle local,
     553              :     CcuVariableHandle len, HcclDataType dataType,
     554              :     HcclReduceOp opType, CcuEventHandle event, uint16_t mask)
     555              : {
     556            2 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     557            2 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     558            2 :     CCU_CHK_PTR_NULL(kernel);
     559            2 :     CCU_CHK_RET(kernel->WriteMemToMemReduce(channel, remote, local, len, dataType, opType, event, mask));
     560            2 :     return CcuResult::CCU_SUCCESS;
     561              : }
     562              : 
     563              : /*========== 控制流操作 ==========*/
     564           30 : CcuResult CcuIfBegin(CcuVariableHandle var, uint64_t immediate,
     565              :     CcuConditionType condType, const char *label)
     566              : {
     567           30 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     568           30 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     569           30 :     CCU_CHK_PTR_NULL(kernel);
     570           30 :     CCU_CHK_RET(kernel->IfBegin(var, immediate, condType, label));
     571              : 
     572           29 :     return CcuResult::CCU_SUCCESS;
     573              : }
     574              : 
     575            4 : CcuResult CcuIfElse(const char *label)
     576              : {
     577            4 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     578            4 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     579            4 :     CCU_CHK_PTR_NULL(kernel);
     580            4 :     CCU_CHK_RET(kernel->IfElse(label));
     581              : 
     582            4 :     return CcuResult::CCU_SUCCESS;
     583              : }
     584              : 
     585            4 : CcuResult CcuIfEnd(const char *label)
     586              : {
     587            4 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     588            4 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     589            4 :     CCU_CHK_PTR_NULL(kernel);
     590            4 :     CCU_CHK_RET(kernel->IfEnd(label));
     591              : 
     592            4 :     return CcuResult::CCU_SUCCESS;
     593              : }
     594              : 
     595           32 : CcuResult CcuFlushPendingIfs()
     596              : {
     597           32 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     598           32 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     599           32 :     CCU_CHK_PTR_NULL(kernel);
     600           32 :     kernel->FlushClosablePendingIfs();
     601           32 :     return CcuResult::CCU_SUCCESS;
     602              : }
     603              : 
     604            3 : CcuResult CcuWhileBegin(CcuVariableHandle var, uint64_t immediate,
     605              :     CcuConditionType condType, const char *label)
     606              : {
     607            3 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     608            3 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     609            3 :     CCU_CHK_PTR_NULL(kernel);
     610            3 :     CCU_CHK_RET(kernel->WhileBegin(var, immediate, condType, label));
     611              : 
     612            3 :     return CcuResult::CCU_SUCCESS;
     613              : }
     614              : 
     615            4 : CcuResult CcuWhileEnd(const char *label)
     616              : {
     617            4 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     618            4 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     619            4 :     CCU_CHK_PTR_NULL(kernel);
     620            4 :     CCU_CHK_RET(kernel->WhileEnd(label));
     621              : 
     622            4 :     return CcuResult::CCU_SUCCESS;
     623              : }
     624              : 
     625            6 : CcuResult CcuDoWhileBegin(const char *label)
     626              : {
     627            6 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     628            6 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     629            6 :     CCU_CHK_PTR_NULL(kernel);
     630            6 :     CCU_CHK_RET(kernel->DoWhileBegin(label));
     631              : 
     632            6 :     return CcuResult::CCU_SUCCESS;
     633              : }
     634              : 
     635            5 : CcuResult CcuDoWhileEnd(CcuVariableHandle var, uint64_t immediate,
     636              :     CcuConditionType condType, const char *label)
     637              : {
     638            5 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     639            5 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     640            5 :     CCU_CHK_PTR_NULL(kernel);
     641            5 :     CCU_CHK_RET(kernel->DoWhileEnd(var, immediate, condType, label));
     642              : 
     643            5 :     return CcuResult::CCU_SUCCESS;
     644              : }
     645              : 
     646            3 : CcuResult CcuIfBeginVar(CcuVariableHandle lhs, CcuVariableHandle rhs,
     647              :     CcuConditionType condType, const char *label)
     648              : {
     649            3 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     650            3 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     651            3 :     CCU_CHK_PTR_NULL(kernel);
     652            3 :     CCU_CHK_RET(kernel->IfBeginVar(lhs, rhs, condType, label));
     653              : 
     654            3 :     return CcuResult::CCU_SUCCESS;
     655              : }
     656              : 
     657            1 : CcuResult CcuWhileBeginVar(CcuVariableHandle lhs, CcuVariableHandle rhs,
     658              :     CcuConditionType condType, const char *label)
     659              : {
     660            1 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     661            1 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     662            1 :     CCU_CHK_PTR_NULL(kernel);
     663            1 :     CCU_CHK_RET(kernel->WhileBeginVar(lhs, rhs, condType, label));
     664              : 
     665            1 :     return CcuResult::CCU_SUCCESS;
     666              : }
     667              : 
     668            1 : CcuResult CcuDoWhileEndVar(CcuVariableHandle lhs, CcuVariableHandle rhs,
     669              :     CcuConditionType condType, const char *label)
     670              : {
     671            1 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     672            1 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     673            1 :     CCU_CHK_PTR_NULL(kernel);
     674            1 :     CCU_CHK_RET(kernel->DoWhileEndVar(lhs, rhs, condType, label));
     675              : 
     676            1 :     return CcuResult::CCU_SUCCESS;
     677              : }
     678              : 
     679              : /*========== 函数调用操作 ==========*/
     680            8 : CcuResult CcuFuncBlockLookup(const void *funcPtr, uint64_t *outHandle)
     681              : {
     682            8 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     683            8 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     684            8 :     CCU_CHK_PTR_NULL(kernel);
     685            8 :     CCU_CHK_RET(kernel->FuncBlockLookup(funcPtr, outHandle));
     686            6 :     return CcuResult::CCU_SUCCESS;
     687              : }
     688              : 
     689            5 : CcuResult CcuFuncBlockBegin(const void *funcPtr, uint64_t *outHandle)
     690              : {
     691            5 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     692            5 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     693            5 :     CCU_CHK_PTR_NULL(kernel);
     694            5 :     CCU_CHK_RET(kernel->FuncBlockBegin(funcPtr, outHandle));
     695            5 :     return CcuResult::CCU_SUCCESS;
     696              : }
     697              : 
     698            4 : CcuResult CcuFuncBlockEnd(uint64_t handle)
     699              : {
     700            4 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     701            4 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     702            4 :     CCU_CHK_PTR_NULL(kernel);
     703            4 :     CCU_CHK_RET(kernel->FuncBlockEnd(handle));
     704            4 :     return CcuResult::CCU_SUCCESS;
     705              : }
     706              : 
     707            7 : CcuResult CcuFuncDefineInArg(uint64_t handle, CcuVariableHandle formal)
     708              : {
     709            7 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     710            7 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     711            7 :     CCU_CHK_PTR_NULL(kernel);
     712            7 :     CCU_CHK_RET(kernel->FuncDefineInArg(handle, formal));
     713            7 :     return CcuResult::CCU_SUCCESS;
     714              : }
     715              : 
     716            5 : CcuResult CcuFuncCall(uint64_t handle, const CcuVariableHandle *inArgs, uint32_t numIn)
     717              : {
     718            5 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     719            5 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     720            5 :     CCU_CHK_PTR_NULL(kernel);
     721            5 :     CCU_CHK_RET(kernel->FuncCall(handle, inArgs, numIn));
     722            5 :     return CcuResult::CCU_SUCCESS;
     723              : }
     724              : 
     725              : /*========== 循环操作 ==========*/
     726           51 : CcuResult CcuLoopCreate(CcuLoop *loop)
     727              : {
     728           51 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     729           51 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     730           51 :     CCU_CHK_PTR_NULL(kernel);
     731           51 :     CCU_CHK_RET(kernel->LoopCreate(loop));
     732           51 :     return CcuResult::CCU_SUCCESS;
     733              : }
     734              : 
     735           51 : CcuResult _CcuLoopBodyEnter(CcuLoop loop)
     736              : {
     737           51 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     738           51 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     739           51 :     CCU_CHK_PTR_NULL(kernel);
     740           51 :     CCU_CHK_RET(kernel->LoopBodyEnter(loop));
     741           51 :     return CcuResult::CCU_SUCCESS;
     742              : }
     743              : 
     744           51 : CcuResult _CcuLoopBodyExit(CcuLoop loop)
     745              : {
     746           51 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     747           51 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     748           51 :     CCU_CHK_PTR_NULL(kernel);
     749           51 :     CCU_CHK_RET(kernel->LoopBodyExit(loop));
     750           45 :     return CcuResult::CCU_SUCCESS;
     751              : }
     752              : 
     753            0 : CcuResult CcuLoopGroupCreate(CcuLoopGroup *group, uint32_t maxLoopNum,
     754              :     const CcuLoopGroupConfig *config)
     755              : {
     756            0 :     if (config == nullptr) {
     757            0 :         return CcuResult::CCU_E_PTR;
     758              :     }
     759              :     // 旧 config 无 varOffset,在边界归一化为 cfg(varOffset=0),kernel 只认 cfg。
     760            0 :     CcuLoopGroupCfg cfg{};
     761            0 :     CcuLoopGroupCfgInit(&cfg);
     762            0 :     cfg.cloneNum = config->cloneNum;
     763            0 :     cfg.cloneLoopOffset = config->cloneLoopOffset;
     764            0 :     cfg.addrOffset = config->addrOffset;
     765            0 :     cfg.ccuBufferOffset = config->ccuBufferOffset;
     766            0 :     cfg.eventOffset = config->eventOffset;
     767            0 :     cfg.varOffset = 0;
     768            0 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     769            0 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     770            0 :     CCU_CHK_PTR_NULL(kernel);
     771            0 :     CCU_CHK_RET(kernel->LoopGroupCreate(group, maxLoopNum, &cfg));
     772            0 :     return CcuResult::CCU_SUCCESS;
     773              : }
     774              : 
     775           11 : CcuResult CcuLoopGroupCreateFromVar(CcuLoopGroup *group, uint32_t maxLoopNum,
     776              :     CcuVariableHandle parallelVar, CcuVariableHandle offsetVar)
     777              : {
     778           11 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     779           11 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     780           11 :     CCU_CHK_PTR_NULL(kernel);
     781           11 :     CCU_CHK_RET(kernel->LoopGroupCreateFromVar(group, maxLoopNum, parallelVar, offsetVar));
     782           11 :     return CcuResult::CCU_SUCCESS;
     783              : }
     784              : 
     785            5 : CcuResult CcuLoopGroupCreateFromVarV2(CcuLoopGroup *group, uint32_t maxLoopNum,
     786              :     CcuVariableHandle parallelVarV2, CcuVariableHandle offsetVarV2, CcuVariableHandle varOffsetVar)
     787              : {
     788            5 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     789            5 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     790            5 :     CCU_CHK_PTR_NULL(kernel);
     791            5 :     CCU_CHK_RET(kernel->LoopGroupCreateFromVarV2(group, maxLoopNum, parallelVarV2, offsetVarV2, varOffsetVar));
     792            4 :     return CcuResult::CCU_SUCCESS;
     793              : }
     794              : 
     795            0 : CcuResult CcuLoopGroupAddLoop(CcuLoopGroup group,
     796              :     CcuLoop loop, const CcuLoopConfig *config)
     797              : {
     798            0 :     if (config == nullptr) {
     799            0 :         return CcuResult::CCU_E_PTR;
     800              :     }
     801            0 :     CcuLoopCfg cfg{};
     802            0 :     CcuLoopCfgInit(&cfg);
     803            0 :     cfg.addrOffset = config->addrOffset;
     804            0 :     cfg.iterNum = config->iterNum;
     805            0 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     806            0 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     807            0 :     CCU_CHK_PTR_NULL(kernel);
     808            0 :     CCU_CHK_RET(kernel->LoopGroupAddLoop(group, loop, &cfg));
     809            0 :     return CcuResult::CCU_SUCCESS;
     810              : }
     811              : 
     812           14 : CcuResult CcuLoopGroupCreateCfg(CcuLoopGroup *group, uint32_t maxLoopNum,
     813              :     const CcuLoopGroupCfg *cfg)
     814              : {
     815           14 :     if (cfg == nullptr) {
     816            0 :         return CcuResult::CCU_E_PTR;
     817              :     }
     818           14 :     CCU_CHK_RET(ValidateCcuCfgHeader(&cfg->header, sizeof(CcuLoopGroupCfg), CCU_LOOPGROUP_CFG_VERSION));
     819           13 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     820           13 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     821           13 :     CCU_CHK_PTR_NULL(kernel);
     822           13 :     CCU_CHK_RET(kernel->LoopGroupCreate(group, maxLoopNum, cfg));
     823           13 :     return CcuResult::CCU_SUCCESS;
     824              : }
     825              : 
     826           26 : CcuResult CcuLoopGroupAddLoopCfg(CcuLoopGroup group,
     827              :     CcuLoop loop, const CcuLoopCfg *cfg)
     828              : {
     829           26 :     if (cfg == nullptr) {
     830            0 :         return CcuResult::CCU_E_PTR;
     831              :     }
     832           26 :     CCU_CHK_RET(ValidateCcuCfgHeader(&cfg->header, sizeof(CcuLoopCfg), CCU_LOOP_CFG_VERSION));
     833           25 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     834           25 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     835           25 :     CCU_CHK_PTR_NULL(kernel);
     836           25 :     CCU_CHK_RET(kernel->LoopGroupAddLoop(group, loop, cfg));
     837           25 :     return CcuResult::CCU_SUCCESS;
     838              : }
     839              : 
     840           23 : CcuResult CcuLoopGroupAddLoopFromVar(CcuLoopGroup group,
     841              :     CcuLoop loop, CcuVariableHandle loopParamVar)
     842              : {
     843           23 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     844           23 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     845           23 :     CCU_CHK_PTR_NULL(kernel);
     846           23 :     CCU_CHK_RET(kernel->LoopGroupAddLoopFromVar(group, loop, loopParamVar));
     847           23 :     return CcuResult::CCU_SUCCESS;
     848              : }
     849              : 
     850            8 : CcuResult CcuLoopGroupAddLoopFromVarV2(CcuLoopGroup group,
     851              :     CcuLoop loop, CcuVariableHandle iterNumVar, CcuVariableHandle addrOffsetVar, CcuVariableHandle ctxIdVar)
     852              : {
     853            8 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     854            8 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     855            8 :     CCU_CHK_PTR_NULL(kernel);
     856            8 :     CCU_CHK_RET(kernel->LoopGroupAddLoopFromVarV2(group, loop, iterNumVar, addrOffsetVar, ctxIdVar));
     857            8 :     return CcuResult::CCU_SUCCESS;
     858              : }
     859              : 
     860              : //控制流标签栈 C 接口(_CcuIfStack* / _CcuDoWhileStack*)
     861              :  
     862           32 : void _CcuIfStackPush(const char *label)
     863              : {
     864           32 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     865           32 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     866           32 :     if (kernel == nullptr) {
     867            0 :         HCCL_ERROR("[_CcuIfStackPush] no current kernel, label=%s",
     868              :             label != nullptr ? label : "(null)");
     869            0 :         return;
     870              :     }
     871           32 :     kernel->IfLabelStackPush(label);
     872              : }
     873              : 
     874           32 : void _CcuIfStackMarkBodyDone()
     875              : {
     876           32 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     877           32 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     878           32 :     if (kernel == nullptr) {
     879            0 :         HCCL_ERROR("[_CcuIfStackMarkBodyDone] no current kernel");
     880            0 :         return;
     881              :     }
     882           32 :     kernel->IfLabelStackMarkBodyDone();
     883              : }
     884              : 
     885            4 : const char *_CcuIfStackPopForElse()
     886              : {
     887            4 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     888            4 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     889            4 :     if (kernel == nullptr) {
     890            0 :         HCCL_ERROR("[_CcuIfStackPopForElse] no current kernel");
     891            0 :         return nullptr;
     892              :     }
     893            4 :     return kernel->IfLabelStackPopForElse();
     894              : }
     895              : 
     896            6 : void _CcuDoWhileStackPush(const char *label)
     897              : {
     898            6 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     899            6 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     900            6 :     if (kernel == nullptr) {
     901            0 :         HCCL_ERROR("[_CcuDoWhileStackPush] no current kernel, label=%s",
     902              :             label != nullptr ? label : "(null)");
     903            0 :         return;
     904              :     }
     905            6 :     kernel->DoWhileLabelStackPush(label);
     906              : }
     907              : 
     908           10 : const char *_CcuDoWhileStackPopForWhile()
     909              : {
     910           10 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     911           10 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     912           10 :     if (kernel == nullptr) {
     913              :         // 见上方注释:CCU_WHILE 每次都会调本函数做模式判别,保持沉默。
     914            0 :         return nullptr;
     915              :     }
     916           10 :     return kernel->DoWhileLabelStackPopForWhile();
     917              : }
        

Generated by: LCOV version 2.0-1