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 HCCLV2_INS_QUEUE_H
12 : #define HCCLV2_INS_QUEUE_H
13 :
14 : #include "instruction.h"
15 : #include "hierarchical_queue.h"
16 :
17 : #include <unordered_set>
18 : #include <vector>
19 : namespace Hccl {
20 : using namespace std;
21 :
22 : class InsQueue : public HierarchicalQueue<Instruction, InsQueue>, public enable_shared_from_this<InsQueue> {
23 : public:
24 5 : vector<LinkData> GetUniqueLinks()
25 : {
26 5 : unordered_set<LinkData> uniqueLinks;
27 5 : for (auto iter = Iter(); iter.HasNext(); ++iter) {
28 0 : auto linkPtr = iter->GetLink();
29 0 : if (linkPtr == nullptr) {
30 0 : continue;
31 : }
32 0 : uniqueLinks.insert(*linkPtr);
33 5 : }
34 5 : for (auto slaveIter = IterSlaves(); slaveIter.HasNext(); ++slaveIter) {
35 0 : for (auto iterSlave = slaveIter->Iter(); iterSlave.HasNext(); ++iterSlave) {
36 0 : auto linkPtrSlave = iterSlave->GetLink();
37 0 : if (linkPtrSlave == nullptr) {
38 0 : continue;
39 : }
40 0 : uniqueLinks.insert(*linkPtrSlave);
41 0 : }
42 5 : }
43 15 : return {uniqueLinks.begin(), uniqueLinks.end()};
44 5 : };
45 :
46 62 : void Append(unique_ptr<Instruction> ins) override
47 : {
48 62 : auto insPtr = ins.get();
49 62 : if (insPtr->GetType() == InstructionType::LOCAL_POST_TO) {
50 1 : InsLocalPostTo& postTo = static_cast<InsLocalPostTo&>(*insPtr);
51 1 : postTo.SetPostQid(GetId());
52 61 : } else if (insPtr->GetType() == InstructionType::LOCAL_WAIT_FROM) {
53 1 : InsLocalWaitFrom& waitFrom = static_cast<InsLocalWaitFrom&>(*insPtr);
54 1 : waitFrom.SetWaitQid(GetId());
55 60 : } else if (insPtr->GetType() == InstructionType::LOCAL_WAIT_GROUP) {
56 1 : InsLocalWaitGroup& waitGroup = static_cast<InsLocalWaitGroup&>(*insPtr);
57 1 : waitGroup.SetWaitQid(GetId());
58 59 : } else if (insPtr->GetType() == InstructionType::LOCAL_BCAST_POST) {
59 1 : InsLocalBcastPost& bcastPost = static_cast<InsLocalBcastPost&>(*insPtr);
60 1 : bcastPost.SetPostQid(GetId());
61 : }
62 62 : HierarchicalQueue::Append(std::move(ins));
63 62 : }
64 : };
65 : } // namespace Hccl
66 :
67 : #endif // !HCCLV2_INS_QUEUE_H
|