Line data Source code
1 : /**
2 : * Copyright (c) 2025 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 : #ifndef HCOMM_CCU_DATATYPE_H
12 : #define HCOMM_CCU_DATATYPE_H
13 :
14 : #include <memory>
15 :
16 : #include "ccu_rep_base_v1.h"
17 : #include "ccu_operator_v1.h"
18 : #include "ccu_rep_context_v1.h"
19 :
20 : namespace hcomm {
21 : namespace CcuRep {
22 :
23 : class Variable;
24 : class Address;
25 :
26 : class CcuPhyRes {
27 : public:
28 129827 : CcuPhyRes() = default;
29 : ~CcuPhyRes() = default;
30 : void Reset(uint16_t id);
31 : void SetDieId(uint16_t dieId);
32 : uint16_t Id() const;
33 : uint16_t DieId() const;
34 :
35 : private:
36 : uint16_t dieId{0};
37 : uint16_t id{0};
38 : };
39 :
40 : class CcuVirRes {
41 : public:
42 : CcuVirRes(CcuRepContext* context);
43 142936 : virtual ~CcuVirRes() = default;
44 : void Reset(uint16_t id);
45 : void Reset(uint16_t id, uint16_t dieId);
46 : void SetDieId(uint16_t dieId);
47 : virtual uint16_t Id() const;
48 : uint16_t DieId() const;
49 :
50 91 : CcuRepContext* GetCurContext() { return context; }
51 :
52 91 : std::shared_ptr<CcuPhyRes> GetCurPhyRes() { return phyRes; }
53 :
54 : protected:
55 : std::shared_ptr<CcuPhyRes> phyRes{nullptr};
56 : CcuRepContext* context{nullptr};
57 : };
58 :
59 : class Variable : public CcuVirRes {
60 : public:
61 : explicit Variable(CcuRepContext* context = nullptr);
62 : Variable(const Variable& other);
63 : void operator=(Variable&& other);
64 :
65 : void operator=(uint64_t immediate);
66 : void operator=(const Variable& other);
67 : void operator=(CcuArithmeticOperator<Variable, Variable> op);
68 : void operator=(CcuArithmeticOperator<Variable, uint16_t> op);
69 : void operator=(CcuArithmeticOperator<Address, uint16_t> op);
70 : void operator=(CcuArithmeticOperator<Address, Address> op);
71 :
72 : void operator=(CcuLogicOperator<Variable, Variable> op);
73 : void operator=(CcuLogicOperator<Variable> op);
74 :
75 : void operator=(CcuShiftOperator<Variable, Variable> op);
76 :
77 : CcuArithmeticOperator<Variable, Variable> operator+(const Variable& varB) const;
78 : CcuArithmeticOperator<Variable, uint16_t> operator+(const uint16_t offset) const;
79 : CcuArithmeticOperator<Variable, Address> operator+(const Address& addrB) const;
80 :
81 : CcuArithmeticOperator<Variable, Variable> operator*(const Variable& varB) const;
82 : CcuArithmeticOperator<Variable, uint16_t> operator*(const uint16_t offset) const;
83 : CcuArithmeticOperator<Variable, Address> operator*(const Address& addrB) const;
84 :
85 : CcuArithmeticOperator<Variable, Variable> operator-(const Variable& varB) const;
86 : CcuArithmeticOperator<Variable, Address> operator-(const Address& addrB) const;
87 : CcuArithmeticOperator<Variable, uint16_t> operator-(const uint16_t offset) const;
88 :
89 : void operator+=(const Variable& other);
90 : void operator+=(const uint16_t immediate);
91 : void operator+=(const Address& addrB);
92 : void operator*=(const Variable& other);
93 : void operator*=(const uint16_t immediate);
94 : void operator*=(const Address& addrB);
95 : void operator-=(const Variable& other);
96 : void operator-=(const uint16_t immediate);
97 : void operator-=(const Address& addrB);
98 : CcuRelationalOperator<Variable, uint64_t> operator!=(uint64_t immediate) const;
99 : CcuRelationalOperator<Variable, uint64_t> operator==(uint64_t immediate) const;
100 : CcuRelationalOperator<Variable, uint64_t> operator<=(uint64_t immediate) const;
101 : CcuRelationalOperator<Variable, uint64_t> operator>(uint64_t immediate) const;
102 : CcuRelationalOperator<Variable, Variable> operator<=(const Variable& varB) const;
103 : CcuRelationalOperator<Variable, Variable> operator>(const Variable& varB) const;
104 :
105 : CcuLogicOperator<Variable, Variable> operator&(const Variable& varB) const;
106 : CcuLogicOperator<Variable, Address> operator&(const Address& addrB) const;
107 : CcuLogicOperator<Variable, Variable> operator|(const Variable& varB) const;
108 : CcuLogicOperator<Variable, Address> operator|(const Address& addrB) const;
109 : CcuLogicOperator<Variable, Variable> operator^(const Variable& varB) const;
110 : CcuLogicOperator<Variable, Address> operator^(const Address& addrB) const;
111 : CcuLogicOperator<Variable> operator~() const;
112 :
113 : void operator&=(const Variable& other);
114 : void operator&=(const Address& addrB);
115 : void operator|=(const Variable& other);
116 : void operator|=(const Address& addrB);
117 : void operator^=(const Variable& other);
118 : void operator^=(const Address& addrB);
119 :
120 : CcuShiftOperator<Variable, Variable> operator<<(const Variable& other) const;
121 : void operator<<=(const Variable& other) const;
122 : CcuShiftOperator<Variable, Variable> operator>>(const Variable& other) const;
123 : void operator>>=(const Variable& other) const;
124 :
125 : void VarVarAppendToContext(CcuArithmeticOperator<Variable, Variable> op);
126 : void VarImmedAppendToContext(CcuArithmeticOperator<Variable, uint16_t> op);
127 : void AddrImmedAppendToContext(CcuArithmeticOperator<Address, uint16_t> op);
128 : void AddrAddrAppendToContext(CcuArithmeticOperator<Address, Address> op);
129 :
130 : void VarVarLogicAppendToContext(CcuLogicOperator<Variable, Variable> op);
131 : void AddrLogicAppendToContext(CcuLogicOperator<Variable> op);
132 : };
133 :
134 : class Address : public CcuVirRes {
135 : public:
136 : explicit Address(CcuRepContext* context = nullptr);
137 : Address(const Address& other);
138 : Address(Variable&& other);
139 : void operator=(Address&& other);
140 :
141 : void operator=(uint64_t immediate);
142 : void operator=(const Address& other);
143 : void operator=(const Variable& other);
144 :
145 : void operator=(CcuArithmeticOperator<Variable, Address> op);
146 : void operator=(CcuArithmeticOperator<Address, Address> op);
147 : void operator=(CcuArithmeticOperator<Address, uint16_t> op);
148 : void operator=(CcuArithmeticOperator<Variable, Variable> op);
149 : void operator=(CcuArithmeticOperator<Variable, uint16_t> op);
150 :
151 : void operator=(CcuLogicOperator<Variable, Address> op);
152 : void operator=(CcuLogicOperator<Address, Address> op);
153 : void operator=(CcuLogicOperator<Variable, Variable> op);
154 : void operator=(CcuLogicOperator<Variable> op);
155 : void operator=(CcuShiftOperator<Variable, Variable> op);
156 :
157 : CcuArithmeticOperator<Address, uint16_t> operator+(const uint16_t offset) const;
158 : CcuArithmeticOperator<Variable, Address> operator+(const Variable& varB) const;
159 : CcuArithmeticOperator<Address, Address> operator+(const Address& addrB) const;
160 : CcuArithmeticOperator<Address, Address> operator*(const Address& varB) const;
161 : CcuArithmeticOperator<Variable, Address> operator*(const Variable& addrB) const;
162 : CcuArithmeticOperator<Address, uint16_t> operator*(const uint16_t offset) const;
163 :
164 : CcuArithmeticOperator<Variable, Address> operator-(const Variable& varB) const;
165 : CcuArithmeticOperator<Address, Address> operator-(const Address& addrB) const;
166 : CcuArithmeticOperator<Address, uint16_t> operator-(const uint16_t offset) const;
167 :
168 : void operator+=(const Variable& other);
169 : void operator+=(const uint16_t immediate);
170 : void operator*=(const Variable& other);
171 : void operator*=(const uint16_t immediate);
172 : void operator-=(const Variable& other);
173 : void operator-=(const uint16_t immediate);
174 :
175 : CcuLogicOperator<Variable, Address> operator&(const Variable& varB) const;
176 : CcuLogicOperator<Address, Address> operator&(const Address& addrB) const;
177 : CcuLogicOperator<Variable, Address> operator|(const Variable& varB) const;
178 : CcuLogicOperator<Address, Address> operator|(const Address& addrB) const;
179 : CcuLogicOperator<Variable, Address> operator^(const Variable& varB) const;
180 : CcuLogicOperator<Address, Address> operator^(const Address& addrB) const;
181 :
182 : CcuShiftOperator<Variable, Variable> operator<<(const Variable& other) const;
183 : void operator<<=(const Variable& other) const;
184 : CcuShiftOperator<Variable, Variable> operator>>(const Variable& other) const;
185 : void operator>>=(const Variable& other) const;
186 :
187 : void VarAddrAppendToContext(CcuArithmeticOperator<Variable, Address> op);
188 : void AddrAddrAppendToContext(CcuArithmeticOperator<Address, Address> op);
189 : void VarImmedAppendToContext(CcuArithmeticOperator<Variable, uint16_t> op);
190 : void AddrImmedAppendToContext(CcuArithmeticOperator<Address, uint16_t> op);
191 : void VarVarAppendToContext(CcuArithmeticOperator<Variable, Variable> op);
192 : };
193 :
194 : class MaskSignal : public CcuVirRes {
195 : public:
196 : explicit MaskSignal(CcuRepContext* context = nullptr);
197 : };
198 :
199 : class CcuBuffer : public CcuVirRes {
200 : public:
201 : explicit CcuBuffer(CcuRepContext* context = nullptr);
202 : uint16_t Id() const override;
203 : static constexpr uint16_t CCUBUFFER_DIE_ID_BIT = 0x8000; // bit15 表示MS所在的IO Die id
204 : };
205 :
206 : class CcuBuf : public CcuVirRes {
207 : public:
208 : explicit CcuBuf(CcuRepContext* context = nullptr);
209 : uint16_t Id() const override;
210 : static constexpr uint16_t CCUBUFFER_DIE_ID_BIT = 0x8000; // bit15 表示MS所在的IO Die id
211 : };
212 :
213 : class Executor : public CcuVirRes {
214 : public:
215 : explicit Executor(CcuRepContext* context = nullptr);
216 : };
217 :
218 : class Memory {
219 : public:
220 44 : Memory() = default;
221 6 : Memory(Address addr, Variable token) : addr(addr), token(token) {}
222 : Address addr;
223 : Variable token;
224 : };
225 :
226 : /*------------------将Memory改为LocalAddr与RemoteAddr------------------------*/
227 : class LocalAddr {
228 : public:
229 42 : LocalAddr() = default;
230 190 : LocalAddr(Address addr, Variable token) : addr(addr), token(token) {}
231 :
232 : Address addr;
233 : Variable token;
234 : };
235 :
236 : class RemoteAddr {
237 : public:
238 44 : RemoteAddr() = default;
239 63 : RemoteAddr(Address addr, Variable token) : addr(addr), token(token) {}
240 :
241 : Address addr;
242 : Variable token;
243 : };
244 :
245 : /*------------------将MaskSignal改为LocalNotify------------------------*/
246 : class LocalNotify : public CcuVirRes {
247 : public:
248 : explicit LocalNotify(CcuRepContext* context = nullptr);
249 : };
250 :
251 : // CompletedEvent 退化为纯虚拟资源句柄持有者;
252 : // mask 由调用方(Rep / CcuKernel / C API / wrapper 各层)作为独立参数传入,
253 : // 不再绑定到 Event 上。
254 : class CompletedEvent : public CcuVirRes {
255 : public:
256 : explicit CompletedEvent(CcuRepContext* context = nullptr);
257 : };
258 :
259 : }; // namespace CcuRep
260 : }; // namespace hcomm
261 : #endif // HCOMM_CCU_DATATYPE_H
|