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