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 : #include <iostream>
12 : #include "prim_translator.h"
13 : #include "prim_rules.h"
14 :
15 : namespace Hccl {
16 280 : PrimTranslator::PrimTranslator()
17 3360 : : primTranslateRuleMap(
18 280 : {{PrimType::POST_TO, GetRule<PrimPostTo>()},
19 280 : {PrimType::WAIT_FROM, GetRule<PrimWaitFrom>()},
20 280 : {PrimType::WAIT_GROUP, GetRule<PrimWaitGroup>()},
21 280 : {PrimType::LOCAL_COPY, GetRule<PrimLocalCopy>()},
22 280 : {PrimType::LOCAL_REDUCE, GetRule<PrimLocalReduce>()},
23 280 : {PrimType::SEND, GetRule<PrimSend>()},
24 280 : {PrimType::RECV, GetRule<PrimRecv>()},
25 280 : {PrimType::GROUP, GetRule<PrimGroup>()},
26 280 : {PrimType::SEND_REDUCE, GetRule<PrimSendReduce>()},
27 280 : {PrimType::RECV_REDUCE, GetRule<PrimRecvReduce>()}})
28 560 : {}
29 :
30 5 : void PrimTranslator::TranslateOnePrimQue(const PrimQueue& primQueue, shared_ptr<InsQueue> insQueue)
31 : {
32 9 : for (auto iter = primQueue.Iter(); iter.HasNext(); ++iter) {
33 12 : HCCL_INFO("primitive being translated is %s", iter->Describe().c_str());
34 4 : vector<unique_ptr<Instruction>> instructions = primTranslateRuleMap.at(iter->GetType())(*iter);
35 8 : for (auto& instruction : instructions) {
36 12 : HCCL_INFO("instruction is %s", instruction->Describe().c_str());
37 4 : insQueue->Append(std::move(instruction));
38 : }
39 9 : }
40 5 : }
41 :
42 3 : shared_ptr<InsQueue> PrimTranslator::Translate(const PrimQueue& primQueue)
43 : {
44 3 : auto masterInsQue = make_shared<InsQueue>();
45 5 : for (auto slaveIter = primQueue.IterSlaves(); slaveIter.HasNext(); ++slaveIter) {
46 2 : auto slaveInsQue = masterInsQue->Fork();
47 2 : TranslateOnePrimQue(*slaveIter, slaveInsQue);
48 5 : }
49 3 : TranslateOnePrimQue(primQueue, masterInsQue);
50 3 : return masterInsQue;
51 0 : }
52 : } // namespace Hccl
|