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 "ccu_ins_generator_v1.h"
13 : #include "string_util.h"
14 : #include "exception_util.h"
15 : #include "ccu_api_exception.h"
16 : #include "ccu_kernel.h"
17 :
18 : namespace hcomm {
19 : namespace CcuRep {
20 :
21 526 : void CcuRepAssign::SetCommonInfo()
22 : {
23 526 : type = CcuRepType::ASSIGN;
24 526 : instrCount = insGenPtr->GetInstrCount(type);
25 526 : }
26 :
27 287 : CcuRepAssign::CcuRepAssign(CcuInsGeneratorBase* insGenPtr, const Variable& varA, uint64_t immediate)
28 287 : : insGenPtr(insGenPtr),
29 287 : subType(AssignSubType::IMD_TO_VARIABLE),
30 287 : immediate(immediate),
31 287 : varA(varA)
32 : {
33 287 : SetCommonInfo();
34 287 : }
35 :
36 17 : CcuRepAssign::CcuRepAssign(CcuInsGeneratorBase* insGenPtr, const Address& addrA, uint64_t immediate)
37 17 : : insGenPtr(insGenPtr),
38 17 : subType(AssignSubType::IMD_TO_ADDR),
39 17 : immediate(immediate),
40 17 : addrA(addrA)
41 : {
42 17 : SetCommonInfo();
43 17 : }
44 :
45 18 : CcuRepAssign::CcuRepAssign(CcuInsGeneratorBase* insGenPtr, const Address& addrA, const Variable& varA)
46 18 : : insGenPtr(insGenPtr),
47 18 : subType(AssignSubType::VAR_TO_ADDR),
48 18 : immediate(0),
49 18 : varA(varA),
50 18 : addrA(addrA)
51 : {
52 18 : SetCommonInfo();
53 18 : }
54 :
55 42 : CcuRepAssign::CcuRepAssign(CcuInsGeneratorBase* insGenPtr, const Address& addrB, const Address& addrA)
56 42 : : insGenPtr(insGenPtr),
57 42 : subType(AssignSubType::ADDR_TO_ADDR),
58 42 : immediate(0),
59 42 : addrA(addrA),
60 84 : addrB(addrB)
61 : {
62 42 : SetCommonInfo();
63 42 : }
64 :
65 162 : CcuRepAssign::CcuRepAssign(CcuInsGeneratorBase* insGenPtr, const Variable& varB, const Variable& varA)
66 162 : : insGenPtr(insGenPtr),
67 162 : subType(AssignSubType::VAR_TO_VAR),
68 162 : immediate(0),
69 162 : varA(varA),
70 162 : varB(varB)
71 : {
72 162 : SetCommonInfo();
73 162 : }
74 :
75 485 : bool CcuRepAssign::Translate(CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& instrId, const TransDep& dep)
76 : {
77 485 : Hccl::CHECK_NULLPTR(instr, "[CcuRepAssign::Translate] instr is nullptr!");
78 485 : this->instrId = instrId;
79 485 : translated = true;
80 :
81 485 : CHK_PRT_THROW(
82 : insGenPtr->CcuRepAssignTranslate(ccuKernel, instr, this, dep) != HcclResult::HCCL_SUCCESS,
83 : HCCL_ERROR("[CcuRepAssign][Translate] failed to translate for instrId[%u]", instrId), Hccl::CcuApiException,
84 : "CcuRepAssign translate failed");
85 :
86 485 : CHK_PRT_THROW(
87 : (instrId > UINT16_MAX - instrCount),
88 : HCCL_ERROR(
89 : "[CcuRepAssign::Translate]uint16 integer overflow occurs, instrId = [%hu], instrCount = [%hu]", instrId,
90 : instrCount),
91 : Hccl::InternalException, "integer overflow");
92 485 : instrId += instrCount;
93 :
94 485 : return translated;
95 : }
96 :
97 483 : std::string CcuRepAssign::Describe()
98 : {
99 483 : switch (subType) {
100 260 : case AssignSubType::IMD_TO_VARIABLE: {
101 260 : return Hccl::StringFormat("Variable[%u] = Value[%lu]", varA.Id(), immediate);
102 : }
103 11 : case AssignSubType::IMD_TO_ADDR: {
104 11 : return Hccl::StringFormat("Address[%u] = Value[%lu]", addrA.Id(), immediate);
105 : }
106 15 : case AssignSubType::VAR_TO_ADDR: {
107 15 : return Hccl::StringFormat("Address[%u] = Variable[%u]", addrA.Id(), varA.Id());
108 : }
109 39 : case AssignSubType::ADDR_TO_ADDR: {
110 39 : return Hccl::StringFormat("Address[%u] = Address[%u]", addrB.Id(), addrA.Id());
111 : }
112 158 : case AssignSubType::VAR_TO_VAR: {
113 158 : return Hccl::StringFormat("Var[%u] = Var[%u]", varB.Id(), varA.Id());
114 : }
115 0 : default: {
116 0 : return Hccl::StringFormat("Invalid Assign");
117 : }
118 : }
119 : }
120 :
121 65 : Address CcuRepAssign::GetAddrA() { return addrA; }
122 :
123 39 : Address CcuRepAssign::GetAddrB() { return addrB; }
124 :
125 435 : Variable CcuRepAssign::GetVarA() { return varA; }
126 :
127 158 : Variable CcuRepAssign::GetVarB() { return varB; }
128 :
129 275 : uint64_t CcuRepAssign::GetImmed() { return immediate; }
130 :
131 1001 : AssignSubType CcuRepAssign::GetSubType() { return subType; }
132 : }; // namespace CcuRep
133 : }; // namespace hcomm
|