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-08-18 17:47:01 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              : HcclResult
      28            0 : DevAicpuTsHccsChannel::SetTransportMachinePara(hccl::MachinePara& machinePara, 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(
      50              :         "%s success, linkAttribute[%x], localUserRank[%u], remoteWorldRank[%u], "
      51              :         "remoteUserrank[%u], deviceLogicId[%d], localDeviceId[%d], deviceType[%d], newTag[%s], "
      52              :         "specifyLink[%d], machineType[%u], localBufSize[%u],remoteBufSize[%u], localBufMem[%p], remoteBufMem[%p]",
      53              :         __func__, machinePara.linkAttribute, machinePara.localUserrank, machinePara.remoteWorldRank,
      54              :         machinePara.remoteUserrank, machinePara.deviceLogicId, machinePara.localDeviceId, machinePara.deviceType,
      55              :         machinePara.tag.c_str(), machinePara.specifyLink, static_cast<u32>(machinePara.machineType),
      56              :         machinePara.localBufSize, machinePara.remoteBufSize, machinePara.localBufMem, machinePara.remoteBufMem);
      57            0 :     return HCCL_SUCCESS;
      58              : }
      59              : 
      60            0 : HcclResult DevAicpuTsHccsChannel::Create(
      61              :     const void* blob, u64 blobBytes, [[maybe_unused]] 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]", static_cast<unsigned long long>(blobBytes));
      66            0 :         return HCCL_E_PARA;
      67              :     }
      68              : 
      69            0 :     const HcclChannelHccsRes& channelHccsRes = *static_cast<const HcclChannelHccsRes*>(blob);
      70            0 :     const HcclChannelP2p& channelP2p = channelHccsRes.channelP2p;
      71              : 
      72              :     // 创建Transport对象
      73            0 :     MachinePara machinePara;
      74            0 :     CHK_RET(SetTransportMachinePara(machinePara, channelHccsRes));
      75            0 :     machinePara.notifyNum = channelHccsRes.p2pNotifyNum;
      76              : 
      77            0 :     TransportDeviceP2pData transDevP2pData;
      78            0 :     transDevP2pData.inputBufferPtr = nullptr;
      79            0 :     transDevP2pData.outputBufferPtr = nullptr;
      80              : 
      81              :     //  获取transportAttr信息
      82            0 :     transDevP2pData.transportAttr = channelP2p.transportAttr;
      83              : 
      84              :     //  创建Transport对象
      85            0 :     TransportPara para{};
      86            0 :     const std::unique_ptr<hccl::NotifyPool> notifyPool;
      87              : 
      88            0 :     u32 devId = 0;
      89            0 :     CHK_RET(hrtDrvGetLocalDevIDByHostDevID(channelHccsRes.localDevicePhyId, &devId));
      90              :     // for data dispatcher read/write with DEFAULT_DISPATCH_NAME
      91            0 :     DispatcherCtxPtr dispatcherCtx{nullptr};
      92            0 :     if (!FindDispatcherByCommId(&dispatcherCtx, DEFAULT_DISPATCH_NAME)) {
      93            0 :         CHK_RET(CreateDispatcherCtx(&dispatcherCtx, devId, DEFAULT_DISPATCH_NAME));
      94              :     }
      95            0 :     CHK_PTR_NULL(dispatcherCtx);
      96              : 
      97            0 :     DispatcherCtx* ctx = static_cast<DispatcherCtx*>(dispatcherCtx);
      98            0 :     CHK_PRT(ctx->SetDispatcherHcclQos(channelHccsRes.channelP2p.qos)); // 调度器添加hcclQos
      99            0 :     CHK_PTR_NULL(ctx);
     100              : 
     101            0 :     std::shared_ptr<Transport> transport;
     102            0 :     transport.reset(new (std::nothrow) Transport(
     103            0 :         TransportType::TRANS_TYPE_DEVICE_P2P, para, ctx->GetDispatcher(), notifyPool, machinePara, transDevP2pData));
     104            0 :     CHK_SMART_PTR_NULL(transport);
     105              : 
     106            0 :     CHK_RET(transport->Init()); // 初始化需要增加远端用户注册内存
     107              : 
     108            0 :     outHandle = reinterpret_cast<ChannelHandle>(transport.get());
     109            0 :     HccsSlot slot;
     110            0 :     slot.dispatcherCtx = dispatcherCtx;
     111            0 :     slot.transport = std::move(transport);
     112            0 :     slot.tag = channelHccsRes.channelTag;
     113              :     {
     114            0 :         std::lock_guard<std::mutex> lock(mutex_);
     115            0 :         slots_.emplace(outHandle, std::move(slot));
     116            0 :     }
     117            0 :     HCCL_INFO("[DevAicpuTsHccsChannel][%s] transport[%p] create done", __func__, outHandle);
     118            0 :     return HCCL_SUCCESS;
     119            0 : }
     120              : 
     121            0 : bool DevAicpuTsHccsChannel::Destroy(ChannelHandle handle)
     122              : {
     123            0 :     HccsSlot slot;
     124              :     {
     125            0 :         std::lock_guard<std::mutex> lock(mutex_);
     126            0 :         auto it = slots_.find(handle);
     127            0 :         if (it == slots_.end()) {
     128            0 :             return false;
     129              :         }
     130            0 :         slot = std::move(it->second);
     131            0 :         slots_.erase(it);
     132            0 :     }
     133            0 :     if (slot.transport != nullptr) {
     134            0 :         (void)slot.transport->DeInit();
     135            0 :         slot.transport.reset();
     136              :     }
     137            0 :     HCCL_DEBUG("[DevAicpuTsHccsChannel][Destroy] destroyed handle[0x%llx]", handle);
     138            0 :     return true;
     139            0 : }
     140              : } // namespace hccl
        

Generated by: LCOV version 2.0-1