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

Generated by: LCOV version 2.0-1