xaiefal
Loading...
Searching...
No Matches
xaiefal-rsc-group-impl.hpp
Go to the documentation of this file.
1// Copyright(C) 2020 - 2021 by Xilinx, Inc. All rights reserved.
2// SPDX-License-Identifier: MIT
7
8#include <vector>
9#include <xaiengine.h>
10#include <xaiefal/rsc/xaiefal-rsc-group.hpp>
11#include <xaiefal/common/xaiefal-base.hpp>
12
13#pragma once
14
15namespace xaiefal {
22 public:
23 XAieRscGroupRuntime(std::shared_ptr<XAieDevHandle> DevHd,
24 const std::string &Name = ""):
25 XAieRscGroupBase(DevHd, Name) {}
28
35 AieRC addRsc(std::shared_ptr<XAieRsc> Rsc) {
36 bool toAdd = true;
37 std::vector<std::weak_ptr<XAieRsc>>::iterator it;
38
39 for (it = vRefs.begin(); it != vRefs.end();) {
40 auto lR = it->lock();
41
42 if (lR == nullptr) {
43 vRefs.erase(it);
44 continue;
45 }
46 it++;
47 if (lR == Rsc) {
48 toAdd = false;
49 break;
50 }
51 }
52 if (toAdd) {
53 vRefs.push_back(Rsc);
54 }
55 return XAIE_OK;
56 }
57 private:
58 std::vector<std::weak_ptr<XAieRsc>> vRefs;
59
60 XAieRscStat _getRscStat(const std::vector<XAie_LocType> &vLocs,
61 XAie_ModuleType Mod, XAieRscType RscType,
62 uint32_t RscId) const {
63 XAieRscStat RscStat(FuncName);
64 std::vector<XAieUserRsc> vRscs;
65
66 for (auto Ref: vRefs) {
67 auto Rsc = Ref.lock();
68
69 if (Rsc == nullptr) {
70 continue;
71 }
72
73 auto RscWrapper = std::make_shared<
74 XAieRscGetRscsWrapper>(Rsc, vRscs);
75 }
76
77 for (auto Rsc: vRscs) {
78 for (auto L: vLocs) {
79 if ((L.Col != XAIE_LOC_ANY && Rsc.Loc.Col != L.Col) ||
80 (L.Row != XAIE_LOC_ANY && Rsc.Loc.Row != L.Row) ||
81 (Mod != static_cast<XAie_ModuleType>(XAIE_MOD_ANY)
82 && Rsc.Mod != Mod) ||
83 (RscType != static_cast<XAieRscType>(XAIE_RSC_TYPE_ANY)
84 && Rsc.RscType != RscType) ||
85 (RscId != XAIE_RSC_ID_ANY && Rsc.RscId != RscId)) {
86 continue;
87 }
88 RscStat.addRscStat(Rsc.Loc, Rsc.Mod, Rsc.RscType, 1);
89 }
90 }
91
92 return RscStat;
93 }
94 };
95
102 public:
103 XAieRscGroupStatic(std::shared_ptr<XAieDevHandle> DevHd,
104 const std::string &Name = "Static"):
105 XAieRscGroupBase(DevHd, Name) {}
108 private:
109 XAieRscStat _getRscStat(const std::vector<XAie_LocType> &vLocs,
110 XAie_ModuleType Mod, XAieRscType RscType,
111 uint32_t RscId) const {
112 XAieRscStat RscStat(FuncName);
113 std::vector<XAieUserRscStat> RscStats;
114
115 (void)RscId;
116
117 if (RscType == XAIE_TRACEEVENT) {
118 // Trace events are only allocated at runtime by AIEFAL
119 return RscStat;
120 }
121
122 auto AieHdPtr = AieHd.lock();
123 if (AieHdPtr == nullptr) {
124 throw std::invalid_argument("failed to get Aie ptr to get rsc stat for " +
125 FuncName);
126 }
127
128 if (vLocs[0].Col == XAIE_LOC_ANY) {
129 // Any tiles in the AI engine partition
130 auto lvLocs = _getAllTilesLocs(AieHdPtr->dev());
131 RscStats = _createDrvRscStats(AieHdPtr->dev(),
132 lvLocs, Mod, RscType);
133 } else {
134 RscStats = _createDrvRscStats(AieHdPtr->dev(),
135 vLocs, Mod, RscType);
136 }
137
138 if (AieHdPtr->rscMgr()->getStaticRscs(RscStats) != XAIE_OK) {
139 Logger::log(LogLevel::FAL_ERROR) << "failed to get static resource stat." << std::endl;
140 } else {
141 for (auto S: RscStats) {
142 if (S.NumRscs != 0) {
143 RscStat.addRscStat(S.Loc, S.Mod, S.RscType, S.NumRscs);
144 }
145 }
146 }
147
148 return RscStat;
149 }
150 };
151
158 public:
159 XAieRscGroupAvail(std::shared_ptr<XAieDevHandle> DevHd,
160 const std::string &Name = "Avail"):
161 XAieRscGroupBase(DevHd, Name) {}
163
176 AieRC addRsc(std::shared_ptr<XAieRsc> Rsc) {
177 bool toAdd = true;
178 std::vector<std::weak_ptr<XAieRsc>>::iterator it;
179
180 if (Rsc->getRscType() != XAIE_TRACECTRL) {
181 throw std::invalid_argument(
182 "failed to add rsc to avail group, only trace controller is allowed");
183 }
184 for (it = vRefs.begin(); it != vRefs.end();) {
185 auto lR = it->lock();
186
187 if (lR == nullptr) {
188 vRefs.erase(it);
189 continue;
190 }
191 it++;
192 if (lR == Rsc) {
193 toAdd = false;
194 break;
195 }
196 }
197 if (toAdd) {
198 vRefs.push_back(Rsc);
199 }
200 return XAIE_OK;
201 }
202 private:
203 std::vector<std::weak_ptr<XAieRsc>> vRefs;
206 private:
207 XAieRscStat _getRscStat(const std::vector<XAie_LocType> &vLocs,
208 XAie_ModuleType Mod, XAieRscType RscType,
209 uint32_t RscId) const {
210 std::vector<XAieUserRscStat> RscStats;
211 XAieRscStat RscStat(FuncName);
212 XAieRscType lRscType = RscType;
213
214 (void)RscId;
215 auto AieHdPtr = AieHd.lock();
216 if (AieHdPtr == nullptr) {
217 throw std::invalid_argument("failed to get Aie ptr to get rsc stat for " +
218 FuncName);
219 }
220
221 if (RscType == XAIE_TRACEEVENT) {
222 // If user wants to know the trace events availability,
223 // we also needs to know the trace control availability as
224 // the trace control is managed by the lower level driver
225 // while the trace events avaialability is managed by
226 // the AIEFAL.
227 lRscType = XAIE_TRACECTRL;
228 }
229
230 if (vLocs[0].Col == XAIE_LOC_ANY) {
231 // Any tiles in the AI engine partition
232 auto lvLocs = _getAllTilesLocs(AieHdPtr->dev());
233 RscStats = _createDrvRscStats(AieHdPtr->dev(),
234 lvLocs, Mod, lRscType);
235 } else {
236 RscStats = _createDrvRscStats(AieHdPtr->dev(),
237 vLocs, Mod, lRscType);
238 }
239
240 if (AieHdPtr->rscMgr()->getAvailRscs(RscStats) != XAIE_OK) {
241 Logger::log(LogLevel::FAL_ERROR) << "failed to get avail resource stat." << std::endl;
242 } else {
243 for (auto S: RscStats) {
244 if (S.NumRscs == 0) {
245 continue;
246 }
247 RscStat.addRscStat(S.Loc, S.Mod, S.RscType, S.NumRscs);
248 }
249 }
250
251 /* Handle resoure whose availability is managed by AIE FAL layer */
252 for (auto Ref: vRefs) {
253 uint32_t NumRscs;
254 XAie_LocType Loc;
255 XAie_ModuleType Mod;
256 XAieRscType ManagedRscType;
257
258 auto Rsc = Ref.lock();
259 if (Rsc == nullptr) {
260 continue;
261 }
262
263 ManagedRscType = Rsc->getManagedRscsType();
264 if (RscType != XAIE_RSC_TYPE_ANY &&
265 ManagedRscType != RscType) {
266 continue;
267 }
268 NumRscs = Rsc->getAvailManagedRscs();
269 if (NumRscs == 0) {
270 continue;
271 }
272
273 Loc = std::static_pointer_cast<XAieSingleTileRsc>(Rsc)->loc();
274 Mod = std::static_pointer_cast<XAieSingleTileRsc>(Rsc)->mod();
275 if (RscStat.getNumRsc(Loc, Mod, Rsc->getRscType()) == 0 &&
276 Rsc->isReserved() == false) {
277 // If the parent resource is occupied
278 // but not by the current app, number of
279 // AIEFAL managed child resources is not
280 // available.
281 continue;
282 }
283 RscStat.addRscStat(std::static_pointer_cast<XAieSingleTileRsc>(Rsc)->loc(),
284 std::static_pointer_cast<XAieSingleTileRsc>(Rsc)->mod(),
285 ManagedRscType, NumRscs);
286 }
287 return RscStat;
288 }
289 };
290}
static std::ostream & log(LogLevel Lvl=LogLevel::FAL_MAX)
Definition xaiefal-log.hpp:50
XAieRscGroupAvail(std::shared_ptr< XAieDevHandle > DevHd, const std::string &Name="Avail")
Definition xaiefal-rsc-group-impl.hpp:159
XAieRscGroupAvail()
Definition xaiefal-rsc-group-impl.hpp:162
AieRC addRsc(std::shared_ptr< XAieRsc > Rsc)
Definition xaiefal-rsc-group-impl.hpp:176
std::weak_ptr< XAieDevHandle > AieHd
Definition xaiefal-rsc-group.hpp:327
static std::vector< XAie_LocType > _getAllTilesLocs(XAie_DevInst *DevInst)
Definition xaiefal-rsc-group.hpp:369
XAieRscGroupBase(std::shared_ptr< XAieDevHandle > DevHd, const std::string &Name="")
Definition xaiefal-rsc-group.hpp:205
std::string FuncName
Definition xaiefal-rsc-group.hpp:326
static std::vector< XAieUserRscStat > _createDrvRscStats(XAie_DevInst *DevInst, const std::vector< XAie_LocType > &vLocs, XAie_ModuleType Mod, XAieRscType RscType)
Definition xaiefal-rsc-group.hpp:401
XAieRscGroupRuntime(std::shared_ptr< XAieDevHandle > DevHd, const std::string &Name="")
Definition xaiefal-rsc-group-impl.hpp:23
~XAieRscGroupRuntime()
Definition xaiefal-rsc-group-impl.hpp:27
AieRC addRsc(std::shared_ptr< XAieRsc > Rsc)
Definition xaiefal-rsc-group-impl.hpp:35
XAieRscGroupRuntime()
Definition xaiefal-rsc-group-impl.hpp:26
XAieRscGroupStatic()
Definition xaiefal-rsc-group-impl.hpp:106
~XAieRscGroupStatic()
Definition xaiefal-rsc-group-impl.hpp:107
XAieRscGroupStatic(std::shared_ptr< XAieDevHandle > DevHd, const std::string &Name="Static")
Definition xaiefal-rsc-group-impl.hpp:103
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two distribute and or modify the software for each author s protection and we want to make certain that everyone understands that there is no warranty for this free software If the software is modified by someone else and passed we want its recipients to know that what they have is not the so that any problems introduced by others will not reflect on the original authors reputations any free program is threatened constantly by software patents We wish to avoid the danger that redistributors of a free program will individually obtain patent in effect making the program proprietary To prevent we have made it clear that any patent must be licensed for everyone s free use or not licensed at all The precise terms and conditions for distribution and modification follow GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR DISTRIBUTION AND MODIFICATION This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License The refers to any such program or and a work based on the Program means either the Program or any derivative work under copyright a work containing the Program or a portion of it
Definition license.txt:89
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
Definition license.txt:197
Definition xaiefal-base.hpp:23
XAieRscType
Enums representing all requestable resources.
Definition xaiefal-rsc-group.hpp:27
@ XAIE_TRACEEVENT
Definition xaiefal-rsc-group.hpp:38
@ XAIE_TRACECTRL
Definition xaiefal-rsc-group.hpp:30
@ FAL_ERROR
Definition xaiefal-log.hpp:14
struct of resource usage statistics
Definition xaiefal-rsc-group.hpp:66
#define XAIE_RSC_TYPE_ANY
Definition xaiefal-common.hpp:8
#define XAIE_LOC_ANY
Definition xaiefal-common.hpp:10
#define XAIE_MOD_ANY
Definition xaiefal-common.hpp:9
#define XAIE_RSC_ID_ANY
Definition xaiefal-common.hpp:7