Line data Source code
1 : /**
2 : * Copyright (c) 2026 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 "uboe_endpoint.h"
12 : #include "endpoint_mgr.h"
13 : #include "log.h"
14 : #include "hccl/hccl_res.h"
15 : #include "urma_mem.h"
16 : #include "proc_reged_mem_mgr_cache.h"
17 : #include "adapter_rts_common.h"
18 :
19 : namespace hcomm {
20 :
21 13 : UboeEndpoint::UboeEndpoint(const EndpointDesc& endpointDesc) : UboeUbRtpEndpointHelper(endpointDesc) {}
22 :
23 26 : UboeEndpoint::~UboeEndpoint() noexcept { ProcRegedMemMgrCache::GetInstance().Release(cacheKey_); }
24 :
25 13 : HcclResult UboeEndpoint::Init()
26 : {
27 13 : HCCL_INFO("[%s] localEndpoint protocol[%d]", __func__, endpointDesc_.protocol);
28 :
29 13 : Hccl::IpAddress ipAddr{};
30 13 : CHK_RET(CommAddrToIpAddress(endpointDesc_.commAddr, ipAddr));
31 :
32 : s32 deviceLogicId;
33 : u32 devPhyId;
34 11 : CHK_RET(hrtGetDevice(&deviceLogicId));
35 11 : CHK_RET(hrtGetDevicePhyIdByIndex(deviceLogicId, devPhyId));
36 11 : endpointDesc_.loc.device.devPhyId = devPhyId;
37 :
38 11 : Hccl::HccpHdcManager::GetInstance().Init(deviceLogicId);
39 11 : auto& rdmaHandleMgr = Hccl::RdmaHandleManager::GetInstance();
40 11 : Hccl::IpAddress eidAddress{};
41 11 : rdmaHandleMgr.UboeIpv4ToEid(ipAddr, eidAddress, devPhyId);
42 11 : EXCEPTION_CATCH(
43 : ctxHandle_ = static_cast<void*>(rdmaHandleMgr.GetByIp(endpointDesc_.loc.device.devPhyId, eidAddress)),
44 : return HCCL_E_PARA);
45 11 : CHK_PTR_NULL(ctxHandle_);
46 11 : HCCL_INFO(
47 : "%s success, devPhyId[%u], eidAddress[%s], ctxHandle[%p]", __func__, devPhyId, eidAddress.Describe().c_str(),
48 : ctxHandle_);
49 :
50 11 : cacheKey_ = MemMgrCacheKey{devPhyId, COMM_PROTOCOL_UB_CTP, ipAddr, LocTypeToPortType(endpointDesc_.loc.locType)};
51 11 : auto& cache = ProcRegedMemMgrCache::GetInstance();
52 13 : EXCEPTION_CATCH(
53 : regedMemMgr_ = cache.GetOrCreate(
54 : cacheKey_,
55 : [this]() {
56 : auto m = std::make_shared<UbRegedMemMgr>();
57 : m->rdmaHandle_ = this->ctxHandle_;
58 : return m;
59 : }),
60 : return HCCL_E_INTERNAL);
61 :
62 11 : return HcclResult::HCCL_SUCCESS;
63 : }
64 :
65 : } // namespace hcomm
|