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(uint64_t beginTime, bool cachedReq, bool isOpBase);
44 : void ReportMc2CommInfo(const Mc2CommInfo& mc2CommInfo);
45 : HcclResult UpdateProfStat();
46 :
47 : static void AddChannelRemoteRankId(const std::string& commTag, u64 handle, u32 remoteRankId);
48 : static HcclResult GetChannelRemoteRankId(const std::string& commTag, u64 handle, u32& remoteRankId);
49 : static u32 GetTaskId(u32 streamId);
50 14 : std::function<HcclResult(u32, u32, const Hccl::TaskParam&, u64)> GetCallback() const { return setAddTaskCallback_; }
51 4 : std::function<HcclResult(const Hccl::TaskParam&, u64)> GetDpuCallback() const { return setAddDpuTaskCallback_; }
52 : HcclResult ReportKernel(
53 : uint64_t beginTime, const std::string& commTag, const std::string& kernelName, uint32_t threadId,
54 : bool cachedReq);
55 : HcclResult GetOpModeFlags(bool& isOpBase, bool& isCached);
56 :
57 : void SetDpuStreamId(u32 dpuStreamId);
58 3 : void SetAicpuTaskIdAndStreamId(u32 taskId, u32 streamId)
59 : {
60 3 : aicpuTaskId_ = taskId;
61 3 : aicpuStreamId_ = streamId;
62 3 : }
63 :
64 : private:
65 : std::unique_ptr<Hccl::MirrorTaskManager> mirrorTaskManager_{nullptr};
66 : std::unique_ptr<HcclCommProfiling> profiling_{nullptr};
67 : static std::unordered_map<std::string, std::unordered_map<u64, u32>> channelRemoteRankId_;
68 : static std::unordered_map<u32, u32> streamIdToTaskId_;
69 : static std::shared_mutex baseLock_;
70 : static std::mutex taskIdMutex_;
71 : std::string commTag_{};
72 : u32 deviceId_{0};
73 : u32 myRankId_{0};
74 : u32 dpuStreamId_{0};
75 : u32 aicpuTaskId_{INVALID_UINT};
76 : u32 aicpuStreamId_{INVALID_UINT};
77 : std::function<HcclResult(u32, u32, const Hccl::TaskParam&, u64)> setAddTaskCallback_{};
78 : std::function<HcclResult(const Hccl::TaskParam&, u64)> setAddDpuTaskCallback_{};
79 : bool initializedFlag_{false};
80 : void AddTaskInfoCallbackLog(const Hccl::TaskParam& taskParam, const std::unordered_map<u64, u32>& handleMap) const;
81 : };
82 :
83 : } // namespace hccl
84 :
85 : #endif
|