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 : #ifndef HCOMM_NIC_PLUGIN_HOLDER_H
11 : #define HCOMM_NIC_PLUGIN_HOLDER_H
12 :
13 : #include "endpoint.h"
14 : #include "channel.h"
15 : #include "nic_plugin_manager.h"
16 :
17 : namespace hcomm {
18 :
19 : template <typename Ops>
20 6 : void DestroyNicPluginOpsAndCtx(Ops*& nicOps, void* nicCtx)
21 : {
22 6 : if (nicOps != nullptr) {
23 6 : if (nicOps->destroy != nullptr) {
24 6 : int32_t ret = nicOps->destroy(nicCtx);
25 6 : if (ret != HCCL_SUCCESS) {
26 0 : HCCL_WARNING("[%s] plugin destroy failed, ret[%d].", __func__, ret);
27 : }
28 : }
29 6 : delete nicOps;
30 6 : nicOps = nullptr;
31 : }
32 6 : }
33 :
34 : /**
35 : * @note 职责:NIC插件Endpoint/Channel占位子类,仅用于在EndpointMap、ChannelMap中占位,
36 : * 接口业务功能由NIC插件实现。
37 : */
38 : class PluginEndpointHolder : public Endpoint {
39 : public:
40 4 : explicit PluginEndpointHolder(const EndpointDesc& endpointDesc, const NicPluginEntry* pluginEntry)
41 4 : : Endpoint(endpointDesc),
42 4 : pluginEntry_(pluginEntry)
43 4 : {}
44 8 : ~PluginEndpointHolder() override { DestroyNicPluginOpsAndCtx(nicOps_, nicCtx_); }
45 :
46 2 : const NicPluginEntry* GetPluginEntry() const { return pluginEntry_; }
47 :
48 0 : HcclResult Init() override { return HCCL_E_NOT_SUPPORT; }
49 0 : HcclResult ServerSocketListen(const uint32_t port) override
50 : {
51 : (void)port;
52 0 : return HCCL_E_NOT_SUPPORT;
53 : }
54 0 : HcclResult RegisterMemory(HcommMem mem, const char* memTag, void** memHandle) override
55 : {
56 : (void)mem;
57 : (void)memTag;
58 : (void)memHandle;
59 0 : return HCCL_E_NOT_SUPPORT;
60 : }
61 0 : HcclResult UnregisterMemory(void* memHandle) override
62 : {
63 : (void)memHandle;
64 0 : return HCCL_E_NOT_SUPPORT;
65 : }
66 0 : HcclResult MemoryExport(void* memHandle, void** memDesc, uint32_t* memDescLen) override
67 : {
68 : (void)memHandle;
69 : (void)memDesc;
70 : (void)memDescLen;
71 0 : return HCCL_E_NOT_SUPPORT;
72 : }
73 0 : HcclResult MemoryImport(const void* memDesc, uint32_t descLen, HcommMem* outMem) override
74 : {
75 : (void)memDesc;
76 : (void)descLen;
77 : (void)outMem;
78 0 : return HCCL_E_NOT_SUPPORT;
79 : }
80 0 : HcclResult MemoryUnimport(const void* memDesc, uint32_t descLen) override
81 : {
82 : (void)memDesc;
83 : (void)descLen;
84 0 : return HCCL_E_NOT_SUPPORT;
85 : }
86 0 : HcclResult GetAllMemHandles(void** memHandles, uint32_t* memHandleNum) override
87 : {
88 : (void)memHandles;
89 : (void)memHandleNum;
90 0 : return HCCL_E_NOT_SUPPORT;
91 : }
92 :
93 : private:
94 : const NicPluginEntry* pluginEntry_;
95 : };
96 :
97 : class PluginChannelHolder : public Channel {
98 : public:
99 2 : explicit PluginChannelHolder(const NicPluginEntry* pluginEntry) : pluginEntry_(pluginEntry) {}
100 2 : ~PluginChannelHolder() override { DestroyNicPluginOpsAndCtx(nicOps_, nicCtx_); }
101 :
102 : const NicPluginEntry* GetPluginEntry() const { return pluginEntry_; }
103 :
104 0 : HcclResult Init() override { return HCCL_E_NOT_SUPPORT; }
105 0 : HcclResult GetNotifyNum(uint32_t* notifyNum) const override
106 : {
107 : (void)notifyNum;
108 0 : return HCCL_E_NOT_SUPPORT;
109 : }
110 0 : HcclResult GetRemoteMems(uint32_t* memNum, CommMem** remoteMem, char*** memInfos) override
111 : {
112 : (void)memNum;
113 : (void)remoteMem;
114 : (void)memInfos;
115 0 : return HCCL_E_NOT_SUPPORT;
116 : }
117 0 : ChannelStatus GetStatus() override { return ChannelStatus::FAILED; }
118 0 : HcclResult Clean() override { return HCCL_E_NOT_SUPPORT; }
119 0 : HcclResult Resume() override { return HCCL_E_NOT_SUPPORT; }
120 0 : HcclResult NotifyRecord(const uint32_t remoteNotifyIdx) override
121 : {
122 : (void)remoteNotifyIdx;
123 0 : return HCCL_E_NOT_SUPPORT;
124 : }
125 0 : HcclResult NotifyWait(const uint32_t localNotifyIdx, const uint32_t timeout) override
126 : {
127 : (void)localNotifyIdx;
128 : (void)timeout;
129 0 : return HCCL_E_NOT_SUPPORT;
130 : }
131 0 : HcclResult WriteWithNotify(void* dst, const void* src, const uint64_t len, uint32_t remoteNotifyIdx) override
132 : {
133 : (void)dst;
134 : (void)src;
135 : (void)len;
136 : (void)remoteNotifyIdx;
137 0 : return HCCL_E_NOT_SUPPORT;
138 : }
139 0 : HcclResult Write(void* dst, const void* src, uint64_t len) override
140 : {
141 : (void)dst;
142 : (void)src;
143 : (void)len;
144 0 : return HCCL_E_NOT_SUPPORT;
145 : }
146 0 : HcclResult Read(void* dst, const void* src, uint64_t len) override
147 : {
148 : (void)dst;
149 : (void)src;
150 : (void)len;
151 0 : return HCCL_E_NOT_SUPPORT;
152 : }
153 0 : HcclResult ChannelFence() override { return HCCL_E_NOT_SUPPORT; }
154 0 : const HcommChannelDesc& GetChannelDesc() const override
155 : {
156 : static const HcommChannelDesc kEmptyDesc{};
157 0 : return kEmptyDesc;
158 : }
159 :
160 : private:
161 : const NicPluginEntry* pluginEntry_;
162 : };
163 :
164 : } // namespace hcomm
165 :
166 : #endif // HCOMM_NIC_PLUGIN_HOLDER_H
|