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 "aicpusd_mpi_mgr.h"
11 : #include <chrono>
12 : #include <cmath>
13 : #include "aicpusd_status.h"
14 : #include "aicpusd_common.h"
15 : #include "aicpu_pulse.h"
16 :
17 : namespace AicpuSchedule {
18 : namespace mpi {
19 : namespace {
20 : // time interval of print mpi dvpp event
21 : constexpr uint32_t PRINT_MPI_DVPP_RECORD_IN_SECOND = 5U;
22 : } // namespace
23 :
24 19 : MpiDvppStatisticManager& MpiDvppStatisticManager::Instance()
25 : {
26 19 : static MpiDvppStatisticManager statisticManagerInstance;
27 19 : return statisticManagerInstance;
28 : }
29 :
30 2 : MpiDvppStatisticManager::~MpiDvppStatisticManager() { (void)PrintStatisticInfo(); }
31 :
32 1 : void MpiDvppStatisticManager::OnPulse(const MpiDvppTimePoint& nowTimePoint)
33 : {
34 1 : const float64_t duration = std::chrono::duration<float64_t>(nowTimePoint - lastTimePoint_).count();
35 1 : if (round(duration) < static_cast<float64_t>(PRINT_MPI_DVPP_RECORD_IN_SECOND)) {
36 0 : return;
37 : }
38 1 : (void)PrintStatisticInfo();
39 1 : lastTimePoint_ = nowTimePoint;
40 : }
41 :
42 18 : int32_t MpiDvppStatisticManager::PrintStatisticInfo() const
43 : {
44 36 : aicpusd_run_info("Mpi Dvpp event statistics: [%lld]", mpiEventStatistic_.load());
45 18 : return AicpuSchedule::AICPU_SCHEDULE_OK;
46 : }
47 :
48 1 : void MpiDvppStatisticManager::Record() { mpiEventStatistic_++; }
49 :
50 1 : void MpiDvppStatisticManager::InitMpiDvpp()
51 : {
52 1 : if (!registerFlag_.load()) {
53 1 : const std::lock_guard<std::mutex> lk(registerFlagMutex_);
54 1 : if (!registerFlag_.load()) {
55 1 : (void)RegisterPulseNotifyFunc("MpiDvppKernel", &AicpuSchedule::mpi::MpiDvppPulse::MpiDvppPulseNotify);
56 1 : registerFlag_.store(true);
57 : }
58 1 : }
59 1 : }
60 : MpiDvppPulseListener* MpiDvppPulse::pulseListener_ = &MpiDvppStatisticManager::Instance();
61 :
62 1 : void MpiDvppPulse::MpiDvppPulseNotify()
63 : {
64 1 : const auto nowTime = std::chrono::high_resolution_clock::now();
65 1 : pulseListener_->OnPulse(nowTime);
66 1 : }
67 : } // namespace mpi
68 : } // namespace AicpuSchedule
|