xaiefal
Loading...
Searching...
No Matches
xaiefal-rsc-group.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 <fstream>
9#include <functional>
10#include <map>
11#include <vector>
12#include <xaiengine.h>
13#include <xaiefal/common/xaiefal-common.hpp>
14#include <xaiefal/common/xaiefal-log.hpp>
15
16#pragma once
17
18namespace xaiefal {
19 class XAieRsc;
21 class XAieDevHandle;
22
40
47 XAie_LocType Loc {
48 XAie_TileLoc(XAIE_LOC_ANY, XAIE_LOC_ANY)
49 };
50
54
58
59 uint32_t NumRscs {0U};
60 };
61
66 struct XAieRscStat {
67 XAieRscStat(const std::string &Name = ""):
68 GroupName(Name) {}
69 std::string GroupName;
70 std::map<std::tuple<uint8_t, uint8_t, uint32_t, uint32_t>,
71 uint32_t> Rscs;
82 void addRscStat(XAie_LocType Loc, XAie_ModuleType Mod,
83 XAieRscType RscType, uint32_t NumRscs) {
84 (void)Mod;
85 (void)RscType;
86 (void)NumRscs;
87
88 std::tuple<uint8_t, uint8_t, uint32_t, uint32_t> rKey {
89 Loc.Col, Loc.Row, static_cast<uint32_t>(Mod),
90 static_cast<uint32_t>(RscType)};
91
92 if (Rscs.find(rKey) != Rscs.end()) {
93 Rscs[rKey] += NumRscs;
94 } else {
95 Rscs[rKey] = NumRscs;
96 }
97 }
98
109 uint32_t getNumRsc(XAie_LocType Loc, XAie_ModuleType Mod,
110 XAieRscType RscType) {
111 uint32_t NumRscs = 0;
112 std::tuple<uint8_t, uint8_t, uint32_t, uint32_t> rKey {
113 Loc.Col, Loc.Row, static_cast<uint32_t>(Mod),
114 static_cast<uint32_t>(RscType)};
115
116 if (Rscs.find(rKey) != Rscs.end()) {
117 NumRscs = Rscs[rKey];
118 }
119
120 return NumRscs;
121 }
122
129 bool hasRsc() const {
130 return (Rscs.size() == 0) ? false : true;
131 }
132
136 void show() const {
137 Logger::log(LogLevel::FAL_INFO) << GroupName << ":" << std::endl;
138 for (auto const& r : Rscs) {
139 std::string Str = "\t(" +
140 std::to_string(static_cast<uint32_t>(std::get<0>(r.first))) +
141 ", " +
142 std::to_string(static_cast<uint32_t>(std::get<1>(r.first))) +
143 "): ";
144
145 switch (std::get<2>(r.first)) {
146 case XAIE_MEM_MOD:
147 Str += "Mem";
148 break;
149 case XAIE_CORE_MOD:
150 Str += "Core";
151 break;
152 case XAIE_PL_MOD:
153 Str += "SHIM";
154 break;
155 default:
156 Str += "Unknown";
157 break;
158 }
159 Str += ": ";
160
161 switch (std::get<3>(r.first)) {
162 case static_cast<uint32_t>(XAIE_PERFCOUNT):
163 Str += "Perfcount ";
164 break;
165 case static_cast<uint32_t>(XAIE_USEREVENT):
166 Str += "UserEvents ";
167 break;
168 case static_cast<uint32_t>(XAIE_TRACECTRL):
169 Str += "TraceCntr ";
170 break;
171 case static_cast<uint32_t>(XAIE_PCEVENT):
172 Str += "PCEvents ";
173 break;
174 case static_cast<uint32_t>(XAIE_SSEVENT):
175 Str += "SSEventsPorts ";
176 break;
177 case static_cast<uint32_t>(XAIE_BROADCAST):
178 Str += "BC ";
179 break;
180 case static_cast<uint32_t>(XAIE_COMBOEVENT):
181 Str += "ComboEvents ";
182 break;
183 case static_cast<uint32_t>(XAIE_GROUPEVENT):
184 Str += "GroupEvents ";
185 break;
186 case static_cast<uint32_t>(XAIE_TRACEEVENT):
187 Str += "TraceEvents ";
188 break;
189 default:
190 Str += "Unknown ";
191 break;
192 }
193 Str += ": " + std::to_string(r.second);
194 std::cout << Str << std::endl;
195 }
196 }
197 };
198
204 public:
205 XAieRscGroupBase(std::shared_ptr<XAieDevHandle> DevHd,
206 const std::string &Name = ""):
207 FuncName(Name), AieHd(DevHd) {}
210
218 return getRscStat(XAie_TileLoc(XAIE_LOC_ANY, XAIE_LOC_ANY));
219 }
220
228 XAieRscStat getRscStat(XAie_LocType Loc) const {
229 return _getRscStatTile(Loc, static_cast<XAie_ModuleType>(XAIE_MOD_ANY),
231 }
232
241 XAieRscStat getRscStat(XAie_LocType Loc, XAieRscType RscType) const {
242 return _getRscStatTile(Loc, static_cast<XAie_ModuleType>(XAIE_MOD_ANY),
243 RscType, XAIE_RSC_ID_ANY);
244 }
245
254 XAieRscStat getRscStat(XAie_LocType Loc, XAie_ModuleType Mod) const {
255 return getRscStat(Loc, Mod, static_cast<XAieRscType>(XAIE_RSC_TYPE_ANY));
256 }
257
268 XAieRscType RscType) const {
269 return getRscStat(Loc, Mod, RscType, XAIE_RSC_ID_ANY);
270 }
271
284 XAieRscType RscType, uint32_t RscId) const {
285 return _getRscStatTile(Loc, Mod, RscType, RscId);
286 }
287
297 XAieRscStat getRscStat(const std::vector<XAie_LocType> &vLocs,
298 XAieRscType RscType) const {
299 return _getRscStat(vLocs, static_cast<XAie_ModuleType>(XAIE_MOD_ANY),
300 RscType, XAIE_RSC_ID_ANY);
301 }
302
314 XAieRscStat getRscStat(const std::vector<XAie_LocType> &vLocs,
315 XAieRscType RscType, uint32_t RscId) const {
316 return _getRscStat(vLocs, static_cast<XAie_ModuleType>(XAIE_MOD_ANY),
317 RscType, RscId);
318 }
319
320 virtual AieRC addRsc(std::shared_ptr<XAieRsc> Rsc) {
321 (void)Rsc;
322 throw std::invalid_argument("Add Rsc not supported, rsc group: " + FuncName);
323 return XAIE_ERR;
324 }
325 protected:
326 std::string FuncName;
327 std::weak_ptr<XAieDevHandle> AieHd;
328
340 virtual XAieRscStat _getRscStat(const std::vector<XAie_LocType> &vLocs,
341 XAie_ModuleType Mod, XAieRscType RscType,
342 uint32_t RscId) const {
343 XAieRscStat RscStat(FuncName);
344
345 (void)vLocs;
346 (void)Mod;
347 (void)RscType;
348 (void)RscId;
349
350 throw std::invalid_argument("Get rsc stat not supported, rsc group: " + FuncName);
351 return RscStat;
352 }
354 XAieRscType RscType, uint32_t RscId) const {
355 std::vector<XAie_LocType> vLocs;
356
357 vLocs.push_back(Loc);
358 return _getRscStat(vLocs, Mod, RscType, RscId);
359 }
360
369 static inline std::vector<XAie_LocType> _getAllTilesLocs(
370 XAie_DevInst *DevInst) {
371 std::vector<XAie_LocType> vLocs(DevInst->NumCols *
372 DevInst->NumRows);
373 uint8_t Col = 0, Row = 0;
374
375 for (std::vector<XAie_LocType>::iterator it = vLocs.begin() ;
376 it != vLocs.end(); ++it) {
377 *it = XAie_TileLoc(Col, Row);
378
379 Row++;
380 if (Row == DevInst->NumRows) {
381 Row = 0;
382 Col++;
383 }
384 }
385
386 return vLocs;
387 }
388
401 static inline std::vector<XAieUserRscStat> _createDrvRscStats(
402 XAie_DevInst *DevInst,
403 const std::vector<XAie_LocType> &vLocs,
404 XAie_ModuleType Mod, XAieRscType RscType) {
405 uint32_t NumStats = 0;
406 uint32_t MaxNumRscs = static_cast<uint32_t>(XAIE_MAXRSC);
407 uint32_t ShimModNumRscs = 0, CoreModNumRscs = 0;
408 uint32_t CoreMemModNumRscs = 0, MemModNumRscs = 0;
409 uint32_t NumTiles = 0, NumCoreTiles = 0, NumShimTiles = 0;
410 uint32_t i, MdmPresent = 0;
411
412 if (RscType != XAIE_RSC_TYPE_ANY && RscType >= XAIE_MAXRSC) {
413 throw std::invalid_argument("Invalid Rsc Type to get rsc stat");
414 }
415
416 if (XAie_IsUcModulePresent(DevInst, DevInst->ShimRow)) {
417 MdmPresent = 1;
418 } else {
419 MdmPresent = 0;
420 }
421
422 // Get number of resources per module
423 if (Mod == static_cast<XAie_ModuleType>(XAIE_MOD_ANY) ||
424 Mod == XAIE_PL_MOD) {
425 if (RscType == static_cast<XAieRscType>(XAIE_RSC_TYPE_ANY)) {
426 ShimModNumRscs = MdmPresent ? MaxNumRscs - 1 : MaxNumRscs - 2;
427 } else if (RscType == XAIE_PCEVENT) {
428 ShimModNumRscs = 0;
429 } else if (RscType == XAIE_MDMPERFCNT) {
430 ShimModNumRscs = MdmPresent;
431 } else {
432 ShimModNumRscs = 1;
433 }
434 }
435 if (Mod == static_cast<XAie_ModuleType>(XAIE_MOD_ANY) ||
436 Mod == XAIE_CORE_MOD) {
437 if (RscType == static_cast<XAieRscType>(XAIE_RSC_TYPE_ANY)) {
438 CoreModNumRscs = MaxNumRscs - 1;
439 } else if (RscType == XAIE_MDMPERFCNT) {
440 CoreModNumRscs = 0;
441 } else {
442 CoreModNumRscs = 1;
443 }
444 }
445
446 if (Mod == static_cast<XAie_ModuleType>(XAIE_MOD_ANY) ||
447 Mod == XAIE_MEM_MOD) {
448 if (RscType == static_cast<XAieRscType>(XAIE_RSC_TYPE_ANY)) {
449 MemModNumRscs = MaxNumRscs - 2;
450 CoreMemModNumRscs = MaxNumRscs - 3;
451 } else if (RscType == XAIE_PCEVENT) {
452 MemModNumRscs = 0;
453 CoreMemModNumRscs = 0;
454 } else if (RscType == XAIE_MDMPERFCNT) {
455 MemModNumRscs = 0;
456 CoreMemModNumRscs = 0;
457 } else {
458 MemModNumRscs = 1;
459 if (RscType == XAIE_SSEVENT) {
460 CoreMemModNumRscs = 0;
461 } else {
462 CoreMemModNumRscs = 1;
463 }
464 }
465 }
466
467 for (auto L: vLocs) {
468 if (L.Row == XAIE_LOC_ANY ||
469 L.Col == XAIE_LOC_ANY) {
470 throw std::invalid_argument("Invalid tile location to get rsc stat");
471 }
472 NumTiles++;
473 if (L.Row == 0) {
474 NumShimTiles++;
475 } else if (L.Row >= DevInst->AieTileRowStart) {
476 NumCoreTiles++;
477 }
478 }
479
480 // Calculate number of resource statistics
481 NumStats += NumShimTiles * ShimModNumRscs;
482 NumStats += NumCoreTiles * CoreModNumRscs;
483 NumStats += NumCoreTiles * CoreMemModNumRscs;
484 NumStats += (NumTiles - NumShimTiles - NumCoreTiles) * MemModNumRscs;
485
486 std::vector<XAieUserRscStat> RscsStats(NumStats);
487
488 // Fill in Rsc stats parameters
489 i = 0;
490 for (auto L: vLocs) {
491 if (L.Row == 0) {
492 // Shim Tiles
493 if (ShimModNumRscs == 0) {
494 continue;
495 }
496 if (ShimModNumRscs == 1) {
497 RscsStats[i].Loc = L;
498 RscsStats[i].Mod = XAIE_PL_MOD;
499 RscsStats[i].RscType = RscType;
500 RscsStats[i].NumRscs = 0;
501 i++;
502 continue;
503 }
504 for (uint8_t Rsc = static_cast<uint8_t>(XAIE_PERFCOUNT);
505 Rsc < static_cast<uint8_t>(XAIE_MAXRSC); Rsc++) {
506 if (Rsc == static_cast<uint8_t>(XAIE_PCEVENT)) {
507 continue;
508 }
509 if (Rsc == static_cast<uint8_t>(XAIE_MDMPERFCNT)) {
510 if (MdmPresent == 0) {
511 continue;
512 }
513 }
514 RscsStats[i].Loc = L;
515 RscsStats[i].Mod = XAIE_PL_MOD;
516 RscsStats[i].RscType = static_cast<XAieRscType>(Rsc);
517 RscsStats[i].NumRscs = 0;
518 i++;
519 }
520 } else if (L.Row >= DevInst->AieTileRowStart) {
521 // Core tiles, core modules
522 if (CoreModNumRscs == 1) {
523 RscsStats[i].Loc = L;
524 RscsStats[i].Mod = XAIE_CORE_MOD;
525 RscsStats[i].RscType = RscType;
526 RscsStats[i].NumRscs = 0;
527 i++;
528 } else if (CoreModNumRscs > 1) {
529 for (uint8_t Rsc = static_cast<uint8_t>(XAIE_PERFCOUNT);
530 Rsc < static_cast<uint8_t>(XAIE_MAXRSC); Rsc++) {
531 if (Rsc == static_cast<uint8_t>(XAIE_MDMPERFCNT)) {
532 continue;
533 }
534 RscsStats[i].Loc = L;
535 RscsStats[i].Mod = XAIE_CORE_MOD;
536 RscsStats[i].RscType = static_cast<XAieRscType>(Rsc);
537 RscsStats[i].NumRscs = 0;
538 i++;
539 }
540 }
541
542 // Core tiles, mem modules
543 if (CoreMemModNumRscs == 0) {
544 continue;
545 }
546 if (CoreMemModNumRscs == 1) {
547 RscsStats[i].Loc = L;
548 RscsStats[i].Mod = XAIE_MEM_MOD;
549 RscsStats[i].RscType = RscType;
550 RscsStats[i].NumRscs = 0;
551 i++;
552 continue;
553 }
554 for (uint8_t Rsc = static_cast<uint8_t>(XAIE_PERFCOUNT);
555 Rsc < static_cast<uint8_t>(XAIE_MAXRSC); Rsc++) {
556 if (Rsc == static_cast<uint8_t>(XAIE_PCEVENT) ||
557 Rsc == static_cast<uint8_t>(XAIE_SSEVENT) ||
558 Rsc == static_cast<uint8_t>(XAIE_MDMPERFCNT)) {
559 continue;
560 }
561 RscsStats[i].Loc = L;
562 RscsStats[i].Mod = XAIE_MEM_MOD;
563 RscsStats[i].RscType = static_cast<XAieRscType>(Rsc);
564 RscsStats[i].NumRscs = 0;
565 i++;
566 }
567 } else {
568 // Other tiles
569 if (MemModNumRscs == 0) {
570 continue;
571 }
572 if (MemModNumRscs == 1) {
573 RscsStats[i].Loc = L;
574 RscsStats[i].Mod = XAIE_MEM_MOD;
575 RscsStats[i].RscType = RscType;
576 RscsStats[i].NumRscs = 0;
577 i++;
578 continue;
579 }
580 for (uint8_t Rsc = static_cast<uint8_t>(XAIE_PERFCOUNT);
581 Rsc < static_cast<uint8_t>(XAIE_MAXRSC); Rsc++) {
582 if (Rsc == static_cast<uint8_t>(XAIE_PCEVENT) ||
583 Rsc == static_cast<uint8_t>(XAIE_MDMPERFCNT)) {
584 continue;
585 }
586 RscsStats[i].Loc = L;
587 RscsStats[i].Mod = XAIE_MEM_MOD;
588 RscsStats[i].RscType = static_cast<XAieRscType>(Rsc);
589 RscsStats[i].NumRscs = 0;
590 i++;
591 }
592 }
593 }
594
595 return RscsStats;
596 }
597 };
598}
static std::ostream & log(LogLevel Lvl=LogLevel::FAL_MAX)
Definition xaiefal-log.hpp:50
AI engine low level device pointer handle.
Definition xaiefal-base.hpp:104
std::weak_ptr< XAieDevHandle > AieHd
Definition xaiefal-rsc-group.hpp:327
XAieRscStat getRscStat(XAie_LocType Loc, XAieRscType RscType) const
Definition xaiefal-rsc-group.hpp:241
XAieRscStat getRscStat(XAie_LocType Loc, XAie_ModuleType Mod) const
Definition xaiefal-rsc-group.hpp:254
virtual XAieRscStat _getRscStat(const std::vector< XAie_LocType > &vLocs, XAie_ModuleType Mod, XAieRscType RscType, uint32_t RscId) const
Definition xaiefal-rsc-group.hpp:340
static std::vector< XAie_LocType > _getAllTilesLocs(XAie_DevInst *DevInst)
Definition xaiefal-rsc-group.hpp:369
~XAieRscGroupBase()
Definition xaiefal-rsc-group.hpp:209
XAieRscStat getRscStat(const std::vector< XAie_LocType > &vLocs, XAieRscType RscType) const
Definition xaiefal-rsc-group.hpp:297
virtual AieRC addRsc(std::shared_ptr< XAieRsc > Rsc)
Definition xaiefal-rsc-group.hpp:320
XAieRscStat getRscStat(XAie_LocType Loc, XAie_ModuleType Mod, XAieRscType RscType, uint32_t RscId) const
Definition xaiefal-rsc-group.hpp:283
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
XAieRscGroupBase()
Definition xaiefal-rsc-group.hpp:208
XAieRscStat getRscStat(const std::vector< XAie_LocType > &vLocs, XAieRscType RscType, uint32_t RscId) const
Definition xaiefal-rsc-group.hpp:314
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
XAieRscStat getRscStat(XAie_LocType Loc, XAie_ModuleType Mod, XAieRscType RscType) const
Definition xaiefal-rsc-group.hpp:267
XAieRscStat _getRscStatTile(XAie_LocType Loc, XAie_ModuleType Mod, XAieRscType RscType, uint32_t RscId) const
Definition xaiefal-rsc-group.hpp:353
XAieRscStat getRscStat(XAie_LocType Loc) const
Definition xaiefal-rsc-group.hpp:228
XAieRscStat getRscStat() const
Definition xaiefal-rsc-group.hpp:217
Base AI engine resource class. It defines resource operations and maintains resource state machine.
Definition xaiefal-rsc-base.hpp:69
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_COMBOEVENT
Definition xaiefal-rsc-group.hpp:34
@ XAIE_MDMPERFCNT
Definition xaiefal-rsc-group.hpp:36
@ XAIE_GROUPEVENT
Definition xaiefal-rsc-group.hpp:35
@ XAIE_SSEVENT
Definition xaiefal-rsc-group.hpp:32
@ XAIE_PERFCOUNT
Definition xaiefal-rsc-group.hpp:28
@ XAIE_TRACEEVENT
Definition xaiefal-rsc-group.hpp:38
@ XAIE_PCEVENT
Definition xaiefal-rsc-group.hpp:31
@ XAIE_MAXRSC
Definition xaiefal-rsc-group.hpp:37
@ XAIE_TRACECTRL
Definition xaiefal-rsc-group.hpp:30
@ XAIE_BROADCAST
Definition xaiefal-rsc-group.hpp:33
@ XAIE_USEREVENT
Definition xaiefal-rsc-group.hpp:29
@ FAL_INFO
Definition xaiefal-log.hpp:12
Definition xaiefal-rsc-base.hpp:609
struct of resource usage statistics
Definition xaiefal-rsc-group.hpp:66
std::map< std::tuple< uint8_t, uint8_t, uint32_t, uint32_t >, uint32_t > Rscs
Definition xaiefal-rsc-group.hpp:71
uint32_t getNumRsc(XAie_LocType Loc, XAie_ModuleType Mod, XAieRscType RscType)
Definition xaiefal-rsc-group.hpp:109
std::string GroupName
Definition xaiefal-rsc-group.hpp:69
XAieRscStat(const std::string &Name="")
Definition xaiefal-rsc-group.hpp:67
void show() const
Definition xaiefal-rsc-group.hpp:136
bool hasRsc() const
Definition xaiefal-rsc-group.hpp:129
void addRscStat(XAie_LocType Loc, XAie_ModuleType Mod, XAieRscType RscType, uint32_t NumRscs)
Definition xaiefal-rsc-group.hpp:82
Data needed to make resource statistics request.
Definition xaiefal-rsc-group.hpp:45
XAie_LocType Loc
Definition xaiefal-rsc-group.hpp:47
XAieRscType RscType
Definition xaiefal-rsc-group.hpp:55
XAie_ModuleType Mod
Definition xaiefal-rsc-group.hpp:51
uint32_t NumRscs
Definition xaiefal-rsc-group.hpp:59
#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