LCOV - code coverage report
Current view: top level - base_comm/primitives/api_c_adpt/nic_plugin - nic_plugin_manager.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 59.8 % 266 159
Test Date: 2026-08-18 17:47:01 Functions: 85.4 % 48 41

            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            7 :     bool IsOpsHeaderValid(const CommAbiHeader& header, uint32_t magicWord, uint32_t version, const char* opsName)
      61              :     {
      62            7 :         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            7 :         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            7 :         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            7 :         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            1 : bool ValidatePluginInfo(
     235              :     const char* soPath, const HcommNicPluginInfo* info, HcommNicPluginCreateEndpointFunc createEndpoint,
     236              :     HcommNicPluginCreateChannelFunc createChannel)
     237              : {
     238            1 :     if (info == nullptr) {
     239            0 :         HCCL_RUN_WARNING("[NicPlugin] %s exports null plugin info.", soPath);
     240            0 :         return false;
     241              :     }
     242            1 :     if (!IsOpsHeaderValid(
     243            1 :             info->header, HCOMM_NIC_PLUGIN_INFO_MAGIC_WORD, HCOMM_NIC_PLUGIN_INFO_VERSION, "plugin info")) {
     244            0 :         return false;
     245              :     }
     246            1 :     constexpr size_t requiredSize
     247              :         = offsetof(HcommNicPluginInfo, protocols) + sizeof(static_cast<HcommNicPluginInfo*>(nullptr)->protocols);
     248            1 :     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            1 :     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            1 :     if (createEndpoint == nullptr || createChannel == nullptr) {
     259            0 :         HCCL_RUN_WARNING("[NicPlugin] %s missing create endpoint/channel symbol.", soPath);
     260            0 :         return false;
     261              :     }
     262            1 :     for (uint32_t idx = 0; idx < info->protocolCount; ++idx) {
     263            1 :         const CommProtocol protocol = info->protocols[idx];
     264            1 :         if ((protocol < COMM_PROTOCOL_HCCS || protocol > COMM_PROTOCOL_UBG) && protocol < COMM_PROTOCOL_CUSTOM_BASE) {
     265            1 :             HCCL_RUN_WARNING("[NicPlugin] %s invalid protocol[%d].", soPath, info->protocols[idx]);
     266            1 :             return false;
     267              :         }
     268              :     }
     269            0 :     return true;
     270              : }
     271              : 
     272           20 : void LoadAllNicPlugins() { std::call_once(LoadOnce(), LoadPluginsOnce); }
     273              : 
     274           20 : const NicPluginEntry* FindHostNicPlugin(CommProtocol protocol)
     275              : {
     276           20 :     LoadAllNicPlugins();
     277           20 :     const auto& protocolPlugins = ProtocolPlugins();
     278           20 :     auto iter = protocolPlugins.find(protocol);
     279           20 :     const NicPluginEntry* entry = iter == protocolPlugins.end() ? nullptr : iter->second;
     280           20 :     return entry;
     281              : }
     282              : 
     283            1 : int32_t DefaultEndpointInit(void* ctx)
     284              : {
     285              :     (void)ctx;
     286            1 :     HCCL_RUN_WARNING("[NicPlugin] plugin endpoint init is not supported.");
     287            1 :     return HCCL_SUCCESS;
     288              : }
     289              : 
     290            1 : int32_t DefaultEndpointRegisterMemory(void* ctx, const CommMem* mem, const char* tag, void** handle)
     291              : {
     292              :     (void)ctx;
     293              :     (void)mem;
     294              :     (void)tag;
     295              :     (void)handle;
     296            1 :     HCCL_RUN_WARNING("[NicPlugin] plugin endpoint registerMemory is not supported.");
     297            1 :     return HCCL_E_NOT_SUPPORT;
     298              : }
     299              : 
     300            1 : int32_t DefaultEndpointUnregisterMemory(void* ctx, void* handle)
     301              : {
     302              :     (void)ctx;
     303              :     (void)handle;
     304            1 :     HCCL_RUN_WARNING("[NicPlugin] plugin endpoint unregisterMemory is not supported.");
     305            1 :     return HCCL_E_NOT_SUPPORT;
     306              : }
     307              : 
     308            1 : int32_t DefaultEndpointMemoryExport(void* ctx, void* handle, void** desc, uint32_t* descLen)
     309              : {
     310              :     (void)ctx;
     311              :     (void)handle;
     312              :     (void)desc;
     313              :     (void)descLen;
     314            1 :     HCCL_RUN_WARNING("[NicPlugin] plugin endpoint memoryExport is not supported.");
     315            1 :     return HCCL_E_NOT_SUPPORT;
     316              : }
     317              : 
     318            1 : int32_t DefaultEndpointMemoryImport(void* ctx, const void* desc, uint32_t descLen, CommMem* outMem)
     319              : {
     320              :     (void)ctx;
     321              :     (void)desc;
     322              :     (void)descLen;
     323              :     (void)outMem;
     324            1 :     HCCL_RUN_WARNING("[NicPlugin] plugin endpoint memoryImport is not supported.");
     325            1 :     return HCCL_E_NOT_SUPPORT;
     326              : }
     327              : 
     328            1 : int32_t DefaultEndpointMemoryUnimport(void* ctx, const void* desc, uint32_t descLen)
     329              : {
     330              :     (void)ctx;
     331              :     (void)desc;
     332              :     (void)descLen;
     333            1 :     HCCL_RUN_WARNING("[NicPlugin] plugin endpoint memoryUnimport is not supported.");
     334            1 :     return HCCL_E_NOT_SUPPORT;
     335              : }
     336              : 
     337            1 : int32_t DefaultEndpointGetListenPort(void* ctx, uint32_t* port)
     338              : {
     339              :     (void)ctx;
     340              :     (void)port;
     341            1 :     HCCL_RUN_WARNING("[NicPlugin] plugin endpoint getListenPort is not supported.");
     342            1 :     return HCCL_E_NOT_SUPPORT;
     343              : }
     344              : 
     345            4 : HcommResult FillDefaultEndpointOps(const HcommNicEndpointOps* src, HcommNicEndpointOps** outOps)
     346              : {
     347            4 :     if (src == nullptr || outOps == nullptr) {
     348            0 :         return HCCL_E_PARA;
     349              :     }
     350            4 :     HcommNicEndpointOps* dst = new (std::nothrow) HcommNicEndpointOps();
     351            4 :     if (dst == nullptr) {
     352            0 :         return HCCL_E_MEMORY;
     353              :     }
     354              : 
     355            4 :     size_t copySize = (src->header.size < sizeof(HcommNicEndpointOps)) ? src->header.size : sizeof(HcommNicEndpointOps);
     356            4 :     (void)memcpy_s(dst, sizeof(HcommNicEndpointOps), src, copySize);
     357              : 
     358            4 :     FOR_EACH_ENDPOINT_OP_DEFAULT(FILL_ENDPOINT_OP_DEFAULT)
     359            4 :     *outOps = dst;
     360            4 :     return HCCL_SUCCESS;
     361              : }
     362              : 
     363              : // ---- Channel ops 默认实现 ----
     364              : 
     365            0 : int32_t DefaultChannelInit(void* ctx)
     366              : {
     367              :     (void)ctx;
     368            0 :     HCCL_RUN_WARNING("[NicPlugin] channel init is not supported.");
     369            0 :     return HCCL_SUCCESS;
     370              : }
     371              : 
     372            1 : int32_t DefaultChannelGetStatus(void* ctx, int32_t* status)
     373              : {
     374              :     (void)ctx;
     375              :     (void)status;
     376            1 :     HCCL_RUN_WARNING("[NicPlugin] channel getStatus is not supported.");
     377            1 :     return HCCL_E_NOT_SUPPORT;
     378              : }
     379              : 
     380            1 : int32_t DefaultChannelWriteNbi(void* ctx, void* dst, const void* src, uint64_t len)
     381              : {
     382              :     (void)ctx;
     383              :     (void)dst;
     384              :     (void)src;
     385              :     (void)len;
     386            1 :     HCCL_RUN_WARNING("[NicPlugin] channel writeNbi is not supported.");
     387            1 :     return HCCL_E_NOT_SUPPORT;
     388              : }
     389              : 
     390            1 : int32_t DefaultChannelWriteNbiOnThread(void* ctx, ThreadHandle thread, void* dst, const void* src, uint64_t len)
     391              : {
     392              :     (void)ctx;
     393              :     (void)thread;
     394              :     (void)dst;
     395              :     (void)src;
     396              :     (void)len;
     397            1 :     HCCL_RUN_WARNING("[NicPlugin] channel writeNbiOnThread is not supported.");
     398            1 :     return HCCL_E_NOT_SUPPORT;
     399              : }
     400              : 
     401            1 : int32_t DefaultChannelWriteOnThread(void* ctx, ThreadHandle thread, void* dst, const void* src, uint64_t len)
     402              : {
     403              :     (void)ctx;
     404              :     (void)thread;
     405              :     (void)dst;
     406              :     (void)src;
     407              :     (void)len;
     408            1 :     HCCL_RUN_WARNING("[NicPlugin] channel writeOnThread is not supported.");
     409            1 :     return HCCL_E_NOT_SUPPORT;
     410              : }
     411              : 
     412            1 : int32_t DefaultChannelWriteWithNotifyNbi(void* ctx, void* dst, const void* src, uint64_t len, uint32_t remoteNotifyIdx)
     413              : {
     414              :     (void)ctx;
     415              :     (void)dst;
     416              :     (void)src;
     417              :     (void)len;
     418              :     (void)remoteNotifyIdx;
     419            1 :     HCCL_RUN_WARNING("[NicPlugin] channel writeWithNotifyNbi is not supported.");
     420            1 :     return HCCL_E_NOT_SUPPORT;
     421              : }
     422              : 
     423            1 : int32_t DefaultChannelWriteWithNotifyNbiOnThread(
     424              :     void* ctx, ThreadHandle thread, void* dst, const void* src, uint64_t len, uint32_t remoteNotifyIdx)
     425              : {
     426              :     (void)ctx;
     427              :     (void)thread;
     428              :     (void)dst;
     429              :     (void)src;
     430              :     (void)len;
     431              :     (void)remoteNotifyIdx;
     432            1 :     HCCL_RUN_WARNING("[NicPlugin] channel writeWithNotifyNbiOnThread is not supported.");
     433            1 :     return HCCL_E_NOT_SUPPORT;
     434              : }
     435              : 
     436            1 : int32_t DefaultChannelWriteWithNotifyOnThread(
     437              :     void* ctx, ThreadHandle thread, void* dst, const void* src, uint64_t len, uint32_t remoteNotifyIdx)
     438              : {
     439              :     (void)ctx;
     440              :     (void)thread;
     441              :     (void)dst;
     442              :     (void)src;
     443              :     (void)len;
     444              :     (void)remoteNotifyIdx;
     445            1 :     HCCL_RUN_WARNING("[NicPlugin] channel writeWithNotifyOnThread is not supported.");
     446            1 :     return HCCL_E_NOT_SUPPORT;
     447              : }
     448              : 
     449            1 : int32_t DefaultChannelWriteReduceOnThread(
     450              :     void* ctx, ThreadHandle thread, void* dst, const void* src, uint64_t count, HcommDataType dataType,
     451              :     HcommReduceOp reduceOp)
     452              : {
     453              :     (void)ctx;
     454              :     (void)thread;
     455              :     (void)dst;
     456              :     (void)src;
     457              :     (void)count;
     458              :     (void)dataType;
     459              :     (void)reduceOp;
     460            1 :     HCCL_RUN_WARNING("[NicPlugin] channel writeReduceOnThread is not supported.");
     461            1 :     return HCCL_E_NOT_SUPPORT;
     462              : }
     463              : 
     464            1 : int32_t DefaultChannelReadReduceOnThread(
     465              :     void* ctx, ThreadHandle thread, void* dst, const void* src, uint64_t count, HcommDataType dataType,
     466              :     HcommReduceOp reduceOp)
     467              : {
     468              :     (void)reduceOp;
     469              :     (void)dataType;
     470              :     (void)count;
     471              :     (void)src;
     472              :     (void)dst;
     473              :     (void)thread;
     474              :     (void)ctx;
     475            1 :     HCCL_RUN_WARNING("[NicPlugin] channel readReduceOnThread is not supported.");
     476            1 :     return HCCL_E_NOT_SUPPORT;
     477              : }
     478              : 
     479            1 : int32_t DefaultChannelWriteReduceWithNotifyOnThread(
     480              :     void* ctx, ThreadHandle thread, void* dst, const void* src, uint64_t count, HcommDataType dataType,
     481              :     HcommReduceOp reduceOp, uint32_t remoteNotifyIdx)
     482              : {
     483              :     (void)ctx;
     484              :     (void)thread;
     485              :     (void)dst;
     486              :     (void)src;
     487              :     (void)count;
     488              :     (void)dataType;
     489              :     (void)reduceOp;
     490              :     (void)remoteNotifyIdx;
     491            1 :     HCCL_RUN_WARNING("[NicPlugin] channel writeReduceWithNotifyOnThread is not supported.");
     492            1 :     return HCCL_E_NOT_SUPPORT;
     493              : }
     494              : 
     495            1 : int32_t DefaultChannelReadNbi(void* ctx, void* dst, const void* src, uint64_t len)
     496              : {
     497              :     (void)ctx;
     498              :     (void)dst;
     499              :     (void)src;
     500              :     (void)len;
     501            1 :     HCCL_RUN_WARNING("[NicPlugin] channel readNbi is not supported.");
     502            1 :     return HCCL_E_NOT_SUPPORT;
     503              : }
     504              : 
     505            1 : int32_t DefaultChannelReadNbiOnThread(void* ctx, ThreadHandle thread, void* dst, const void* src, uint64_t len)
     506              : {
     507              :     (void)ctx;
     508              :     (void)thread;
     509              :     (void)dst;
     510              :     (void)src;
     511              :     (void)len;
     512            1 :     HCCL_RUN_WARNING("[NicPlugin] channel readNbiOnThread is not supported.");
     513            1 :     return HCCL_E_NOT_SUPPORT;
     514              : }
     515              : 
     516            1 : int32_t DefaultChannelReadOnThread(void* ctx, ThreadHandle thread, void* dst, const void* src, uint64_t len)
     517              : {
     518              :     (void)ctx;
     519              :     (void)thread;
     520              :     (void)dst;
     521              :     (void)src;
     522              :     (void)len;
     523            1 :     HCCL_RUN_WARNING("[NicPlugin] channel readOnThread is not supported.");
     524            1 :     return HCCL_E_NOT_SUPPORT;
     525              : }
     526              : 
     527            1 : int32_t DefaultChannelNotifyRecord(void* ctx, uint32_t remoteNotifyIdx)
     528              : {
     529              :     (void)ctx;
     530              :     (void)remoteNotifyIdx;
     531            1 :     HCCL_RUN_WARNING("[NicPlugin] channel notifyRecord is not supported.");
     532            1 :     return HCCL_E_NOT_SUPPORT;
     533              : }
     534              : 
     535            1 : int32_t DefaultChannelNotifyRecordOnThread(void* ctx, ThreadHandle thread, uint32_t remoteNotifyIdx)
     536              : {
     537              :     (void)ctx;
     538              :     (void)thread;
     539              :     (void)remoteNotifyIdx;
     540            1 :     HCCL_RUN_WARNING("[NicPlugin] channel notifyRecordOnThread is not supported.");
     541            1 :     return HCCL_E_NOT_SUPPORT;
     542              : }
     543              : 
     544            1 : int32_t DefaultChannelNotifyWait(void* ctx, uint32_t localNotifyIdx, uint32_t timeOut)
     545              : {
     546              :     (void)ctx;
     547              :     (void)localNotifyIdx;
     548              :     (void)timeOut;
     549            1 :     HCCL_RUN_WARNING("[NicPlugin] channel notifyWait is not supported.");
     550            1 :     return HCCL_E_NOT_SUPPORT;
     551              : }
     552              : 
     553            1 : int32_t DefaultChannelNotifyWaitOnThread(void* ctx, ThreadHandle thread, uint32_t localNotifyIdx, uint32_t timeOut)
     554              : {
     555              :     (void)ctx;
     556              :     (void)thread;
     557              :     (void)localNotifyIdx;
     558              :     (void)timeOut;
     559            1 :     HCCL_RUN_WARNING("[NicPlugin] channel notifyWaitOnThread is not supported.");
     560            1 :     return HCCL_E_NOT_SUPPORT;
     561              : }
     562              : 
     563            1 : int32_t DefaultChannelNotifyWaitOnThreadWithDefaultTimeout(void* ctx, ThreadHandle thread, uint32_t localNotifyIdx)
     564              : {
     565              :     (void)ctx;
     566              :     (void)thread;
     567              :     (void)localNotifyIdx;
     568            1 :     HCCL_RUN_WARNING("[NicPlugin] channel notifyWaitOnThreadWithDefaultTimeout is not supported.");
     569            1 :     return HCCL_E_NOT_SUPPORT;
     570              : }
     571              : 
     572            1 : int32_t DefaultChannelBatchTransferOnThread(
     573              :     void* ctx, ThreadHandle thread, const HcommBatchTransferDesc* transferDescs, uint32_t transferDescNum)
     574              : {
     575              :     (void)ctx;
     576              :     (void)thread;
     577              :     (void)transferDescs;
     578              :     (void)transferDescNum;
     579            1 :     HCCL_RUN_WARNING("[NicPlugin] channel batchTransferOnThread is not supported.");
     580            1 :     return HCCL_E_NOT_SUPPORT;
     581              : }
     582              : 
     583            1 : int32_t DefaultChannelFence(void* ctx)
     584              : {
     585              :     (void)ctx;
     586            1 :     HCCL_RUN_WARNING("[NicPlugin] channel fence is not supported.");
     587            1 :     return HCCL_E_NOT_SUPPORT;
     588              : }
     589              : 
     590            1 : int32_t DefaultChannelFenceOnThread(void* ctx, ThreadHandle thread)
     591              : {
     592              :     (void)ctx;
     593              :     (void)thread;
     594            1 :     HCCL_RUN_WARNING("[NicPlugin] channel fenceOnThread is not supported.");
     595            1 :     return HCCL_E_NOT_SUPPORT;
     596              : }
     597              : 
     598            1 : int32_t DefaultChannelDrainOnThread(void* ctx, ThreadHandle thread)
     599              : {
     600              :     (void)ctx;
     601              :     (void)thread;
     602            1 :     HCCL_RUN_WARNING("[NicPlugin] channel drainOnThread is not supported.");
     603            1 :     return HCCL_E_NOT_SUPPORT;
     604              : }
     605              : 
     606            2 : HcommResult FillDefaultChannelOps(const HcommNicChannelOps* src, HcommNicChannelOps** outOps)
     607              : {
     608            2 :     if (src == nullptr || outOps == nullptr) {
     609            0 :         return HCCL_E_PARA;
     610              :     }
     611            2 :     HcommNicChannelOps* dst = new (std::nothrow) HcommNicChannelOps();
     612            2 :     if (dst == nullptr) {
     613            0 :         return HCCL_E_MEMORY;
     614              :     }
     615              : 
     616            2 :     size_t copySize = (src->header.size < sizeof(HcommNicChannelOps)) ? src->header.size : sizeof(HcommNicChannelOps);
     617            2 :     (void)memcpy_s(dst, sizeof(HcommNicChannelOps), src, copySize);
     618              : 
     619            2 :     FOR_EACH_CHANNEL_OP_DEFAULT(FILL_CHANNEL_OP_DEFAULT)
     620            2 :     *outOps = dst;
     621            2 :     return HCCL_SUCCESS;
     622              : }
     623              : 
     624              : } // namespace hcomm
        

Generated by: LCOV version 2.0-1