xaiefal
Loading...
Searching...
No Matches
xaiefal-ss.hpp
Go to the documentation of this file.
1// Copyright(C) 2020 - 2021 by Xilinx, Inc. All rights reserved.
2// SPDX-License-Identifier: MIT
3
4#include <fstream>
5#include <functional>
6#include <string.h>
7#include <vector>
8#include <xaiengine.h>
9
10#include <xaiefal/rsc/xaiefal-rsc-base.hpp>
11
12#pragma once
13
14namespace xaiefal {
23 public:
25 XAieStreamPortSelect(std::shared_ptr<XAieDevHandle> DevHd,
26 XAie_LocType Loc):
28 State.Initialized = 1;
29 }
30 XAieStreamPortSelect(XAieDev &Dev, XAie_LocType Loc):
31 XAieSingleTileRsc(Dev.getDevHandle(), Loc, XAIE_SSEVENT) {}
32
41 AieRC setPortToSelect(XAie_StrmPortIntf PIntf, StrmSwPortType PType,
42 uint32_t PNum) {
43 AieRC RC;
44
45 if (State.Running == 1) {
46 Logger::log(LogLevel::FAL_ERROR) << "Stream port select " << __func__ << " (" <<
47 (uint32_t)Loc.Col << "," << (uint32_t)Loc.Row << ")" <<
48 " resource is in use." << std::endl;
49 RC = XAIE_ERR;
50 } else {
51 PortIntf = PIntf;
52 PortType = PType;
53 PortNum = PNum;
54 State.Configured = 1;
55 RC = XAIE_OK;
56 }
57 return RC;
58 }
59
65 AieRC getSSIdleEvent(XAie_Events &Event) const {
66 AieRC RC;
67
68 if (State.Reserved == 0) {
69 Logger::log(LogLevel::FAL_ERROR) << "Stream port select " << __func__ << " (" <<
70 (uint32_t)Loc.Col << "," << (uint32_t)Loc.Row << ")" <<
71 " resource not reserved." << std::endl;
72 RC = XAIE_ERR;
73 } else {
74 XAie_EventGetIdlePortEventBase(AieHd->dev(), Loc, Mod, &Event);
75 Event = static_cast<XAie_Events>(static_cast<XAie_Events>(Event) + vRscs[0].RscId * 4);
76 RC = XAIE_OK;
77 }
78 return RC;
79 }
80
86 AieRC getSSRunningEvent(XAie_Events &Event) const {
87 AieRC RC;
88
89 RC = getSSIdleEvent(Event);
90 if (RC == XAIE_OK) {
91 Event = (XAie_Events)((uint32_t)Event + 1);
92 }
93 return RC;
94 }
95
101 AieRC getSSStalledEvent(XAie_Events &Event) const {
102 AieRC RC;
103
104 RC = getSSIdleEvent(Event);
105 if (RC == XAIE_OK) {
106 Event = (XAie_Events)((uint32_t)Event + 2);
107 }
108 return RC;
109 }
110
116 AieRC getSSTlastEvent(XAie_Events &Event) const {
117 AieRC RC;
118
119 RC = getSSIdleEvent(Event);
120 if (RC == XAIE_OK) {
121 Event = (XAie_Events)((uint32_t)Event + 3);
122 }
123 return RC;
124 }
125 private:
126 XAie_StrmPortIntf PortIntf;
127 StrmSwPortType PortType;
128 uint8_t PortNum;
129 protected:
130 AieRC _reserve() {
131 AieRC RC;
132 XAieUserRsc Rsc;
133
134 Rsc.Loc = Loc;
135 Rsc.Mod = Mod;
136 Rsc.RscType = Type;
137 Rsc.RscId = preferredId;
138
139 vRscs.push_back(Rsc);
140 RC = AieHd->rscMgr()->request(*this);
141 if (RC != XAIE_OK) {
142 Logger::log(LogLevel::FAL_WARN) << "Stream port select " << __func__ <<
143 " (" << static_cast<int>(Loc.Col) << "," <<
144 static_cast<int>(Loc.Row) << ")" << " resource not available.\n";
145 vRscs.clear();
146 } else {
147 reservedId = vRscs[0].RscId;
148 }
149 return RC;
150 }
151 AieRC _release() {
152 AieRC RC;
153
154 RC = AieHd->rscMgr()->free(*this);
155 vRscs.clear();
156 return RC;
157 }
158 AieRC _start() {
159 AieRC RC;
160
161 RC = XAie_EventSelectStrmPort(dev(), Loc, vRscs[0].RscId,
162 PortIntf, PortType, PortNum);
163 if (RC != XAIE_OK) {
164 Logger::log(LogLevel::FAL_ERROR) << "Stream port select " << __func__ << " (" <<
165 (uint32_t)Loc.Col << "," << (uint32_t)Loc.Row << ")" <<
166 " failed to start." << std::endl;
167 }
168 return RC;
169 }
170 AieRC _stop() {
171 AieRC RC;
172
173 RC = XAie_EventSelectStrmPortReset(dev(), Loc, vRscs[0].RscId);
174 if (RC != XAIE_OK) {
175 Logger::log(LogLevel::FAL_ERROR) << "Stream port select " << __func__ << " (" <<
176 (uint32_t)Loc.Col << "," << (uint32_t)Loc.Row << ")" <<
177 " failed to stop." << std::endl;
178 }
179 return RC;
180 }
181 };
182}
static std::ostream & log(LogLevel Lvl=LogLevel::FAL_MAX)
Definition xaiefal-log.hpp:50
AI engine device class. It defines AI engine device operations.
Definition xaiefal-base.hpp:259
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
XAie_DevInst * dev()
Definition xaiefal-rsc-base.hpp:373
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
XAie_LocType Loc
Definition xaiefal-rsc-base.hpp:594
XAie_ModuleType Mod
Definition xaiefal-rsc-base.hpp:595
XAieStreamPortSelect(std::shared_ptr< XAieDevHandle > DevHd, XAie_LocType Loc)
Definition xaiefal-ss.hpp:25
AieRC getSSRunningEvent(XAie_Events &Event) const
Definition xaiefal-ss.hpp:86
AieRC _stop()
Definition xaiefal-ss.hpp:170
AieRC _reserve()
Definition xaiefal-ss.hpp:130
AieRC setPortToSelect(XAie_StrmPortIntf PIntf, StrmSwPortType PType, uint32_t PNum)
Definition xaiefal-ss.hpp:41
AieRC getSSStalledEvent(XAie_Events &Event) const
Definition xaiefal-ss.hpp:101
AieRC _release()
Definition xaiefal-ss.hpp:151
XAieStreamPortSelect(XAieDev &Dev, XAie_LocType Loc)
Definition xaiefal-ss.hpp:30
AieRC _start()
Definition xaiefal-ss.hpp:158
AieRC getSSTlastEvent(XAie_Events &Event) const
Definition xaiefal-ss.hpp:116
AieRC getSSIdleEvent(XAie_Events &Event) const
Definition xaiefal-ss.hpp:65
Definition xaiefal-base.hpp:23
@ XAIE_SSEVENT
Definition xaiefal-rsc-group.hpp:32
@ FAL_ERROR
Definition xaiefal-log.hpp:14
@ FAL_WARN
Definition xaiefal-log.hpp:13
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