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 "nic_plugin_manager.h"
12 :
13 : #include <acl/acl_rt.h>
14 : #include <dirent.h>
15 : #include <dlfcn.h>
16 : #include <climits>
17 : #include <algorithm>
18 : #include <cstddef>
19 : #include <cstdlib>
20 : #include <cstring>
21 : #include <memory>
22 : #include <mutex>
23 : #include <string>
24 : #include <unordered_map>
25 : #include <vector>
26 :
27 : #include "hcomm_result_defs.h"
28 : #include "log.h"
29 : #include "param_check_pub.h"
30 : #include "shared_jetty_mgr.h"
31 :
32 : namespace hcomm {
33 : namespace {
34 : constexpr const char* HCOMM_NIC_PLUGIN_DIR = "hcomm_plugin";
35 : constexpr const char* HCOMM_NIC_PLUGIN_SO_ENV = "HCOMM_NIC_PLUGIN_SO";
36 :
37 22 : std::once_flag& LoadOnce()
38 : {
39 : static std::once_flag loadOnce;
40 22 : return loadOnce;
41 : }
42 :
43 0 : std::vector<std::unique_ptr<NicPluginEntry>>& LoadedPlugins()
44 : {
45 0 : static std::vector<std::unique_ptr<NicPluginEntry>> loadedPlugins;
46 0 : return loadedPlugins;
47 : }
48 :
49 20 : std::unordered_map<CommProtocol, const NicPluginEntry*>& ProtocolPlugins()
50 : {
51 20 : static std::unordered_map<CommProtocol, const NicPluginEntry*> protocolPlugins;
52 20 : return protocolPlugins;
53 : }
54 :
55 0 : bool EndsWithSo(const std::string& path)
56 : {
57 0 : constexpr const char* suffix = ".so";
58 0 : constexpr size_t suffixLen = 3U;
59 0 : return path.size() >= suffixLen && path.compare(path.size() - suffixLen, suffixLen, suffix) == 0;
60 : }
61 :
62 7 : bool IsOpsHeaderValid(const CommAbiHeader& header, uint32_t magicWord, uint32_t version, const char* opsName)
63 : {
64 7 : if (header.magicWord != magicWord) {
65 0 : HCCL_RUN_WARNING(
66 : "[NicPlugin] %s magicWord[0x%08x] mismatch, expected[0x%08x].", opsName, header.magicWord, magicWord);
67 0 : return false;
68 : }
69 7 : if (header.version != version) {
70 0 : HCCL_RUN_WARNING("[NicPlugin] %s version[%u] mismatch, expected[%u].", opsName, header.version, version);
71 0 : return false;
72 : }
73 7 : if (header.size < sizeof(CommAbiHeader)) {
74 0 : HCCL_RUN_WARNING(
75 : "[NicPlugin] %s size[%u] is smaller than ABI header[%zu].", opsName, header.size,
76 : sizeof(CommAbiHeader));
77 0 : return false;
78 : }
79 7 : return true;
80 : }
81 :
82 0 : void RegisterPluginProtocols(const NicPluginEntry* plugin)
83 : {
84 0 : auto& protocolPlugins = ProtocolPlugins();
85 0 : for (uint32_t idx = 0; idx < plugin->info->protocolCount; ++idx) {
86 0 : const CommProtocol protocol = plugin->info->protocols[idx];
87 0 : auto iter = protocolPlugins.find(protocol);
88 0 : if (iter != protocolPlugins.end()) {
89 0 : HCCL_RUN_WARNING(
90 : "[NicPlugin] protocol[%d] handler[%s] is overwritten by plugin[%s].", protocol,
91 : iter->second->info->name == nullptr ? "unknown" : iter->second->info->name,
92 : plugin->info->name == nullptr ? "unknown" : plugin->info->name);
93 : }
94 0 : protocolPlugins[protocol] = plugin;
95 0 : HCCL_RUN_INFO(
96 : "[NicPlugin] protocol[%d] is handled by plugin[%s].", protocol,
97 : plugin->info->name == nullptr ? "unknown" : plugin->info->name);
98 : }
99 0 : }
100 :
101 0 : void* LoadSymbol(void* soHandle, const char* soPath, const char* symbol)
102 : {
103 0 : dlerror();
104 0 : void* addr = dlsym(soHandle, symbol);
105 0 : const char* dlsymErr = dlerror();
106 0 : if (dlsymErr != nullptr || addr == nullptr) {
107 0 : HCCL_RUN_WARNING(
108 : "[NicPlugin] dlsym %s from %s failed: %s.", symbol, soPath, dlsymErr == nullptr ? "unknown" : dlsymErr);
109 0 : return nullptr;
110 : }
111 0 : return addr;
112 : }
113 :
114 2 : void LoadOnePlugin(const std::string& path)
115 : {
116 2 : if (path.empty()) {
117 2 : return;
118 : }
119 : // 规范化文件路径后再使用,防范路径遍历风险
120 2 : char canonicalPath[PATH_MAX] = {0};
121 2 : if (realpath(path.c_str(), canonicalPath) == nullptr) {
122 1 : HCCL_RUN_WARNING("[LoadOnePlugin] %s is not a valid real path.", path.c_str());
123 1 : return;
124 : }
125 1 : void* soHandle = dlopen(canonicalPath, RTLD_NOW | RTLD_LOCAL);
126 1 : if (soHandle == nullptr) {
127 1 : HCCL_RUN_WARNING("[NicPlugin] dlopen %s failed: %s.", path.c_str(), dlerror());
128 1 : return;
129 : }
130 :
131 : auto getInfo
132 0 : = reinterpret_cast<HcommNicPluginGetInfoFunc>(LoadSymbol(soHandle, path.c_str(), "HcommNicPluginGetInfo"));
133 : auto createEndpoint = reinterpret_cast<HcommNicPluginCreateEndpointFunc>(
134 0 : LoadSymbol(soHandle, path.c_str(), "HcommNicPluginCreateEndpoint"));
135 : auto createChannel = reinterpret_cast<HcommNicPluginCreateChannelFunc>(
136 0 : LoadSymbol(soHandle, path.c_str(), "HcommNicPluginCreateChannel"));
137 0 : if (getInfo == nullptr || createEndpoint == nullptr || createChannel == nullptr) {
138 0 : dlclose(soHandle);
139 0 : return;
140 : }
141 :
142 0 : const HcommNicPluginInfo* info = getInfo();
143 0 : if (!ValidatePluginInfo(path.c_str(), info, createEndpoint, createChannel)) {
144 0 : dlclose(soHandle);
145 0 : return;
146 : }
147 :
148 : std::unique_ptr<NicPluginEntry> plugin(new (std::nothrow)
149 0 : NicPluginEntry{soHandle, info, createEndpoint, createChannel});
150 0 : if (plugin == nullptr) {
151 0 : HCCL_RUN_WARNING("[NicPlugin] allocate plugin entry for %s failed.", path.c_str());
152 0 : dlclose(soHandle);
153 0 : return;
154 : }
155 0 : RegisterPluginProtocols(plugin.get());
156 0 : LoadedPlugins().emplace_back(std::move(plugin));
157 0 : }
158 :
159 2 : void LoadDefaultDirectory(const std::string& pluginDir)
160 : {
161 2 : DIR* dir = opendir(pluginDir.c_str());
162 2 : if (dir == nullptr) {
163 2 : HCCL_RUN_INFO("[NicPlugin] plugin directory %s is unavailable.", pluginDir.c_str());
164 2 : return;
165 : }
166 0 : std::vector<std::string> soPaths;
167 0 : for (dirent* entry = readdir(dir); entry != nullptr; entry = readdir(dir)) {
168 0 : const std::string name(entry->d_name);
169 0 : if (name == "." || name == ".." || !EndsWithSo(name)) {
170 0 : continue;
171 : }
172 0 : soPaths.emplace_back(pluginDir + "/" + name);
173 0 : }
174 0 : closedir(dir);
175 0 : std::sort(soPaths.begin(), soPaths.end());
176 0 : for (const auto& path : soPaths) {
177 0 : LoadOnePlugin(path);
178 : }
179 0 : }
180 :
181 1 : void LoadExplicitPlugins(const char* envValue)
182 : {
183 1 : if (envValue == nullptr || envValue[0] == '\0') {
184 0 : return;
185 : }
186 1 : const std::string paths(envValue);
187 1 : size_t start = 0;
188 2 : while (start <= paths.size()) {
189 2 : const size_t end = paths.find(':', start);
190 2 : const std::string path = paths.substr(start, end == std::string::npos ? std::string::npos : end - start);
191 2 : LoadOnePlugin(path);
192 2 : if (end == std::string::npos) {
193 1 : break;
194 : }
195 1 : start = end + 1;
196 2 : }
197 1 : }
198 :
199 3 : void LoadPluginsOnce()
200 : {
201 3 : const char* ascendHomePath = getenv("ASCEND_HOME_PATH");
202 3 : if (ascendHomePath != nullptr && ascendHomePath[0] != '\0') {
203 4 : LoadDefaultDirectory(std::string(ascendHomePath) + "/" + HCOMM_NIC_PLUGIN_DIR);
204 : } else {
205 1 : HCCL_RUN_INFO("[NicPlugin] ASCEND_HOME_PATH is empty, skip default plugin directory.");
206 1 : LoadExplicitPlugins(getenv(HCOMM_NIC_PLUGIN_SO_ENV));
207 : }
208 3 : }
209 :
210 : } // namespace
211 :
212 4 : bool ValidateEndpointOps(const HcommNicEndpointOps* ops)
213 : {
214 4 : if (ops == nullptr
215 8 : || !IsOpsHeaderValid(
216 4 : ops->header, HCOMM_NIC_ENDPOINT_OPS_MAGIC_WORD, HCOMM_NIC_ENDPOINT_OPS_VERSION, "endpoint ops")) {
217 0 : return false;
218 : }
219 4 : if (!IsPluginOpAvailable(ops, offsetof(HcommNicEndpointOps, destroy), sizeof(decltype(ops->destroy)))
220 4 : || ops->destroy == nullptr) {
221 0 : HCCL_ERROR("[NicPlugin] plugin endpoint destroy is not implemented.");
222 0 : return false;
223 : }
224 4 : return true;
225 : }
226 :
227 2 : bool ValidateChannelOps(const HcommNicChannelOps* ops)
228 : {
229 2 : if (ops == nullptr
230 4 : || !IsOpsHeaderValid(
231 2 : ops->header, HCOMM_NIC_CHANNEL_OPS_MAGIC_WORD, HCOMM_NIC_CHANNEL_OPS_VERSION, "channel ops")) {
232 0 : return false;
233 : }
234 2 : if (!IsPluginOpAvailable(ops, offsetof(HcommNicChannelOps, destroy), sizeof(decltype(ops->destroy)))
235 2 : || ops->destroy == nullptr) {
236 0 : HCCL_ERROR("[NicPlugin] channel destroy is not implemented.");
237 0 : return false;
238 : }
239 2 : return true;
240 : }
241 :
242 1 : bool ValidatePluginInfo(
243 : const char* soPath, const HcommNicPluginInfo* info, HcommNicPluginCreateEndpointFunc createEndpoint,
244 : HcommNicPluginCreateChannelFunc createChannel)
245 : {
246 1 : if (info == nullptr) {
247 0 : HCCL_RUN_WARNING("[NicPlugin] %s exports null plugin info.", soPath);
248 0 : return false;
249 : }
250 1 : if (!IsOpsHeaderValid(
251 1 : info->header, HCOMM_NIC_PLUGIN_INFO_MAGIC_WORD, HCOMM_NIC_PLUGIN_INFO_VERSION, "plugin info")) {
252 0 : return false;
253 : }
254 1 : constexpr size_t requiredSize
255 : = offsetof(HcommNicPluginInfo, protocols) + sizeof(static_cast<HcommNicPluginInfo*>(nullptr)->protocols);
256 1 : if (info->header.size < requiredSize) {
257 0 : HCCL_RUN_WARNING(
258 : "[NicPlugin] %s plugin info size[%u] is smaller than required[%zu].", soPath, info->header.size,
259 : requiredSize);
260 0 : return false;
261 : }
262 1 : if (info->protocolCount == 0 || info->protocolCount > HCOMM_NIC_PLUGIN_MAX_PROTOCOLS) {
263 0 : HCCL_RUN_WARNING("[NicPlugin] %s invalid protocolCount[%u].", soPath, info->protocolCount);
264 0 : return false;
265 : }
266 1 : if (createEndpoint == nullptr || createChannel == nullptr) {
267 0 : HCCL_RUN_WARNING("[NicPlugin] %s missing create endpoint/channel symbol.", soPath);
268 0 : return false;
269 : }
270 1 : for (uint32_t idx = 0; idx < info->protocolCount; ++idx) {
271 1 : const CommProtocol protocol = info->protocols[idx];
272 1 : if ((protocol < COMM_PROTOCOL_HCCS || protocol > COMM_PROTOCOL_UBG) && protocol < COMM_PROTOCOL_CUSTOM_BASE) {
273 1 : HCCL_RUN_WARNING("[NicPlugin] %s invalid protocol[%d].", soPath, info->protocols[idx]);
274 1 : return false;
275 : }
276 : }
277 0 : return true;
278 : }
279 :
280 22 : void LoadAllNicPlugins() { std::call_once(LoadOnce(), LoadPluginsOnce); }
281 :
282 20 : const NicPluginEntry* FindHostNicPlugin(CommProtocol protocol)
283 : {
284 20 : LoadAllNicPlugins();
285 20 : const auto& protocolPlugins = ProtocolPlugins();
286 20 : auto iter = protocolPlugins.find(protocol);
287 20 : const NicPluginEntry* entry = iter == protocolPlugins.end() ? nullptr : iter->second;
288 20 : return entry;
289 : }
290 :
291 1 : int32_t DefaultEndpointInit(void* ctx)
292 : {
293 : (void)ctx;
294 1 : HCCL_RUN_WARNING("[NicPlugin] plugin endpoint init is not supported.");
295 1 : return HCCL_SUCCESS;
296 : }
297 :
298 1 : int32_t DefaultEndpointRegisterMemory(void* ctx, const CommMem* mem, const char* tag, void** handle)
299 : {
300 : (void)ctx;
301 : (void)mem;
302 : (void)tag;
303 : (void)handle;
304 1 : HCCL_RUN_WARNING("[NicPlugin] plugin endpoint registerMemory is not supported.");
305 1 : return HCCL_E_NOT_SUPPORT;
306 : }
307 :
308 1 : int32_t DefaultEndpointUnregisterMemory(void* ctx, void* handle)
309 : {
310 : (void)ctx;
311 : (void)handle;
312 1 : HCCL_RUN_WARNING("[NicPlugin] plugin endpoint unregisterMemory is not supported.");
313 1 : return HCCL_E_NOT_SUPPORT;
314 : }
315 :
316 1 : int32_t DefaultEndpointMemoryExport(void* ctx, void* handle, void** desc, uint32_t* descLen)
317 : {
318 : (void)ctx;
319 : (void)handle;
320 : (void)desc;
321 : (void)descLen;
322 1 : HCCL_RUN_WARNING("[NicPlugin] plugin endpoint memoryExport is not supported.");
323 1 : return HCCL_E_NOT_SUPPORT;
324 : }
325 :
326 1 : int32_t DefaultEndpointMemoryImport(void* ctx, const void* desc, uint32_t descLen, CommMem* outMem)
327 : {
328 : (void)ctx;
329 : (void)desc;
330 : (void)descLen;
331 : (void)outMem;
332 1 : HCCL_RUN_WARNING("[NicPlugin] plugin endpoint memoryImport is not supported.");
333 1 : return HCCL_E_NOT_SUPPORT;
334 : }
335 :
336 1 : int32_t DefaultEndpointMemoryUnimport(void* ctx, const void* desc, uint32_t descLen)
337 : {
338 : (void)ctx;
339 : (void)desc;
340 : (void)descLen;
341 1 : HCCL_RUN_WARNING("[NicPlugin] plugin endpoint memoryUnimport is not supported.");
342 1 : return HCCL_E_NOT_SUPPORT;
343 : }
344 :
345 1 : int32_t DefaultEndpointGetListenPort(void* ctx, uint32_t* port)
346 : {
347 : (void)ctx;
348 : (void)port;
349 1 : HCCL_RUN_WARNING("[NicPlugin] plugin endpoint getListenPort is not supported.");
350 1 : return HCCL_E_NOT_SUPPORT;
351 : }
352 :
353 4 : HcommResult FillDefaultEndpointOps(const HcommNicEndpointOps* src, HcommNicEndpointOps** outOps)
354 : {
355 4 : if (src == nullptr || outOps == nullptr) {
356 0 : return HCCL_E_PARA;
357 : }
358 4 : HcommNicEndpointOps* dst = new (std::nothrow) HcommNicEndpointOps();
359 4 : if (dst == nullptr) {
360 0 : return HCCL_E_MEMORY;
361 : }
362 :
363 4 : size_t copySize = (src->header.size < sizeof(HcommNicEndpointOps)) ? src->header.size : sizeof(HcommNicEndpointOps);
364 4 : (void)memcpy_s(dst, sizeof(HcommNicEndpointOps), src, copySize);
365 :
366 4 : FOR_EACH_ENDPOINT_OP_DEFAULT(FILL_ENDPOINT_OP_DEFAULT)
367 4 : *outOps = dst;
368 4 : return HCCL_SUCCESS;
369 : }
370 :
371 : // ---- Channel ops 默认实现 ----
372 :
373 0 : int32_t DefaultChannelInit(void* ctx)
374 : {
375 : (void)ctx;
376 0 : HCCL_RUN_WARNING("[NicPlugin] channel init is not supported.");
377 0 : return HCCL_SUCCESS;
378 : }
379 :
380 1 : int32_t DefaultChannelGetStatus(void* ctx, int32_t* status)
381 : {
382 : (void)ctx;
383 : (void)status;
384 1 : HCCL_RUN_WARNING("[NicPlugin] channel getStatus is not supported.");
385 1 : return HCCL_E_NOT_SUPPORT;
386 : }
387 :
388 1 : int32_t DefaultChannelWriteNbi(void* ctx, void* dst, const void* src, uint64_t len)
389 : {
390 : (void)ctx;
391 : (void)dst;
392 : (void)src;
393 : (void)len;
394 1 : HCCL_RUN_WARNING("[NicPlugin] channel writeNbi is not supported.");
395 1 : return HCCL_E_NOT_SUPPORT;
396 : }
397 :
398 1 : int32_t DefaultChannelWriteNbiOnThread(void* ctx, ThreadHandle thread, void* dst, const void* src, uint64_t len)
399 : {
400 : (void)ctx;
401 : (void)thread;
402 : (void)dst;
403 : (void)src;
404 : (void)len;
405 1 : HCCL_RUN_WARNING("[NicPlugin] channel writeNbiOnThread is not supported.");
406 1 : return HCCL_E_NOT_SUPPORT;
407 : }
408 :
409 1 : int32_t DefaultChannelWriteOnThread(void* ctx, ThreadHandle thread, void* dst, const void* src, uint64_t len)
410 : {
411 : (void)ctx;
412 : (void)thread;
413 : (void)dst;
414 : (void)src;
415 : (void)len;
416 1 : HCCL_RUN_WARNING("[NicPlugin] channel writeOnThread is not supported.");
417 1 : return HCCL_E_NOT_SUPPORT;
418 : }
419 :
420 1 : int32_t DefaultChannelWriteWithNotifyNbi(void* ctx, void* dst, const void* src, uint64_t len, uint32_t remoteNotifyIdx)
421 : {
422 : (void)ctx;
423 : (void)dst;
424 : (void)src;
425 : (void)len;
426 : (void)remoteNotifyIdx;
427 1 : HCCL_RUN_WARNING("[NicPlugin] channel writeWithNotifyNbi is not supported.");
428 1 : return HCCL_E_NOT_SUPPORT;
429 : }
430 :
431 1 : int32_t DefaultChannelWriteWithNotifyNbiOnThread(
432 : void* ctx, ThreadHandle thread, void* dst, const void* src, uint64_t len, uint32_t remoteNotifyIdx)
433 : {
434 : (void)ctx;
435 : (void)thread;
436 : (void)dst;
437 : (void)src;
438 : (void)len;
439 : (void)remoteNotifyIdx;
440 1 : HCCL_RUN_WARNING("[NicPlugin] channel writeWithNotifyNbiOnThread is not supported.");
441 1 : return HCCL_E_NOT_SUPPORT;
442 : }
443 :
444 1 : int32_t DefaultChannelWriteWithNotifyOnThread(
445 : void* ctx, ThreadHandle thread, void* dst, const void* src, uint64_t len, uint32_t remoteNotifyIdx)
446 : {
447 : (void)ctx;
448 : (void)thread;
449 : (void)dst;
450 : (void)src;
451 : (void)len;
452 : (void)remoteNotifyIdx;
453 1 : HCCL_RUN_WARNING("[NicPlugin] channel writeWithNotifyOnThread is not supported.");
454 1 : return HCCL_E_NOT_SUPPORT;
455 : }
456 :
457 1 : int32_t DefaultChannelWriteReduceOnThread(
458 : void* ctx, ThreadHandle thread, void* dst, const void* src, uint64_t count, HcommDataType dataType,
459 : HcommReduceOp reduceOp)
460 : {
461 : (void)ctx;
462 : (void)thread;
463 : (void)dst;
464 : (void)src;
465 : (void)count;
466 : (void)dataType;
467 : (void)reduceOp;
468 1 : HCCL_RUN_WARNING("[NicPlugin] channel writeReduceOnThread is not supported.");
469 1 : return HCCL_E_NOT_SUPPORT;
470 : }
471 :
472 1 : int32_t DefaultChannelReadReduceOnThread(
473 : void* ctx, ThreadHandle thread, void* dst, const void* src, uint64_t count, HcommDataType dataType,
474 : HcommReduceOp reduceOp)
475 : {
476 : (void)reduceOp;
477 : (void)dataType;
478 : (void)count;
479 : (void)src;
480 : (void)dst;
481 : (void)thread;
482 : (void)ctx;
483 1 : HCCL_RUN_WARNING("[NicPlugin] channel readReduceOnThread is not supported.");
484 1 : return HCCL_E_NOT_SUPPORT;
485 : }
486 :
487 1 : int32_t DefaultChannelWriteReduceWithNotifyOnThread(
488 : void* ctx, ThreadHandle thread, void* dst, const void* src, uint64_t count, HcommDataType dataType,
489 : HcommReduceOp reduceOp, uint32_t remoteNotifyIdx)
490 : {
491 : (void)ctx;
492 : (void)thread;
493 : (void)dst;
494 : (void)src;
495 : (void)count;
496 : (void)dataType;
497 : (void)reduceOp;
498 : (void)remoteNotifyIdx;
499 1 : HCCL_RUN_WARNING("[NicPlugin] channel writeReduceWithNotifyOnThread is not supported.");
500 1 : return HCCL_E_NOT_SUPPORT;
501 : }
502 :
503 1 : int32_t DefaultChannelReadNbi(void* ctx, void* dst, const void* src, uint64_t len)
504 : {
505 : (void)ctx;
506 : (void)dst;
507 : (void)src;
508 : (void)len;
509 1 : HCCL_RUN_WARNING("[NicPlugin] channel readNbi is not supported.");
510 1 : return HCCL_E_NOT_SUPPORT;
511 : }
512 :
513 1 : int32_t DefaultChannelReadNbiOnThread(void* ctx, ThreadHandle thread, void* dst, const void* src, uint64_t len)
514 : {
515 : (void)ctx;
516 : (void)thread;
517 : (void)dst;
518 : (void)src;
519 : (void)len;
520 1 : HCCL_RUN_WARNING("[NicPlugin] channel readNbiOnThread is not supported.");
521 1 : return HCCL_E_NOT_SUPPORT;
522 : }
523 :
524 1 : int32_t DefaultChannelReadOnThread(void* ctx, ThreadHandle thread, void* dst, const void* src, uint64_t len)
525 : {
526 : (void)ctx;
527 : (void)thread;
528 : (void)dst;
529 : (void)src;
530 : (void)len;
531 1 : HCCL_RUN_WARNING("[NicPlugin] channel readOnThread is not supported.");
532 1 : return HCCL_E_NOT_SUPPORT;
533 : }
534 :
535 1 : int32_t DefaultChannelNotifyRecord(void* ctx, uint32_t remoteNotifyIdx)
536 : {
537 : (void)ctx;
538 : (void)remoteNotifyIdx;
539 1 : HCCL_RUN_WARNING("[NicPlugin] channel notifyRecord is not supported.");
540 1 : return HCCL_E_NOT_SUPPORT;
541 : }
542 :
543 1 : int32_t DefaultChannelNotifyRecordOnThread(void* ctx, ThreadHandle thread, uint32_t remoteNotifyIdx)
544 : {
545 : (void)ctx;
546 : (void)thread;
547 : (void)remoteNotifyIdx;
548 1 : HCCL_RUN_WARNING("[NicPlugin] channel notifyRecordOnThread is not supported.");
549 1 : return HCCL_E_NOT_SUPPORT;
550 : }
551 :
552 1 : int32_t DefaultChannelNotifyWait(void* ctx, uint32_t localNotifyIdx, uint32_t timeOut)
553 : {
554 : (void)ctx;
555 : (void)localNotifyIdx;
556 : (void)timeOut;
557 1 : HCCL_RUN_WARNING("[NicPlugin] channel notifyWait is not supported.");
558 1 : return HCCL_E_NOT_SUPPORT;
559 : }
560 :
561 1 : int32_t DefaultChannelNotifyWaitOnThread(void* ctx, ThreadHandle thread, uint32_t localNotifyIdx, uint32_t timeOut)
562 : {
563 : (void)ctx;
564 : (void)thread;
565 : (void)localNotifyIdx;
566 : (void)timeOut;
567 1 : HCCL_RUN_WARNING("[NicPlugin] channel notifyWaitOnThread is not supported.");
568 1 : return HCCL_E_NOT_SUPPORT;
569 : }
570 :
571 1 : int32_t DefaultChannelNotifyWaitOnThreadWithDefaultTimeout(void* ctx, ThreadHandle thread, uint32_t localNotifyIdx)
572 : {
573 : (void)ctx;
574 : (void)thread;
575 : (void)localNotifyIdx;
576 1 : HCCL_RUN_WARNING("[NicPlugin] channel notifyWaitOnThreadWithDefaultTimeout is not supported.");
577 1 : return HCCL_E_NOT_SUPPORT;
578 : }
579 :
580 1 : int32_t DefaultChannelBatchTransferOnThread(
581 : void* ctx, ThreadHandle thread, const HcommBatchTransferDesc* transferDescs, uint32_t transferDescNum)
582 : {
583 : (void)ctx;
584 : (void)thread;
585 : (void)transferDescs;
586 : (void)transferDescNum;
587 1 : HCCL_RUN_WARNING("[NicPlugin] channel batchTransferOnThread is not supported.");
588 1 : return HCCL_E_NOT_SUPPORT;
589 : }
590 :
591 1 : int32_t DefaultChannelFence(void* ctx)
592 : {
593 : (void)ctx;
594 1 : HCCL_RUN_WARNING("[NicPlugin] channel fence is not supported.");
595 1 : return HCCL_E_NOT_SUPPORT;
596 : }
597 :
598 1 : int32_t DefaultChannelFenceOnThread(void* ctx, ThreadHandle thread)
599 : {
600 : (void)ctx;
601 : (void)thread;
602 1 : HCCL_RUN_WARNING("[NicPlugin] channel fenceOnThread is not supported.");
603 1 : return HCCL_E_NOT_SUPPORT;
604 : }
605 :
606 1 : int32_t DefaultChannelDrainOnThread(void* ctx, ThreadHandle thread)
607 : {
608 : (void)ctx;
609 : (void)thread;
610 1 : HCCL_RUN_WARNING("[NicPlugin] channel drainOnThread is not supported.");
611 1 : return HCCL_E_NOT_SUPPORT;
612 : }
613 :
614 2 : HcommResult FillDefaultChannelOps(const HcommNicChannelOps* src, HcommNicChannelOps** outOps)
615 : {
616 2 : if (src == nullptr || outOps == nullptr) {
617 0 : return HCCL_E_PARA;
618 : }
619 2 : HcommNicChannelOps* dst = new (std::nothrow) HcommNicChannelOps();
620 2 : if (dst == nullptr) {
621 0 : return HCCL_E_MEMORY;
622 : }
623 :
624 2 : size_t copySize = (src->header.size < sizeof(HcommNicChannelOps)) ? src->header.size : sizeof(HcommNicChannelOps);
625 2 : (void)memcpy_s(dst, sizeof(HcommNicChannelOps), src, copySize);
626 :
627 2 : FOR_EACH_CHANNEL_OP_DEFAULT(FILL_CHANNEL_OP_DEFAULT)
628 2 : *outOps = dst;
629 2 : return HCCL_SUCCESS;
630 : }
631 :
632 : } // namespace hcomm
|