LCOV - code coverage report
Current view: top level - base_comm/resources/endpoints - builtin_endpoint_ops.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 91.7 % 72 66
Test Date: 2026-08-18 17:47:01 Functions: 75.0 % 8 6

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2026 Huawei Technologies Co., Ltd.
       3              :  * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
       4              :  * CANN Open Software License Agreement Version 2.0 (the "License").
       5              :  * Please refer to the License for details. You may not use this file except in compliance with the License.
       6              :  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
       7              :  * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
       8              :  * See LICENSE in the root of the software repository for the full text of the License.
       9              :  */
      10              : 
      11              : #ifndef BUILTIN_ENDPOINT_OPS_H
      12              : #define BUILTIN_ENDPOINT_OPS_H
      13              : 
      14              : #include "hcomm_nic_plugin.h"
      15              : #include "endpoint.h"
      16              : #include "exception_handler.h"
      17              : #include "hcomm_c_adpt_common.h"
      18              : 
      19              : // CreateBuiltinEndpoint 已调用 endpointPtr->Init(),此处 no-op。
      20            0 : inline int32_t BuiltinEndpointInit(void* ctx)
      21              : {
      22              :     (void)ctx;
      23            0 :     return HCCL_SUCCESS;
      24              : }
      25              : 
      26              : // endpoint 生命周期由 g_EndpointMap 的 unique_ptr 管理,此处 no-op。
      27            0 : inline int32_t BuiltinEndpointDestroy(void* ctx)
      28              : {
      29              :     (void)ctx;
      30            0 :     return HCCL_SUCCESS;
      31              : }
      32              : 
      33           42 : inline int32_t BuiltinRegisterMemory(void* ctx, const CommMem* mem, const char* tag, void** handle)
      34              : {
      35           42 :     CHK_PTR_NULL(mem);
      36           41 :     CHK_PTR_NULL(handle);
      37           39 :     EXCEPTION_HANDLE_BEGIN(void) HcommResMgrInit();
      38           39 :     EndpointHandle epHandle = reinterpret_cast<EndpointHandle>(ctx);
      39           39 :     HCCL_INFO("[%s] START. endpointHandle[0x%llx].", __func__, epHandle);
      40           39 :     auto endpoint = GetEndpointMap().GetEndpoint(epHandle);
      41           39 :     CHK_PRT_RET(
      42              :         endpoint == nullptr, HCCL_ERROR("[%s] endpoint not found, endpointHandle[0x%llx]", __func__, epHandle),
      43              :         HCCL_E_NOT_FOUND);
      44           39 :     CHK_RET(RefreshEndpointContext(endpoint->GetEndpointDesc()));
      45           39 :     CHK_RET(endpoint->RegisterMemory(*mem, tag, handle));
      46              : 
      47            0 :     EXCEPTION_HANDLE_END
      48           30 :     return HCCL_SUCCESS;
      49              : }
      50              : 
      51           45 : inline int32_t BuiltinUnregisterMemory(void* ctx, void* handle)
      52              : {
      53           45 :     CHK_PTR_NULL(handle);
      54           39 :     (void)HcommResMgrInit();
      55              :     EXCEPTION_HANDLE_BEGIN
      56           39 :     EndpointHandle epHandle = reinterpret_cast<EndpointHandle>(ctx);
      57           39 :     HCCL_INFO("[%s] START. endpointHandle[0x%llx].", __func__, epHandle);
      58           39 :     auto endpoint = GetEndpointMap().GetEndpoint(epHandle);
      59           39 :     CHK_PRT_RET(
      60              :         endpoint == nullptr, HCCL_ERROR("[%s] endpoint not found, endpointHandle[0x%llx]", __func__, epHandle),
      61              :         HCCL_E_NOT_FOUND);
      62           39 :     CHK_RET(RefreshEndpointContext(endpoint->GetEndpointDesc()));
      63           39 :     CHK_RET(endpoint->UnregisterMemory(handle));
      64            0 :     EXCEPTION_HANDLE_END
      65           30 :     return HCCL_SUCCESS;
      66              : }
      67              : 
      68            5 : inline int32_t BuiltinMemoryExport(void* ctx, void* handle, void** desc, uint32_t* descLen)
      69              : {
      70            5 :     CHK_PTR_NULL(handle);
      71            4 :     CHK_PTR_NULL(desc);
      72            3 :     CHK_PTR_NULL(descLen);
      73            3 :     (void)HcommResMgrInit();
      74            3 :     EndpointHandle epHandle = reinterpret_cast<EndpointHandle>(ctx);
      75            3 :     HCCL_INFO("[%s] START. endpointHandle[0x%llx].", __func__, epHandle);
      76            3 :     auto endpoint = GetEndpointMap().GetEndpoint(epHandle);
      77            3 :     CHK_PRT_RET(
      78              :         endpoint == nullptr, HCCL_ERROR("[%s] endpoint not found, endpointHandle[0x%llx]", __func__, epHandle),
      79              :         HCCL_E_NOT_FOUND);
      80            3 :     CHK_RET(RefreshEndpointContext(endpoint->GetEndpointDesc()));
      81            3 :     CHK_RET(endpoint->MemoryExport(handle, desc, descLen));
      82            3 :     return HCCL_SUCCESS;
      83              : }
      84              : 
      85            5 : inline int32_t BuiltinMemoryImport(void* ctx, const void* desc, uint32_t descLen, CommMem* outMem)
      86              : {
      87            5 :     CHK_PTR_NULL(desc);
      88            4 :     CHK_PTR_NULL(outMem);
      89            4 :     CHK_PRT_RET(descLen == 0, HCCL_ERROR("[%s] descLen[0] is invalid", __func__), HCCL_E_PARA);
      90            3 :     (void)HcommResMgrInit();
      91            3 :     EndpointHandle handle = reinterpret_cast<EndpointHandle>(ctx);
      92            3 :     HCCL_INFO("[%s] START. endpointHandle[0x%llx].", __func__, handle);
      93            3 :     auto endpoint = GetEndpointMap().GetEndpoint(handle);
      94            3 :     CHK_PRT_RET(
      95              :         endpoint == nullptr, HCCL_ERROR("[%s] endpoint not found, endpointHandle[0x%llx]", __func__, handle),
      96              :         HCCL_E_NOT_FOUND);
      97            3 :     CHK_RET(RefreshEndpointContext(endpoint->GetEndpointDesc()));
      98            3 :     CommMem importedMem{};
      99            3 :     CHK_RET(endpoint->MemoryImport(desc, descLen, &importedMem));
     100            3 :     *outMem = importedMem;
     101            3 :     return HCCL_SUCCESS;
     102              : }
     103              : 
     104            4 : inline int32_t BuiltinMemoryUnimport(void* ctx, const void* desc, uint32_t descLen)
     105              : {
     106            4 :     CHK_PTR_NULL(desc);
     107            3 :     (void)HcommResMgrInit();
     108            3 :     EndpointHandle epHandle = reinterpret_cast<EndpointHandle>(ctx);
     109            3 :     HCCL_INFO("[%s] START. endpointHandle[0x%llx].", __func__, epHandle);
     110            3 :     auto endpoint = GetEndpointMap().GetEndpoint(epHandle);
     111            3 :     CHK_PRT_RET(
     112              :         endpoint == nullptr, HCCL_ERROR("[%s] endpoint not found, endpointHandle[0x%llx]", __func__, epHandle),
     113              :         HCCL_E_NOT_FOUND);
     114            3 :     CHK_RET(RefreshEndpointContext(endpoint->GetEndpointDesc()));
     115            3 :     CHK_RET(endpoint->MemoryUnimport(desc, descLen));
     116            3 :     return HCCL_SUCCESS;
     117              : }
     118              : 
     119            2 : inline int32_t BuiltinGetListenPort(void* ctx, uint32_t* port)
     120              : {
     121            2 :     CHK_PTR_NULL(port);
     122            1 :     (void)HcommResMgrInit();
     123            1 :     EndpointHandle epHandle = reinterpret_cast<EndpointHandle>(ctx);
     124            1 :     HCCL_INFO("[%s] START. endpointHandle[0x%llx].", __func__, epHandle);
     125            1 :     auto endpoint = GetEndpointMap().GetEndpoint(epHandle);
     126            1 :     CHK_PRT_RET(
     127              :         endpoint == nullptr, HCCL_ERROR("[%s] endpoint not found, endpointHandle[0x%llx]", __func__, epHandle),
     128              :         HCCL_E_NOT_FOUND);
     129            1 :     CHK_RET(RefreshEndpointContext(endpoint->GetEndpointDesc()));
     130            1 :     return endpoint->ServerSocketGetListenPort(port);
     131              : }
     132              : 
     133              : inline HcommNicEndpointOps g_BuiltinEndpointOps = {
     134              :     {HCOMM_NIC_ENDPOINT_OPS_VERSION, HCOMM_NIC_ENDPOINT_OPS_MAGIC_WORD, sizeof(HcommNicEndpointOps), 0},
     135              :     BuiltinEndpointInit,     // init
     136              :     BuiltinEndpointDestroy,  // destroy
     137              :     BuiltinRegisterMemory,   // registerMemory
     138              :     BuiltinUnregisterMemory, // unregisterMemory
     139              :     BuiltinMemoryExport,     // memoryExport
     140              :     BuiltinMemoryImport,     // memoryImport
     141              :     BuiltinMemoryUnimport,   // memoryUnimport
     142              :     BuiltinGetListenPort,    // getListenPort
     143              : };
     144              : 
     145              : #endif // BUILTIN_ENDPOINT_OPS_H
        

Generated by: LCOV version 2.0-1