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 "adapter_rts_common.h"
17 :
18 : namespace hcomm {
19 :
20 13 : UboeEndpoint::UboeEndpoint(const EndpointDesc &endpointDesc)
21 13 : : UboeUbgEndpointHelper(endpointDesc)
22 : {
23 13 : }
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(ctxHandle_ = static_cast<void *>(rdmaHandleMgr.GetByIp(endpointDesc_.loc.device.devPhyId, eidAddress)),
43 : return HCCL_E_PARA);
44 11 : CHK_PTR_NULL(ctxHandle_);
45 11 : HCCL_INFO("%s success, devId[%u], eidAddress[%s], ctxHandle[%p]",
46 : __func__, devPhyId, eidAddress.Describe().c_str(), ctxHandle_);
47 :
48 11 : EXCEPTION_CATCH(regedMemMgr_ = std::make_unique<UbRegedMemMgr>(), return HCCL_E_INTERNAL);
49 11 : regedMemMgr_->rdmaHandle_ = ctxHandle_;
50 :
51 11 : return HcclResult::HCCL_SUCCESS;
52 : }
53 :
54 : }
55 :
|