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

Generated by: LCOV version 2.0-1