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