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 "string_util.h"
13 : #include "exception_util.h"
14 : #include "ccu_api_exception.h"
15 : #include "ccu_ins_generator_v1.h"
16 : #include "ccu_kernel.h"
17 : namespace hcomm {
18 : namespace CcuRep {
19 :
20 2 : CcuRepOr::CcuRepOr(CcuInsGeneratorBase* insGenPtr, const Variable &varC, const Variable &varA, const Variable &varB)
21 2 : : subType(OrSubType::VAR_OR_VAR_TO_VAR), varA(varA), varB(varB), varC(varC), insGenPtr(insGenPtr)
22 : {
23 2 : type = CcuRepType::OR;
24 2 : instrCount = insGenPtr->GetInstrCount(type);
25 2 : }
26 :
27 0 : CcuRepOr::CcuRepOr(CcuInsGeneratorBase* insGenPtr, const Variable &varC, const Variable &varB)
28 0 : : subType(OrSubType::SELF_OR_VAR_VARIABLE), varB(varB), varC(varC), insGenPtr(insGenPtr)
29 : {
30 0 : type = CcuRepType::OR;
31 0 : instrCount = insGenPtr->GetInstrCount(type);
32 0 : }
33 :
34 2 : bool CcuRepOr::Translate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId, const TransDep &dep)
35 : {
36 2 : Hccl::CHECK_NULLPTR(instr, "[CcuRepOr::Translate] instr is nullptr!");
37 2 : this->instrId = curInstrId;
38 2 : translated = true;
39 2 : instrCount = insGenPtr->GetInstrCount(type);
40 2 : insGenPtr->CcuRepOrTranslate(ccuKernel, instr, this, dep);
41 2 : CHK_PRT_THROW((curInstrId > UINT16_MAX - instrCount),
42 : HCCL_ERROR("[CcuRepOr::Translate]uint16 integer overflow occurs, curInstrId = [%hu], instrCount = [%hu]", curInstrId, instrCount),
43 : Hccl::InternalException, "integer overflow");
44 2 : curInstrId += instrCount;
45 2 : return translated;
46 : }
47 :
48 2 : std::string CcuRepOr::Describe()
49 : {
50 2 : switch (subType) {
51 2 : case OrSubType::VAR_OR_VAR_TO_VAR: {
52 2 : return Hccl::StringFormat("Variable[%u] = Variable[%u] | Variable[%u]", varC.Id(), varA.Id(), varB.Id());
53 : }
54 0 : case OrSubType::SELF_OR_VAR_VARIABLE: {
55 0 : return Hccl::StringFormat("Variable[%u] |= Variable[%u]", varC.Id(), varB.Id());
56 : }
57 0 : default: {
58 0 : return Hccl::StringFormat("Invalid Or");
59 : }
60 : }
61 : }
62 :
63 : }; // namespace CcuRep
64 : }; // namespace hcomm
|