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