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 <regex>
12 : #include "ins_to_sqe_rule.h"
13 :
14 : namespace Hccl {
15 :
16 : using InsToSqeRule = std::function<std::vector<std::unique_ptr<HcclSqe>>(
17 : const Instruction& ins, const u32 streamId, ResMgrFetcher* resMgrFetcher)>;
18 :
19 : template <class InsType>
20 11 : InsToSqeRule Rules()
21 : {
22 11 : return [](const Instruction& ins, const u32 streamId, ResMgrFetcher* resMgrFetcher) {
23 0 : return Interpret(static_cast<const InsType&>(ins), streamId, resMgrFetcher);
24 11 : };
25 : }
26 :
27 : const std::map<InstructionType, InsToSqeRule> ruleMap{
28 : {InstructionType::LOCAL_COPY, Rules<InsLocalCopy>()},
29 : {InstructionType::LOCAL_POST_TO, Rules<InsLocalPostTo>()},
30 : {InstructionType::LOCAL_WAIT_FROM, Rules<InsLocalWaitFrom>()},
31 : {InstructionType::WAIT_READY, Rules<InsWaitReady>()},
32 : {InstructionType::POST_READY, Rules<InsPostReady>()},
33 : {InstructionType::WAIT_FIN, Rules<InsWaitFin>()},
34 : {InstructionType::POST_FIN, Rules<InsPostFin>()},
35 : {InstructionType::WRITE, Rules<InsWaitFinAck>()},
36 : {InstructionType::WRITE_REDUCE, Rules<InsPostFinAck>()},
37 : {InstructionType::READ, Rules<InsWaitFinAck>()},
38 : {InstructionType::READ_REDUCE, Rules<InsPostFinAck>()},
39 : };
40 :
41 : std::vector<std::unique_ptr<HcclSqe>>
42 0 : Interpret(const Instruction& ins, const u32 streamId, ResMgrFetcher* resMgrFetcher)
43 : {
44 0 : if (ruleMap.find(ins.GetType()) != ruleMap.end()) {
45 0 : return ruleMap.at(ins.GetType())(ins, streamId, resMgrFetcher);
46 : }
47 0 : return vector<std::unique_ptr<HcclSqe>>();
48 : }
49 :
50 : std::vector<std::unique_ptr<HcclSqe>>
51 0 : Interpret(const InsLocalCopy& ins, const u32 streamId, ResMgrFetcher* resMgrFetcher)
52 : {
53 0 : std::vector<std::unique_ptr<HcclSqe>> res(1);
54 :
55 0 : u64 srcAddr = resMgrFetcher->GetLocAddr(ins.GetSrcSlice().GetType()) + ins.GetSrcSlice().GetOffset();
56 0 : u64 dstAddr = resMgrFetcher->GetLocAddr(ins.GetDstSlice().GetType()) + ins.GetDstSlice().GetOffset();
57 0 : auto sqe = std::make_unique<HcclSdmaSqe>();
58 0 : sqe->Config(
59 0 : streamId, RTSQ_TASK_ID, srcAddr, ins.GetSrcSlice().GetSize(), RtDataType::RT_DATA_TYPE_END,
60 : RtReduceKind::RT_REDUCE_KIND_END, dstAddr, RTSQ_PART_ID);
61 0 : res[0] = std::move(sqe);
62 0 : return res;
63 0 : }
64 :
65 : std::vector<std::unique_ptr<HcclSqe>>
66 0 : Interpret(const InsWriteReduce& ins, const u32 streamId, ResMgrFetcher* resMgrFetcher)
67 : {
68 : (void)ins;
69 : (void)streamId;
70 : (void)resMgrFetcher;
71 0 : std::vector<std::unique_ptr<HcclSqe>> res;
72 0 : return res;
73 : }
74 :
75 : std::vector<std::unique_ptr<HcclSqe>>
76 0 : Interpret(const InsLocalPostTo& ins, const u32 streamId, ResMgrFetcher* resMgrFetcher)
77 : {
78 : (void)ins;
79 : (void)streamId;
80 : (void)resMgrFetcher;
81 0 : return std::vector<std::unique_ptr<HcclSqe>>(0);
82 : }
83 : } // namespace Hccl
|