Line data Source code
1 : /**
2 : * Copyright (c) 2026 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 HCOMM_CCU_REPRESENTATION_LOOPGROUP_BUNDLE_H
12 : #define HCOMM_CCU_REPRESENTATION_LOOPGROUP_BUNDLE_H
13 :
14 : #include <vector>
15 : #include "ccu_types.h"
16 : #include "ccu_datatype_v1.h"
17 : #include "ccu_rep_base_v1.h"
18 : #include "ccu_rep_loopblock_v1.h"
19 :
20 : namespace hcomm {
21 : namespace CcuRep {
22 :
23 : class CcuRepLoopGroupBundle : public CcuRepBase {
24 : public:
25 : enum class Layout {
26 : Config, // 结构体 config 构造
27 : PackedVar, // 旧打包变量构造(兼容路径)
28 : VersionV2, // 960 三变量直传
29 : };
30 :
31 : struct LoopEntry {
32 : CcuLoopCfg config;
33 : Executor executor;
34 : std::shared_ptr<CcuRepLoopBlock> repLoopBlock;
35 : Variable loopParamVar;
36 : Variable iterNumVar;
37 : Variable addrOffsetVar;
38 : Variable ctxIdVar;
39 : Layout layout{Layout::Config};
40 : };
41 :
42 : CcuRepLoopGroupBundle(
43 : CcuInsGeneratorBase* insGenPtr, const CcuLoopGroupCfg& config, const Variable& parallelVar,
44 : const Variable& offsetVar);
45 : explicit CcuRepLoopGroupBundle(
46 : CcuInsGeneratorBase* insGenPtr, const Variable& parallelVar, const Variable& offsetVar);
47 :
48 : void AddLoop(const LoopEntry& entry);
49 28 : void SetRepeatLoopIdx(uint64_t idx) { repeatLoopIdx_ = idx; }
50 28 : void SetTotalLoopNum(uint64_t num) { totalLoopNum_ = num; }
51 4 : void SetLayout(Layout layout) { layout_ = layout; }
52 8 : void SetXnOffsetVar(const Variable& xnOffsetVar) { xnOffsetVar_ = Variable(xnOffsetVar); }
53 1 : void SetCompatRemapVars(const Variable& newParallelVar, const Variable& scratchVar)
54 : {
55 : // Variable 的 const& operator= 是 DSL 赋值,须用临时量走移动赋值做纯拷贝
56 1 : newParallelVar_ = Variable(newParallelVar);
57 1 : scratchVar_ = Variable(scratchVar);
58 1 : }
59 :
60 : bool Translate(CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& instrId, const TransDep& dep) override;
61 : uint16_t InstrCount() override;
62 : std::string Describe() override;
63 :
64 : uint16_t GetStartLoopInstrId() const;
65 44 : const Variable& GetOffsetParam() const { return offsetVar_; }
66 :
67 120 : const std::vector<LoopEntry>& GetLoops() const { return loops_; }
68 44 : const CcuLoopGroupCfg& GetConfig() const { return config_; }
69 44 : const Variable& GetParallelVar() const { return parallelVar_; }
70 14 : uint64_t GetRepeatLoopIdx() const { return repeatLoopIdx_; }
71 14 : uint64_t GetTotalLoopNum() const { return totalLoopNum_; }
72 111 : Layout GetLayout() const { return layout_; }
73 1 : const Variable& GetNewParallelVar() const { return newParallelVar_; }
74 1 : const Variable& GetScratchVar() const { return scratchVar_; }
75 12 : const Variable& GetXnOffsetVar() const { return xnOffsetVar_; }
76 :
77 : private:
78 : uint16_t LoopGroupInstrOffsetInBundle() const;
79 :
80 : CcuInsGeneratorBase* insGenPtr_{nullptr};
81 : CcuLoopGroupCfg config_;
82 : Variable parallelVar_;
83 : Variable offsetVar_;
84 : uint64_t repeatLoopIdx_{0};
85 : uint64_t totalLoopNum_{0};
86 : std::vector<LoopEntry> loops_;
87 : Layout layout_{Layout::Config};
88 : Variable newParallelVar_;
89 : Variable scratchVar_;
90 : Variable xnOffsetVar_;
91 : };
92 :
93 : }; // namespace CcuRep
94 : }; // namespace hcomm
95 : #endif // HCOMM_CCU_REPRESENTATION_LOOPGROUP_BUNDLE_H
|