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