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 : #include "ccu_datatype.h"
11 : #include "ccu_rep.h"
12 : #include "ccu_context_resource.h"
13 : #include "ccu_interface_assist.h"
14 :
15 : #include "exception_util.h"
16 : #include "ccu_api_exception.h"
17 :
18 : namespace Hccl {
19 : namespace CcuRep {
20 :
21 4328 : uint16_t CcuPhyRes::Id() const
22 : {
23 4328 : return id;
24 : }
25 116 : uint16_t CcuPhyRes::DieId() const
26 : {
27 116 : return dieId;
28 : }
29 25539 : void CcuPhyRes::Reset(uint16_t id)
30 : {
31 25539 : this->id = id;
32 25539 : }
33 21581 : void CcuPhyRes::SetDieId(uint16_t dieId)
34 : {
35 21581 : this->dieId = dieId;
36 21581 : }
37 :
38 56836 : CcuVirRes::CcuVirRes(CcuRepContext *context) : context(context)
39 : {
40 56836 : phyRes = std::make_shared<CcuPhyRes>();
41 56836 : }
42 :
43 3959 : void CcuVirRes::Reset(uint16_t id)
44 : {
45 3959 : phyRes->Reset(id);
46 3959 : }
47 :
48 21580 : void CcuVirRes::Reset(uint16_t id, uint16_t dieId)
49 : {
50 21580 : phyRes->Reset(id);
51 21580 : phyRes->SetDieId(dieId);
52 21580 : }
53 :
54 1 : void CcuVirRes::SetDieId(uint16_t dieId)
55 : {
56 1 : phyRes->SetDieId(dieId);
57 1 : }
58 :
59 4239 : uint16_t CcuVirRes::Id() const
60 : {
61 4239 : return phyRes->Id();
62 : }
63 :
64 27 : uint16_t CcuVirRes::DieId() const
65 : {
66 27 : return phyRes->DieId();
67 : }
68 :
69 6287 : Variable::Variable(CcuRepContext* context) : CcuVirRes(context)
70 : {
71 6287 : }
72 :
73 21447 : Variable::Variable(const Variable& other): CcuVirRes(other.context)
74 : {
75 21447 : phyRes = other.phyRes;
76 21447 : }
77 :
78 355 : void Variable::operator=(Variable&& other)
79 : {
80 355 : phyRes = other.phyRes;
81 355 : context = other.context;
82 355 : }
83 :
84 163 : void Variable::operator=(const Variable &other)
85 : {
86 163 : AppendToContext(context, std::make_shared<CcuRepAssign>(*this, other));
87 163 : }
88 :
89 182 : void Variable::operator=(uint64_t immediate)
90 : {
91 182 : AppendToContext(context, std::make_shared<CcuRepAssign>(*this, immediate));
92 182 : }
93 :
94 1 : void Variable::operator=(CcuArithmeticOperator<Variable, Variable> op)
95 : {
96 1 : AppendToContext(context, std::make_shared<CcuRepAdd>(*this, op.lhs, op.rhs));
97 1 : }
98 :
99 26 : void Variable::operator+=(const Variable &other)
100 : {
101 26 : AppendToContext(context, std::make_shared<CcuRepAdd>(*this, other));
102 26 : }
103 :
104 2881 : Address::Address(CcuRepContext* context) : CcuVirRes(context)
105 : {
106 2881 : }
107 :
108 6296 : Address::Address(const Address& other): CcuVirRes(other.context)
109 : {
110 6296 : phyRes = other.phyRes;
111 6296 : }
112 :
113 2 : void Address::operator=(Address&& other)
114 : {
115 2 : phyRes = other.phyRes;
116 2 : context = other.context;
117 2 : }
118 :
119 8 : void Address::operator=(const Address &other)
120 : {
121 8 : AppendToContext(context, std::make_shared<CcuRepAssign>(*this, other));
122 8 : }
123 :
124 153 : void Address::operator=(const Variable &other)
125 : {
126 153 : AppendToContext(context, std::make_shared<CcuRepAssign>(*this, other));
127 153 : }
128 :
129 1 : void Address::operator=(uint64_t immediate)
130 : {
131 1 : AppendToContext(context, std::make_shared<CcuRepAssign>(*this, immediate));
132 1 : }
133 :
134 8 : void Address::operator=(CcuArithmeticOperator<Variable, Address> op)
135 : {
136 8 : AppendToContext(context, std::make_shared<CcuRepAdd>(*this, op.rhs, op.lhs));
137 8 : }
138 :
139 1 : void Address::operator=(CcuArithmeticOperator<Address, Address> op)
140 : {
141 1 : AppendToContext(context, std::make_shared<CcuRepAdd>(*this, op.lhs, op.rhs));
142 1 : }
143 :
144 456 : void Address::operator+=(const Variable &other)
145 : {
146 456 : AppendToContext(context, std::make_shared<CcuRepAdd>(*this, other));
147 456 : }
148 :
149 2221 : MaskSignal::MaskSignal(CcuRepContext* context) : CcuVirRes(context)
150 : {
151 2221 : }
152 :
153 15724 : CcuBuffer::CcuBuffer(CcuRepContext* context) : CcuVirRes(context)
154 : {
155 15724 : }
156 :
157 89 : uint16_t CcuBuffer::Id() const
158 : {
159 89 : return phyRes->Id() + CCUBUFFER_DIE_ID_BIT * phyRes->DieId();
160 : }
161 :
162 1980 : Executor::Executor(CcuRepContext* context) : CcuVirRes(context)
163 : {
164 1980 : }
165 :
166 : }; // namespace CcuRep
167 : }; // namespace Hccl
|