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 :
11 : #ifndef HCCL_COMM_DFX_H
12 : #define HCCL_COMM_DFX_H
13 :
14 : #include <memory>
15 : #include "mirror_task_manager.h"
16 : #include "hcclCommProfiling.h"
17 : #include "global_mirror_tasks.h"
18 : #include <shared_mutex>
19 : #include "hccl_common.h"
20 : #include <unordered_map>
21 : #include <mutex>
22 : #include "buffer.h"
23 : #include "common.h"
24 : #include "hcclCommOp.h"
25 :
26 : namespace hccl {
27 :
28 : class HcclCommDfx {
29 : public:
30 : HcclCommDfx();
31 :
32 : ~HcclCommDfx();
33 :
34 : HcclResult Init(u32 deviceId, const std::string& comTag, u32 myRankId);
35 :
36 : HcclResult AddTaskInfoCallback(u32 streamId, u32 taskId, const Hccl::TaskParam& taskParam, u64 handle);
37 : HcclResult AddDpuTaskInfoCallback(const Hccl::TaskParam& taskParam, u64 handle);
38 :
39 : Hccl::MirrorTaskManager* GetMirrorTaskManager() const;
40 :
41 : HcclResult SetCurrDfxOpInfo(std::shared_ptr<Hccl::DfxOpInfo> dfxOpInfo);
42 :
43 : HcclResult ReportAllTasks(bool cachedReq);
44 : HcclResult ReportOp(uint64_t beginTime, bool cachedReq, bool isOpBase);
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 14 : std::function<HcclResult(u32, u32, const Hccl::TaskParam&, u64)> GetCallback() const { return setAddTaskCallback_; }
52 4 : std::function<HcclResult(const Hccl::TaskParam&, u64)> GetDpuCallback() const { return setAddDpuTaskCallback_; }
53 : HcclResult ReportKernel(
54 : uint64_t beginTime, const std::string& commTag, const std::string& kernelName, uint32_t threadId,
55 : bool cachedReq);
56 : HcclResult GetOpModeFlags(bool& isOpBase, bool& isCached);
57 :
58 : void SetDpuStreamId(u32 dpuStreamId);
59 3 : void SetAicpuTaskIdAndStreamId(u32 taskId, u32 streamId)
60 : {
61 3 : aicpuTaskId_ = taskId;
62 3 : aicpuStreamId_ = streamId;
63 3 : }
64 :
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
|