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 : #ifndef ENDPOINT_H
11 : #define ENDPOINT_H
12 :
13 : #include <memory>
14 : #include <vector>
15 : #include <string>
16 : #include "reged_mem_mgr.h"
17 : #include "socket/socket.h"
18 : #include "socket_handle_manager.h"
19 : #include "rdma_handle_manager.h"
20 : #include "../../common/orion_adpt_utils.h"
21 : #include "hccp_hdc_manager.h"
22 :
23 : namespace hcomm {
24 : /**
25 : * @note 职责:通信设备Endpoint的C++抽象接口类,管理通信设备上下文,以及设备上的注册内存。
26 : */
27 : class Endpoint {
28 : public:
29 : explicit Endpoint(const EndpointDesc &endpointDesc);
30 :
31 241 : virtual ~Endpoint() = default;
32 :
33 : static HcclResult CreateEndpoint(const EndpointDesc &endpointDesc, std::unique_ptr<Endpoint> &endpointPtr);
34 :
35 : virtual HcclResult Init() = 0;
36 :
37 : virtual HcclResult ServerSocketListen(const uint32_t port) = 0;
38 :
39 0 : virtual HcclResult ServerSocketStopListen(const uint32_t port) {return HCCL_E_NOT_SUPPORT;};
40 1 : virtual HcclResult ServerSocketGetListenPort(uint32_t *port) {return HCCL_E_NOT_SUPPORT;};
41 :
42 43 : virtual std::shared_ptr<RegedMemMgr> GetRegedMemMgr()
43 : {
44 43 : return regedMemMgr_;
45 : }
46 :
47 136 : void* GetRdmaHandle()
48 : {
49 136 : return ctxHandle_;
50 : }
51 :
52 7 : bool IsCtxHandleValid() const
53 : {
54 7 : if (ctxHandle_ == nullptr) {
55 2 : return false;
56 : }
57 5 : return Hccl::RdmaHandleManager::GetInstance().IsHandleValid(
58 5 : static_cast<Hccl::RdmaHandle>(ctxHandle_));
59 : }
60 :
61 264 : EndpointDesc GetEndpointDesc()
62 : {
63 264 : return endpointDesc_;
64 : }
65 :
66 : // 注册内存
67 : virtual HcclResult RegisterMemory(HcommMem mem, const char *memTag, void **memHandle) = 0;
68 :
69 : // 注销内存
70 : virtual HcclResult UnregisterMemory(void* memHandle) = 0;
71 :
72 : // 导出指定内存描述,用于交换
73 : virtual HcclResult MemoryExport(void *memHandle, void **memDesc, uint32_t *memDescLen) = 0;
74 :
75 : // 基于内存描述,导入获得内存
76 : virtual HcclResult MemoryImport(const void *memDesc, uint32_t descLen, HcommMem *outMem) = 0;
77 :
78 : // 关闭内存
79 : virtual HcclResult MemoryUnimport(const void *memDesc, uint32_t descLen) = 0;
80 :
81 : virtual HcclResult GetAllMemHandles(void **memHandles, uint32_t *memHandleNum) = 0;
82 :
83 0 : virtual HcclResult MemoryGrant(const HcommMemGrantInfo *remoteGrantInfo)
84 : {
85 0 : return HCCL_SUCCESS;
86 : }
87 :
88 : static HcclResult CheckFeature(const EndpointDesc &endpointDesc, HcommEndpointFeatureType featureType, bool &value);
89 :
90 : // 获取UB异步事件
91 0 : virtual HcclResult GetAsyncEvents(uint32_t devPhyId, struct AsyncEvent events[], uint32_t &num)
92 : {
93 : (void) devPhyId;
94 : (void) events;
95 0 : num = 0;
96 0 : return HCCL_SUCCESS;
97 : }
98 :
99 : protected:
100 : static HcclResult CreateEndpointBase(const EndpointDesc &endpointDesc, std::unique_ptr<Endpoint> &endpointPtr);
101 : void* ctxHandle_{nullptr};
102 : std::shared_ptr<RegedMemMgr> regedMemMgr_{};
103 : EndpointDesc endpointDesc_;
104 : };
105 :
106 : }
107 : #endif // ENDPOINT_H
|