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