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 HCCL_COMM_DFX_H
11 : #define HCCL_COMM_DFX_H
12 :
13 : #include <memory>
14 : #include "mirror_task_manager.h"
15 : #include "hcclCommProfiling.h"
16 : #include "global_mirror_tasks.h"
17 : #include <shared_mutex>
18 : #include "hccl_common.h"
19 : #include <unordered_map>
20 : #include <mutex>
21 : #include "buffer.h"
22 : #include "common.h"
23 : #include "hcclCommOp.h"
24 :
25 : namespace hccl {
26 :
27 : class HcclCommDfx {
28 : public:
29 : HcclCommDfx();
30 :
31 : ~HcclCommDfx();
32 :
33 : HcclResult Init(u32 deviceId, const std::string& comTag, u32 myRankId);
34 :
35 : HcclResult AddTaskInfoCallback(u32 streamId, u32 taskId, const Hccl::TaskParam &taskParam, u64 handle);
36 : HcclResult AddDpuTaskInfoCallback(const Hccl::TaskParam &taskParam, u64 handle);
37 :
38 : Hccl::MirrorTaskManager* GetMirrorTaskManager() const;
39 :
40 : HcclResult SetCurrDfxOpInfo(std::shared_ptr<Hccl::DfxOpInfo> dfxOpInfo);
41 :
42 : HcclResult ReportAllTasks(bool cachedReq);
43 : HcclResult ReportOp(u64 beginTime, bool cachedReq, bool opbased);
44 : HcclResult ReporCcuTaskInfo(u64 beginTime, u64 endTime, bool cachedReq, bool opbased);
45 : void ReportMc2CommInfo(const Mc2CommInfo& mc2CommInfo);
46 : HcclResult UpdateProfStat();
47 :
48 : static void AddChannelRemoteRankId(const std::string& commTag, u64 handle, u32 remoteRankId);
49 : static HcclResult GetChannelRemoteRankId(const std::string& commTag, u64 handle, u32& remoteRankId);
50 : static u32 GetTaskId(u32 streamId);
51 15 : std::function<HcclResult(u32, u32, const Hccl::TaskParam&, u64)> GetCallback() const {
52 15 : return setAddTaskCallback_;
53 : }
54 4 : std::function<HcclResult(const Hccl::TaskParam&, u64)> GetDpuCallback() const {
55 4 : return setAddDpuTaskCallback_;
56 : }
57 : HcclResult ReportKernel(uint64_t beginTime, const std::string& commTag, const std::string& kernelName, uint32_t threadId, bool cachedReq);
58 : HcclResult IsOpBase(bool &isOpBase);
59 :
60 : void SetDpuStreamId(u32 dpuStreamId);
61 3 : void SetAicpuTaskIdAndStreamId(u32 taskId, u32 streamId) {
62 3 : aicpuTaskId_ = taskId;
63 3 : aicpuStreamId_ = streamId;
64 3 : }
65 : private:
66 : std::unique_ptr<Hccl::MirrorTaskManager> mirrorTaskManager_{nullptr};
67 : std::unique_ptr<HcclCommProfiling> profiling_{nullptr};
68 : static std::unordered_map<std::string,std::unordered_map<u64, u32> > channelRemoteRankId_;
69 : static std::unordered_map<u32, u32> streamIdToTaskId_;
70 : static std::shared_mutex baseLock_;
71 : static std::mutex taskIdMutex_;
72 : std::string commTag_{};
73 : u32 deviceId_{0};
74 : u32 myRankId_{0};
75 : u32 dpuStreamId_{0};
76 : u32 aicpuTaskId_{INVALID_UINT};
77 : u32 aicpuStreamId_{INVALID_UINT};
78 : std::function<HcclResult(u32, u32, const Hccl::TaskParam&, u64)> setAddTaskCallback_{};
79 : std::function<HcclResult(const Hccl::TaskParam&, u64)> setAddDpuTaskCallback_{};
80 : bool initializedFlag_{false};
81 : void AddTaskInfoCallbackLog(const Hccl::TaskParam &taskParam, const std::unordered_map<u64, u32> &handleMap) const;
82 : };
83 :
84 : } // namespace hccl
85 :
86 : #endif
|