11#include <xaiefal/rsc/xaiefal-bc.hpp>
12#include <xaiefal/rsc/xaiefal-rsc-base.hpp>
13#include <xaiefal/rsc/xaiefal-rscmgr.hpp>
17#define NUM_LATENCY_READS 4U
37 bool CrossM =
false, uint32_t Threshold = 0):
44 State.Initialized = 1;
52 if (
State.Reserved == 1) {
59 if (
RstEvent != XAIE_EVENT_NONE_CORE &&
79 XAie_ModuleType RstM = XAIE_CORE_MOD, XAie_Events RstE = XAIE_EVENT_NONE_CORE) {
82 if (
State.Reserved == 1) {
84 (uint32_t)
Loc.Col <<
"," << (uint32_t)
Loc.Row <<
")" <<
85 " Expect Mod= " <<
Mod <<
" resource reserved." << std::endl;
90 RC = XAie_EventLogicalToPhysicalConv(
dev(),
Loc,
91 StartM, StartE, &HwEvent);
93 RC = XAie_EventLogicalToPhysicalConv(
dev(),
Loc,
94 StopM, StopE, &HwEvent);
96 if (RC == XAIE_OK && RstE != XAIE_EVENT_NONE_CORE) {
97 RC = XAie_EventLogicalToPhysicalConv(
dev(),
Loc,
98 RstM, RstE, &HwEvent);
106 if (RstE != XAIE_EVENT_NONE_CORE) {
109 State.Initialized = 1;
110 State.Configured = 1;
113 (uint32_t)
Loc.Col <<
"," << (uint32_t)
Loc.Row <<
")" <<
114 " Expect Mod= " <<
Mod <<
115 " StartEvent=" <<StartM <<
"|" << StartE <<
" (" <<
116 XAie_EventGetString(StartE) <<
") " <<
117 " StopEvent=" <<StopM <<
"|" << StopE <<
" (" <<
118 XAie_EventGetString(StopE) <<
") " <<
119 " RstEvent=" <<RstM <<
"|" << RstE <<
" (" <<
120 XAie_EventGetString(RstE) <<
") " <<
148 if (
State.Running == 1) {
150 (int)
Loc.Col <<
"," << (
int)
Loc.Row <<
")" <<
151 " Expect Mod= " <<
Mod <<
" Actual Mod=" << (int)
vRscs[0].
Mod <<
152 " resource is in use" << std::endl;
154 }
else if (
State.Reserved == 1 && Module !=
RstMod) {
156 (int)
Loc.Col <<
"," << (
int)
Loc.Row <<
")" <<
157 " Expect Mod= " <<
Mod <<
" Actual Mod=" << (int)
vRscs[0].
Mod <<
158 " resource is reserved, event module type cannot change." <<
160 RC = XAIE_INVALID_ARGS;
164 RC = XAie_EventLogicalToPhysicalConv(
dev(),
165 Loc, Module, Event, &HwEvent);
184 if (
State.Running == 1) {
186 (int)
Loc.Col <<
"," << (
int)
Loc.Row <<
")" <<
187 " Expect Mod= " <<
Mod <<
" Actual Mod=" << (int)
vRscs[0].
Mod <<
188 " resource is in use." << std::endl;
209 if (
State.Running == 1) {
211 (int)
Loc.Col <<
"," << (
int)
Loc.Row <<
")" <<
212 " Expect Mod= " <<
Mod <<
" Actual Mod=" << (int)
vRscs[0].
Mod <<
213 " resource is in use." << std::endl;
217 (int)
Loc.Col <<
"," << (
int)
Loc.Row <<
")" <<
218 " Expect Mod= " <<
Mod <<
" Actual Mod=" << (int)
vRscs[0].
Mod <<
219 " resource is reserved, event module type cannot change." <<
221 RC = XAIE_INVALID_ARGS;
225 RC = XAie_EventLogicalToPhysicalConv(
dev(),
Loc,
226 Module, Event, &HwEvent);
246 if (
State.Running == 1) {
248 (int)
Loc.Col <<
"," << (
int)
Loc.Row <<
")" <<
249 " Expect Mod= " <<
Mod <<
" Actual Mod=" << (int)
vRscs[0].
Mod <<
250 " resource is in use." << std::endl;
254 (int)
Loc.Col <<
"," << (
int)
Loc.Row <<
")" <<
255 " Expect Mod= " <<
Mod <<
" Actual Counter Mod=" << (int)
vRscs[0].
Mod <<
256 " resource is reserved, event module type cannot change." <<
258 RC = XAIE_INVALID_ARGS;
262 RC = XAie_EventLogicalToPhysicalConv(
dev(),
Loc,
263 Module, Event, &HwEvent);
281 if (
State.Running == 0) {
283 (uint32_t)
Loc.Col <<
"," << (uint32_t)
Loc.Row <<
")" <<
284 " Expect Mod= " <<
Mod <<
285 " resource not in use." << std::endl;
289 vRscs[0].RscId, &Result);
303 if (
State.Reserved == 0) {
305 (uint32_t)
Loc.Col <<
"," << (uint32_t)
Loc.Row <<
")" <<
306 " Expect Mod= " <<
Mod <<
307 " resource not allocated." << std::endl;
310 Module =
vRscs[0].Mod;
311 XAie_PerfCounterGetEventBase(
AieHd->dev(),
Loc, Module, &Event);
312 Event =
static_cast<XAie_Events
>(
static_cast<uint32_t
>(Event) +
vRscs[0].RscId);
324 return AieHd->getRscGroup(GName).getRscStat(
Loc,
327 return AieHd->getRscGroup(GName).getRscStat(
Loc,
331 return AieHd->getRscGroup(GName).getRscStat(
Loc,
351 uint32_t TType = XAie_GetTileTypefromLoc(
dev(),
Loc);
358 vRscs.push_back(Rsc);
359 RC =
AieHd->rscMgr()->request(*
this);
361 if (TType == XAIEGBL_TILE_TYPE_AIETILE &&
CrossMod) {
364 if (
Mod == XAIE_CORE_MOD) {
370 RC =
AieHd->rscMgr()->request(*
this);
373 if (RC == XAIE_OK && TType == XAIEGBL_TILE_TYPE_AIETILE) {
374 std::vector<XAie_LocType> vL;
397 if (RC == XAIE_OK &&
RstEvent != XAIE_EVENT_NONE_CORE &&
401 RC =
RstBC->reserve();
415 AieHd->rscMgr()->release(*
this);
421 (uint32_t)
Loc.Col <<
"," << (uint32_t)
Loc.Row <<
")" <<
422 " Expect Mod= " <<
Mod <<
" resource not available.\n";
426 RC = _reserveAppend();
447 RC =
AieHd->rscMgr()->release(*
this);
454 RC = _startPrepend();
488 vRscs[0].RscId, lStartE, lStopE);
490 if (RC == XAIE_OK &&
RstEvent != XAIE_EVENT_NONE_CORE) {
491 RC = XAie_PerfCounterResetControlSet(
dev(),
Loc,
498 (int)
Loc.Col <<
"," << (
int)
Loc.Row <<
")" <<
499 " Expect Mod= " <<
Mod <<
" Actual Mod=" << (int)
vRscs[0].
Mod <<
500 " failed to start." << std::endl;
515 iRC |= XAie_EventBroadcastReset(
dev(),
Loc,
521 iRC |= XAie_EventBroadcastReset(
dev(),
Loc,
527 iRC |= XAie_EventBroadcastReset(
dev(),
Loc,
529 iRC |=
RstBC->stop();
531 if (iRC != (
int)XAIE_OK) {
533 (uint32_t)
Loc.Col <<
"," << (uint32_t)
Loc.Row <<
")" <<
534 " Expect Mod= " << (int)
Mod <<
" Actual Mod=" << (
int)
vRscs[0].Mod <<
535 " failed to stop." << std::endl;
543 void _getReservedRscs(std::vector<XAieUserRsc> &vOutRscs)
const {
544 vOutRscs.push_back(
vRscs[0]);
546 StartBC->getReservedRscs(vOutRscs);
549 StopBC->getReservedRscs(vOutRscs);
552 RstBC->getReservedRscs(vOutRscs);
554 _getRscsAppend(vOutRscs);
556 virtual AieRC _startPrepend() {
559 virtual AieRC _reserveAppend() {
562 virtual AieRC _stopAppend() {
565 virtual AieRC _releaseAppend() {
568 virtual void _getRscsAppend(std::vector<XAieUserRsc> &vOutRscs)
const {
583 uint8_t TType =
dev()->DevOps->GetTTypefromLoc(
dev(),
Loc);
585 if(XAie_IsUcModulePresent(
dev(), TType) == 0U)
586 throw std::invalid_argument(
"Tile does not contain uC MDM");
588 if (XAie_MdmPerfCounterGetConfig(
dev(),
Loc,
589 &NumEventCounters, &NumLatCounters,
590 &CounterWidth) != XAIE_OK)
591 throw std::invalid_argument(
"Failed to get MDM configuration");
593 if (CounterWidth != 32U)
594 throw std::invalid_argument(
"MDM configuration not supported");
596 CounterStatus.resize(NumEventCounters + NumLatCounters, 0U);
598 CounterVals.resize(NumEventCounters + (NumLatCounters * 4U), 0U);
599 State.Initialized = 1;
612 if (
State.Reserved == 1) {
614 (uint32_t)
Loc.Col <<
"," << (uint32_t)
Loc.Row <<
")" <<
615 " resource reserved." << std::endl;
618 if (UcEvents.size() != NumLatCounters + NumEventCounters) {
620 << __func__ <<
" (" << (uint32_t)
Loc.Col <<
621 "," << (uint32_t)
Loc.Row <<
")" <<
622 " invalid UcEvent size" << std::endl;
623 return XAIE_INVALID_ARGS;
626 RC = XAie_MdmPerfCounterControlSet(
dev(),
Loc,
630 "MDM perfcount " << __func__ <<
631 " (" << (uint32_t)
Loc.Col <<
"," <<
632 (uint32_t)
Loc.Row <<
")" <<
633 " failed to set MDM counter event control." <<
638 State.Configured = 1;
652 if (
State.Running == 0) {
654 __func__ <<
" (" << (uint32_t)
Loc.Col <<
"," <<
655 (uint32_t)
Loc.Row <<
")" <<
656 " resource not in use." << std::endl;
660 RC = XAie_MdmPerfCounterStop(
dev(),
Loc, 1U);
663 "MDM perfcount " << __func__ <<
664 " (" << (uint32_t)
Loc.Col <<
"," <<
665 (uint32_t)
Loc.Row <<
")" <<
666 " failed to stop MDM counters" <<
672 RC = XAie_MdmPerfCounterGetStatus(
dev(),
Loc,
673 CounterStatus.data());
676 "MDM perfcount " << __func__ <<
677 " (" << (uint32_t)
Loc.Col <<
"," <<
678 (uint32_t)
Loc.Row <<
")" <<
679 " failed to read MDM counters status" <<
684 for (uint8_t i = 0; i < CounterStatus.size(); i++) {
685 if (CounterStatus[i] & 0x1) {
687 "MDM perfcount " << __func__ <<
688 " (" << (uint32_t)
Loc.Col <<
"," <<
689 (uint32_t)
Loc.Row <<
")" <<
691 " is full" << std::endl;
692 }
else if (CounterStatus[i] & 0x2) {
694 "MDM perfcount " << __func__ <<
695 " (" << (uint32_t)
Loc.Col <<
"," <<
696 (uint32_t)
Loc.Row <<
")" <<
698 " overflowed" << std::endl;
703 RC = XAie_MdmPerfCounterGet(
dev(),
Loc,
707 "MDM perfcount " << __func__ <<
708 " (" << (uint32_t)
Loc.Col <<
"," <<
709 (uint32_t)
Loc.Row <<
")" <<
710 " failed to read MDM counters values" <<
715 Result = CounterVals;
722 std::vector<uint8_t> CounterStatus;
723 std::vector<uint32_t> CounterVals;
724 u8 NumLatCounters, NumEventCounters, CounterWidth;
734 vRscs.push_back(Rsc);
736 RC =
AieHd->rscMgr()->request(*
this);
739 __func__ <<
" (" << (uint32_t)
Loc.Col <<
740 "," << (uint32_t)
Loc.Row <<
")" <<
741 " resource not available.\n";
752 RC =
AieHd->rscMgr()->release(*
this);
760 RC = XAie_MdmPerfCounterReset(
dev(),
Loc);
763 typeid(*this).name() <<
" failed to clear MDM counters"
768 RC = XAie_MdmPerfCounterStart(
dev(),
Loc);
771 typeid(*this).name() <<
" failed to start MDM counters"
781 RC = XAie_MdmPerfCounterReset(
dev(),
Loc);
784 typeid(*this).name() <<
" failed to clear MDM counters"
789 RC = XAie_MdmPerfCounterControlReset(
dev(),
Loc);
792 typeid(*this).name() <<
793 " failed to clear MDM counter event control"
static std::ostream & log(LogLevel Lvl=LogLevel::FAL_MAX)
Definition xaiefal-log.hpp:50
class for broadcast channel resource. A broadcast channel resource represents a broadcast channel bet...
Definition xaiefal-bc.hpp:29
AI engine device class. It defines AI engine device operations.
Definition xaiefal-base.hpp:259
~XAieMdmPerfCounter()
Definition xaiefal-perf.hpp:601
AieRC readResult(std::vector< uint32_t > &Result)
Definition xaiefal-perf.hpp:649
AieRC initialize(std::vector< uint8_t > &UcEvents)
Definition xaiefal-perf.hpp:609
XAieMdmPerfCounter()=delete
XAieMdmPerfCounter(std::shared_ptr< XAieDevHandle > DevHd, XAie_LocType Loc)
Definition xaiefal-perf.hpp:580
XAiePerfCounter(XAieDev &Dev, XAie_LocType Loc, XAie_ModuleType Mod, bool CrossM=false)
Definition xaiefal-perf.hpp:47
AieRC readResult(uint32_t &Result)
Definition xaiefal-perf.hpp:278
XAie_Events RstEvent
Definition xaiefal-perf.hpp:338
XAieBroadcast * RstBC
Definition xaiefal-perf.hpp:347
bool CrossMod
Definition xaiefal-perf.hpp:343
AieRC getCounterEvent(XAie_ModuleType &Module, XAie_Events &Event) const
Definition xaiefal-perf.hpp:300
AieRC changeStartEvent(XAie_ModuleType Module, XAie_Events Event)
Definition xaiefal-perf.hpp:206
AieRC changeStopEvent(XAie_ModuleType Module, XAie_Events Event)
Definition xaiefal-perf.hpp:243
uint32_t EventVal
Definition xaiefal-perf.hpp:342
XAieBroadcast * StopBC
Definition xaiefal-perf.hpp:346
XAie_Events StopEvent
Definition xaiefal-perf.hpp:337
AieRC changeThreshold(uint32_t Val)
Definition xaiefal-perf.hpp:181
XAie_ModuleType StartMod
Definition xaiefal-perf.hpp:339
XAie_ModuleType StopMod
Definition xaiefal-perf.hpp:340
XAieRscStat getRscStat(const std::string &GName) const
Definition xaiefal-perf.hpp:318
XAiePerfCounter(std::shared_ptr< XAieDevHandle > DevHd, XAie_LocType Loc, XAie_ModuleType Mod, bool CrossM=false, uint32_t Threshold=0)
Definition xaiefal-perf.hpp:35
AieRC changeRstEvent(XAie_ModuleType Module, XAie_Events Event)
Definition xaiefal-perf.hpp:145
AieRC initialize(XAie_ModuleType StartM, XAie_Events StartE, XAie_ModuleType StopM, XAie_Events StopE, XAie_ModuleType RstM=XAIE_CORE_MOD, XAie_Events RstE=XAIE_EVENT_NONE_CORE)
Definition xaiefal-perf.hpp:77
bool getCrossMod()
Definition xaiefal-perf.hpp:132
XAieBroadcast * StartBC
Definition xaiefal-perf.hpp:345
~XAiePerfCounter()
Definition xaiefal-perf.hpp:51
XAie_ModuleType RstMod
Definition xaiefal-perf.hpp:341
XAie_Events StartEvent
Definition xaiefal-perf.hpp:336
XAieRscType Type
Definition xaiefal-rsc-base.hpp:399
std::vector< XAieUserRsc > vRscs
Definition xaiefal-rsc-base.hpp:403
XAieRscState State
Definition xaiefal-rsc-base.hpp:398
virtual XAieRscType getRscType() const
Definition xaiefal-rsc-base.hpp:351
XAie_DevInst * dev()
Definition xaiefal-rsc-base.hpp:373
AieRC release()
Definition xaiefal-rsc-base.hpp:188
uint32_t preferredId
Definition xaiefal-rsc-base.hpp:401
uint32_t reservedId
Definition xaiefal-rsc-base.hpp:402
std::shared_ptr< XAieDevHandle > AieHd
Definition xaiefal-rsc-base.hpp:400
XAieSingleTileRsc()=delete
XAie_LocType Loc
Definition xaiefal-rsc-base.hpp:594
XAie_ModuleType Mod
Definition xaiefal-rsc-base.hpp:595
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
@ XAIE_MDMPERFCNT
Definition xaiefal-rsc-group.hpp:36
@ XAIE_PERFCOUNT
Definition xaiefal-rsc-group.hpp:28
@ FAL_ERROR
Definition xaiefal-log.hpp:14
@ FAL_WARN
Definition xaiefal-log.hpp:13
struct of resource usage statistics
Definition xaiefal-rsc-group.hpp:66
Data needed to make a resource request.
Definition xaiefal-rsc-base.hpp:27
uint32_t RscId
Definition xaiefal-rsc-base.hpp:41
XAieRscType RscType
Definition xaiefal-rsc-base.hpp:37
XAie_LocType Loc
Definition xaiefal-rsc-base.hpp:29
XAie_ModuleType Mod
Definition xaiefal-rsc-base.hpp:33
#define XAIE_RSC_ID_ANY
Definition xaiefal-common.hpp:7