LCOV - code coverage report
Current view: top level - aicpu_schedule/core - aicpusd_mpi_mgr.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 8 8
Test Date: 2026-07-28 10:54:05 Functions: 75.0 % 4 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              : #ifndef CORE_AICPUSD_MPI_MGR_H
      11              : #define CORE_AICPUSD_MPI_MGR_H
      12              : 
      13              : #include <chrono>
      14              : #include <vector>
      15              : #include <mutex>
      16              : #include <atomic>
      17              : 
      18              : namespace AicpuSchedule {
      19              : namespace mpi {
      20              : // for future more another MpiDvpp event
      21              : class MpiDvppPulseListener {
      22              : public:
      23              :     using MpiDvppTimePoint = std::chrono::high_resolution_clock::time_point;
      24              : 
      25            3 :     MpiDvppPulseListener() = default;
      26              : 
      27            3 :     virtual ~MpiDvppPulseListener() = default;
      28              : 
      29              :     virtual void OnPulse(const MpiDvppTimePoint &nowTimePoint) = 0;
      30              : 
      31              : private:
      32              :     MpiDvppPulseListener(const MpiDvppPulseListener &) = delete;
      33              :     MpiDvppPulseListener &operator = (const MpiDvppPulseListener &) = delete;
      34              :     MpiDvppPulseListener(MpiDvppPulseListener &&) = delete;
      35              :     MpiDvppPulseListener &operator = (MpiDvppPulseListener &&) = delete;
      36              : };
      37              : 
      38              : class MpiDvppStatisticManager : public MpiDvppPulseListener {
      39              : public:
      40              :     using MpiDvppTimePoint = std::chrono::high_resolution_clock::time_point;
      41              :     static MpiDvppStatisticManager &Instance();
      42              : 
      43              :     ~MpiDvppStatisticManager() override;
      44              : 
      45              :     /**
      46              :      * @ingroup mpi
      47              :      * @brief it is used to print statistics at regular intervals
      48              :      * @param [in] MpiDvppTimePoint: current time
      49              :      */
      50              :     void OnPulse(const MpiDvppTimePoint &nowTimePoint) override;
      51              : 
      52              :     /**
      53              :      * @ingroup mpi
      54              :      * @brief register notify function
      55              :      */
      56              :     void InitMpiDvpp();
      57              : 
      58              :     /**
      59              :      * @ingroup mpi
      60              :      * @brief record mpi dvpp event
      61              :      */
      62              :     void Record();
      63              : 
      64              :     /**
      65              :      * @ingroup mpi
      66              :      * @brief print statistic data of mpi dvpp event
      67              :      */
      68              :     int32_t PrintStatisticInfo() const;
      69              : 
      70              : private:
      71            3 :     MpiDvppStatisticManager()
      72            3 :         : MpiDvppPulseListener(),
      73            3 :           lastTimePoint_(std::chrono::high_resolution_clock::now()),
      74            3 :           mpiEventStatistic_(0UL),
      75            6 :           registerFlag_(false)
      76            3 :     {}
      77              : 
      78              :     // last time of print statistic
      79              :     MpiDvppTimePoint lastTimePoint_;
      80              :     // statistic of receive mpi dvpp event
      81              :     std::atomic<uint64_t> mpiEventStatistic_;
      82              :     // mutex for register notify function
      83              :     std::mutex registerFlagMutex_;
      84              :     // flag of first register notify function
      85              :     std::atomic<bool> registerFlag_;
      86              : };
      87              : 
      88              : class MpiDvppPulse {
      89              : public:
      90              :     /**
      91              :      * @ingroup mpi
      92              :      * @brief it is used to print statistics at regular intervals
      93              :      */
      94              :     static void MpiDvppPulseNotify();
      95              : 
      96              : private:
      97              :     static MpiDvppPulseListener *pulseListener_;
      98              : };
      99              : } // namespace mpi
     100              : }
     101              : 
     102              : #endif // CORE_AICPUSD_MPI_MGR_H
        

Generated by: LCOV version 2.0-1