LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/ccu/ccu_context - ccu_context_mgr.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 66.7 % 18 12
Test Date: 2026-08-18 17:47:01 Functions: 41.7 % 12 5

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2025 Huawei Technologies Co., Ltd.
       3              :  * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
       4              :  * CANN Open Software License Agreement Version 2.0 (the "License").
       5              :  * Please refer to the License for details. You may not use this file except in compliance with the License.
       6              :  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
       7              :  * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
       8              :  * See LICENSE in the root of the software repository for the full text of the License.
       9              :  */
      10              : 
      11              : #include "ccu_ctx_mgr.h"
      12              : #include "ins_exe_que.h"
      13              : #include "ccu_context_mgr_imp.h"
      14              : #include "hccl_common_v2.h"
      15              : #include "exception_util.h"
      16              : 
      17              : namespace Hccl {
      18              : /**
      19              :  * @brief 分配资源
      20              :  *
      21              :  * @param deviceLogicId device逻辑ID
      22              :  * @param ctxGroup CCU上下文组
      23              :  * @param resPack 资源包
      24              :  *
      25              :  * @return 返回HcclResult,表示分配资源是否成功
      26              :  * @note 此函数用于分配资源
      27              :  */
      28            3 : HcclResult CcuCtxMgr::AllocRes(s32 deviceLogicId, CcuCtxGroup& ctxGroup, CcuResPack& resPack)
      29              : {
      30           12 :     TRY_CATCH_RETURN(
      31              :         HCCL_INFO("[AllocRes] Input params: deviceLogicId[%d], ctxGroup size[%u]", deviceLogicId, ctxGroup.ctxs.size());
      32              :         // 入参校验拦截
      33              :         CHK_PRT_RET(
      34              :             (deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
      35              :             HCCL_ERROR(
      36              :                 "[CcuCtxMgr][AllocRes]deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId,
      37              :                 MAX_MODULE_DEVICE_NUM),
      38              :             HcclResult::HCCL_E_PARA);
      39              : 
      40              :         CHK_PRT_RET(
      41              :             ctxGroup.ctxs.size() == 0, HCCL_ERROR("[CcuCtxMgr][AllocRes]ctxs size is zero"), HcclResult::HCCL_E_PARA);
      42              : 
      43              :         CHK_RET_UNAVAIL(CtxMgrImp::GetInstance(deviceLogicId).AllocRes(ctxGroup, resPack)););
      44              : 
      45            3 :     return HcclResult::HCCL_SUCCESS;
      46              : }
      47              : 
      48              : /**
      49              :  * @brief 释放资源
      50              :  *
      51              :  * @param deviceLogicId device逻辑ID
      52              :  * @param ctxGroup CCU上下文组
      53              :  *
      54              :  * @return 返回HcclResult,表示释放资源是否成功
      55              :  *
      56              :  * @note 此函数用于释放指定device设备ID的CCU上下文组的资源
      57              :  */
      58            0 : HcclResult CcuCtxMgr::ReleaseRes(s32 deviceLogicId, CcuCtxGroup& ctxGroup)
      59              : {
      60            0 :     TRY_CATCH_RETURN(
      61              :         HCCL_RUN_INFO(
      62              :             "[CcuCtxMgr]ReleaseRes: deviceLogicId[%d], ctxGroup size[%u]", deviceLogicId, ctxGroup.ctxs.size());
      63              : 
      64              :         // 入参校验拦截
      65              :         CHK_PRT_RET(
      66              :             (deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
      67              :             HCCL_ERROR("[CcuCtxMgr][ReleaseRes]deviceLogicId[%d] error", deviceLogicId), HcclResult::HCCL_E_PARA);
      68              : 
      69              :         CHK_PRT_RET(
      70              :             ctxGroup.ctxs.size() == 0, HCCL_ERROR("[CcuCtxMgr][ReleaseRes]ctxs size is zero"), HcclResult::HCCL_E_PARA);
      71              : 
      72              :         CHK_RET(CtxMgrImp::GetInstance(deviceLogicId).ReleaseRes(ctxGroup));
      73              : 
      74              :         HCCL_RUN_INFO(
      75              :             "[CcuCtxMgr]ReleaseRes:success deviceLogicId[%d], ctxGroup size[%u]", deviceLogicId,
      76              :             ctxGroup.ctxs.size()););
      77              : 
      78            0 :     return HcclResult::HCCL_SUCCESS;
      79              : }
      80              : 
      81              : /**
      82              :  * @brief 获取任务参数
      83              :  *
      84              :  * @param deviceLogicId device逻辑ID
      85              :  * @param ccuTaskArg CCU 任务参数
      86              :  * @param executorId 执行器ID
      87              :  * @param taskParam 任务参数
      88              :  *
      89              :  * @return HcclResult 获取参数结果
      90              :  * @note 无
      91              :  */
      92            8 : HcclResult CcuCtxMgr::GetTaskParam(
      93              :     s32 deviceLogicId, CcuTaskArg& ccuTaskArg, const uint64_t executorId,
      94              :     std::vector<std::vector<CcuTaskParam>>& taskParam)
      95              : {
      96          410 :     TRY_CATCH_RETURN(
      97              :         HCCL_INFO("[GetTaskParam] Input params: deviceLogicId[%d], executorId[%llu]", deviceLogicId, executorId);
      98              :         // 入参校验拦截
      99              :         CHK_PRT_RET(
     100              :             (deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
     101              :             HCCL_ERROR(
     102              :                 "[CcuCtxMgr][GetTaskParam]deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId,
     103              :                 MAX_MODULE_DEVICE_NUM),
     104              :             HcclResult::HCCL_E_PARA);
     105              : 
     106              :         taskParam = CtxMgrImp::GetInstance(deviceLogicId).GetTaskParam(ccuTaskArg, executorId);
     107              : 
     108              :         // 校验taskParam是否为空
     109              :         CHK_PRT_RET(
     110              :             (taskParam.size() == 0), HCCL_ERROR("[CcuCtxMgr][GetTaskParam]GetTaskParam fail"),
     111              :             HcclResult::HCCL_E_PARA););
     112              : 
     113            2 :     return HcclResult::HCCL_SUCCESS;
     114              : }
     115              : 
     116              : /**
     117              :  * @brief 注册扩展指令
     118              :  *
     119              :  * @param deviceLogicId device逻辑ID
     120              :  * @param entity 扩展指令执行实体
     121              :  * @param entityId 扩展指令执行实体ID
     122              :  * @return HcclResult 返回HcclResult类型的结果
     123              :  * @note 无
     124              :  */
     125            3 : HcclResult InsExeQue::RegisterExtendInstruction(s32 deviceLogicId, ExtInsExeEntity& entity, ExtInsExeEntityId& entityId)
     126              : {
     127            3 :     TRY_CATCH_RETURN(
     128              :         // 入参校验拦截
     129              :         CHK_PRT_RET(
     130              :             (deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
     131              :             HCCL_ERROR("[CcuCtxMgr][RegisterExtendInstruction]deviceLogicId[%d] error", deviceLogicId),
     132              :             HcclResult::HCCL_E_PARA);
     133              : 
     134              :         CHK_PRT_RET(
     135              :             entity.ctxGroup.ctxs.size() == 0, HCCL_ERROR("[InsExeQue][RegisterExtendInstruction]ctxs size is zero"),
     136              :             HcclResult::HCCL_E_PARA);
     137              : 
     138              :         entityId = CtxMgrImp::GetInstance(deviceLogicId).Register(entity.ctxGroup, entity.isFuncBlock););
     139            3 :     return HcclResult::HCCL_SUCCESS;
     140              : }
     141              : 
     142              : /**
     143              :  * @brief 注销扩展指令
     144              :  *
     145              :  * @param deviceLogicId device逻辑ID
     146              :  * @param entityId 扩展指令执行实体ID
     147              :  * @return HcclResult 返回HcclResult类型的结果
     148              :  * @note 此函数用于注销扩展指令
     149              :  */
     150            9 : HcclResult InsExeQue::DeregisterExtendInstruction(s32 deviceLogicId, const ExtInsExeEntityId& entityId)
     151              : {
     152           61 :     TRY_CATCH_RETURN(
     153              :         HCCL_RUN_INFO(
     154              :             "[InsExeQue]DeregisterExtendInstruction: deviceLogicId[%d], executorId[%llu]", deviceLogicId, entityId);
     155              :         // 入参校验拦截
     156              :         CHK_PRT_RET(
     157              :             (deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
     158              :             HCCL_ERROR("[CcuCtxMgr][DeregisterExtendInstruction]deviceLogicId[%d] error", deviceLogicId),
     159              :             HcclResult::HCCL_E_PARA);
     160              : 
     161              :         CHK_RET(CtxMgrImp::GetInstance(deviceLogicId).UnRegister(entityId));
     162              : 
     163              :         HCCL_RUN_INFO(
     164              :             "[InsExeQue]DeregisterExtendInstruction:success deviceLogicId[%d], executorId[%llu]", deviceLogicId,
     165              :             entityId););
     166            2 :     return HcclResult::HCCL_SUCCESS;
     167              : }
     168              : 
     169              : /**
     170              :  * @brief 获取任务Profiling信息
     171              :  *
     172              :  * @param deviceLogicId device逻辑ID
     173              :  * @param ccuTaskArg CCU 任务参数
     174              :  * @param entityId 执行器ID
     175              :  * @param profilingInfo 任务profiling信息
     176              :  *
     177              :  * @return HcclResult 获取profiling结果
     178              :  * @note 无
     179              :  */
     180            0 : HcclResult CcuCtxMgr::GetProfilingInfo(
     181              :     s32 deviceLogicId, CcuTaskArg& ccuTaskArg, uint64_t entityId,
     182              :     std::vector<std::vector<CcuProfilingInfo>>& profilingInfo)
     183              : {
     184            0 :     TRY_CATCH_RETURN(
     185              :         HCCL_INFO("[GetProfilingInfo] Input params: deviceLogicId[%d], entityId[%llu]", deviceLogicId, entityId);
     186              :         // 入参校验拦截
     187              :         CHK_PRT_RET(
     188              :             (deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
     189              :             HCCL_ERROR(
     190              :                 "[CcuCtxMgr][GetProfilingInfo]deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId,
     191              :                 MAX_MODULE_DEVICE_NUM),
     192              :             HcclResult::HCCL_E_PARA);
     193              : 
     194              :         profilingInfo = CtxMgrImp::GetInstance(deviceLogicId).GetProfilingInfo(ccuTaskArg, entityId);
     195              : 
     196              :         // 校验profilingInfo是否为空
     197              :         CHK_PRT_RET(
     198              :             (profilingInfo.size() == 0), HCCL_ERROR("[CcuCtxMgr][GetProfilingInfo]GetProfilingInfo fail"),
     199              :             HcclResult::HCCL_E_PARA););
     200              : 
     201            0 :     return HcclResult::HCCL_SUCCESS;
     202              : }
     203              : 
     204              : }; // namespace Hccl
        

Generated by: LCOV version 2.0-1