Line data Source code
1 : /**
2 : * Copyright (c) 2025 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.h"
12 : #include "ccu_assist.h"
13 : #include <climits>
14 :
15 : #include "string_util.h"
16 :
17 : namespace Hccl {
18 : namespace CcuRep {
19 :
20 53 : CcuRepSetLoop::CcuRepSetLoop(const Variable& loopParam, const Executor& executor, const Variable& var)
21 53 : : loopParam(loopParam),
22 53 : executor(executor),
23 106 : var(var)
24 : {
25 53 : type = CcuRepType::SET_LOOP;
26 53 : instrCount = 2; // set loop 指令数量为2
27 53 : }
28 :
29 11 : bool CcuRepSetLoop::Translate(CcuInstr*& instr, uint16_t& instrId, [[maybe_unused]] const TransDep& dep)
30 : {
31 11 : this->instrId = instrId;
32 11 : translated = true;
33 :
34 11 : LoadImdToXnInstr(instr++, loopParam.Id(), GetLoopParam(executor.Id(), 0, 0));
35 11 : LoadXXInstr(instr++, loopParam.Id(), loopParam.Id(), var.Id());
36 :
37 11 : if (instrId > USHRT_MAX - instrCount) {
38 1 : THROW<InternalException>(StringFormat(
39 : "[CcuRepSetLoop][Translate] instrId[%u] + instrCount[%u] exceeds the "
40 : "maximum value of unsigned short int.",
41 1 : instrId, instrCount));
42 : }
43 10 : instrId += instrCount;
44 :
45 10 : return translated;
46 : }
47 :
48 13 : std::string CcuRepSetLoop::Describe()
49 : {
50 : return StringFormat(
51 13 : "loopParam[%u] = var[%u], execute on LoopEngine[%u]", loopParam.Id(), var.Id(), executor.Id());
52 : }
53 :
54 : }; // namespace CcuRep
55 : }; // namespace Hccl
|