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 13 : HcclResult UboeEndpoint::Init()
24 : {
25 13 : HCCL_INFO("[%s] localEndpoint protocol[%d]", __func__, endpointDesc_.protocol);
26 :
27 13 : Hccl::IpAddress ipAddr{};
28 13 : CHK_RET(CommAddrToIpAddress(endpointDesc_.commAddr, ipAddr));
29 :
30 : s32 deviceLogicId;
31 : u32 devPhyId;
32 11 : CHK_RET(hrtGetDevice(&deviceLogicId));
33 11 : CHK_RET(hrtGetDevicePhyIdByIndex(deviceLogicId, devPhyId));
34 11 : endpointDesc_.loc.device.devPhyId = devPhyId;
35 :
36 11 : Hccl::HccpHdcManager::GetInstance().Init(deviceLogicId);
37 11 : auto& rdmaHandleMgr = Hccl::RdmaHandleManager::GetInstance();
38 11 : Hccl::IpAddress eidAddress{};
39 11 : rdmaHandleMgr.UboeIpv4ToEid(ipAddr, eidAddress, devPhyId);
40 11 : EXCEPTION_CATCH(
41 : ctxHandle_ = static_cast<void*>(rdmaHandleMgr.GetByIp(endpointDesc_.loc.device.devPhyId, eidAddress)),
42 : return HCCL_E_PARA);
43 11 : CHK_PTR_NULL(ctxHandle_);
44 11 : HCCL_INFO(
45 : "%s success, devPhyId[%u], eidAddress[%s], ctxHandle[%p]", __func__, devPhyId, eidAddress.Describe().c_str(),
46 : ctxHandle_);
47 :
48 11 : MemMgrCacheKey key{devPhyId, COMM_PROTOCOL_UB_CTP, ipAddr, LocTypeToPortType(endpointDesc_.loc.locType)};
49 2 : auto createMgr = [this]() {
50 2 : auto mgr = std::make_shared<UbRegedMemMgr>();
51 2 : mgr->rdmaHandle_ = ctxHandle_;
52 2 : return mgr;
53 11 : };
54 11 : CHK_RET(AttachCache(key, createMgr));
55 :
56 11 : return HcclResult::HCCL_SUCCESS;
57 : }
58 :
59 : } // namespace hcomm
|