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(CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& instrId, const TransDep& dep)
39 : {
40 1 : this->instrId = instrId;
41 1 : translated = true;
42 :
43 1 : if (instrId > USHRT_MAX - instrCount) {
44 0 : Hccl::THROW<Hccl::InternalException>(Hccl::StringFormat(
45 : "[CcuRepSetLoop][Translate] instrId[%u] + instrCount[%u] exceeds the "
46 : "maximum value of unsigned short int.",
47 0 : instrId, instrCount));
48 : }
49 1 : instrId += instrCount;
50 :
51 1 : return translated;
52 : }
53 :
54 1 : std::string CcuRepSetLoop::Describe()
55 : {
56 : return Hccl::StringFormat(
57 1 : "loopParam[%u] = var[%u], execute on LoopEngine[%u]", loopParam.Id(), var.Id(), executor.Id());
58 : }
59 :
60 : }; // namespace CcuRep
61 : }; // namespace hcomm
|