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 : #include "ccu_rep_loopgroup_bundle_v1.h"
12 : #include "ccu_ins_generater_base.h"
13 : #include "ccu_api_exception.h"
14 : #include "exception_util.h"
15 : #include "string_util.h"
16 :
17 : namespace hcomm {
18 : namespace CcuRep {
19 :
20 : using namespace Hccl;
21 :
22 13 : CcuRepLoopGroupBundle::CcuRepLoopGroupBundle(CcuInsGeneraterBase* insGenPtr, const CcuLoopGroupConfig &config,
23 13 : const Variable ¶llelVar, const Variable &offsetVar)
24 13 : : insGenPtr_(insGenPtr), config_(config), parallelVar_(parallelVar), offsetVar_(offsetVar)
25 : {
26 13 : type = CcuRepType::LOOPGROUP;
27 13 : }
28 :
29 10 : CcuRepLoopGroupBundle::CcuRepLoopGroupBundle(CcuInsGeneraterBase* insGenPtr,
30 10 : const Variable ¶llelVar, const Variable &offsetVar)
31 10 : : insGenPtr_(insGenPtr), parallelVar_(parallelVar), offsetVar_(offsetVar), layout_(Layout::PackedVar)
32 : {
33 10 : type = CcuRepType::LOOPGROUP;
34 10 : }
35 :
36 38 : void CcuRepLoopGroupBundle::AddLoop(const LoopEntry &entry)
37 : {
38 38 : loops_.push_back(entry);
39 38 : }
40 :
41 1 : uint16_t CcuRepLoopGroupBundle::LoopGroupInstrOffsetInBundle() const
42 : {
43 1 : uint16_t loopCount = static_cast<uint16_t>(loops_.size());
44 1 : uint16_t varBasedLoopCount = 0;
45 2 : for (const auto &loop : loops_) {
46 1 : if (loop.layout != Layout::Config) {
47 0 : varBasedLoopCount++;
48 : }
49 : }
50 1 : return (loopCount - varBasedLoopCount)
51 1 : + (varBasedLoopCount * 2)
52 1 : + (layout_ != Layout::Config ? 0 : 2);
53 : }
54 :
55 1 : uint16_t CcuRepLoopGroupBundle::GetStartLoopInstrId() const
56 : {
57 1 : return instrId + LoopGroupInstrOffsetInBundle() + 3;
58 : }
59 :
60 54 : uint16_t CcuRepLoopGroupBundle::InstrCount()
61 : {
62 54 : instrCount = insGenPtr_->CcuRepLoopGroupBundleInstrCount(this);
63 54 : return instrCount;
64 : }
65 :
66 20 : bool CcuRepLoopGroupBundle::Translate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &instrId, const TransDep &dep)
67 : {
68 58 : for (const auto &loop : loops_) {
69 38 : if (!loop.repLoopBlock->Translated()) {
70 0 : return false;
71 : }
72 : }
73 :
74 20 : this->instrId = instrId;
75 20 : translated = true;
76 :
77 20 : CHK_RET_THROW(Hccl::CcuApiException,
78 : Hccl::StringFormat("[CcuRepLoopGroupBundle][%s] failed to translate for instrId[%u]", __func__, instrId),
79 : insGenPtr_->CcuRepLoopGroupBundleTranslate(ccuKernel, instr, instrId, this, dep));
80 :
81 20 : return translated;
82 : }
83 :
84 19 : std::string CcuRepLoopGroupBundle::Describe()
85 : {
86 : return Hccl::StringFormat("LoopGroupBundle[loops=%zu, totalLoopNum=%lu]",
87 19 : loops_.size(), totalLoopNum_);
88 : }
89 :
90 : }; // namespace CcuRep
91 : }; // namespace hcomm
|