LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/resource/connection - p2p_connection.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 46.8 % 47 22
Test Date: 2026-08-17 10:19:35 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 "p2p_connection.h"
      11              : #include "socket.h"
      12              : #include "log.h"
      13              : #include "exception_util.h"
      14              : #include "rma_conn_exception.h"
      15              : 
      16              : namespace Hccl {
      17              : 
      18            5 : P2PConnection::P2PConnection(Socket* socket, const std::string& tag) : RmaConnection(socket, RmaConnType::P2P)
      19              : {
      20           15 :     HCCL_INFO("P2PConnection::P2PConnection tag = [%s]", tag.c_str());
      21            5 : }
      22              : 
      23            0 : void P2PConnection::Connect()
      24              : {
      25            0 :     EnableP2p();
      26            0 :     GetStatus();
      27            0 : }
      28              : 
      29            0 : RmaConnStatus P2PConnection::GetStatus()
      30              : {
      31            0 :     switch (status) {
      32            0 :         case RmaConnStatus::READY:
      33            0 :             break;
      34            0 :         case RmaConnStatus::INIT:
      35            0 :             if (socket->GetStatus() == SocketStatus::OK) {
      36            0 :                 status = RmaConnStatus::READY;
      37            0 :             } else if (socket->GetStatus() == SocketStatus::TIMEOUT) {
      38            0 :                 status = RmaConnStatus::CONN_INVALID;
      39              :             }
      40            0 :             break;
      41            0 :         case RmaConnStatus::CLOSE:
      42            0 :             break;
      43            0 :         default:
      44            0 :             auto msg = StringFormat("Invalid status of %s", status.Describe().c_str());
      45            0 :             THROW<RmaConnException>(msg);
      46              :             break;
      47            0 :     }
      48              : 
      49            0 :     return status;
      50              : }
      51              : 
      52            0 : void P2PConnection::EnableP2p() const
      53              : {
      54              :     // SDMA P2pEnable
      55            0 : }
      56              : 
      57              : unique_ptr<BaseTask>
      58            5 : P2PConnection::PrepareRead(const MemoryBuffer& remoteMemBuf, const MemoryBuffer& localMemBuf, const SqeConfig& config)
      59              : {
      60            6 :     VerifySizeIsEqual(remoteMemBuf, localMemBuf, "P2PConnection PrepareRead");
      61            4 :     if (localMemBuf.size == 0) {
      62            1 :         return nullptr;
      63              :     }
      64            3 :     return make_unique<TaskP2pMemcpy>(localMemBuf.addr, remoteMemBuf.addr, localMemBuf.size, MemcpyKind::D2D);
      65              : }
      66              : 
      67            5 : unique_ptr<BaseTask> P2PConnection::PrepareReadReduce(
      68              :     const MemoryBuffer& remoteMemBuf, const MemoryBuffer& localMemBuf, DataType datatype, ReduceOp reduceOp,
      69              :     const SqeConfig& config)
      70              : {
      71            6 :     VerifySizeIsEqual(remoteMemBuf, localMemBuf, "P2PConnection PrepareReadReduce");
      72            4 :     if (localMemBuf.size == 0) {
      73            1 :         return nullptr;
      74              :     }
      75            3 :     return make_unique<TaskSdmaReduce>(localMemBuf.addr, remoteMemBuf.addr, localMemBuf.size, datatype, reduceOp);
      76              : }
      77              : 
      78              : unique_ptr<BaseTask>
      79            1 : P2PConnection::PrepareWrite(const MemoryBuffer& remoteMemBuf, const MemoryBuffer& localMemBuf, const SqeConfig& config)
      80              : {
      81            1 :     VerifySizeIsEqual(remoteMemBuf, localMemBuf, "P2PConnection PrepareWrite");
      82            1 :     if (localMemBuf.size == 0) {
      83            0 :         return nullptr;
      84              :     }
      85            1 :     return make_unique<TaskP2pMemcpy>(remoteMemBuf.addr, localMemBuf.addr, localMemBuf.size, MemcpyKind::D2D);
      86              : }
      87              : 
      88            2 : unique_ptr<BaseTask> P2PConnection::PrepareWriteReduce(
      89              :     const MemoryBuffer& remoteMemBuf, const MemoryBuffer& localMemBuf, DataType datatype, ReduceOp reduceOp,
      90              :     const SqeConfig& config)
      91              : {
      92            1 :     VerifySizeIsEqual(remoteMemBuf, localMemBuf, "P2PConnection PrepareWriteReduce");
      93            1 :     if (localMemBuf.size == 0) {
      94            0 :         return nullptr;
      95              :     }
      96            1 :     return make_unique<TaskSdmaReduce>(remoteMemBuf.addr, localMemBuf.addr, localMemBuf.size, datatype, reduceOp);
      97              : }
      98              : 
      99            3 : string P2PConnection::Describe() const { return StringFormat("P2PConnection[status=%s]", status.Describe().c_str()); }
     100              : 
     101              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1