LCOV - code coverage report
Current view: top level - base_comm/resources/endpoint_pairs/channels/aicpu/device - dev_aicpu_ts_hccs_channel.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 79 0
Test Date: 2026-07-28 12:11:00 Functions: 0.0 % 5 0

            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 "dev_aicpu_ts_hccs_channel.h"
      12              : #include "dispatcher_ctx.h"
      13              : #include "adapter_hal_pub.h"
      14              : 
      15              : namespace hccl {
      16            0 : DevAicpuTsHccsChannel::~DevAicpuTsHccsChannel()
      17              : {
      18            0 :     for (auto &pair : slots_) {
      19            0 :         if (pair.second.transport != nullptr) {
      20            0 :             (void)pair.second.transport->DeInit();
      21            0 :             pair.second.transport.reset();
      22              :         }
      23              :     }
      24            0 :     slots_.clear();
      25            0 : }
      26              : 
      27            0 : HcclResult DevAicpuTsHccsChannel::SetTransportMachinePara(hccl::MachinePara &machinePara,
      28              :     const HcclChannelHccsRes &channelHccsRes)
      29              : {
      30            0 :     machinePara.linkAttribute = 0x03; /* 0x03同时支持目的端和源端发起 */
      31              : 
      32            0 :     machinePara.remoteDeviceId = channelHccsRes.remoteDevicePhyId;
      33            0 :     machinePara.localDeviceId = channelHccsRes.localDevicePhyId;
      34            0 :     machinePara.deviceLogicId = channelHccsRes.localDeviceLogicId;
      35              : 
      36            0 :     machinePara.deviceType = static_cast<DevType>(channelHccsRes.deviceType);
      37            0 :     machinePara.tag = channelHccsRes.channelTag;
      38            0 :     machinePara.machineType = channelHccsRes.machineType;
      39              : 
      40              :     // 非910_93 2die sio与hccs并发场景,specifyLink设置为RESERVED_LINK_TYPE,平台层将按实际链路类型建链
      41            0 :     machinePara.specifyLink = LinkTypeInServer::RESERVED_LINK_TYPE;
      42            0 :     machinePara.isNewOneSide = true;
      43              : 
      44            0 :     machinePara.localBufSize = channelHccsRes.localBufSize;
      45            0 :     machinePara.remoteBufSize = channelHccsRes.remoteBufSize;
      46            0 :     machinePara.localBufMem = channelHccsRes.localBufMem;
      47            0 :     machinePara.remoteBufMem = channelHccsRes.remoteBufMem;
      48              : 
      49            0 :     HCCL_INFO("%s success, linkAttribute[%x], localUserRank[%u], remoteWorldRank[%u], "
      50              :         "remoteUserrank[%u], deviceLogicId[%d], localDeviceId[%d], deviceType[%d], newTag[%s], "
      51              :         "specifyLink[%d], machineType[%u], localBufSize[%u],remoteBufSize[%u], localBufMem[%p], remoteBufMem[%p]",
      52              :         __func__, machinePara.linkAttribute, machinePara.localUserrank,
      53              :         machinePara.remoteWorldRank, machinePara.remoteUserrank, machinePara.deviceLogicId, machinePara.localDeviceId,
      54              :         machinePara.deviceType, machinePara.tag.c_str(), machinePara.specifyLink,
      55              :         static_cast<u32>(machinePara.machineType), machinePara.localBufSize,
      56              :         machinePara.remoteBufSize, machinePara.localBufMem, machinePara.remoteBufMem);
      57            0 :     return HCCL_SUCCESS;
      58              : }
      59              : 
      60            0 : HcclResult DevAicpuTsHccsChannel::Create(const void *blob, u64 blobBytes,
      61              :     const HcommDeviceInfo &deviceInfo, ChannelHandle &outHandle)
      62              : {
      63            0 :     CHK_PTR_NULL(blob);
      64            0 :     if (blobBytes < sizeof(HcclChannelHccsRes)) {
      65            0 :         HCCL_ERROR("[DevAicpuTsHccsChannel][Create] blob too small[%llu]",
      66              :             static_cast<unsigned long long>(blobBytes));
      67            0 :         return HCCL_E_PARA;
      68              :     }
      69              : 
      70            0 :     const HcclChannelHccsRes &channelHccsRes = *static_cast<const HcclChannelHccsRes *>(blob);
      71            0 :     const HcclChannelP2p &channelP2p = channelHccsRes.channelP2p;
      72              : 
      73              :     // 创建Transport对象
      74            0 :     MachinePara machinePara;
      75            0 :     CHK_RET(SetTransportMachinePara(machinePara, channelHccsRes));
      76            0 :     machinePara.notifyNum = channelHccsRes.p2pNotifyNum;
      77              : 
      78            0 :     TransportDeviceP2pData transDevP2pData;
      79            0 :     transDevP2pData.inputBufferPtr = nullptr;
      80            0 :     transDevP2pData.outputBufferPtr = nullptr;
      81              : 
      82              :     //  获取transportAttr信息
      83            0 :     transDevP2pData.transportAttr = channelP2p.transportAttr;
      84              :  
      85              :     //  创建Transport对象
      86            0 :     TransportPara para{};
      87            0 :     const std::unique_ptr<hccl::NotifyPool> notifyPool;
      88              : 
      89            0 :     u32 devId = 0;
      90            0 :     CHK_RET(hrtDrvGetLocalDevIDByHostDevID(channelHccsRes.localDevicePhyId, &devId));
      91              :     // for data dispatcher read/write with DEFAULT_DISPATCH_NAME
      92            0 :     DispatcherCtxPtr dispatcherCtx{nullptr};
      93            0 :     if (!FindDispatcherByCommId(&dispatcherCtx, DEFAULT_DISPATCH_NAME)) {
      94            0 :         CHK_RET(CreateDispatcherCtx(&dispatcherCtx, devId, DEFAULT_DISPATCH_NAME));
      95              :     }
      96            0 :     CHK_PTR_NULL(dispatcherCtx);
      97              : 
      98            0 :     DispatcherCtx *ctx = static_cast<DispatcherCtx *>(dispatcherCtx);
      99            0 :     CHK_PRT(ctx->SetDispatcherHcclQos(channelHccsRes.channelP2p.qos)); // 调度器添加hcclQos
     100            0 :     CHK_PTR_NULL(ctx);
     101              : 
     102            0 :     std::shared_ptr<Transport> transport;
     103            0 :     transport.reset(new (std::nothrow) Transport(
     104              :         TransportType::TRANS_TYPE_DEVICE_P2P, para, ctx->GetDispatcher(),
     105            0 :         notifyPool, machinePara, transDevP2pData));
     106            0 :     CHK_SMART_PTR_NULL(transport);
     107              : 
     108            0 :     CHK_RET(transport->Init()); // 初始化需要增加远端用户注册内存
     109              : 
     110            0 :     outHandle = reinterpret_cast<ChannelHandle>(transport.get());
     111            0 :     HccsSlot slot;
     112            0 :     slot.dispatcherCtx = dispatcherCtx;
     113            0 :     slot.transport = std::move(transport);
     114            0 :     slot.tag = channelHccsRes.channelTag;
     115              :     {
     116            0 :         std::lock_guard<std::mutex> lock(mutex_);
     117            0 :         slots_.emplace(outHandle, std::move(slot));
     118            0 :     }
     119            0 :     HCCL_INFO("[DevAicpuTsHccsChannel][%s] transport[%p] create done", __func__, outHandle);
     120            0 :     return HCCL_SUCCESS;
     121            0 : }
     122              : 
     123            0 : bool DevAicpuTsHccsChannel::Destroy(ChannelHandle handle)
     124              : {
     125            0 :     HccsSlot slot;
     126              :     {
     127            0 :         std::lock_guard<std::mutex> lock(mutex_);
     128            0 :         auto it = slots_.find(handle);
     129            0 :         if (it == slots_.end()) {
     130            0 :             return false;
     131              :         }
     132            0 :         slot = std::move(it->second);
     133            0 :         slots_.erase(it);
     134            0 :     }
     135            0 :     if (slot.transport != nullptr) {
     136            0 :         (void)slot.transport->DeInit();
     137            0 :         slot.transport.reset();
     138              :     }
     139            0 :     HCCL_DEBUG("[DevAicpuTsHccsChannel][Destroy] destroyed handle[0x%llx]", handle);
     140            0 :     return true;
     141            0 : }
     142              : }
        

Generated by: LCOV version 2.0-1