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: 87.9 % 423 372
Test Date: 2026-07-28 12:11:00 Functions: 92.5 % 67 62

            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              : //Alloc 相关接口
      19          246 : CcuResult CcuVariableAlloc(CcuVariableHandle *varHandle)
      20              : {
      21          246 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
      22          246 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
      23          246 :     CCU_CHK_PTR_NULL(kernel);
      24          246 :     CCU_CHK_RET(kernel->VariableAlloc(varHandle));
      25          246 :     return CcuResult::CCU_SUCCESS;
      26              : }
      27              : 
      28            3 : CcuResult CcuAddressAlloc(CcuAddressHandle *addrHandle)
      29              : {
      30            3 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
      31            3 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
      32            3 :     CCU_CHK_PTR_NULL(kernel);
      33            3 :     CCU_CHK_RET(kernel->AddressAlloc(addrHandle));
      34            3 :     return CcuResult::CCU_SUCCESS;
      35              : }
      36              : 
      37            6 : CcuResult CcuEventAlloc(CcuEventHandle *eventHandle)
      38              : {
      39            6 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
      40            6 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
      41            6 :     CCU_CHK_PTR_NULL(kernel);
      42            6 :     CCU_CHK_RET(kernel->EventAlloc(eventHandle));
      43            6 :     return CcuResult::CCU_SUCCESS;
      44              : }
      45              : 
      46            0 : CcuResult CcuBufferAlloc(CcuBufferHandle *bufHandle)
      47              : {
      48            0 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
      49            0 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
      50            0 :     CCU_CHK_PTR_NULL(kernel);
      51            0 :     CCU_CHK_RET(kernel->BufferAlloc(bufHandle));
      52            0 :     return CcuResult::CCU_SUCCESS;
      53              : }
      54              : 
      55           81 : CcuResult CcuLocalAddrAlloc(CcuLocalAddrHandle *localAddrHandle, CcuAddressHandle *addrHandle, CcuVariableHandle *tokenHandle)
      56              : {
      57           81 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
      58           81 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
      59           81 :     CCU_CHK_PTR_NULL(kernel);
      60           81 :     CCU_CHK_RET(kernel->LocalAddrAlloc(localAddrHandle, addrHandle, tokenHandle));
      61           81 :     return CcuResult::CCU_SUCCESS;
      62              : }
      63              : 
      64           20 : CcuResult CcuRemoteAddrAlloc(CcuRemoteAddrHandle *remoteAddrHandle, CcuAddressHandle *addrHandle, CcuVariableHandle *tokenHandle)
      65              : {
      66           20 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
      67           20 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
      68           20 :     CCU_CHK_PTR_NULL(kernel);
      69           20 :     CCU_CHK_RET(kernel->RemoteAddrAlloc(remoteAddrHandle, addrHandle, tokenHandle));
      70           20 :     return CcuResult::CCU_SUCCESS;
      71              : }
      72              : 
      73            2 : CcuResult CcuBlockVariableAlloc(CcuVariableHandle *varHandles, uint32_t count)
      74              : {
      75            2 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
      76            2 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
      77            2 :     CCU_CHK_PTR_NULL(kernel);
      78            2 :     CCU_CHK_RET(kernel->BlockVariableAlloc(varHandles, count));
      79            2 :     return CcuResult::CCU_SUCCESS;
      80              : }
      81              : 
      82            3 : CcuResult CcuBlockEventAlloc(CcuEventHandle *eventHandles, uint32_t count)
      83              : {
      84            3 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
      85            3 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
      86            3 :     CCU_CHK_PTR_NULL(kernel);
      87            3 :     CCU_CHK_RET(kernel->BlockEventAlloc(eventHandles, count));
      88            3 :     return CcuResult::CCU_SUCCESS;
      89              : }
      90            4 : CcuResult CcuBlockBufferAlloc(CcuBufferHandle *bufHandles, uint32_t count)
      91              : {
      92            4 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
      93            4 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
      94            4 :     CCU_CHK_PTR_NULL(kernel);
      95            4 :     CCU_CHK_RET(kernel->BlockBufferAlloc(bufHandles, count));
      96            4 :     return CcuResult::CCU_SUCCESS;
      97              : }
      98            6 : CcuResult CcuVariableCreateByChannel(ChannelHandle channel, uint32_t varIndex, CcuVariableHandle *varHandle)
      99              : {
     100            6 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     101            6 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     102            6 :     CCU_CHK_PTR_NULL(kernel);
     103            6 :     CCU_CHK_RET(kernel->VariableCreateByChannel(channel, varIndex, varHandle));
     104            6 :     return CcuResult::CCU_SUCCESS;
     105              : }
     106              : 
     107              : //Variable操作类 相关接口
     108           99 : CcuResult CcuVariableAssignImm(CcuVariableHandle resVar, uint64_t immediate)
     109              : {
     110           99 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     111           99 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     112           99 :     CCU_CHK_PTR_NULL(kernel);
     113           99 :     CCU_CHK_RET(kernel->VariableAssignImm(resVar, immediate));
     114              :     
     115           99 :     return CcuResult::CCU_SUCCESS;
     116              : }
     117           47 : CcuResult CcuVariableAssignVar(CcuVariableHandle dstVarHandle, CcuVariableHandle srcVarHandle)
     118              : {
     119           47 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     120           47 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     121           47 :     CCU_CHK_PTR_NULL(kernel);
     122           47 :     CCU_CHK_RET(kernel->VariableAssignVar(dstVarHandle, srcVarHandle));
     123              :     
     124           47 :     return CcuResult::CCU_SUCCESS;
     125              : }
     126              : 
     127           52 : CcuResult CcuVariableAddVarToVar(CcuVariableHandle resVar, CcuVariableHandle varA, CcuVariableHandle varB)
     128              : {
     129           52 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     130           52 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     131           52 :     CCU_CHK_PTR_NULL(kernel);
     132           52 :     CCU_CHK_RET(kernel->VariableAddVarToVar(resVar, varA, varB));
     133              :     
     134           52 :     return CcuResult::CCU_SUCCESS;
     135              : }
     136              : 
     137              : /*
     138              : Address 相关接口
     139              : */
     140            6 : CcuResult CcuAddressAssignImm(CcuAddressHandle addr, uint64_t immediate)
     141              : {
     142            6 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     143            6 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     144            6 :     CCU_CHK_PTR_NULL(kernel);
     145            6 :     CCU_CHK_RET(kernel->AddressAssignImm(addr, immediate));
     146            6 :     return CcuResult::CCU_SUCCESS;
     147              : }
     148              : 
     149           22 : CcuResult CcuAddressAssignAddr(CcuAddressHandle dstAddrHandle, CcuAddressHandle srcAddrHandle)
     150              : {
     151           22 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     152           22 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     153           22 :     CCU_CHK_PTR_NULL(kernel);
     154           22 :     CCU_CHK_RET(kernel->AddressAssignAddr(dstAddrHandle, srcAddrHandle));
     155           22 :     return CcuResult::CCU_SUCCESS;
     156              : }
     157              : 
     158            9 : CcuResult CcuAddressAssignVar(CcuAddressHandle addr, CcuVariableHandle var)
     159              : {
     160            9 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     161            9 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     162            9 :     CCU_CHK_PTR_NULL(kernel);
     163            9 :     CCU_CHK_RET(kernel->AddressAssignVar(addr, var));
     164            9 :     return CcuResult::CCU_SUCCESS;
     165              : }
     166              : 
     167            0 : CcuResult CcuAddressAddVarToAddr(CcuAddressHandle resAddr, CcuAddressHandle lhsAddr, CcuVariableHandle rhsVar)
     168              : {
     169            0 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     170            0 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     171            0 :     CCU_CHK_PTR_NULL(kernel);
     172            0 :     CCU_CHK_RET(kernel->AddressAddVarToAddr(resAddr, lhsAddr, rhsVar));
     173            0 :     return CcuResult::CCU_SUCCESS;
     174              : }
     175              : 
     176            1 : CcuResult CcuAddressAddAddrToAddr(CcuAddressHandle resAddr, CcuAddressHandle addrA, CcuAddressHandle addrB)
     177              : {
     178            1 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     179            1 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     180            1 :     CCU_CHK_PTR_NULL(kernel);
     181            1 :     CCU_CHK_RET(kernel->AddressAddAddrToAddr(resAddr, addrA, addrB));
     182            1 :     return CcuResult::CCU_SUCCESS;
     183              : }
     184              : 
     185           26 : CcuResult CcuAddressAddAssignVar(CcuAddressHandle addr, CcuVariableHandle var)
     186              : {
     187           26 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     188           26 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     189           26 :     CCU_CHK_PTR_NULL(kernel);
     190           26 :     CCU_CHK_RET(kernel->AddressAddAssignVar(addr, var));
     191           26 :     return CcuResult::CCU_SUCCESS;
     192              : }
     193              : 
     194              : //参数加载类 相关接口
     195           32 : CcuResult CcuLoadArg(CcuVariableHandle varHandle, uint32_t argId)
     196              : {
     197           32 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     198           32 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     199           32 :     CCU_CHK_PTR_NULL(kernel);
     200           32 :     CCU_CHK_RET(kernel->LoadArg(varHandle, argId));
     201           32 :     return CcuResult::CCU_SUCCESS;
     202              : }
     203              : 
     204            2 : CcuResult CcuLoadVar(uint64_t addr, CcuVariableHandle varHandle, uint32_t num)
     205              : {
     206            2 :     if (num == 0) {
     207            0 :         HCCL_ERROR("[CcuLoadVar] invalid args, num[%u]", num);
     208            0 :         return CcuResult::CCU_E_PARA;
     209              :     }
     210            2 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     211            2 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     212            2 :     CCU_CHK_PTR_NULL(kernel);
     213            2 :     CCU_CHK_RET(kernel->LoadVar(addr, varHandle, num));
     214            2 :     return CcuResult::CCU_SUCCESS;
     215              : }
     216              : 
     217            2 : CcuResult CcuLoadVarFromVarAddr(CcuVariableHandle addrHandle, CcuVariableHandle varHandle, uint32_t num)
     218              : {
     219            2 :     if (num == 0) {
     220            0 :         HCCL_ERROR("[CcuLoadVarFromVarAddr] invalid args, num[%u]", num);
     221            0 :         return CcuResult::CCU_E_PARA;
     222              :     }
     223            2 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     224            2 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     225            2 :     CCU_CHK_PTR_NULL(kernel);
     226            2 :     CCU_CHK_RET(kernel->CcuLoadVarFromVarAddr(addrHandle, varHandle, num));
     227            2 :     return CcuResult::CCU_SUCCESS;
     228              : }
     229              : 
     230            2 : CcuResult CcuStoreVar(uint64_t addr, CcuVariableHandle varHandle, uint32_t num)
     231              : {
     232            2 :     if (num == 0) {
     233            0 :         HCCL_ERROR("[CcuStoreVar] invalid args, num[%u]", num);
     234            0 :         return CcuResult::CCU_E_PARA;
     235              :     }
     236            2 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     237            2 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     238            2 :     CCU_CHK_PTR_NULL(kernel);
     239            2 :     CCU_CHK_RET(kernel->StoreVar(addr, varHandle, num));
     240            2 :     return CcuResult::CCU_SUCCESS;
     241              : }
     242              : 
     243            2 : CcuResult CcuStoreVarToVarAddr(CcuVariableHandle addrHandle, CcuVariableHandle varHandle, uint32_t num)
     244              : {
     245            2 :     if (num == 0) {
     246            0 :         HCCL_ERROR("[CcuStoreVarToVarAddr] invalid args, num[%u]", num);
     247            0 :         return CcuResult::CCU_E_PARA;
     248              :     }
     249            2 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     250            2 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     251            2 :     CCU_CHK_PTR_NULL(kernel);
     252            2 :     CCU_CHK_RET(kernel->CcuStoreVarToVarAddr(addrHandle, varHandle, num));
     253            2 :     return CcuResult::CCU_SUCCESS;
     254              : }
     255              : 
     256              : //Event信号同步类 相关接口
     257            6 : CcuResult CcuEventRecord(CcuEventHandle eventHandle, uint16_t mask)
     258              : {
     259            6 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     260            6 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     261            6 :     CCU_CHK_PTR_NULL(kernel);
     262            6 :     CCU_CHK_RET(kernel->EventRecord(eventHandle, mask));
     263            5 :     return CcuResult::CCU_SUCCESS;
     264              : }
     265           21 : CcuResult CcuEventWait(CcuEventHandle eventHandle, uint16_t mask)
     266              : {
     267           21 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     268           21 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     269           21 :     CCU_CHK_PTR_NULL(kernel);
     270           21 :     CCU_CHK_RET(kernel->EventWait(eventHandle, mask));
     271           21 :     return CcuResult::CCU_SUCCESS;
     272              : }
     273            3 : CcuResult CcuNotifyRecord(ChannelHandle channel, uint32_t remoteNotifyIdx, uint16_t mask)
     274              : {
     275            3 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     276            3 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     277            3 :     CCU_CHK_PTR_NULL(kernel);
     278            3 :     CCU_CHK_RET(kernel->NotifyRecord(channel, remoteNotifyIdx, mask));
     279            2 :     return CcuResult::CCU_SUCCESS;
     280              : }
     281            4 : CcuResult CcuNotifyWait(ChannelHandle channel, uint32_t localNotifyIdx, uint16_t mask)  
     282              : {
     283            4 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     284            4 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     285            4 :     CCU_CHK_PTR_NULL(kernel);
     286            4 :     CCU_CHK_RET(kernel->NotifyWait(channel, localNotifyIdx, mask));
     287            4 :     return CcuResult::CCU_SUCCESS;
     288              : }
     289            6 : CcuResult CcuWriteVariableWithNotify(ChannelHandle channel, CcuVariableHandle varHandle,uint32_t remoteVarIdx, uint32_t remoteNotifyIdx, uint16_t mask)
     290              : {
     291            6 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     292            6 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     293            6 :     CCU_CHK_PTR_NULL(kernel);
     294            6 :     CCU_CHK_RET(kernel->WriteVariableWithNotify(channel, varHandle, remoteVarIdx, remoteNotifyIdx, mask));
     295            5 :     return CcuResult::CCU_SUCCESS;
     296              : }
     297            1 : CcuResult CcuLocalNotifyRecord(const char *notifyTag, uint16_t mask)
     298              : {
     299            1 :     CCU_CHK_PTR_NULL(notifyTag);
     300            1 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     301            1 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     302            1 :     CCU_CHK_PTR_NULL(kernel);
     303            1 :     CCU_CHK_RET(kernel->LocalNotifyRecord(notifyTag, mask));
     304            0 :     return CcuResult::CCU_SUCCESS;
     305              : }
     306            0 : CcuResult CcuLocalNotifyWait(const char *notifyTag, uint16_t mask)
     307              : {
     308            0 :     CCU_CHK_PTR_NULL(notifyTag);
     309            0 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     310            0 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     311            0 :     CCU_CHK_PTR_NULL(kernel);
     312            0 :     CCU_CHK_RET(kernel->LocalNotifyWait(notifyTag, mask));
     313            0 :     return CcuResult::CCU_SUCCESS;
     314              : }
     315              : 
     316              : //本地数据拷贝 相关接口
     317            0 : CcuResult CcuLocalCopyMemToMem(
     318              :     CcuLocalAddrHandle dst, CcuLocalAddrHandle src,
     319              :     CcuVariableHandle len, CcuEventHandle event, uint16_t mask)
     320              : {
     321            0 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     322            0 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     323            0 :     CCU_CHK_PTR_NULL(kernel);
     324            0 :     CCU_CHK_RET(kernel->LocalCopyMemToMem(dst, src, len, event, mask));
     325            0 :     return CcuResult::CCU_SUCCESS;
     326              : }
     327              : 
     328            6 : CcuResult CcuLocalCopyMemToBuffer(
     329              :     CcuBufferHandle dst, CcuLocalAddrHandle src,
     330              :     CcuVariableHandle len, CcuEventHandle event, uint16_t mask)
     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->LocalCopyMemToBuffer(dst, src, len, event, mask));
     336            6 :     return CcuResult::CCU_SUCCESS;
     337              : }
     338              : 
     339            4 : CcuResult CcuLocalCopyBufferToMem(
     340              :     CcuLocalAddrHandle dst, CcuBufferHandle src,
     341              :     CcuVariableHandle len, CcuEventHandle event, uint16_t mask)
     342              : {
     343            4 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     344            4 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     345            4 :     CCU_CHK_PTR_NULL(kernel);
     346            4 :     CCU_CHK_RET(kernel->LocalCopyBufferToMem(dst, src, len, event, mask));
     347            4 :     return CcuResult::CCU_SUCCESS;
     348              : }
     349              : //本地reduce 相关接口
     350            0 : CcuResult CcuLocalMemReduce(CcuLocalAddrHandle dst, CcuLocalAddrHandle src, CcuVariableHandle len, HcclDataType dataType, HcclReduceOp opType, CcuEventHandle event, uint16_t mask)
     351              : {
     352            0 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     353            0 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     354            0 :     CCU_CHK_PTR_NULL(kernel);
     355            0 :     CCU_CHK_RET(kernel->LocalMemReduce(dst, src, len, dataType, opType, event, mask));
     356            0 :     return CcuResult::CCU_SUCCESS;
     357              : }
     358              : 
     359            2 : CcuResult CcuLocalBufferReduce(CcuBufferHandle* buffers, uint32_t count, HcclDataType dataType, HcclDataType outputDataType, HcclReduceOp opType, CcuVariableHandle len, CcuEventHandle event, uint16_t mask)
     360              : {
     361            2 :     if (buffers == nullptr || count == 0) {
     362            0 :         HCCL_ERROR("[CcuLocalBufferReduce] invalid args, buffers[%p] count[%u]", buffers, count);
     363            0 :         return CcuResult::CCU_E_PARA;
     364              :     }
     365            2 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     366            2 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     367            2 :     CCU_CHK_PTR_NULL(kernel);
     368            2 :     CCU_CHK_RET(kernel->LocalBufferReduce(buffers, count, dataType, outputDataType, opType, len, event, mask));
     369            2 :     return CcuResult::CCU_SUCCESS;
     370              : }
     371              : 
     372              : /*========== 远端数据传输操作 ==========*/
     373            2 : CcuResult CcuReadMemToMem(
     374              :     ChannelHandle channel, CcuLocalAddrHandle localHandle, CcuRemoteAddrHandle remoteHandle,
     375              :     CcuVariableHandle len, CcuEventHandle event, uint16_t mask)
     376              : {
     377            2 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     378            2 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     379            2 :     CCU_CHK_PTR_NULL(kernel);
     380            2 :     CCU_CHK_RET(kernel->ReadMemToMem(channel, localHandle, remoteHandle, len, event, mask));
     381            2 :     return CcuResult::CCU_SUCCESS;
     382              : }
     383              : 
     384            1 : CcuResult CcuReadMemToBuffer(
     385              :     ChannelHandle channel, CcuBufferHandle localHandle, CcuRemoteAddrHandle remoteHandle,
     386              :     CcuVariableHandle len, CcuEventHandle event, uint16_t mask)
     387              : {
     388            1 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     389            1 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     390            1 :     CCU_CHK_PTR_NULL(kernel);
     391            1 :     CCU_CHK_RET(kernel->ReadMemToBuffer(channel, localHandle, remoteHandle, len, event, mask));
     392            1 :     return CcuResult::CCU_SUCCESS;
     393              : }
     394              : 
     395            1 : CcuResult CcuReadMemToMemReduce(
     396              :     ChannelHandle channel, CcuLocalAddrHandle localHandle, CcuRemoteAddrHandle remoteHandle,
     397              :     CcuVariableHandle len, HcclDataType dataType,
     398              :     HcclReduceOp opType, CcuEventHandle event, uint16_t mask)
     399              : {
     400            1 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     401            1 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     402            1 :     CCU_CHK_PTR_NULL(kernel);
     403            1 :     CCU_CHK_RET(kernel->ReadMemToMemReduce(channel, localHandle, remoteHandle, len, dataType, opType, event, mask));
     404            1 :     return CcuResult::CCU_SUCCESS;
     405              : }
     406              : 
     407            2 : CcuResult CcuWriteMemToMem(
     408              :     ChannelHandle channel, CcuRemoteAddrHandle remoteHandle, CcuLocalAddrHandle localHandle, 
     409              :     CcuVariableHandle len, CcuEventHandle event, uint16_t mask)
     410              : {
     411            2 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     412            2 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     413            2 :     CCU_CHK_PTR_NULL(kernel);
     414            2 :     CCU_CHK_RET(kernel->WriteMemToMem(channel, remoteHandle, localHandle, len, event, mask));
     415            2 :     return CcuResult::CCU_SUCCESS;
     416              : }
     417              : 
     418            1 : CcuResult CcuWriteBufferToMem(
     419              :     ChannelHandle channel, CcuRemoteAddrHandle remote, CcuBufferHandle local, 
     420              :     CcuVariableHandle len, CcuEventHandle event, uint16_t mask)
     421              : {
     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->WriteBufferToMem(channel, remote, local, len, event, mask));
     426            1 :     return CcuResult::CCU_SUCCESS;
     427              : }
     428              : 
     429            1 : CcuResult CcuWriteMemToMemReduce(
     430              :     ChannelHandle channel, CcuRemoteAddrHandle remote, CcuLocalAddrHandle local,
     431              :     CcuVariableHandle len, HcclDataType dataType,
     432              :     HcclReduceOp opType, CcuEventHandle event, uint16_t mask)
     433              : {
     434            1 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     435            1 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     436            1 :     CCU_CHK_PTR_NULL(kernel);
     437            1 :     CCU_CHK_RET(kernel->WriteMemToMemReduce(channel, remote, local, len, dataType, opType, event, mask));
     438            1 :     return CcuResult::CCU_SUCCESS;
     439              : }
     440              : 
     441              : /*========== 控制流操作 ==========*/
     442           17 : CcuResult CcuIfBegin(CcuVariableHandle var, uint64_t immediate,
     443              :     CcuConditionType condType, const char *label)
     444              : {
     445           17 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     446           17 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     447           17 :     CCU_CHK_PTR_NULL(kernel);
     448           17 :     CCU_CHK_RET(kernel->IfBegin(var, immediate, condType, label));
     449              : 
     450           16 :     return CcuResult::CCU_SUCCESS;
     451              : }
     452              : 
     453            2 : CcuResult CcuIfElse(const char *label)
     454              : {
     455            2 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     456            2 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     457            2 :     CCU_CHK_PTR_NULL(kernel);
     458            2 :     CCU_CHK_RET(kernel->IfElse(label));
     459              : 
     460            2 :     return CcuResult::CCU_SUCCESS;
     461              : }
     462              : 
     463            2 : CcuResult CcuIfEnd(const char *label)
     464              : {
     465            2 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     466            2 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     467            2 :     CCU_CHK_PTR_NULL(kernel);
     468            2 :     CCU_CHK_RET(kernel->IfEnd(label));
     469              : 
     470            2 :     return CcuResult::CCU_SUCCESS;
     471              : }
     472              : 
     473           16 : CcuResult CcuFlushPendingIfs()
     474              : {
     475           16 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     476           16 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     477           16 :     CCU_CHK_PTR_NULL(kernel);
     478           16 :     kernel->FlushClosablePendingIfs();
     479           16 :     return CcuResult::CCU_SUCCESS;
     480              : }
     481              : 
     482            2 : CcuResult CcuWhileBegin(CcuVariableHandle var, uint64_t immediate,
     483              :     CcuConditionType condType, const char *label)
     484              : {
     485            2 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     486            2 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     487            2 :     CCU_CHK_PTR_NULL(kernel);
     488            2 :     CCU_CHK_RET(kernel->WhileBegin(var, immediate, condType, label));
     489              : 
     490            2 :     return CcuResult::CCU_SUCCESS;
     491              : }
     492              : 
     493            2 : CcuResult CcuWhileEnd(const char *label)
     494              : {
     495            2 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     496            2 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     497            2 :     CCU_CHK_PTR_NULL(kernel);
     498            2 :     CCU_CHK_RET(kernel->WhileEnd(label));
     499              : 
     500            2 :     return CcuResult::CCU_SUCCESS;
     501              : }
     502              : 
     503            3 : CcuResult CcuDoWhileBegin(const char *label)
     504              : {
     505            3 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     506            3 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     507            3 :     CCU_CHK_PTR_NULL(kernel);
     508            3 :     CCU_CHK_RET(kernel->DoWhileBegin(label));
     509              : 
     510            3 :     return CcuResult::CCU_SUCCESS;
     511              : }
     512              : 
     513            3 : CcuResult CcuDoWhileEnd(CcuVariableHandle var, uint64_t immediate,
     514              :     CcuConditionType condType, const char *label)
     515              : {
     516            3 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     517            3 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     518            3 :     CCU_CHK_PTR_NULL(kernel);
     519            3 :     CCU_CHK_RET(kernel->DoWhileEnd(var, immediate, condType, label));
     520              : 
     521            3 :     return CcuResult::CCU_SUCCESS;
     522              : }
     523              : 
     524              : /*========== 函数调用操作 ==========*/
     525            8 : CcuResult CcuFuncBlockLookup(const void *funcPtr, uint64_t *outHandle)
     526              : {
     527            8 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     528            8 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     529            8 :     CCU_CHK_PTR_NULL(kernel);
     530            8 :     CCU_CHK_RET(kernel->FuncBlockLookup(funcPtr, outHandle));
     531            6 :     return CcuResult::CCU_SUCCESS;
     532              : }
     533              : 
     534            5 : CcuResult CcuFuncBlockBegin(const void *funcPtr, uint64_t *outHandle)
     535              : {
     536            5 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     537            5 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     538            5 :     CCU_CHK_PTR_NULL(kernel);
     539            5 :     CCU_CHK_RET(kernel->FuncBlockBegin(funcPtr, outHandle));
     540            5 :     return CcuResult::CCU_SUCCESS;
     541              : }
     542              : 
     543            4 : CcuResult CcuFuncBlockEnd(uint64_t handle)
     544              : {
     545            4 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     546            4 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     547            4 :     CCU_CHK_PTR_NULL(kernel);
     548            4 :     CCU_CHK_RET(kernel->FuncBlockEnd(handle));
     549            4 :     return CcuResult::CCU_SUCCESS;
     550              : }
     551              : 
     552            7 : CcuResult CcuFuncDefineInArg(uint64_t handle, CcuVariableHandle formal)
     553              : {
     554            7 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     555            7 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     556            7 :     CCU_CHK_PTR_NULL(kernel);
     557            7 :     CCU_CHK_RET(kernel->FuncDefineInArg(handle, formal));
     558            7 :     return CcuResult::CCU_SUCCESS;
     559              : }
     560              : 
     561            5 : CcuResult CcuFuncCall(uint64_t handle, const CcuVariableHandle *inArgs, uint32_t numIn)
     562              : {
     563            5 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     564            5 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     565            5 :     CCU_CHK_PTR_NULL(kernel);
     566            5 :     CCU_CHK_RET(kernel->FuncCall(handle, inArgs, numIn));
     567            5 :     return CcuResult::CCU_SUCCESS;
     568              : }
     569              : 
     570              : /*========== 循环操作 ==========*/
     571           30 : CcuResult CcuLoopCreate(CcuLoop *loop)
     572              : {
     573           30 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     574           30 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     575           30 :     CCU_CHK_PTR_NULL(kernel);
     576           30 :     CCU_CHK_RET(kernel->LoopCreate(loop));
     577           30 :     return CcuResult::CCU_SUCCESS;
     578              : }
     579              : 
     580           30 : CcuResult _CcuLoopBodyEnter(CcuLoop loop)
     581              : {
     582           30 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     583           30 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     584           30 :     CCU_CHK_PTR_NULL(kernel);
     585           30 :     CCU_CHK_RET(kernel->LoopBodyEnter(loop));
     586           30 :     return CcuResult::CCU_SUCCESS;
     587              : }
     588              : 
     589           30 : CcuResult _CcuLoopBodyExit(CcuLoop loop)
     590              : {
     591           30 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     592           30 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     593           30 :     CCU_CHK_PTR_NULL(kernel);
     594           30 :     CCU_CHK_RET(kernel->LoopBodyExit(loop));
     595           24 :     return CcuResult::CCU_SUCCESS;
     596              : }
     597              : 
     598            8 : CcuResult CcuLoopGroupCreate(CcuLoopGroup *group, uint32_t maxLoopNum,
     599              :     const CcuLoopGroupConfig *config)
     600              : {
     601            8 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     602            8 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     603            8 :     CCU_CHK_PTR_NULL(kernel);
     604            8 :     CCU_CHK_RET(kernel->LoopGroupCreate(group, maxLoopNum, config));
     605            8 :     return CcuResult::CCU_SUCCESS;
     606              : }
     607              : 
     608           10 : CcuResult CcuLoopGroupCreateFromVar(CcuLoopGroup *group, uint32_t maxLoopNum,
     609              :     CcuVariableHandle parallelVar, CcuVariableHandle offsetVar)
     610              : {
     611           10 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     612           10 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     613           10 :     CCU_CHK_PTR_NULL(kernel);
     614           10 :     CCU_CHK_RET(kernel->LoopGroupCreateFromVar(group, maxLoopNum, parallelVar, offsetVar));
     615           10 :     return CcuResult::CCU_SUCCESS;
     616              : }
     617              : 
     618           17 : CcuResult CcuLoopGroupAddLoop(CcuLoopGroup group,
     619              :     CcuLoop loop, const CcuLoopConfig *config)
     620              : {
     621           17 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     622           17 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     623           17 :     CCU_CHK_PTR_NULL(kernel);
     624           17 :     CCU_CHK_RET(kernel->LoopGroupAddLoop(group, loop, config));
     625           17 :     return CcuResult::CCU_SUCCESS;
     626              : }
     627              : 
     628           19 : CcuResult CcuLoopGroupAddLoopFromVar(CcuLoopGroup group,
     629              :     CcuLoop loop, CcuVariableHandle loopParamVar)
     630              : {
     631           19 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     632           19 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     633           19 :     CCU_CHK_PTR_NULL(kernel);
     634           19 :     CCU_CHK_RET(kernel->LoopGroupAddLoopFromVar(group, loop, loopParamVar));
     635           19 :     return CcuResult::CCU_SUCCESS;
     636              : }
     637              : 
     638              : //控制流标签栈 C 接口(_CcuIfStack* / _CcuDoWhileStack*)
     639              :  
     640           16 : void _CcuIfStackPush(const char *label)
     641              : {
     642           16 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     643           16 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     644           16 :     if (kernel == nullptr) {
     645            0 :         HCCL_ERROR("[_CcuIfStackPush] no current kernel, label=%s",
     646              :             label != nullptr ? label : "(null)");
     647            0 :         return;
     648              :     }
     649           16 :     kernel->IfLabelStackPush(label);
     650              : }
     651              : 
     652           16 : void _CcuIfStackMarkBodyDone()
     653              : {
     654           16 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     655           16 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     656           16 :     if (kernel == nullptr) {
     657            0 :         HCCL_ERROR("[_CcuIfStackMarkBodyDone] no current kernel");
     658            0 :         return;
     659              :     }
     660           16 :     kernel->IfLabelStackMarkBodyDone();
     661              : }
     662              : 
     663            2 : const char *_CcuIfStackPopForElse()
     664              : {
     665            2 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     666            2 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     667            2 :     if (kernel == nullptr) {
     668            0 :         HCCL_ERROR("[_CcuIfStackPopForElse] no current kernel");
     669            0 :         return nullptr;
     670              :     }
     671            2 :     return kernel->IfLabelStackPopForElse();
     672              : }
     673              : 
     674            3 : void _CcuDoWhileStackPush(const char *label)
     675              : {
     676            3 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     677            3 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     678            3 :     if (kernel == nullptr) {
     679            0 :         HCCL_ERROR("[_CcuDoWhileStackPush] no current kernel, label=%s",
     680              :             label != nullptr ? label : "(null)");
     681            0 :         return;
     682              :     }
     683            3 :     kernel->DoWhileLabelStackPush(label);
     684              : }
     685              : 
     686            5 : const char *_CcuDoWhileStackPopForWhile()
     687              : {
     688            5 :     const uint32_t devLogicId = HcclGetThreadDeviceId();
     689            5 :     auto kernel = hcomm::CcuKernelMgr::GetInstance(devLogicId).GetCurrentKernel();
     690            5 :     if (kernel == nullptr) {
     691              :         // 见上方注释:CCU_WHILE 每次都会调本函数做模式判别,保持沉默。
     692            0 :         return nullptr;
     693              :     }
     694            5 :     return kernel->DoWhileLabelStackPopForWhile();
     695              : }
        

Generated by: LCOV version 2.0-1