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 57 : Condition::Condition(CcuRepContext *context, CcuRelationalOperator<Variable, uint64_t> rel) : context(context)
22 : {
23 57 : std::string label = "Condition";
24 57 : endLabel = std::make_shared<CcuRepJumpLabel>(label);
25 57 : Variable tmp;
26 57 : auto ret = CreateVariable(context, tmp);
27 57 : if (ret != HcclResult::HCCL_SUCCESS) {
28 0 : THROW<CcuApiException>("CreateVariable failed!");
29 : }
30 : // 当传入条件为真时, 执行Block, 对应不执行Jump
31 57 : if (rel.type == CcuRelationalOperatorType::NOT_EQUAL) {
32 45 : jump = std::make_shared<CcuRepJumpEQ>(label, tmp, rel.lhs, rel.rhs);
33 12 : } else if (rel.type == CcuRelationalOperatorType::EQUAL) {
34 12 : jump = std::make_shared<CcuRepJumpNE>(label, tmp, rel.lhs, rel.rhs);
35 : } else {
36 0 : THROW<CcuApiException>("Unsupported relational operation");
37 : }
38 57 : jump->Reference(endLabel);
39 :
40 57 : AppendToContext(context, jump);
41 57 : }
42 :
43 57 : Condition::~Condition()
44 : {
45 57 : DECTOR_TRY_CATCH("Condition", AppendToContext(context, endLabel));
46 57 : }
47 :
48 96 : bool Condition::Check() const
49 : {
50 96 : return !isExecuted;
51 : }
52 :
53 48 : void Condition::Run()
54 : {
55 48 : isExecuted = true;
56 48 : }
57 :
58 : }; // namespace CcuRep
59 : }; // namespace Hccl
|