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 : CcuRepAnd::CcuRepAnd(
21 2 : CcuInsGeneratorBase* insGenPtr, const Variable& varC, const Variable& varA, const Variable& varB)
22 2 : : subType(AndSubType::VAR_AND_VAR_TO_VAR),
23 2 : varA(varA),
24 2 : varB(varB),
25 2 : varC(varC),
26 2 : insGenPtr(insGenPtr)
27 : {
28 2 : type = CcuRepType::AND;
29 2 : instrCount = insGenPtr->GetInstrCount(type);
30 2 : }
31 :
32 0 : CcuRepAnd::CcuRepAnd(CcuInsGeneratorBase* insGenPtr, const Variable& varC, const Variable& varB)
33 0 : : subType(AndSubType::SELF_AND_VAR_VARIABLE),
34 0 : varB(varB),
35 0 : varC(varC),
36 0 : insGenPtr(insGenPtr)
37 : {
38 0 : type = CcuRepType::AND;
39 0 : instrCount = insGenPtr->GetInstrCount(type);
40 0 : }
41 :
42 2 : bool CcuRepAnd::Translate(CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, const TransDep& dep)
43 : {
44 2 : Hccl::CHECK_NULLPTR(instr, "[CcuRepAnd::Translate] instr is nullptr!");
45 2 : this->instrId = curInstrId;
46 2 : translated = true;
47 2 : instrCount = insGenPtr->GetInstrCount(type);
48 2 : CHK_PRT_THROW(
49 : insGenPtr->CcuRepAndTranslate(ccuKernel, instr, this, dep) != HcclResult::HCCL_SUCCESS,
50 : HCCL_ERROR("[CcuRepAnd][Translate] failed to translate for instrId[%u]", instrId), Hccl::CcuApiException,
51 : "CcuRepAnd translate failed");
52 2 : CHK_PRT_THROW(
53 : (curInstrId > UINT16_MAX - instrCount),
54 : HCCL_ERROR(
55 : "[CcuRepAnd::Translate]uint16 integer overflow occurs, curInstrId = [%hu], instrCount = [%hu]",
56 : curInstrId, instrCount),
57 : Hccl::InternalException, "integer overflow");
58 2 : curInstrId += instrCount;
59 2 : return translated;
60 : }
61 :
62 2 : std::string CcuRepAnd::Describe()
63 : {
64 2 : switch (subType) {
65 2 : case AndSubType::VAR_AND_VAR_TO_VAR: {
66 : return Hccl::StringFormat(
67 2 : "Variable[%u] = Variable[%u] & Variable[%u]", varC.Id(), varA.Id(), varB.Id());
68 : }
69 0 : case AndSubType::SELF_AND_VAR_VARIABLE: {
70 0 : return Hccl::StringFormat("Variable[%u] &= Variable[%u]", varC.Id(), varB.Id());
71 : }
72 0 : default: {
73 0 : return Hccl::StringFormat("Invalid And");
74 : }
75 : }
76 : }
77 :
78 : }; // namespace CcuRep
79 : }; // namespace hcomm
|