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 3 : AicpuTsHccsChannel::AicpuTsHccsChannel(EndpointHandle endpointHandle, const HcommChannelDesc& channelDesc)
35 3 : : endpointHandle_(endpointHandle),
36 3 : channelDesc_(channelDesc)
37 3 : {}
38 :
39 5 : AicpuTsHccsChannel::~AicpuTsHccsChannel()
40 : {
41 : try {
42 3 : TransportDeInit();
43 0 : } catch (...) {
44 0 : }
45 :
46 : try {
47 3 : DisableMemAccess();
48 0 : } catch (...) {
49 0 : }
50 :
51 : try {
52 3 : DestroyConnection();
53 0 : } catch (...) {
54 0 : }
55 :
56 : try {
57 3 : DisableP2P();
58 0 : } catch (...) {
59 0 : }
60 5 : }
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[%s] 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[%s] 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[%s] "
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 3 : void AicpuTsHccsChannel::DestroyConnection()
148 : {
149 3 : if (socket_ != nullptr) {
150 2 : GlobalNetDevMgr::GetInstance(localEp_.loc.device.devPhyId).CloseSocket(socket_);
151 : }
152 :
153 3 : if (serverInited_) {
154 2 : (void)hccl::GlobalNetDevMgr::GetInstance(localEp_.loc.device.devPhyId).ServerDeInit(serverPort_);
155 2 : serverInited_ = false;
156 : }
157 3 : HCCL_INFO("[AicpuTsHccsChannel][%s] finish DestroyConnection", __func__);
158 3 : }
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 3 : void AicpuTsHccsChannel::TransportDeInit()
228 : {
229 3 : if (transport_ != nullptr) {
230 3 : transport_ = nullptr;
231 : }
232 3 : if (notifyPool_ != nullptr) {
233 2 : notifyPool_ = nullptr;
234 : }
235 3 : if (dispatcherCtx_ != nullptr) {
236 2 : (void)DestroyDispatcherCtx(dispatcherCtx_, DEFAULT_DISPATCH_NAME);
237 2 : dispatcherCtx_ = nullptr;
238 : }
239 3 : if (dispatcher_ != nullptr) {
240 2 : (void)HcclDispatcherDestroy(dispatcher_);
241 2 : dispatcher_ = nullptr;
242 : }
243 3 : HCCL_INFO("[AicpuTsHccsChannel][%s] finish TransportDeInit", __func__);
244 3 : }
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 3 : void AicpuTsHccsChannel::DisableP2P()
255 : {
256 3 : if (localEpPtr_ != nullptr) {
257 3 : (void)localEpPtr_->MemoryDisableP2P(remoteEp_);
258 : }
259 :
260 3 : HCCL_INFO("[AicpuTsHccsChannel][%s] finish DisableP2P", __func__);
261 3 : }
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 3 : void AicpuTsHccsChannel::DisableMemAccess()
295 : {
296 3 : if (localEpPtr_ != nullptr) {
297 3 : (void)localEpPtr_->MemoryCloseRemoteIpc();
298 : }
299 3 : HCCL_INFO("[AicpuTsHccsChannel][%s] finish DisableMemAccess", __func__);
300 3 : }
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 1 : HcclResult AicpuTsHccsChannel::BuildHcclChannelHccsRes(HcclChannelHccsRes& channelHccsRes)
355 : {
356 1 : HcclChannelP2p& linkp2p = channelHccsRes.channelP2p;
357 :
358 1 : CHK_SAFETY_FUNC_RET(memcpy_s(
359 : channelHccsRes.channelTag, sizeof(channelHccsRes.channelTag) - 1, socketTag_.c_str(), socketTag_.length()));
360 1 : HCCL_DEBUG("[AicpuTsHccsChannel][%s] channelHccsRes.channelTag[%s]", __func__, channelHccsRes.channelTag);
361 :
362 1 : linkp2p.remoteHcclbuffer.addr = nullptr;
363 1 : linkp2p.remoteHcclbuffer.size = 0;
364 1 : linkp2p.remoteUserMem = nullptr;
365 1 : linkp2p.remoteUserMemCount = 0;
366 1 : linkp2p.qos = channelDesc_.qos;
367 :
368 1 : HCCL_DEBUG("[AicpuTsHccsChannel][%s] finish set remoteMem info", __func__);
369 :
370 1 : u64 notifyNum = 0;
371 1 : channelHccsRes.p2pNotifyNum = transport_->GetNotifyNum();
372 1 : HCCL_DEBUG(
373 : "[AicpuTsHccsChannel][%s] finish set localnotify & remotenotify info, "
374 : "notifyNum[%llu], p2pNotifyNum[%llu]",
375 : __func__, notifyNum, channelHccsRes.p2pNotifyNum);
376 1 : CHK_RET(transport_->GetTransportAttr(linkp2p.transportAttr));
377 :
378 : DevType devType;
379 1 : CHK_RET(hrtGetDeviceType(devType));
380 1 : channelHccsRes.deviceType = static_cast<u32>(devType);
381 1 : channelHccsRes.remoteDevicePhyId = remoteEp_.loc.device.devPhyId;
382 1 : channelHccsRes.localDevicePhyId = localEp_.loc.device.devPhyId;
383 : channelHccsRes.machineType
384 1 : = isSocketServer_ ? hccl::MachineType::MACHINE_SERVER_TYPE : hccl::MachineType::MACHINE_CLIENT_TYPE;
385 : u32 deviceLogicId;
386 1 : CHK_RET(hrtGetDeviceIndexByPhyId(localEp_.loc.device.devPhyId, deviceLogicId));
387 1 : channelHccsRes.localDeviceLogicId = static_cast<s32>(deviceLogicId);
388 :
389 1 : remoteIpcRmaBufferVecEx_.clear();
390 1 : CHK_RET(localEpPtr_->GetRemoteIpcRmaBufferEx(remoteIpcRmaBufferVecEx_));
391 1 : channelHccsRes.remoteBufSize = remoteIpcRmaBufferVecEx_.size();
392 1 : channelHccsRes.remoteBufMem = remoteIpcRmaBufferVecEx_.data();
393 :
394 1 : localIpcRmaBufferVecEx_.clear();
395 1 : CHK_RET(localEpPtr_->GetLocalIpcRmaBufferEx(localIpcRmaBufferVecEx_));
396 1 : channelHccsRes.localBufSize = localIpcRmaBufferVecEx_.size();
397 1 : channelHccsRes.localBufMem = localIpcRmaBufferVecEx_.data();
398 :
399 1 : HCCL_DEBUG("[AicpuTsHccsChannel][%s] finish set RemoteChannelP2pResParam info", __func__);
400 1 : return HCCL_SUCCESS;
401 : }
402 :
403 0 : HcclResult AicpuTsHccsChannel::Serialize(std::shared_ptr<hccl::DeviceMem>& out)
404 : {
405 0 : HCCL_DEBUG("[AicpuTsHccsChannel][%s] start", __func__);
406 0 : HcclChannelHccsRes hostChannelHccsRes;
407 0 : CHK_RET(BuildHcclChannelHccsRes(hostChannelHccsRes));
408 :
409 : // 临时缓存信息
410 0 : HcclChannelHccsRes deviceChannelHccsRes = hostChannelHccsRes;
411 :
412 : // 计算设备内存分配的空间,包括需要深度拷贝的子域的信息内的内存,然后分配整块设备地址内存
413 0 : u64 outSize = 0;
414 : // cal base info
415 0 : u64 baseSize = sizeof(HcclChannelHccsRes);
416 0 : outSize += baseSize;
417 : // cal local buf mem
418 0 : size_t localBufSize = hostChannelHccsRes.localBufSize * sizeof(HcclMemEx);
419 0 : outSize += localBufSize;
420 : // cal remote buf mem
421 0 : size_t remoteBufSize = hostChannelHccsRes.remoteBufSize * sizeof(HcclMemEx);
422 0 : outSize += remoteBufSize;
423 0 : EXCEPTION_CATCH((out = std::make_shared<hccl::DeviceMem>(hccl::DeviceMem::alloc(outSize))), return HCCL_E_PTR);
424 :
425 0 : void* dstPtr = nullptr;
426 : // 复制 local buf
427 0 : if (hostChannelHccsRes.localBufSize > 0 && hostChannelHccsRes.localBufMem != nullptr) {
428 : // 使用设备地址重置 local buf的地址
429 0 : dstPtr = reinterpret_cast<uint8_t*>(out.get()->ptr()) + baseSize;
430 0 : deviceChannelHccsRes.localBufMem = reinterpret_cast<HcclMemEx*>(dstPtr);
431 0 : CHK_RET(hrtMemSyncCopy(
432 : deviceChannelHccsRes.localBufMem, localBufSize, hostChannelHccsRes.localBufMem, localBufSize,
433 : HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_HOST_TO_DEVICE));
434 : }
435 :
436 : // 复制 remote buf
437 0 : if (hostChannelHccsRes.remoteBufSize > 0 && hostChannelHccsRes.remoteBufMem != nullptr) {
438 : // 使用设备地址重置 remote buf的地址
439 0 : dstPtr = reinterpret_cast<uint8_t*>(out.get()->ptr()) + baseSize + localBufSize;
440 0 : deviceChannelHccsRes.remoteBufMem = reinterpret_cast<HcclMemEx*>(dstPtr);
441 0 : CHK_RET(hrtMemSyncCopy(
442 : deviceChannelHccsRes.remoteBufMem, remoteBufSize, hostChannelHccsRes.remoteBufMem, remoteBufSize,
443 : HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_HOST_TO_DEVICE));
444 : }
445 :
446 : // 复制 base
447 0 : CHK_RET(hrtMemSyncCopy(
448 : out.get()->ptr(), sizeof(HcclChannelHccsRes), &deviceChannelHccsRes, sizeof(HcclChannelHccsRes),
449 : HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_HOST_TO_DEVICE));
450 :
451 0 : HCCL_DEBUG("[AicpuTsHccsChannel][%s] end", __func__);
452 0 : return HCCL_SUCCESS;
453 : }
454 :
455 0 : HcclResult AicpuTsHccsChannel::Clean()
456 : {
457 0 : HCCL_INFO("[AicpuTsHccsChannel][%s] Clean not implemented, no resume needed for AICPU TS Hccs channel", __func__);
458 0 : return HCCL_E_NOT_SUPPORT;
459 : }
460 :
461 0 : HcclResult AicpuTsHccsChannel::Resume()
462 : {
463 0 : HCCL_INFO("[AicpuTsHccsChannel][%s] Resume not implemented, no resume needed for AICPU TS Hccs channel", __func__);
464 0 : return HCCL_E_NOT_SUPPORT;
465 : }
466 :
467 0 : HcommChannelKind AicpuTsHccsChannel::GetChannelKind() const { return HcommChannelKind::AICPU_TS_HCCS; }
468 :
469 0 : HcclResult AicpuTsHccsChannel::NotifyRecord([[maybe_unused]] const uint32_t remoteNotifyIdx)
470 : {
471 0 : HCCL_INFO("[AicpuTsHccsChannel::%s] not supported yet.", __func__);
472 0 : return HCCL_E_NOT_SUPPORT;
473 : }
474 :
475 : HcclResult
476 0 : AicpuTsHccsChannel::NotifyWait([[maybe_unused]] const uint32_t localNotifyIdx, [[maybe_unused]] const uint32_t timeout)
477 : {
478 0 : HCCL_INFO("[AicpuTsHccsChannel::%s] not supported yet.", __func__);
479 0 : return HCCL_E_NOT_SUPPORT;
480 : }
481 :
482 0 : HcclResult AicpuTsHccsChannel::WriteWithNotify(
483 : [[maybe_unused]] void* dst, [[maybe_unused]] const void* src, [[maybe_unused]] const uint64_t len,
484 : [[maybe_unused]] uint32_t remoteNotifyIdx)
485 : {
486 0 : HCCL_INFO("[AicpuTsHccsChannel::%s] not supported yet.", __func__);
487 0 : return HCCL_E_NOT_SUPPORT;
488 : }
489 :
490 : HcclResult
491 0 : AicpuTsHccsChannel::Write([[maybe_unused]] void* dst, [[maybe_unused]] const void* src, [[maybe_unused]] uint64_t len)
492 : {
493 0 : HCCL_INFO("[AicpuTsHccsChannel::%s] not supported yet.", __func__);
494 0 : return HCCL_E_NOT_SUPPORT;
495 : }
496 :
497 : HcclResult
498 0 : AicpuTsHccsChannel::Read([[maybe_unused]] void* dst, [[maybe_unused]] const void* src, [[maybe_unused]] uint64_t len)
499 : {
500 0 : HCCL_INFO("[AicpuTsHccsChannel::%s] not supported yet.", __func__);
501 0 : return HCCL_E_NOT_SUPPORT;
502 : }
503 :
504 0 : HcclResult AicpuTsHccsChannel::ChannelFence()
505 : {
506 0 : HCCL_INFO("[AicpuTsHccsChannel::%s] not supported yet.", __func__);
507 0 : return HCCL_E_NOT_SUPPORT;
508 : }
509 : } // namespace hcomm
|