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_v1.h"
12 : #include "ccu_assist_v1.h"
13 : #include <climits>
14 :
15 : #include "string_util.h"
16 : #include "exception_util.h"
17 : #include "ccu_api_exception.h"
18 : #include "ccu_ins_generator_base.h"
19 : #include "ccu_ins_generator_v1.h"
20 : #include "ccu_kernel.h"
21 :
22 : namespace hcomm {
23 : namespace CcuRep {
24 :
25 : using namespace Hccl;
26 :
27 4 : CcuRepSetLoop::CcuRepSetLoop(
28 4 : CcuInsGeneratorBase* insGeneratorPtr, const Variable& loopParam, const Executor& executor, const Variable& var)
29 4 : : insGeneratorPtr_(insGeneratorPtr),
30 4 : loopParam(loopParam),
31 4 : executor(executor),
32 8 : var(var)
33 : {
34 4 : type = CcuRepType::SET_LOOP;
35 4 : instrCount = insGeneratorPtr_->GetInstrCount(type); // set loop 指令数量为2
36 4 : }
37 :
38 1 : bool CcuRepSetLoop::Translate(
39 : [[maybe_unused]] CcuKernel* ccuKernel, [[maybe_unused]] CcuInstr*& instr, uint16_t& instrId,
40 : [[maybe_unused]] const TransDep& dep)
41 : {
42 1 : this->instrId = instrId;
43 1 : translated = true;
44 :
45 1 : if (instrId > USHRT_MAX - instrCount) {
46 0 : Hccl::THROW<Hccl::InternalException>(Hccl::StringFormat(
47 : "[CcuRepSetLoop][Translate] instrId[%u] + instrCount[%u] exceeds the "
48 : "maximum value of unsigned short int.",
49 0 : instrId, instrCount));
50 : }
51 1 : instrId += instrCount;
52 :
53 1 : return translated;
54 : }
55 :
56 1 : std::string CcuRepSetLoop::Describe()
57 : {
58 : return Hccl::StringFormat(
59 1 : "loopParam[%u] = var[%u], execute on LoopEngine[%u]", loopParam.Id(), var.Id(), executor.Id());
60 : }
61 :
62 : }; // namespace CcuRep
63 : }; // namespace hcomm
|