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

Generated by: LCOV version 2.0-1