LCOV - code coverage report
Current view: top level - base_comm/resources/ccu/pub_inc - ccu_device_pub.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 3 3
Test Date: 2026-07-28 12:11:00 Functions: 100.0 % 1 1

            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              : #ifndef CCU_DEVICE_PUB_H
      12              : #define CCU_DEVICE_PUB_H
      13              : 
      14              : #include <memory>
      15              : #include <vector>
      16              : #include <cstdint>
      17              : 
      18              : #include "ccu_common.h"
      19              : #include "ccu_device_res.h"
      20              : #include "ccu_res_repo.h"
      21              : #include "ccu_drv_handle.h"
      22              : 
      23              : #include "hccl_types.h"
      24              : #include "enum_factory.h"
      25              : #include "hccl_rank_graph.h"
      26              : 
      27              : // 支持新老通信域混跑,引入legacy数据结构
      28              : #include "unified_platform/pub_inc/ccu/ccu_dev_mgr.h"
      29              : 
      30              : namespace hcomm {
      31              : 
      32              : using CcuResHandle = void *;
      33              : 
      34              : // 不复用legacy数据结构,对上层支持CommAddr,不使用Hccl::IpAddress
      35              : struct CcuChannelPara {
      36              :     CommAddr commAddr{};
      37              :     uint32_t channelNum{0};
      38              :     uint32_t jettyNum{0};
      39              :     uint32_t sqSize{0};
      40              : 
      41              :     CcuChannelPara() = default;
      42           12 :     CcuChannelPara(const CommAddr &address, const uint32_t channelNum,
      43              :         const uint32_t jettyNum, const uint32_t sqSize)
      44           12 :         : commAddr(address), channelNum(channelNum), jettyNum(jettyNum), sqSize(sqSize) {
      45           12 :     }
      46              : };
      47              : 
      48              : using CcuJettyType = Hccl::CcuJettyType;
      49              : /* 开源自定义算子CCU设备管理实现,当前支持新老通信域混跑,
      50              :  * 暂时改用legacy数据结构,避免反向依赖
      51              :  * MAKE_ENUM(CcuJettyType, CCUM_CACHED_JETTY, TA_CACHED_JETTY, INVALID_JETTY);
      52              :  */
      53              : 
      54              : using CcuJettyInfo = Hccl::CcuJettyInfo;
      55              : /* 开源自定义算子CCU设备管理实现,当前支持新老通信域混跑,
      56              :  * 暂时改用legacy数据结构,避免反向依赖
      57              :  * struct CcuJettyInfo {
      58              :  *     CcuJettyType jettyType{CcuJettyType::INVALID_JETTY};
      59              :  *     uint16_t jettyCtxId{0};
      60              :  *     uint16_t taJettyId{0};
      61              : 
      62              :  *     uint32_t sqDepth{0};
      63              :  *     uint32_t wqeBBStartId{0};
      64              : 
      65              :  *     uint64_t sqBufVa{0};
      66              :  *     uint32_t sqBufSize{0};
      67              :  * };
      68              :  */
      69              : 
      70              : using CcuChannelInfo = Hccl::CcuChannelInfo;
      71              : /* 开源自定义算子CCU设备管理实现,当前支持新老通信域混跑,
      72              :  * 暂时改用legacy数据结构,避免反向依赖
      73              :  * struct CcuChannelInfo {
      74              :  *     uint32_t channelId{0};
      75              :  *     uint8_t dieId{0};
      76              :  *     std::vector<CcuJettyInfo> jettyInfos;
      77              :  * };
      78              :  */
      79              : 
      80              : /**
      81              :  * @brief 启用CCU特性,初始化CCU平台层
      82              :  *
      83              :  * @param deviceLogicId 设备逻辑ID
      84              :  * @param ccuDrvHandle CCU驱动句柄
      85              :  * @return HcclResult 返回HcclResult类型的结果
      86              :  * @note 资源不足时返回HCCL_E_UNAVIL,其余非HCCL_SUCCESS结果属于错误
      87              :  */
      88              : CcuResult CcuInitFeature(const int32_t devLogicId, std::shared_ptr<CcuDrvHandle> &ccuDrvHandle);
      89              : 
      90              : /**
      91              :  * @brief 关闭CCU特性,解初始化CCU平台层
      92              :  *
      93              :  * @param deviceLogicId 设备逻辑ID
      94              :  * @return HcclResult 返回HcclResult类型的结果
      95              :  * @note 资源不足时返回HCCL_E_UNAVIL,其余非HCCL_SUCCESS结果属于错误
      96              :  */
      97              : CcuResult CcuDeinitFeature(const int32_t devLogicId);
      98              : 
      99              : /**
     100              :  * @brief 申请批量ccu channel资源
     101              :  *
     102              :  * @param deviceLogicId device逻辑ID
     103              :  * @param dieId ccu channel 所属的 IO Die 编号
     104              :  * @param enableFlag 出参,表示该die是否启用
     105              :  * @return HcclResult 返回HcclResult类型的结果
     106              :  * @note dieId越界时返回HCCL_E_PARA
     107              :  */
     108              : CcuResult CcuGetDieEnableInfo(int32_t deviceLogicId, uint8_t dieId, bool &enableFlag);
     109              : 
     110              : /**
     111              :  * @brief 按加速引擎模式申请批量资源
     112              :  *
     113              :  * @param deviceLogicId 设备逻辑ID
     114              :  * @param ccuEngine CCU通信引擎类型
     115              :  * @param resHandle 返回的CCU批量资源句柄
     116              :  * @return HcclResult 返回HcclResult类型的结果
     117              :  * @note 资源不足时返回HCCL_E_UNAVIL,其余非HCCL_SUCCESS结果属于错误
     118              :  */
     119              : CcuResult CcuAllocResHandleByInsType(int32_t deviceLogicId,
     120              :     CcuInstanceType ccuInsType, CcuResHandle &resHandle);
     121              : 
     122              : /**
     123              :  * @brief 根据资源句柄查看对应资源信息
     124              :  *
     125              :  * @param deviceLogicId 设备逻辑ID
     126              :  * @param resHandle 查询的CCU批量资源句柄
     127              :  * @param resRepo 返回的CCU批量资源信息
     128              :  * @return HcclResult 返回HcclResult类型的结果
     129              :  * @note 资源句柄无法查找到时返回HCCL_E_NOT_FOUND,其余非HCCL_SUCCESS结果属于错误
     130              :  */
     131              : CcuResult CcuCheckResource(const int32_t deviceLogicId,
     132              :     const CcuResHandle resHandle, CcuResRepository &resRepo);
     133              : 
     134              : /**
     135              :  * @brief 根据资源句柄释放对应资源信息
     136              :  *
     137              :  * @param deviceLogicId 设备逻辑ID
     138              :  * @param resHandle 查询的CCU批量资源句柄
     139              :  * @note 资源句柄无法查找到时返回HCCL_E_NOT_FOUND,其余非HCCL_SUCCESS结果属于错误
     140              :  * @note 返回批量的channel资源总数可能超过申请数量,jettyNum为0时由平台层决定分配数量
     141              :  */
     142              : HcclResult CcuReleaseResHandle(const int32_t deviceLogicId, const CcuResHandle handle);
     143              : 
     144              : /**
     145              :  * @brief 申请批量ccu channel资源
     146              :  *
     147              :  * @param deviceLogicId device逻辑ID
     148              :  * @param ccuChannelPara ccu channel 申请参数
     149              :  * @param ccuChannelInfos 返回的channel资源信息
     150              :  * @return HcclResult 返回HcclResult类型的结果
     151              :  * @note 返回批量的channel资源总数可能超过申请数量,jettyNum为0时由平台层决定分配数量
     152              :  */
     153              : HcclResult CcuAllocChannels(const int32_t deviceLogicId, const CcuChannelPara &ccuChannelPara,
     154              :     std::vector<CcuChannelInfo> &ccuChannelInfos);
     155              : 
     156              : /**
     157              :  * @brief 释放ccu channel资源
     158              :  *
     159              :  * @param deviceLogicId device逻辑ID
     160              :  * @param dieId ccu channel 所属的 IO Die 编号
     161              :  * @param ccuChannelId ccu channel 编号
     162              :  * @return HcclResult 返回HcclResult类型的结果
     163              :  * @note 无
     164              :  */
     165              : HcclResult CcuReleaseChannel(const int32_t deviceLogicId, const uint8_t dieId, const uint32_t ccuChannelId);
     166              : 
     167              : /**
     168              :  * @brief 查询CCU设备是否已完成初始化
     169              :  *
     170              :  * @param deviceLogicId 设备逻辑ID
     171              :  * @return bool true表示已初始化,false表示未初始化或入参非法
     172              :  * @note 无
     173              :  */
     174              : bool CcuIsInited(const int32_t deviceLogicId);
     175              : 
     176              : /**
     177              :  * @brief 触发CCU Task Kill
     178              :  *
     179              :  * @param deviceLogicId device逻辑ID
     180              :  * @return HcclResult 返回HcclResult类型的结果
     181              :  * @note 该接口会处理全部die,未启用die将跳过
     182              :  */
     183              : HcclResult CcuSetTaskKill(const int32_t deviceLogicId);
     184              : 
     185              : /**
     186              :  * @brief 配置CCU Task Kill完成状态
     187              :  *
     188              :  * @param deviceLogicId device逻辑ID
     189              :  * @return HcclResult 返回HcclResult类型的结果
     190              :  * @note 该接口会处理全部die,未启用die将跳过
     191              :  */
     192              : HcclResult CcuSetTaskKillDone(const int32_t deviceLogicId);
     193              : 
     194              : /**
     195              :  * @brief 清空CCU Task Kill状态
     196              :  *
     197              :  * @param deviceLogicId device逻辑ID
     198              :  * @return HcclResult 返回HcclResult类型的结果
     199              :  * @note 该接口会处理全部die,未启用die将跳过
     200              :  */
     201              : HcclResult CcuCleanTaskKillState(const int32_t deviceLogicId);
     202              : 
     203              : /**
     204              :  * @brief 清理指定ioDie CCU的全部CKE资源,重置为0
     205              :  *
     206              :  * @param deviceLogicId device逻辑ID
     207              :  * @return HcclResult 返回HcclResult类型的结果
     208              :  * @note 未启用die无需清理将视为成功
     209              :  */
     210              : HcclResult CcuCleanDieCkes(const int32_t deviceLogicId, const uint8_t dieId);
     211              : 
     212              : }; // namespace hcomm
     213              : #endif // CCU_DEVICE_PUB_H
        

Generated by: LCOV version 2.0-1