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