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

Generated by: LCOV version 2.0-1