LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/resource/connection - dev_rdma_connection.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 90.2 % 41 37
Test Date: 2026-08-18 17:47:01 Functions: 66.7 % 9 6

            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 "dev_rdma_connection.h"
      12              : #include "not_support_exception.h"
      13              : #include "orion_adapter_rts.h"
      14              : namespace Hccl {
      15              : 
      16           10 : DevRdmaConnection::DevRdmaConnection(Socket* socket, RdmaHandle rdmaHandle, OpMode opMode)
      17           10 :     : RmaConnection(socket, RmaConnType::RDMA)
      18              : {
      19           10 :     int qpMode = 0;
      20           10 :     DevType devType = HrtGetDeviceType();
      21           10 :     if (devType == DevType::DEV_TYPE_910A2 || devType == DevType::DEV_TYPE_910A3) {
      22            9 :         qpMode = (opMode == OpMode::OPBASE) ? OPBASE_QP_MODE_EXT : OFFLINE_QP_MODE_EXT;
      23            1 :     } else if (devType == DevType::DEV_TYPE_910A) {
      24            0 :         qpMode = (opMode == OpMode::OPBASE) ? OPBASE_QP_MODE : OFFLINE_QP_MODE;
      25              :     } else {
      26            3 :         HCCL_ERROR(
      27              :             "Cannot support this device type!"
      28              :             "errNo[0x%016llx], device type[%s]",
      29              :             HCCL_ERROR_CODE(HcclResult::HCCL_E_NOT_SUPPORT), DevTypeToString(devType).c_str());
      30            1 :         throw NotSupportException(DevTypeToString(devType));
      31              :     }
      32            9 :     qpHandle = HrtRaQpCreate(rdmaHandle, QP_FLAG_RC, qpMode);
      33           10 : }
      34              : 
      35            0 : void DevRdmaConnection::Connect() { GetStatus(); }
      36              : 
      37            4 : RmaConnStatus DevRdmaConnection::GetStatus()
      38              : {
      39            4 :     if (status == RmaConnStatus::INIT) {
      40            4 :         if (rdmaConnStatus == RdmaConnStatus::INIT) {
      41            3 :             if (socket->GetStatus() == SocketStatus::OK) {
      42            2 :                 HrtRaQpConnectAsync(qpHandle, socket->GetFdHandle());
      43            2 :                 rdmaConnStatus = RdmaConnStatus::CONNECTING;
      44            2 :                 CheckQpStatus(qpHandle);
      45            1 :             } else if (socket->GetStatus() == SocketStatus::TIMEOUT) {
      46            1 :                 rdmaConnStatus = RdmaConnStatus::SOCKET_TIMEOUT;
      47            1 :                 status = RmaConnStatus::CONN_INVALID;
      48              :             }
      49            1 :         } else if (rdmaConnStatus == RdmaConnStatus::CONNECTING) {
      50            1 :             CheckQpStatus(qpHandle);
      51              :         }
      52              :     }
      53            4 :     return status;
      54              : }
      55              : 
      56            3 : void DevRdmaConnection::CheckQpStatus(QpHandle handle)
      57              : {
      58            3 :     if (HrtGetRaQpStatus(handle) == 1) { // 为1时,qp 建链成功
      59            2 :         status = RmaConnStatus::READY;
      60              :     }
      61            3 : }
      62              : 
      63            1 : QpHandle DevRdmaConnection::GetHandle() { return qpHandle; }
      64              : 
      65            9 : DevRdmaConnection::~DevRdmaConnection() { HrtRaQpDestroy(qpHandle); }
      66              : 
      67            6 : unique_ptr<BaseTask> DevRdmaConnection::PrepareWrite(
      68              :     const MemoryBuffer& remoteMemBuf, const MemoryBuffer& localMemBuf, [[maybe_unused]] const SqeConfig& config)
      69              : {
      70            8 :     VerifySizeIsEqual(remoteMemBuf, localMemBuf, "DevRdmaConnection::PrepareWrite");
      71              : 
      72            4 :     if (localMemBuf.size == 0) {
      73            1 :         return nullptr;
      74              :     }
      75              :     // RDMA_WRITE: op = 0
      76            3 :     HRaSendWr wr(localMemBuf.addr, localMemBuf.size, remoteMemBuf.addr, 0, RA_SEND_SIGNALED);
      77            3 :     RaSendWrResp resp = HrtRaSendOneWr(qpHandle, wr);
      78              : 
      79            3 :     return make_unique<TaskRdmaSend>(resp.dbIndex, static_cast<u64>(resp.dbInfo));
      80              : }
      81              : 
      82            0 : string DevRdmaConnection::Describe() const
      83              : {
      84            0 :     return StringFormat("DevRdmaConnection[status=%s]", status.Describe().c_str());
      85              : }
      86              : 
      87              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1