LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/common - inner_net_dev.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 81.8 % 55 45
Test Date: 2026-08-18 17:47:01 Functions: 80.0 % 5 4

            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 "inner_net_dev.h"
      12              : #include "null_ptr_exception.h"
      13              : #include "exception_util.h"
      14              : #include "network_api_exception.h"
      15              : 
      16              : namespace Hccl {
      17           17 : InnerNetDev::InnerNetDev(const NetDevInfo& info)
      18              : {
      19           17 :     IpAddress localIp = info.addr;
      20              : 
      21           17 :     RaInterface intf{};
      22           17 :     intf.address = localIp;
      23           17 :     intf.phyId = info.devId;
      24              : 
      25           51 :     HCCL_DEBUG("InnerNetDev::Init, devPhyId[%u]", info.devId);
      26              : 
      27           17 :     localProto_ = info.protoType;
      28           17 :     if (info.type == PortDeploymentType::HOST_NET) {
      29            2 :         netMode_ = HrtNetworkMode::PEER;
      30              :     }
      31              : 
      32              :     try {
      33           17 :         if (localProto_ == LinkProtoType::RDMA) {
      34           12 :             rdmaHandle_ = HrtRaRdmaInit(netMode_, intf);
      35           12 :             auto dieAndFuncId = HraGetDieAndFuncId(rdmaHandle_);
      36           12 :             dieId_ = dieAndFuncId.first;
      37           12 :             funcId_ = dieAndFuncId.second;
      38              : 
      39           12 :             auto tokenIdHandlePair = RaUbAllocTokenIdHandle(rdmaHandle_);
      40           12 :             tokenHandle_ = tokenIdHandlePair.first;
      41           12 :             tokenId_ = tokenIdHandlePair.second;
      42            5 :         } else if (localProto_ == LinkProtoType::UB) {
      43            4 :             HrtRaUbCtxInitParam in(HrtNetworkMode::HDC, info.devId, localIp);
      44            4 :             rdmaHandle_ = HrtRaUbCtxInit(in);
      45            4 :             tokenInfoManager_ = make_unique<TokenInfoManager>(info.devId, rdmaHandle_);
      46              :         }
      47           17 :         isValid_ = true;
      48            0 :     } catch (const NetworkApiException& e) {
      49            0 :         HCCL_ERROR("%s", e.what());
      50            0 :         isValid_ = false;
      51            0 :     }
      52           17 : }
      53              : 
      54            2 : JfcHandle InnerNetDev::getUbJfcHandle(HrtUbJfcMode jfcMode)
      55              : {
      56            2 :     if (rdmaHandle_ == nullptr) {
      57            1 :         THROW<NullPtrException>("[InnerNetDev::%s] rdmaHandle_ is nullptr", __func__);
      58              :     }
      59              :     CqCreateInfo cqInfo;
      60            1 :     ubJfcHandle_ = HrtRaUbCreateJfc(rdmaHandle_, cqInfo, jfcMode);
      61            1 :     return ubJfcHandle_;
      62              : }
      63              : 
      64            2 : std::pair<TokenIdHandle, uint32_t> InnerNetDev::getTokenIdInfo(const BufferKey<uintptr_t, u64>& bufKey)
      65              : {
      66            2 :     if (tokenInfoManager_ == nullptr) {
      67            0 :         THROW<NullPtrException>("[InnerNetDev::%s] tokenInfoManager_ is nullptr", __func__);
      68              :     }
      69              : 
      70            2 :     return tokenInfoManager_->GetTokenInfo(bufKey);
      71              : }
      72              : 
      73            0 : void InnerNetDev::putTokenIdInfo(const BufferKey<uintptr_t, u64>& bufKey, TokenIdHandle tokenIdHandle)
      74              : {
      75            0 :     if (tokenInfoManager_ == nullptr) {
      76            0 :         HCCL_WARNING("[InnerNetDev::%s]tokenInfoManager_ is nullptr", __func__);
      77            0 :         return;
      78              :     }
      79            0 :     tokenInfoManager_->PutTokenInfo(bufKey, tokenIdHandle);
      80              : }
      81              : 
      82           17 : InnerNetDev::~InnerNetDev()
      83              : {
      84           17 :     if (ubJfcHandle_ != 0) {
      85            4 :         DECTOR_TRY_CATCH("jfc handle destroy", HrtRaUbDestroyJfc(rdmaHandle_, ubJfcHandle_));
      86              :     }
      87           17 :     if (localProto_ == LinkProtoType::RDMA) {
      88           12 :         if (tokenHandle_ != 0) {
      89            1 :             RaUbFreeTokenIdHandle(rdmaHandle_, tokenHandle_);
      90              :         }
      91           12 :         if (rdmaHandle_ != nullptr) {
      92           11 :             HrtRaRdmaDeInit(rdmaHandle_, netMode_);
      93              :         }
      94            5 :     } else if (localProto_ == LinkProtoType::UB) {
      95            4 :         if (tokenInfoManager_ != nullptr) {
      96            4 :             tokenInfoManager_->Destroy();
      97              :         }
      98            4 :         if (rdmaHandle_ != nullptr) {
      99            4 :             HrtRaUbCtxDestroy(rdmaHandle_);
     100              :         }
     101              :     }
     102           17 : }
     103              : 
     104              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1