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_interface_assist.h"
13 :
14 : #include "string_util.h"
15 : #include "exception_util.h"
16 : #include "ccu_api_exception.h"
17 :
18 : namespace Hccl {
19 : namespace CcuRep {
20 :
21 5 : Repeat::Repeat(CcuRepContext* context, CcuRelationalOperator<Variable, uint64_t> rel) : context(context)
22 : {
23 5 : std::string label = "Repeat";
24 5 : beginLabel = std::make_shared<CcuRepJumpLabel>(label);
25 5 : endLabel = std::make_shared<CcuRepJumpLabel>("Break");
26 5 : Variable tmp;
27 5 : auto ret = CreateVariable(context, tmp);
28 5 : if (ret != HcclResult::HCCL_SUCCESS) {
29 0 : THROW<CcuApiException>("CreateVariable is failed. ret[%d]", ret);
30 : }
31 5 : if (rel.type == CcuRelationalOperatorType::NOT_EQUAL) {
32 3 : jump = std::make_shared<CcuRepJumpNE>(label, tmp, rel.lhs, rel.rhs);
33 2 : } else if (rel.type == CcuRelationalOperatorType::EQUAL) {
34 2 : jump = std::make_shared<CcuRepJumpEQ>(label, tmp, rel.lhs, rel.rhs);
35 : } else {
36 0 : THROW<CcuApiException>("Unsupported relational operation");
37 : }
38 5 : jump->Reference(beginLabel);
39 :
40 5 : AppendToContext(context, beginLabel);
41 5 : }
42 :
43 5 : Repeat::~Repeat()
44 : {
45 5 : DECTOR_TRY_CATCH("Repeat", AppendToContext(context, jump));
46 5 : DECTOR_TRY_CATCH("Repeat", AppendToContext(context, endLabel));
47 5 : }
48 :
49 5 : void Repeat::Break()
50 : {
51 5 : Variable tmp;
52 5 : auto ret = CreateVariable(context, tmp);
53 5 : if (ret != HcclResult::HCCL_SUCCESS) {
54 0 : THROW<CcuApiException>("CreateVariable is failed. ret[%d]", ret);
55 : }
56 5 : auto jumpToEnd = std::make_shared<CcuRepJump>("Break", tmp);
57 5 : jumpToEnd->Reference(endLabel);
58 5 : AppendToContext(context, jumpToEnd);
59 5 : }
60 :
61 10 : bool Repeat::Check() const { return !isExecuted; }
62 :
63 5 : void Repeat::Run() { isExecuted = true; }
64 :
65 : }; // namespace CcuRep
66 : }; // namespace Hccl
|