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 : #include "shared_jetty_mgr.h"
30 :
31 : namespace hcomm {
32 : namespace {
33 : constexpr const char* HCOMM_NIC_PLUGIN_DIR = "hcomm_plugin";
34 : constexpr const char* HCOMM_NIC_PLUGIN_SO_ENV = "HCOMM_NIC_PLUGIN_SO";
35 :
36 20 : std::once_flag& LoadOnce()
37 : {
38 : static std::once_flag loadOnce;
39 20 : return loadOnce;
40 : }
41 :
42 0 : std::vector<std::unique_ptr<NicPluginEntry>>& LoadedPlugins()
43 : {
44 0 : static std::vector<std::unique_ptr<NicPluginEntry>> loadedPlugins;
45 0 : return loadedPlugins;
46 : }
47 :
48 20 : std::unordered_map<CommProtocol, const NicPluginEntry*>& ProtocolPlugins()
49 : {
50 20 : static std::unordered_map<CommProtocol, const NicPluginEntry*> protocolPlugins;
51 20 : return protocolPlugins;
52 : }
53 :
54 0 : bool EndsWithSo(const std::string& path)
55 : {
56 0 : constexpr const char* suffix = ".so";
57 0 : constexpr size_t suffixLen = 3U;
58 0 : return path.size() >= suffixLen && path.compare(path.size() - suffixLen, suffixLen, suffix) == 0;
59 : }
60 :
61 7 : bool IsOpsHeaderValid(const CommAbiHeader& header, uint32_t magicWord, uint32_t version, const char* opsName)
62 : {
63 7 : if (header.magicWord != magicWord) {
64 0 : HCCL_RUN_WARNING(
65 : "[NicPlugin] %s magicWord[0x%08x] mismatch, expected[0x%08x].", opsName, header.magicWord, magicWord);
66 0 : return false;
67 : }
68 7 : if (header.version != version) {
69 0 : HCCL_RUN_WARNING("[NicPlugin] %s version[%u] mismatch, expected[%u].", opsName, header.version, version);
70 0 : return false;
71 : }
72 7 : if (header.size < sizeof(CommAbiHeader)) {
73 0 : HCCL_RUN_WARNING(
74 : "[NicPlugin] %s size[%u] is smaller than ABI header[%zu].", opsName, header.size,
75 : sizeof(CommAbiHeader));
76 0 : return false;
77 : }
78 7 : return true;
79 : }
80 :
81 0 : void RegisterPluginProtocols(const NicPluginEntry* plugin)
82 : {
83 0 : auto& protocolPlugins = ProtocolPlugins();
84 0 : for (uint32_t idx = 0; idx < plugin->info->protocolCount; ++idx) {
85 0 : const CommProtocol protocol = plugin->info->protocols[idx];
86 0 : auto iter = protocolPlugins.find(protocol);
87 0 : if (iter != protocolPlugins.end()) {
88 0 : HCCL_RUN_WARNING(
89 : "[NicPlugin] protocol[%d] handler[%s] is overwritten by plugin[%s].", protocol,
90 : iter->second->info->name == nullptr ? "unknown" : iter->second->info->name,
91 : plugin->info->name == nullptr ? "unknown" : plugin->info->name);
92 : }
93 0 : protocolPlugins[protocol] = plugin;
94 0 : HCCL_RUN_INFO(
95 : "[NicPlugin] protocol[%d] is handled by plugin[%s].", protocol,
96 : plugin->info->name == nullptr ? "unknown" : plugin->info->name);
97 : }
98 0 : }
99 :
100 0 : void* LoadSymbol(void* soHandle, const char* soPath, const char* symbol)
101 : {
102 0 : dlerror();
103 0 : void* addr = dlsym(soHandle, symbol);
104 0 : const char* dlsymErr = dlerror();
105 0 : if (dlsymErr != nullptr || addr == nullptr) {
106 0 : HCCL_RUN_WARNING(
107 : "[NicPlugin] dlsym %s from %s failed: %s.", symbol, soPath, dlsymErr == nullptr ? "unknown" : dlsymErr);
108 0 : return nullptr;
109 : }
110 0 : return addr;
111 : }
112 :
113 0 : void LoadOnePlugin(const std::string& path)
114 : {
115 0 : if (path.empty()) {
116 0 : return;
117 : }
118 0 : void* soHandle = dlopen(path.c_str(), RTLD_NOW | RTLD_LOCAL);
119 0 : if (soHandle == nullptr) {
120 0 : HCCL_RUN_WARNING("[NicPlugin] dlopen %s failed: %s.", path.c_str(), dlerror());
121 0 : return;
122 : }
123 :
124 : auto getInfo
125 0 : = reinterpret_cast<HcommNicPluginGetInfoFunc>(LoadSymbol(soHandle, path.c_str(), "HcommNicPluginGetInfo"));
126 : auto createEndpoint = reinterpret_cast<HcommNicPluginCreateEndpointFunc>(
127 0 : LoadSymbol(soHandle, path.c_str(), "HcommNicPluginCreateEndpoint"));
128 : auto createChannel = reinterpret_cast<HcommNicPluginCreateChannelFunc>(
129 0 : LoadSymbol(soHandle, path.c_str(), "HcommNicPluginCreateChannel"));
130 0 : if (getInfo == nullptr || createEndpoint == nullptr || createChannel == nullptr) {
131 0 : dlclose(soHandle);
132 0 : return;
133 : }
134 :
135 0 : const HcommNicPluginInfo* info = getInfo();
136 0 : if (!ValidatePluginInfo(path.c_str(), info, createEndpoint, createChannel)) {
137 0 : dlclose(soHandle);
138 0 : return;
139 : }
140 :
141 : std::unique_ptr<NicPluginEntry> plugin(new (std::nothrow)
142 0 : NicPluginEntry{soHandle, info, createEndpoint, createChannel});
143 0 : if (plugin == nullptr) {
144 0 : HCCL_RUN_WARNING("[NicPlugin] allocate plugin entry for %s failed.", path.c_str());
145 0 : dlclose(soHandle);
146 0 : return;
147 : }
148 0 : RegisterPluginProtocols(plugin.get());
149 0 : LoadedPlugins().emplace_back(std::move(plugin));
150 0 : }
151 :
152 2 : void LoadDefaultDirectory(const std::string& pluginDir)
153 : {
154 2 : DIR* dir = opendir(pluginDir.c_str());
155 2 : if (dir == nullptr) {
156 2 : HCCL_RUN_INFO("[NicPlugin] plugin directory %s is unavailable.", pluginDir.c_str());
157 2 : return;
158 : }
159 0 : std::vector<std::string> soPaths;
160 0 : for (dirent* entry = readdir(dir); entry != nullptr; entry = readdir(dir)) {
161 0 : const std::string name(entry->d_name);
162 0 : if (name == "." || name == ".." || !EndsWithSo(name)) {
163 0 : continue;
164 : }
165 0 : soPaths.emplace_back(pluginDir + "/" + name);
166 0 : }
167 0 : closedir(dir);
168 0 : std::sort(soPaths.begin(), soPaths.end());
169 0 : for (const auto& path : soPaths) {
170 0 : LoadOnePlugin(path);
171 : }
172 0 : }
173 :
174 0 : void LoadExplicitPlugins(const char* envValue)
175 : {
176 0 : if (envValue == nullptr || envValue[0] == '\0') {
177 0 : return;
178 : }
179 0 : const std::string paths(envValue);
180 0 : size_t start = 0;
181 0 : while (start <= paths.size()) {
182 0 : const size_t end = paths.find(':', start);
183 0 : const std::string path = paths.substr(start, end == std::string::npos ? std::string::npos : end - start);
184 0 : LoadOnePlugin(path);
185 0 : if (end == std::string::npos) {
186 0 : break;
187 : }
188 0 : start = end + 1;
189 0 : }
190 0 : }
191 :
192 2 : void LoadPluginsOnce()
193 : {
194 2 : const char* ascendHomePath = getenv("ASCEND_HOME_PATH");
195 2 : if (ascendHomePath != nullptr && ascendHomePath[0] != '\0') {
196 4 : LoadDefaultDirectory(std::string(ascendHomePath) + "/" + HCOMM_NIC_PLUGIN_DIR);
197 : } else {
198 0 : HCCL_RUN_INFO("[NicPlugin] ASCEND_HOME_PATH is empty, skip default plugin directory.");
199 0 : LoadExplicitPlugins(getenv(HCOMM_NIC_PLUGIN_SO_ENV));
200 : }
201 2 : }
202 :
203 : } // namespace
204 :
205 4 : bool ValidateEndpointOps(const HcommNicEndpointOps* ops)
206 : {
207 4 : if (ops == nullptr
208 8 : || !IsOpsHeaderValid(
209 4 : ops->header, HCOMM_NIC_ENDPOINT_OPS_MAGIC_WORD, HCOMM_NIC_ENDPOINT_OPS_VERSION, "endpoint ops")) {
210 0 : return false;
211 : }
212 4 : if (!IsPluginOpAvailable(ops, offsetof(HcommNicEndpointOps, destroy), sizeof(ops->destroy))
213 4 : || ops->destroy == nullptr) {
214 0 : HCCL_ERROR("[NicPlugin] plugin endpoint destroy is not implemented.");
215 0 : return false;
216 : }
217 4 : return true;
218 : }
219 :
220 2 : bool ValidateChannelOps(const HcommNicChannelOps* ops)
221 : {
222 2 : if (ops == nullptr
223 4 : || !IsOpsHeaderValid(
224 2 : ops->header, HCOMM_NIC_CHANNEL_OPS_MAGIC_WORD, HCOMM_NIC_CHANNEL_OPS_VERSION, "channel ops")) {
225 0 : return false;
226 : }
227 2 : if (!IsPluginOpAvailable(ops, offsetof(HcommNicChannelOps, destroy), sizeof(ops->destroy))
228 2 : || ops->destroy == nullptr) {
229 0 : HCCL_ERROR("[NicPlugin] channel destroy is not implemented.");
230 0 : return false;
231 : }
232 2 : return true;
233 : }
234 :
235 1 : bool ValidatePluginInfo(
236 : const char* soPath, const HcommNicPluginInfo* info, HcommNicPluginCreateEndpointFunc createEndpoint,
237 : HcommNicPluginCreateChannelFunc createChannel)
238 : {
239 1 : if (info == nullptr) {
240 0 : HCCL_RUN_WARNING("[NicPlugin] %s exports null plugin info.", soPath);
241 0 : return false;
242 : }
243 1 : if (!IsOpsHeaderValid(
244 1 : info->header, HCOMM_NIC_PLUGIN_INFO_MAGIC_WORD, HCOMM_NIC_PLUGIN_INFO_VERSION, "plugin info")) {
245 0 : return false;
246 : }
247 1 : constexpr size_t requiredSize
248 : = offsetof(HcommNicPluginInfo, protocols) + sizeof(static_cast<HcommNicPluginInfo*>(nullptr)->protocols);
249 1 : if (info->header.size < requiredSize) {
250 0 : HCCL_RUN_WARNING(
251 : "[NicPlugin] %s plugin info size[%u] is smaller than required[%zu].", soPath, info->header.size,
252 : requiredSize);
253 0 : return false;
254 : }
255 1 : if (info->protocolCount == 0 || info->protocolCount > HCOMM_NIC_PLUGIN_MAX_PROTOCOLS) {
256 0 : HCCL_RUN_WARNING("[NicPlugin] %s invalid protocolCount[%u].", soPath, info->protocolCount);
257 0 : return false;
258 : }
259 1 : if (createEndpoint == nullptr || createChannel == nullptr) {
260 0 : HCCL_RUN_WARNING("[NicPlugin] %s missing create endpoint/channel symbol.", soPath);
261 0 : return false;
262 : }
263 1 : for (uint32_t idx = 0; idx < info->protocolCount; ++idx) {
264 1 : const CommProtocol protocol = info->protocols[idx];
265 1 : if ((protocol < COMM_PROTOCOL_HCCS || protocol > COMM_PROTOCOL_UBG) && protocol < COMM_PROTOCOL_CUSTOM_BASE) {
266 1 : HCCL_RUN_WARNING("[NicPlugin] %s invalid protocol[%d].", soPath, info->protocols[idx]);
267 1 : 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
|