LCOV - code coverage report
Current view: top level - base_comm/resources/endpoint_pairs/channels - shared_jetty_connection_adapter.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 80.4 % 46 37
Test Date: 2026-08-25 19:18:03 Functions: 60.0 % 5 3

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2025 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 "shared_jetty_connection_adapter.h"
      12              : #include "dev_ub_connection.h"
      13              : #include "log.h"
      14              : #include "adapter_rts_common.h"
      15              : 
      16              : namespace hcomm {
      17              : 
      18              : // 适配层当前实现:转发到 Hccl::DevUbConnection 的新增共享 jetty 方法。
      19              : // TODO(architecture): DevUbConnection 自 legacy/ 迁入 base_comm 后,本文件可直接操作 connection,
      20              : //                     届时移除对 dev_ub_connection.h 的 #include,base_comm 完全不依赖 legacy 实现细节。
      21              : // 注意:endpointTag 当前仅 builtin 路径传入,实际类型为 Endpoint*。
      22              : //       若将来 plugin 路径复用此函数,需将 acquireRemoteCb/publishRemoteCb 的构建提升到调用方,
      23              : //       避免适配层直接强转 void* 为 Endpoint* 造成类型不匹配。
      24           12 : HcclResult SetSharedJettyFieldsToConn(
      25              :     void* rawConnection, const Endpoint::SharedJettyCtx& ctx, void* endpointTag, std::function<void(void*)> releaseCb)
      26              : {
      27           12 :     if (rawConnection == nullptr || endpointTag == nullptr) {
      28            2 :         return HCCL_E_PARA;
      29              :     }
      30           10 :     auto* endpoint = static_cast<Endpoint*>(endpointTag);
      31            0 :     auto acquireRemoteCb = [endpoint](
      32              :                                const uint8_t* remoteQpKey, uint32_t keySize, bool& needImport,
      33              :                                Hccl::TargetJettyHandle& handle, void*& handlePtr, uint32_t& tpn) -> HcclResult {
      34            0 :         uint64_t cachedHandle = 0;
      35              :         HcclResult ret
      36            0 :             = endpoint->AcquireSharedRemoteJetty(remoteQpKey, keySize, needImport, cachedHandle, handlePtr, tpn);
      37            0 :         handle = static_cast<Hccl::TargetJettyHandle>(cachedHandle);
      38            0 :         return ret;
      39           10 :     };
      40            0 :     auto publishRemoteCb = [endpoint](
      41              :                                const uint8_t* remoteQpKey, uint32_t keySize, Hccl::TargetJettyHandle handle,
      42              :                                void* handlePtr, uint32_t tpn) -> HcclResult {
      43            0 :         return endpoint->PublishSharedRemoteJetty(remoteQpKey, keySize, static_cast<uint64_t>(handle), handlePtr, tpn);
      44           10 :     };
      45           10 :     auto* conn = static_cast<Hccl::DevUbConnection*>(rawConnection);
      46           40 :     return conn->SetSharedJettyFields(
      47           10 :         ctx.handle, ctx.handlePtr, ctx.jettyId, ctx.sqBuffVa, ctx.dbAddr, ctx.localQpKey, ctx.keySize, ctx.sqDepth,
      48           20 :         static_cast<Hccl::JfcHandle>(ctx.jfcHandle), ctx.cqInfo, ctx.localPsn, endpointTag, std::move(releaseCb),
      49           30 :         std::move(acquireRemoteCb), std::move(publishRemoteCb));
      50              : }
      51              : 
      52            9 : HcclResult ExtractJettyInfoFromConn(void* rawConnection, Endpoint::SharedJettyCtx& ctx)
      53              : {
      54            9 :     if (rawConnection == nullptr) {
      55            1 :         return HCCL_E_PARA;
      56              :     }
      57            8 :     auto* conn = static_cast<Hccl::DevUbConnection*>(rawConnection);
      58            8 :     Hccl::DevUbConnection::JettyInfo info;
      59            8 :     CHK_RET(conn->GetJettyInfo(info));
      60            8 :     ctx.handle = info.handle;
      61            8 :     ctx.handlePtr = info.handlePtr;
      62            8 :     ctx.jettyId = info.jettyId;
      63            8 :     ctx.sqBuffVa = info.sqBuffVa;
      64            8 :     ctx.dbAddr = info.dbAddr;
      65            8 :     ctx.keySize = info.keySize;
      66            8 :     ctx.sqDepth = info.sqDepth;
      67            8 :     ctx.rdmaHandle = info.rdmaHandle;
      68            8 :     ctx.jfcHandle = info.jfcHandle;
      69            8 :     ctx.cqInfo = info.cqInfo;
      70            8 :     ctx.localPsn = info.localPsn;
      71              :     // 严格按实际 keySize 拷贝,避免拷贝超出实际 keySize 的无效尾部
      72            8 :     if (info.keySize > Hccl::HRT_UB_QP_KEY_MAX_LEN) {
      73            0 :         HCCL_ERROR("[%s] invalid keySize[%u], max[%u].", __func__, info.keySize, Hccl::HRT_UB_QP_KEY_MAX_LEN);
      74            0 :         return HCCL_E_PARA;
      75              :     }
      76            8 :     CHK_SAFETY_FUNC_RET(memcpy_s(ctx.localQpKey, Hccl::HRT_UB_QP_KEY_MAX_LEN, info.localQpKey, info.keySize));
      77            8 :     return HCCL_SUCCESS;
      78              : }
      79              : 
      80            8 : HcclResult DetachConnJetty(void* rawConnection)
      81              : {
      82            8 :     if (rawConnection == nullptr) {
      83            1 :         return HCCL_E_PARA;
      84              :     }
      85            7 :     auto* conn = static_cast<Hccl::DevUbConnection*>(rawConnection);
      86            7 :     conn->DetachJetty();
      87            7 :     return HCCL_SUCCESS;
      88              : }
      89              : 
      90              : } // namespace hcomm
        

Generated by: LCOV version 2.0-1