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 MIRROR_TASK_MANAGER_H
11 : #define MIRROR_TASK_MANAGER_H
12 :
13 : #include <unordered_map>
14 : #include <memory>
15 : #include <functional>
16 : #include "circular_queue.h"
17 : #include "task_info.h"
18 : #include "global_mirror_tasks.h"
19 : #include <mutex>
20 :
21 : namespace Hccl {
22 :
23 : using TaskInfoQueue = Queue<std::unique_ptr<TaskInfo>>;
24 :
25 : struct MirrorStreamQueueEntry {
26 : TaskInfoQueue* queue = nullptr;
27 : QueueType queueType = QueueType::Vector_Queue;
28 : u32 taskNum = 0;
29 : };
30 :
31 : class MirrorTaskManager {
32 : public:
33 : MirrorTaskManager(u32 devId, GlobalMirrorTasks* globalMirrorTasks, bool devUsed);
34 :
35 : void RegFullyCallBack(std::function<void()> callBack);
36 : void AddTaskInfo(std::unique_ptr<TaskInfo>&& taskInfo);
37 : HcclResult AddTaskInfo(
38 : u32 streamId, u32 taskId, u32 remoteRankId, const TaskParam& taskParam, std::shared_ptr<DfxOpInfo> dfxOpInfo,
39 : bool isMaster);
40 : void SetCurrDfxOpInfo(std::shared_ptr<DfxOpInfo> dfxOpInfo);
41 :
42 : std::shared_ptr<DfxOpInfo> GetCurrDfxOpInfo() const;
43 : TaskInfoQueue* GetQueue(u32 streamId) const;
44 :
45 : public:
46 : std::unordered_map<u32, MirrorStreamQueueEntry>::iterator Begin();
47 : std::unordered_map<u32, MirrorStreamQueueEntry>::iterator End();
48 2 : std::mutex& GetTaskMutex() { return profMutex; }
49 : ~MirrorTaskManager();
50 :
51 : private:
52 : u32 devId_;
53 : GlobalMirrorTasks* globalMirrorTasks_{nullptr};
54 : bool devUsed_{false};
55 : bool isStaticGraphMode_{false};
56 : OpMode opMode_{OpMode::OPBASE};
57 : std::unordered_map<u32, MirrorStreamQueueEntry> streamQueues_{};
58 : std::shared_ptr<DfxOpInfo> currDfxOpInfo_{nullptr};
59 : std::function<void()> fullyCallBack_{};
60 : std::mutex profMutex;
61 :
62 : private:
63 : bool IsStaticGraphMode(const CollOperator& collOperator) const;
64 : QueueType GetQueueType() const;
65 : };
66 :
67 : } // namespace Hccl
68 :
69 : #endif // MIRROR_TASK_MANAGER_H
|