LCOV - code coverage report
Current view: top level - base_comm/resources/endpoint_pairs/channels/aicpu - aicpu_ts_hccs_channel.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 59.3 % 280 166
Test Date: 2026-08-18 17:47:01 Functions: 53.3 % 30 16

            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 "aicpu_ts_hccs_channel.h"
      12              : #include "endpoint.h"
      13              : #include "../../../endpoints/aicputs_hccs_endpoint.h"
      14              : #include "../../../endpoints/net_dev/global_net_dev_manager.h"
      15              : #include "channel_param.h"
      16              : #include "inner/remote_ipc_rma_buffer.h"
      17              : #include "inner/local_ipc_rma_buffer.h"
      18              : #include "hcomm_c_adpt.h"
      19              : #include "hccl_socket_manager.h"
      20              : #include "externalinput_pub.h"
      21              : // for hccl_network.h
      22              : #include "inner/local_rdma_rma_buffer.h"
      23              : #include "inner/remote_rdma_rma_buffer.h"
      24              : #include "hccl_network.h"
      25              : 
      26              : using LocalIpcRmaBufferMgr
      27              :     = hcomm::RmaBufferMgr<hccl::BufferKey<uintptr_t, u64>, std::shared_ptr<hccl::LocalIpcRmaBuffer>>;
      28              : using RemoteIpcRmaBufferMgr
      29              :     = hcomm::RmaBufferMgr<hccl::BufferKey<uintptr_t, u64>, std::shared_ptr<hccl::RemoteIpcRmaBuffer>>;
      30              : 
      31              : using namespace hccl;
      32              : 
      33              : namespace hcomm {
      34            2 : AicpuTsHccsChannel::AicpuTsHccsChannel(EndpointHandle endpointHandle, const HcommChannelDesc& channelDesc)
      35            2 :     : endpointHandle_(endpointHandle),
      36            2 :       channelDesc_(channelDesc)
      37            2 : {}
      38              : 
      39            4 : AicpuTsHccsChannel::~AicpuTsHccsChannel()
      40              : {
      41              :     try {
      42            2 :         TransportDeInit();
      43            0 :     } catch (...) {
      44            0 :     }
      45              : 
      46              :     try {
      47            2 :         DisableMemAccess();
      48            0 :     } catch (...) {
      49            0 :     }
      50              : 
      51              :     try {
      52            2 :         DestroyConnection();
      53            0 :     } catch (...) {
      54            0 :     }
      55              : 
      56              :     try {
      57            2 :         DisableP2P();
      58            0 :     } catch (...) {
      59            0 :     }
      60            4 : }
      61              : 
      62            2 : HcclResult AicpuTsHccsChannel::ParseInputParam()
      63              : {
      64            2 :     CHK_RET(static_cast<HcclResult>(HcommEndpointGet(endpointHandle_, reinterpret_cast<void**>(&localEpPtr_))));
      65            2 :     CHK_PTR_NULL(localEpPtr_);
      66              : 
      67            2 :     localEp_ = localEpPtr_->GetEndpointDesc();
      68              : 
      69            2 :     remoteEp_ = channelDesc_.remoteEndpoint;
      70            2 :     notifyNum_ = channelDesc_.notifyNum;
      71              : 
      72            2 :     serverPort_ = channelDesc_.port != 0 ? channelDesc_.port : AICPU_CHANNEL_DEFAULT_PORT;
      73              : 
      74            2 :     CHK_RET(GetFirstIpByPhyId(localEp_.loc.device.devPhyId, localEp_.loc.device.superDevId, localIp_));
      75            2 :     CHK_RET(GetFirstIpByPhyId(remoteEp_.loc.device.devPhyId, remoteEp_.loc.device.superDevId, remoteIp_));
      76            4 :     std::string localReadableAddress = localIp_.GetReadableAddress();
      77            2 :     std::string remoteReadableAddress = remoteIp_.GetReadableAddress();
      78              : 
      79            2 :     if (channelDesc_.role == HCOMM_SOCKET_ROLE_SERVER) {
      80            0 :         isSocketServer_ = true;
      81            2 :     } else if (channelDesc_.role != HCOMM_SOCKET_ROLE_CLIENT) {
      82            2 :         HCCL_WARNING(
      83              :             "[AicpuTsHccsChannel] unexpected channelDesc.role[%d]; "
      84              :             "using inner logic to decide socket role based on endpoint IPs",
      85              :             static_cast<int>(channelDesc_.role));
      86            2 :         if (localReadableAddress < remoteReadableAddress) {
      87            1 :             isSocketServer_ = true;
      88              :         }
      89              :     }
      90              : 
      91            2 :     HCCL_INFO(
      92              :         "[AicpuTsHccsChannel][ParseInputParam] local devPhyId [%u] ip[%u] remote devPhyId[%u] ip[%s], "
      93              :         "isSocketServer_[%u], serverPort_[%u]",
      94              :         localEp_.loc.device.devPhyId, localReadableAddress.c_str(), remoteEp_.loc.device.devPhyId,
      95              :         remoteReadableAddress.c_str(), static_cast<u32>(isSocketServer_), serverPort_);
      96              : 
      97            2 :     return HCCL_SUCCESS;
      98            2 : }
      99              : 
     100            4 : HcclResult AicpuTsHccsChannel::GetFirstIpByPhyId(u32 devicePhyId, u32 superDevId, HcclIpAddress& ip)
     101              : {
     102            4 :     CHK_RET(GlobalNetDevMgr::GetDeviceVnicIP(devicePhyId, superDevId, ip));
     103            4 :     HCCL_INFO(
     104              :         "[AicpuTsHccsChannel][GetFirstIpByPhyId]devicePhyId[%u] superDevId[%u] linkInfo.ip[%s]", devicePhyId,
     105              :         superDevId, ip.GetReadableAddress());
     106            4 :     return HCCL_SUCCESS;
     107              : }
     108              : 
     109            2 : HcclResult AicpuTsHccsChannel::BuildConnection()
     110              : {
     111              :     /* delay start server here, uplayer may not call ServerSocketListen of endpoint,
     112              :     and here can get the port from channel desc*/
     113            2 :     CHK_RET(hccl::GlobalNetDevMgr::GetInstance(localEp_.loc.device.devPhyId).ServerInit(serverPort_));
     114            2 :     serverInited_ = true;
     115              : 
     116            4 :     std::string localReadableAddress = localIp_.GetReadableAddress();
     117            2 :     std::string remoteReadableAddress = remoteIp_.GetReadableAddress();
     118              : 
     119            2 :     HCCL_INFO(
     120              :         "[AicpuTsHccsChannel][BuildConnection] local devPhyId [%u] ip[%u] remote devPhyId[%u] ip[%s]",
     121              :         localEp_.loc.device.devPhyId, localReadableAddress.c_str(), remoteEp_.loc.device.devPhyId,
     122              :         remoteReadableAddress.c_str());
     123              : 
     124            2 :     if (channelDesc_.channelName != nullptr) {
     125            0 :         socketTag_ = std::string(channelDesc_.channelName);
     126            2 :     } else if (isSocketServer_) {
     127            1 :         GlobalNetDevMgr::MakeSocketTag(localIp_, serverPort_, remoteIp_, socketTag_);
     128              :     } else {
     129            1 :         GlobalNetDevMgr::MakeSocketTag(remoteIp_, serverPort_, localIp_, socketTag_);
     130              :     }
     131              : 
     132            2 :     if (isSocketServer_) {
     133            1 :         CHK_RET(GlobalNetDevMgr::GetInstance(localEp_.loc.device.devPhyId)
     134              :                     .AcceptClient(serverPort_, remoteIp_, socketTag_, socket_));
     135              :     } else {
     136            1 :         CHK_RET(GlobalNetDevMgr::GetInstance(localEp_.loc.device.devPhyId)
     137              :                     .ConnectToServer(serverPort_, remoteIp_, serverPort_, socketTag_, socket_));
     138              :     }
     139            2 :     HCCL_INFO(
     140              :         "[AicpuTsHccsChannel][BuildConnection] local devPhyId [%u] ip[%u] "
     141              :         "remote devPhyId[%u] ip[%s] socketTag_[%s]",
     142              :         localEp_.loc.device.devPhyId, localReadableAddress.c_str(), remoteEp_.loc.device.devPhyId,
     143              :         remoteReadableAddress.c_str(), socketTag_.c_str());
     144            2 :     return HCCL_SUCCESS;
     145            2 : }
     146              : 
     147            2 : void AicpuTsHccsChannel::DestroyConnection()
     148              : {
     149            2 :     if (socket_ != nullptr) {
     150            2 :         GlobalNetDevMgr::GetInstance(localEp_.loc.device.devPhyId).CloseSocket(socket_);
     151              :     }
     152              : 
     153            2 :     if (serverInited_) {
     154            2 :         (void)hccl::GlobalNetDevMgr::GetInstance(localEp_.loc.device.devPhyId).ServerDeInit(serverPort_);
     155            2 :         serverInited_ = false;
     156              :     }
     157            2 :     HCCL_INFO("[AicpuTsHccsChannel][%s] finish DestroyConnection", __func__);
     158            2 : }
     159              : 
     160            2 : HcclResult AicpuTsHccsChannel::SetMachinePara(hccl::MachinePara& machinePara)
     161              : {
     162            2 :     CHK_RET(hrtGetDeviceType(machinePara.deviceType));
     163              : 
     164              :     u32 deviceLogicId;
     165            2 :     CHK_RET(hrtGetDeviceIndexByPhyId(localEp_.loc.device.devPhyId, deviceLogicId));
     166            2 :     machinePara.deviceLogicId = static_cast<s32>(deviceLogicId);
     167            2 :     machinePara.tag = socketTag_;
     168            2 :     machinePara.notifyNum = channelDesc_.notifyNum;
     169            2 :     machinePara.linkMode = hccl::LinkMode::LINK_DUPLEX_MODE;
     170              :     ;
     171            2 :     machinePara.specifyLink = LinkTypeInServer::RESERVED_LINK_TYPE;
     172              :     machinePara.machineType
     173            2 :         = isSocketServer_ ? hccl::MachineType::MACHINE_SERVER_TYPE : hccl::MachineType::MACHINE_CLIENT_TYPE;
     174            2 :     machinePara.serverId = localEp_.loc.device.serverIdx;
     175            2 :     machinePara.localDeviceId = localEp_.loc.device.devPhyId;
     176            2 :     machinePara.remoteDeviceId = remoteEp_.loc.device.devPhyId;
     177            2 :     machinePara.localIpAddr = socket_->GetLocalIp();
     178            2 :     machinePara.remoteIpAddr = socket_->GetRemoteIp();
     179            2 :     machinePara.localSocketPort = socket_->GetLocalPort();
     180            2 :     machinePara.remoteSocketPort = socket_->GetRemotePort();
     181            2 :     machinePara.srcPorts = std::vector<std::uint16_t>(1, 0); /* 默认填充一个元素,0代表默认不配置 */
     182            2 :     machinePara.mem.clear();
     183            2 :     machinePara.linkAttribute = 0x03; /* 0x03同时支持目的端和源端发起 */
     184            2 :     machinePara.sockets.push_back(socket_);
     185            2 :     machinePara.exchangeInfo.resize(sizeof(HccsExchangeInfo));
     186            2 :     machinePara.isNewOneSide = true;
     187            2 :     return HCCL_SUCCESS;
     188              : }
     189              : 
     190            2 : void AicpuTsHccsChannel::SetTransportParam(hccl::TransportPara& para)
     191              : {
     192            2 :     std::chrono::milliseconds kdefaultTimeout = std::chrono::seconds(GetExternalInputHcclLinkTimeOut());
     193            2 :     para.timeout = kdefaultTimeout;
     194            2 :     para.virtualFlag = false;
     195            2 : }
     196              : 
     197            2 : HcclResult AicpuTsHccsChannel::TransportInit()
     198              : {
     199            2 :     hccl::MachinePara machinePara = {};
     200            2 :     CHK_RET(SetMachinePara(machinePara));
     201              : 
     202            2 :     hccl::TransportPara para = {};
     203            2 :     SetTransportParam(para);
     204              : 
     205            2 :     CHK_RET(HcclDispatcherInit(DispatcherType::DISPATCHER_NORMAL, localEp_.loc.device.devPhyId, &dispatcher_));
     206            2 :     CHK_SMART_PTR_NULL(dispatcher_);
     207              : 
     208            2 :     if (!FindDispatcherByCommId(&dispatcherCtx_, DEFAULT_DISPATCH_NAME)) {
     209            1 :         CHK_RET(CreateDispatcherCtx(&dispatcherCtx_, localEp_.loc.device.devPhyId, DEFAULT_DISPATCH_NAME));
     210              :     }
     211            2 :     CHK_PTR_NULL(dispatcherCtx_);
     212              : 
     213            2 :     notifyPool_.reset(new (std::nothrow) hccl::NotifyPool());
     214            2 :     CHK_SMART_PTR_NULL(notifyPool_);
     215            2 :     CHK_RET(notifyPool_->Init(localEp_.loc.device.devPhyId));
     216            2 :     CHK_RET(notifyPool_->RegisterOp(machinePara.tag));
     217              : 
     218            2 :     transport_.reset(new (std::nothrow)
     219            4 :                          Transport(TransportType::TRANS_TYPE_P2P, para, dispatcher_, notifyPool_, machinePara));
     220              : 
     221            2 :     CHK_RET(transport_->Init());
     222              : 
     223            2 :     HCCL_INFO("[AicpuTsHccsChannel][%s] finish TransportInit", __func__);
     224            2 :     return HCCL_SUCCESS;
     225            2 : }
     226              : 
     227            2 : void AicpuTsHccsChannel::TransportDeInit()
     228              : {
     229            2 :     if (transport_ != nullptr) {
     230            2 :         transport_ = nullptr;
     231              :     }
     232            2 :     if (notifyPool_ != nullptr) {
     233            2 :         notifyPool_ = nullptr;
     234              :     }
     235            2 :     if (dispatcherCtx_ != nullptr) {
     236            2 :         (void)DestroyDispatcherCtx(dispatcherCtx_, DEFAULT_DISPATCH_NAME);
     237            2 :         dispatcherCtx_ = nullptr;
     238              :     }
     239            2 :     if (dispatcher_ != nullptr) {
     240            2 :         (void)HcclDispatcherDestroy(dispatcher_);
     241            2 :         dispatcher_ = nullptr;
     242              :     }
     243            2 :     HCCL_INFO("[AicpuTsHccsChannel][%s] finish TransportDeInit", __func__);
     244            2 : }
     245              : 
     246            2 : HcclResult AicpuTsHccsChannel::EnableP2P()
     247              : {
     248            2 :     CHK_PTR_NULL(localEpPtr_);
     249            2 :     CHK_RET(localEpPtr_->MemoryEnableP2P(remoteEp_));
     250            2 :     HCCL_INFO("[AicpuTsHccsChannel][%s] finish EnableP2P", __func__);
     251            2 :     return HCCL_SUCCESS;
     252              : }
     253              : 
     254            2 : void AicpuTsHccsChannel::DisableP2P()
     255              : {
     256            2 :     if (localEpPtr_ != nullptr) {
     257            2 :         (void)localEpPtr_->MemoryDisableP2P(remoteEp_);
     258              :     }
     259              : 
     260            2 :     HCCL_INFO("[AicpuTsHccsChannel][%s] finish DisableP2P", __func__);
     261            2 : }
     262              : 
     263            2 : HcclResult AicpuTsHccsChannel::EnableMemAccess()
     264              : {
     265            2 :     s32 pid = 0;
     266            2 :     CHK_RET(SalGetBareTgid(&pid));
     267              :     // switch first
     268            2 :     HcommMemGrantInfo localGrantInfo = {localEp_.loc.device.superDevId, pid};
     269            2 :     HcommMemGrantInfo remoteGrantInfo = {};
     270            2 :     if (isSocketServer_) {
     271            1 :         CHK_RET(socket_->Recv(&remoteGrantInfo, sizeof(HcommMemGrantInfo)));
     272            1 :         CHK_RET(socket_->Send(&localGrantInfo, sizeof(HcommMemGrantInfo)));
     273              :     } else {
     274            1 :         CHK_RET(socket_->Send(&localGrantInfo, sizeof(HcommMemGrantInfo)));
     275            1 :         CHK_RET(socket_->Recv(&remoteGrantInfo, sizeof(HcommMemGrantInfo)));
     276              :     }
     277            2 :     CHK_PTR_NULL(localEpPtr_);
     278            2 :     CHK_RET(localEpPtr_->MemoryGrant(&remoteGrantInfo));
     279              :     // need to wait peer grant for me end, not need to check value, just make sure grant process end
     280            2 :     u32 localGrantSync = 1;
     281            2 :     u32 remoteGrantSync = 1;
     282            2 :     if (isSocketServer_) {
     283            1 :         CHK_RET(socket_->Recv(&remoteGrantSync, sizeof(u32)));
     284            1 :         CHK_RET(socket_->Send(&localGrantSync, sizeof(u32)));
     285              :     } else {
     286            1 :         CHK_RET(socket_->Send(&localGrantSync, sizeof(u32)));
     287            1 :         CHK_RET(socket_->Recv(&remoteGrantSync, sizeof(u32)));
     288              :     }
     289            2 :     CHK_RET(localEpPtr_->MemoryOpenRemoteIpc());
     290            2 :     HCCL_INFO("[AicpuTsHccsChannel][%s] finish EnableMemAccess", __func__);
     291            2 :     return HCCL_SUCCESS;
     292              : }
     293              : 
     294            2 : void AicpuTsHccsChannel::DisableMemAccess()
     295              : {
     296            2 :     if (localEpPtr_ != nullptr) {
     297            2 :         (void)localEpPtr_->MemoryCloseRemoteIpc();
     298              :     }
     299            2 :     HCCL_INFO("[AicpuTsHccsChannel][%s] finish DisableMemAccess", __func__);
     300            2 : }
     301              : 
     302            2 : HcclResult AicpuTsHccsChannel::Init()
     303              : {
     304            2 :     CHK_RET(ParseInputParam());
     305            2 :     CHK_RET(EnableP2P());
     306            2 :     HcclResult ret = BuildConnection();
     307            2 :     if (ret != HCCL_SUCCESS) {
     308            0 :         DestroyConnection();
     309            0 :         DisableP2P();
     310            0 :         return ret;
     311              :     }
     312              : 
     313            2 :     ret = EnableMemAccess();
     314            2 :     if (ret != HCCL_SUCCESS) {
     315            0 :         DisableMemAccess();
     316            0 :         DestroyConnection();
     317            0 :         DisableP2P();
     318            0 :         return ret;
     319              :     }
     320              : 
     321            2 :     ret = TransportInit();
     322            2 :     if (ret != HCCL_SUCCESS) {
     323            0 :         TransportDeInit();
     324            0 :         DisableMemAccess();
     325            0 :         DestroyConnection();
     326            0 :         DisableP2P();
     327            0 :         return ret;
     328              :     }
     329            2 :     HCCL_INFO("[AicpuTsHccsChannel][%s] finish Init", __func__);
     330            2 :     return HCCL_SUCCESS;
     331              : }
     332              : 
     333            0 : HcclResult AicpuTsHccsChannel::GetRemoteMems(uint32_t* memNum, CommMem** remoteMem, [[maybe_unused]] char*** memInfos)
     334              : {
     335            0 :     remoteIpcRmaBufferVec_.clear();
     336            0 :     CHK_RET(localEpPtr_->GetRemoteIpcRmaBuffer(remoteIpcRmaBufferVec_));
     337            0 :     *remoteMem = remoteIpcRmaBufferVec_.data();
     338            0 :     *memNum = remoteIpcRmaBufferVec_.size();
     339            0 :     return HCCL_SUCCESS;
     340              : }
     341              : 
     342            0 : ChannelStatus AicpuTsHccsChannel::GetStatus()
     343              : {
     344            0 :     ChannelStatus out = ChannelStatus::READY;
     345            0 :     return out;
     346              : }
     347              : 
     348            0 : HcclResult AicpuTsHccsChannel::GetNotifyNum(uint32_t* notifyNum) const
     349              : {
     350            0 :     *notifyNum = notifyNum_;
     351            0 :     return HCCL_SUCCESS;
     352              : }
     353              : 
     354            0 : HcclResult AicpuTsHccsChannel::BuildHcclChannelHccsRes(HcclChannelHccsRes& channelHccsRes)
     355              : {
     356            0 :     HcclChannelP2p& linkp2p = channelHccsRes.channelP2p;
     357              : 
     358            0 :     CHK_SAFETY_FUNC_RET(memcpy_s(
     359              :         channelHccsRes.channelTag, sizeof(channelHccsRes.channelTag) - 1, socketTag_.c_str(), socketTag_.length()));
     360            0 :     HCCL_DEBUG("[AicpuTsHccsChannel][%s] channelHccsRes.channelTag[%s]", __func__, channelHccsRes.channelTag);
     361              : 
     362            0 :     linkp2p.remoteHcclbuffer.addr = nullptr;
     363            0 :     linkp2p.remoteHcclbuffer.size = 0;
     364            0 :     linkp2p.remoteUserMem = nullptr;
     365            0 :     linkp2p.remoteUserMemCount = 0;
     366              : 
     367            0 :     HCCL_DEBUG("[AicpuTsHccsChannel][%s] finish set remoteMem info", __func__);
     368              : 
     369            0 :     u64 notifyNum = 0;
     370            0 :     channelHccsRes.p2pNotifyNum = transport_->GetNotifyNum();
     371            0 :     HCCL_DEBUG(
     372              :         "[AicpuTsHccsChannel][%s] finish set localnotify & remotenotify info, "
     373              :         "notifyNum[%llu], p2pNotifyNum[%llu]",
     374              :         __func__, notifyNum, channelHccsRes.p2pNotifyNum);
     375            0 :     CHK_RET(transport_->GetTransportAttr(linkp2p.transportAttr));
     376              : 
     377              :     DevType devType;
     378            0 :     CHK_RET(hrtGetDeviceType(devType));
     379            0 :     channelHccsRes.deviceType = static_cast<u32>(devType);
     380            0 :     channelHccsRes.remoteDevicePhyId = remoteEp_.loc.device.devPhyId;
     381            0 :     channelHccsRes.localDevicePhyId = localEp_.loc.device.devPhyId;
     382              :     channelHccsRes.machineType
     383            0 :         = isSocketServer_ ? hccl::MachineType::MACHINE_SERVER_TYPE : hccl::MachineType::MACHINE_CLIENT_TYPE;
     384              :     u32 deviceLogicId;
     385            0 :     CHK_RET(hrtGetDeviceIndexByPhyId(localEp_.loc.device.devPhyId, deviceLogicId));
     386            0 :     channelHccsRes.localDeviceLogicId = static_cast<s32>(deviceLogicId);
     387              : 
     388            0 :     remoteIpcRmaBufferVecEx_.clear();
     389            0 :     CHK_RET(localEpPtr_->GetRemoteIpcRmaBufferEx(remoteIpcRmaBufferVecEx_));
     390            0 :     channelHccsRes.remoteBufSize = remoteIpcRmaBufferVecEx_.size();
     391            0 :     channelHccsRes.remoteBufMem = remoteIpcRmaBufferVecEx_.data();
     392              : 
     393            0 :     localIpcRmaBufferVecEx_.clear();
     394            0 :     CHK_RET(localEpPtr_->GetLocalIpcRmaBufferEx(localIpcRmaBufferVecEx_));
     395            0 :     channelHccsRes.localBufSize = localIpcRmaBufferVecEx_.size();
     396            0 :     channelHccsRes.localBufMem = localIpcRmaBufferVecEx_.data();
     397              : 
     398            0 :     HCCL_DEBUG("[AicpuTsHccsChannel][%s] finish set RemoteChannelP2pResParam info", __func__);
     399            0 :     return HCCL_SUCCESS;
     400              : }
     401              : 
     402            0 : HcclResult AicpuTsHccsChannel::Serialize(std::shared_ptr<hccl::DeviceMem>& out)
     403              : {
     404            0 :     HCCL_DEBUG("[AicpuTsHccsChannel][%s] start", __func__);
     405            0 :     HcclChannelHccsRes hostChannelHccsRes;
     406            0 :     CHK_RET(BuildHcclChannelHccsRes(hostChannelHccsRes));
     407              : 
     408              :     // 临时缓存信息
     409            0 :     HcclChannelHccsRes deviceChannelHccsRes = hostChannelHccsRes;
     410              : 
     411              :     // 计算设备内存分配的空间,包括需要深度拷贝的子域的信息内的内存,然后分配整块设备地址内存
     412            0 :     u64 outSize = 0;
     413              :     // cal base info
     414            0 :     u64 baseSize = sizeof(HcclChannelHccsRes);
     415            0 :     outSize += baseSize;
     416              :     // cal local buf mem
     417            0 :     size_t localBufSize = hostChannelHccsRes.localBufSize * sizeof(HcclMemEx);
     418            0 :     outSize += localBufSize;
     419              :     // cal remote buf mem
     420            0 :     size_t remoteBufSize = hostChannelHccsRes.remoteBufSize * sizeof(HcclMemEx);
     421            0 :     outSize += remoteBufSize;
     422            0 :     EXCEPTION_CATCH((out = std::make_shared<hccl::DeviceMem>(hccl::DeviceMem::alloc(outSize))), return HCCL_E_PTR);
     423              : 
     424            0 :     void* dstPtr = nullptr;
     425              :     // 复制 local buf
     426            0 :     if (hostChannelHccsRes.localBufSize > 0 && hostChannelHccsRes.localBufMem != nullptr) {
     427              :         // 使用设备地址重置 local buf的地址
     428            0 :         dstPtr = reinterpret_cast<uint8_t*>(out.get()->ptr()) + baseSize;
     429            0 :         deviceChannelHccsRes.localBufMem = reinterpret_cast<HcclMemEx*>(dstPtr);
     430            0 :         CHK_RET(hrtMemSyncCopy(
     431              :             deviceChannelHccsRes.localBufMem, localBufSize, hostChannelHccsRes.localBufMem, localBufSize,
     432              :             HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_HOST_TO_DEVICE));
     433              :     }
     434              : 
     435              :     // 复制 remote buf
     436            0 :     if (hostChannelHccsRes.remoteBufSize > 0 && hostChannelHccsRes.remoteBufMem != nullptr) {
     437              :         // 使用设备地址重置 remote buf的地址
     438            0 :         dstPtr = reinterpret_cast<uint8_t*>(out.get()->ptr()) + baseSize + localBufSize;
     439            0 :         deviceChannelHccsRes.remoteBufMem = reinterpret_cast<HcclMemEx*>(dstPtr);
     440            0 :         CHK_RET(hrtMemSyncCopy(
     441              :             deviceChannelHccsRes.remoteBufMem, remoteBufSize, hostChannelHccsRes.remoteBufMem, remoteBufSize,
     442              :             HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_HOST_TO_DEVICE));
     443              :     }
     444              : 
     445              :     // 复制 base
     446            0 :     CHK_RET(hrtMemSyncCopy(
     447              :         out.get()->ptr(), sizeof(HcclChannelHccsRes), &deviceChannelHccsRes, sizeof(HcclChannelHccsRes),
     448              :         HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_HOST_TO_DEVICE));
     449              : 
     450            0 :     HCCL_DEBUG("[AicpuTsHccsChannel][%s] end", __func__);
     451            0 :     return HCCL_SUCCESS;
     452              : }
     453              : 
     454            0 : HcclResult AicpuTsHccsChannel::Clean()
     455              : {
     456            0 :     HCCL_INFO("[AicpuTsHccsChannel][%s] Clean not implemented, no resume needed for AICPU TS Hccs channel", __func__);
     457            0 :     return HCCL_E_NOT_SUPPORT;
     458              : }
     459              : 
     460            0 : HcclResult AicpuTsHccsChannel::Resume()
     461              : {
     462            0 :     HCCL_INFO("[AicpuTsHccsChannel][%s] Resume not implemented, no resume needed for AICPU TS Hccs channel", __func__);
     463            0 :     return HCCL_E_NOT_SUPPORT;
     464              : }
     465              : 
     466            0 : HcommChannelKind AicpuTsHccsChannel::GetChannelKind() const { return HcommChannelKind::AICPU_TS_HCCS; }
     467              : 
     468            0 : HcclResult AicpuTsHccsChannel::NotifyRecord([[maybe_unused]] const uint32_t remoteNotifyIdx)
     469              : {
     470            0 :     HCCL_INFO("[AicpuTsHccsChannel::%s] not supported yet.", __func__);
     471            0 :     return HCCL_E_NOT_SUPPORT;
     472              : }
     473              : 
     474              : HcclResult
     475            0 : AicpuTsHccsChannel::NotifyWait([[maybe_unused]] const uint32_t localNotifyIdx, [[maybe_unused]] const uint32_t timeout)
     476              : {
     477            0 :     HCCL_INFO("[AicpuTsHccsChannel::%s] not supported yet.", __func__);
     478            0 :     return HCCL_E_NOT_SUPPORT;
     479              : }
     480              : 
     481            0 : HcclResult AicpuTsHccsChannel::WriteWithNotify(
     482              :     [[maybe_unused]] void* dst, [[maybe_unused]] const void* src, [[maybe_unused]] const uint64_t len,
     483              :     [[maybe_unused]] uint32_t remoteNotifyIdx)
     484              : {
     485            0 :     HCCL_INFO("[AicpuTsHccsChannel::%s] not supported yet.", __func__);
     486            0 :     return HCCL_E_NOT_SUPPORT;
     487              : }
     488              : 
     489              : HcclResult
     490            0 : AicpuTsHccsChannel::Write([[maybe_unused]] void* dst, [[maybe_unused]] const void* src, [[maybe_unused]] uint64_t len)
     491              : {
     492            0 :     HCCL_INFO("[AicpuTsHccsChannel::%s] not supported yet.", __func__);
     493            0 :     return HCCL_E_NOT_SUPPORT;
     494              : }
     495              : 
     496              : HcclResult
     497            0 : AicpuTsHccsChannel::Read([[maybe_unused]] void* dst, [[maybe_unused]] const void* src, [[maybe_unused]] uint64_t len)
     498              : {
     499            0 :     HCCL_INFO("[AicpuTsHccsChannel::%s] not supported yet.", __func__);
     500            0 :     return HCCL_E_NOT_SUPPORT;
     501              : }
     502              : 
     503            0 : HcclResult AicpuTsHccsChannel::ChannelFence()
     504              : {
     505            0 :     HCCL_INFO("[AicpuTsHccsChannel::%s] not supported yet.", __func__);
     506            0 :     return HCCL_E_NOT_SUPPORT;
     507              : }
     508              : } // namespace hcomm
        

Generated by: LCOV version 2.0-1