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 : * Description: ccu representation loopgroup bundle header file
10 : * Create: 2026-03-22
11 : */
12 :
13 : #ifndef HCOMM_CCU_REPRESENTATION_LOOPGROUP_BUNDLE_H
14 : #define HCOMM_CCU_REPRESENTATION_LOOPGROUP_BUNDLE_H
15 :
16 : #include <vector>
17 : #include "ccu_types.h"
18 : #include "ccu_datatype_v1.h"
19 : #include "ccu_rep_base_v1.h"
20 : #include "ccu_rep_loopblock_v1.h"
21 :
22 : namespace hcomm {
23 : namespace CcuRep {
24 :
25 : class CcuRepLoopGroupBundle : public CcuRepBase {
26 : public:
27 : enum class Layout {
28 : Config, // 结构体 config 构造
29 : PackedVar, // 旧打包变量构造(兼容路径)
30 : VersionV2, // 960 三变量直传
31 : };
32 :
33 : struct LoopEntry {
34 : CcuLoopCfg config;
35 : Executor executor;
36 : std::shared_ptr<CcuRepLoopBlock> repLoopBlock;
37 : Variable loopParamVar;
38 : Variable iterNumVar;
39 : Variable addrOffsetVar;
40 : Variable ctxIdVar;
41 : Layout layout{Layout::Config};
42 : };
43 :
44 : CcuRepLoopGroupBundle(CcuInsGeneratorBase* insGenPtr, const CcuLoopGroupCfg &config,
45 : const Variable ¶llelVar, const Variable &offsetVar);
46 : CcuRepLoopGroupBundle(CcuInsGeneratorBase* insGenPtr, const Variable ¶llelVar, 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
|