Line data Source code
1 : /*
2 : * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
3 : * Description: ccu representation implementation file
4 : * Author: sunzhepeng
5 : * Create: 2024-06-17
6 : */
7 :
8 : #include "ccu_rep_v1.h"
9 : #include "ccu_ins_generater_v1.h"
10 : #include "string_util.h"
11 : #include "exception_util.h"
12 : #include "ccu_api_exception.h"
13 : #include "ccu_kernel.h"
14 :
15 : namespace hcomm {
16 : namespace CcuRep {
17 :
18 101 : void CcuRepAdd::SetCommonInfo()
19 : {
20 101 : type = CcuRepType::ADD;
21 101 : instrCount = 1;
22 101 : }
23 :
24 4 : CcuRepAdd::CcuRepAdd(CcuInsGeneraterBase* insGenPtr, const Address &addrC, const Address &addrA, const Variable &varB)
25 4 : : insGenPtr(insGenPtr), subType(AddSubType::ADDR_PLUS_VAR_TO_ADDR), addrA(addrA), addrC(addrC), varB(varB)
26 : {
27 4 : SetCommonInfo();
28 4 : supportCcuV1 = true;
29 4 : }
30 :
31 5 : CcuRepAdd::CcuRepAdd(CcuInsGeneraterBase* insGenPtr, const Address &addrC, const Address &addrA, const Address &addrB)
32 5 : : insGenPtr(insGenPtr), subType(AddSubType::ADDR_PLUS_ADDR_TO_ADDR), addrA(addrA), addrB(addrB), addrC(addrC)
33 : {
34 5 : SetCommonInfo();
35 5 : supportCcuV1 = true;
36 5 : }
37 :
38 56 : CcuRepAdd::CcuRepAdd(CcuInsGeneraterBase* insGenPtr, const Variable &varC, const Variable &varA, const Variable &varB)
39 56 : : insGenPtr(insGenPtr), subType(AddSubType::VAR_PLUS_VAR_TO_VAR), varA(varA), varB(varB), varC(varC)
40 : {
41 56 : SetCommonInfo();
42 56 : supportCcuV1 = true;
43 56 : }
44 :
45 30 : CcuRepAdd::CcuRepAdd(CcuInsGeneraterBase* insGenPtr, const Address &addrA, const Variable &offset)
46 30 : : insGenPtr(insGenPtr), subType(AddSubType::SELF_ADD_ADDRESS), addrA(addrA), varB(offset)
47 : {
48 30 : SetCommonInfo();
49 30 : supportCcuV1 = true;
50 30 : }
51 :
52 4 : CcuRepAdd::CcuRepAdd(CcuInsGeneraterBase* insGenPtr, const Variable &varA, const Variable &offset)
53 4 : : insGenPtr(insGenPtr), subType(AddSubType::SELF_ADD_VARIABLE), varA(varA), varB(offset)
54 : {
55 4 : SetCommonInfo();
56 4 : supportCcuV1 = true;
57 4 : }
58 :
59 1 : CcuRepAdd::CcuRepAdd(CcuInsGeneraterBase* insGenPtr, const Variable &varA, const uint16_t immedB)
60 1 : : insGenPtr(insGenPtr), subType(AddSubType::SELF_ADD_IMMED_VARIABLE), varA(varA), immedB(immedB)
61 : {
62 1 : SetCommonInfo();
63 1 : supportCcuV1 = false;
64 1 : }
65 :
66 0 : CcuRepAdd::CcuRepAdd(CcuInsGeneraterBase* insGenPtr, const Variable &varC, const Variable &varA, const uint16_t immedB)
67 0 : : insGenPtr(insGenPtr), subType(AddSubType::VAR_PLUS_IMMED_TO_VAR), varA(varA), varC(varC), immedB(immedB)
68 : {
69 0 : SetCommonInfo();
70 0 : supportCcuV1 = false;
71 0 : }
72 :
73 1 : CcuRepAdd::CcuRepAdd(CcuInsGeneraterBase* insGenPtr, const Address &addrC, const Address &addrA, const uint16_t immedB)
74 1 : : insGenPtr(insGenPtr), subType(AddSubType::ADDR_PLUS_IMMED_TO_ADDR), addrA(addrA), addrC(addrC), immedB(immedB)
75 : {
76 1 : SetCommonInfo();
77 1 : supportCcuV1 = false;
78 1 : }
79 :
80 0 : CcuRepAdd::CcuRepAdd(CcuInsGeneraterBase* insGenPtr, const Address &addrA, const uint16_t immedB)
81 0 : : insGenPtr(insGenPtr), subType(AddSubType::SELF_ADD_IMMED_ADDRESS), addrA(addrA), immedB(immedB)
82 : {
83 0 : SetCommonInfo();
84 0 : supportCcuV1 = false;
85 0 : }
86 :
87 0 : CcuRepAdd::CcuRepAdd(CcuInsGeneraterBase* insGenPtr, const Address &addrC, const Variable &varA, const Variable &varB)
88 0 : : insGenPtr(insGenPtr), subType(AddSubType::VAR_PLUS_VAR_TO_ADDR), addrC(addrC), varA(varA), varB(varB)
89 : {
90 0 : SetCommonInfo();
91 0 : supportCcuV1 = false;
92 0 : }
93 :
94 0 : CcuRepAdd::CcuRepAdd(CcuInsGeneraterBase* insGenPtr, const Address &addrC, const Variable &varA, const uint16_t immedB)
95 0 : : insGenPtr(insGenPtr), subType(AddSubType::VAR_PLUS_IMMED_TO_ADDR), addrC(addrC), varA(varA), immedB(immedB)
96 : {
97 0 : SetCommonInfo();
98 0 : supportCcuV1 = false;
99 0 : }
100 :
101 0 : CcuRepAdd::CcuRepAdd(CcuInsGeneraterBase* insGenPtr, const Variable &varC, const Address &addrA, const Address &addrB)
102 0 : : insGenPtr(insGenPtr), subType(AddSubType::ADDR_PLUS_ADDR_TO_VAR), addrA(addrA), addrB(addrB), varC(varC)
103 : {
104 0 : SetCommonInfo();
105 0 : supportCcuV1 = false;
106 0 : }
107 :
108 0 : CcuRepAdd::CcuRepAdd(CcuInsGeneraterBase* insGenPtr, const Variable &varC, const Address &addrA, const uint16_t immedB)
109 0 : : insGenPtr(insGenPtr), subType(AddSubType::ADDR_PLUS_IMMED_TO_VAR), addrA(addrA), varC(varC), immedB(immedB)
110 : {
111 0 : SetCommonInfo();
112 0 : supportCcuV1 = false;
113 0 : }
114 :
115 84 : void CcuRepAdd::ValidateInsGenPtrForAdd()
116 : {
117 84 : CcuInsGeneraterV1* tmpPtrV1 = dynamic_cast<CcuInsGeneraterV1 *>(insGenPtr);
118 84 : CHK_PRT_THROW((tmpPtrV1 && !supportCcuV1),
119 : HCCL_ERROR("[CcuRepAdd][%s]Cannot translate CcuRepAdd for A5 when supportCcuV1 is false", __func__),
120 : Hccl::CcuApiException, "tmpPtrV1 does not match supportCcuV1");
121 84 : }
122 :
123 84 : bool CcuRepAdd::Translate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &instrId, const TransDep &dep)
124 : {
125 84 : ValidateInsGenPtrForAdd();
126 84 : Hccl::CHECK_NULLPTR(instr, "[CcuRepAdd::Translate] instr is nullptr!");
127 84 : this->instrId = instrId;
128 84 : translated = true;
129 :
130 84 : insGenPtr->CcuRepAddTranslate(ccuKernel, instr, this, dep);
131 84 : CHK_PRT_THROW((instrId > UINT16_MAX - instrCount),
132 : HCCL_ERROR("[CcuRepAdd::Translate]uint16 integer overflow occurs, instrId = [%hu], instrCount = [%hu]", instrId, instrCount),
133 : Hccl::InternalException, "integer overflow");
134 84 : instrId += instrCount;
135 84 : return translated;
136 : }
137 :
138 79 : std::string CcuRepAdd::Describe()
139 : {
140 79 : switch (subType) {
141 1 : case AddSubType::ADDR_PLUS_VAR_TO_ADDR: {
142 1 : return Hccl::StringFormat("Address[%u] = Address[%u] + Variable[%u]", addrC.Id(), addrA.Id(), varB.Id());
143 : }
144 2 : case AddSubType::ADDR_PLUS_ADDR_TO_ADDR: {
145 2 : return Hccl::StringFormat("Address[%u] = Address[%u] + Address[%u]", addrC.Id(), addrA.Id(), addrB.Id());
146 : }
147 48 : case AddSubType::VAR_PLUS_VAR_TO_VAR: {
148 48 : return Hccl::StringFormat("Variable[%u] = Variable[%u] + Variable[%u]", varC.Id(), varA.Id(), varB.Id());
149 : }
150 27 : case AddSubType::SELF_ADD_ADDRESS: {
151 27 : return Hccl::StringFormat("Address[%u] += Variable[%u]", addrA.Id(), varB.Id());
152 : }
153 1 : case AddSubType::SELF_ADD_VARIABLE: {
154 1 : return Hccl::StringFormat("Variable[%u] += Variable[%u]", varA.Id(), varB.Id());
155 : }
156 0 : case AddSubType::SELF_ADD_IMMED_VARIABLE: {
157 0 : return Hccl::StringFormat("Variable[%u] += Immed[%u]", varA.Id(), immedB);
158 : }
159 0 : case AddSubType::VAR_PLUS_IMMED_TO_VAR: {
160 0 : return Hccl::StringFormat("Variable[%u] = Variable[%u] + Immed[%u]", varC.Id(), varA.Id(), immedB);
161 : }
162 0 : case AddSubType::ADDR_PLUS_IMMED_TO_ADDR: {
163 0 : return Hccl::StringFormat("Address[%u] += Address[%u] + Immed[%hu]", addrC.Id(), addrA.Id(), immedB);
164 : }
165 0 : case AddSubType::VAR_PLUS_VAR_TO_ADDR: {
166 0 : return Hccl::StringFormat("Address[%u] = Variable[%u] + Variable[%u]", addrC.Id(), varA.Id(), varB.Id());
167 : }
168 0 : case AddSubType::SELF_ADD_IMMED_ADDRESS: {
169 0 : return Hccl::StringFormat("Address[%u] += Immed[%u]", addrA.Id(), immedB);
170 : }
171 0 : case AddSubType::VAR_PLUS_IMMED_TO_ADDR: {
172 0 : return Hccl::StringFormat("Address[%u] += varA[%u] + Immed[%hu]", addrC.Id(), varA.Id(), immedB);
173 : }
174 0 : case AddSubType::ADDR_PLUS_IMMED_TO_VAR: {
175 0 : return Hccl::StringFormat("Variable[%u] = Address[%u] + Immed[%u]", varC.Id(), addrA.Id(), immedB);
176 : }
177 0 : default: {
178 0 : return Hccl::StringFormat("Invalid Add");
179 : }
180 : }
181 : }
182 :
183 57 : Address CcuRepAdd::GetAddrA()
184 : {
185 57 : return addrA;
186 : }
187 :
188 2 : Address CcuRepAdd::GetAddrB()
189 : {
190 2 : return addrB;
191 : }
192 :
193 3 : Address CcuRepAdd::GetAddrC()
194 : {
195 3 : return addrC;
196 : }
197 :
198 55 : Variable CcuRepAdd::GetVarA()
199 : {
200 55 : return varA;
201 : }
202 :
203 82 : Variable CcuRepAdd::GetVarB()
204 : {
205 82 : return varB;
206 : }
207 :
208 53 : Variable CcuRepAdd::GetVarC()
209 : {
210 53 : return varC;
211 : }
212 :
213 0 : uint16_t CcuRepAdd::GetImmedB()
214 : {
215 0 : return immedB;
216 : }
217 :
218 89 : AddSubType CcuRepAdd::GetSubType()
219 : {
220 89 : return subType;
221 : }
222 : }; // namespace CcuRep
223 : }; // namespace hcomm
|