xaiefal
Loading...
Searching...
No Matches
xaiefal-events.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#include <xaiefal/rsc/xaiefal-rscmgr.hpp>
12
13#pragma once
14
15namespace xaiefal {
21 public:
22 XAieComboEvent() = delete;
23 XAieComboEvent(std::shared_ptr<XAieDevHandle> DevHd,
24 XAie_LocType Loc, XAie_ModuleType Mod, uint32_t ENum = 2):
26 if (ENum > 4 || ENum < 2) {
27 throw std::invalid_argument("Combo event failed, invalid input events number");
28 }
29 vEvents.resize(ENum);
30 State.Initialized = 1;
31 }
33 XAie_LocType Loc, XAie_ModuleType Mod, uint32_t ENum = 2):
34 XAieComboEvent(Dev.getDevHandle(), Loc, Mod, ENum) {}
35
48 AieRC setEvents(const std::vector<XAie_Events> &vInEvents,
49 const std::vector<XAie_EventComboOps> &vInOps) {
50 AieRC RC;
51 if ((vInEvents.size() != vEvents.size()) || (vInOps.size() > 3) ||
52 (vInEvents.size() <= 2 && vInOps.size() > 1) ||
53 (vInEvents.size() > 2 && vInOps.size() < 2)) {
54 Logger::log(LogLevel::FAL_ERROR) << "combo event " << __func__ << " (" <<
55 (uint32_t)Loc.Col << "," << (uint32_t)Loc.Row <<
56 " Mod=" << Mod << " invalid number of input events and ops." << std::endl;
57 RC = XAIE_INVALID_ARGS;
58 } else {
59 for (int i = 0; i < (int)vInEvents.size(); i++) {
60 uint16_t HwEvent;
61
62 RC = XAie_EventLogicalToPhysicalConv(dev(), Loc,
63 Mod, vInEvents[i], &HwEvent);
64 if (RC != XAIE_OK) {
65 Logger::log(LogLevel::FAL_ERROR) << "combo event " << __func__ << " (" <<
66 (uint32_t)Loc.Col << "," << (uint32_t)Loc.Row <<
67 " Mod=" << Mod << " invalid E=" << vInEvents[i] <<
68 " (" << XAie_EventGetString(vInEvents[i]) << ")" << std::endl;
69 break;
70 } else {
71 vEvents[i] = vInEvents[i];
72 }
73 }
74 if (RC == XAIE_OK) {
75 vOps.clear();
76 for (int i = 0; i < (int)vInOps.size(); i++) {
77 vOps.push_back(vInOps[i]);
78 }
79 State.Configured = 1;
80 }
81 }
82 return RC;
83 }
84
94 AieRC getEvents(std::vector<XAie_Events> &vOutEvents) {
95 AieRC RC;
96
97 (void)vOutEvents;
98 if (State.Reserved == 0) {
99 Logger::log(LogLevel::FAL_ERROR) << "combo event " << __func__ << " (" <<
100 (uint32_t)Loc.Col << "," << (uint32_t)Loc.Row <<
101 " Mod=" << Mod << " resource is not reserved." << std::endl;
102 RC = XAIE_ERR;
103 } else {
104 XAie_Events BaseEvent;
105 XAie_EventGetComboEventBase(dev(), Loc, Mod, &BaseEvent);
106 vOutEvents.clear();
107 if (vOps.size() == 1) {
108 vOutEvents.push_back((XAie_Events)((uint32_t)BaseEvent + vRscs[0].RscId));
109 } else {
110 for (uint32_t i = 0; i < (uint32_t)vOps.size(); i++) {
111 vOutEvents.push_back((XAie_Events)((uint32_t)BaseEvent + i));
112 }
113 }
114 RC = XAIE_OK;
115 }
116 return RC;
117 }
118
119 AieRC getInputEvents(std::vector<XAie_Events> &vOutEvents,
120 std::vector<XAie_EventComboOps> &vOutOps) {
121 AieRC RC;
122
123 if (State.Configured == 1) {
124 vOutEvents.clear();
125 for (int i = 0; i < (int)vEvents.size(); i++) {
126 vOutEvents.push_back(vEvents[i]);
127 }
128 vOutOps.clear();
129 for (int i = 0; i < (int)vOps.size(); i++) {
130 vOutOps.push_back(vOps[i]);
131 }
132 RC = XAIE_OK;
133 } else {
134 Logger::log(LogLevel::FAL_ERROR) << "combo event " << __func__ << " (" <<
135 (uint32_t)Loc.Col << "," << (uint32_t)Loc.Row <<
136 " Mod=" << Mod << " no input events specified." << std::endl;
137 RC = XAIE_ERR;
138 }
139 return RC;
140 }
141 protected:
142 std::vector<XAie_Events> vEvents;
143 std::vector<XAie_EventComboOps> vOps;
144 private:
145 AieRC _reserve() {
146 AieRC RC;
147 XAieUserRsc Rsc;
148
149 Rsc.Loc = Loc;
150 Rsc.Mod = Mod;
151 Rsc.RscType = Type;
152 Rsc.RscId = 0;
153 for (uint32_t i = 0; i < vEvents.size(); i++) {
154 vRscs.push_back(Rsc);
155 }
156
157 RC = AieHd->rscMgr()->request(*this);
158 if (RC != XAIE_OK) {
159 Logger::log(LogLevel::FAL_WARN) << "comboevent " << __func__ << " (" <<
160 (uint32_t)Loc.Col << "," << (uint32_t)Loc.Row << ")" <<
161 " Expect Mod= " << Mod << " resource not available.\n";
162 vRscs.clear();
163 } else {
164 if (vRscs.size() <= 2) {
165 /*
166 * Only two input events, it can be combo0 or
167 * combo1
168 */
169 if (vRscs[0].RscId < 2) {
170 reservedId = 0;
171 } else {
172 reservedId = 1;
173 }
174 } else {
175 reservedId = 2;
176 }
177 }
178 return RC;
179 }
180 AieRC _release() {
181 AieRC RC;
182
183 RC = AieHd->rscMgr()->release(*this);
184 vRscs.clear();
185 return RC;
186 }
187 AieRC _start() {
188 AieRC RC;
189 XAie_EventComboId StartCId;
190
191 for (uint32_t i = 0 ; i < vEvents.size(); i += 2) {
192 XAie_EventComboId ComboId;
193
194 if (vRscs[i].RscId == 0) {
195 ComboId = XAIE_EVENT_COMBO0;
196 } else {
197 ComboId = XAIE_EVENT_COMBO1;
198 }
199 if (i == 0) {
200 StartCId = ComboId;
201 }
202 RC = XAie_EventComboConfig(dev(), Loc, Mod,
203 ComboId, vOps[i/2], vEvents[i], vEvents[i+1]);
204 if (RC != XAIE_OK) {
205 Logger::log(LogLevel::FAL_ERROR) << "combo event " << __func__ << " (" <<
206 (uint32_t)Loc.Col << "," << (uint32_t)Loc.Row <<
207 " Mod=" << Mod << " failed to config combo " << ComboId << std::endl;
208 for (XAie_EventComboId tId = StartCId;
209 tId < ComboId;
210 tId = (XAie_EventComboId)((int)tId + i)) {
211 XAie_EventComboReset(dev(), Loc, Mod,
212 tId);
213 }
214 break;
215 }
216 }
217 if (RC == XAIE_OK && vOps.size() == 3) {
218 RC = XAie_EventComboConfig(dev(), Loc, Mod,
219 XAIE_EVENT_COMBO2, vOps[2], vEvents[0], vEvents[0]);
220 if (RC != XAIE_OK) {
221 Logger::log(LogLevel::FAL_ERROR) << "combo event " << __func__ << " (" <<
222 (uint32_t)Loc.Col << "," << (uint32_t)Loc.Row <<
223 " Mod=" << Mod << " failed to config combo " << XAIE_EVENT_COMBO2 << std::endl;
224 }
225 }
226 return RC;
227 }
228 AieRC _stop() {
229 XAie_EventComboId ComboId;
230
231 for (int i = 0; i < (int)vOps.size(); i++) {
232 if (i == 0) {
233 if (vRscs[i].RscId == 0) {
234 ComboId = XAIE_EVENT_COMBO0;
235 } else {
236 ComboId = XAIE_EVENT_COMBO1;
237 }
238 XAie_EventComboReset(dev(), Loc, Mod, ComboId);
239 ComboId = (XAie_EventComboId)((uint32_t)ComboId + 1);
240 }
241 }
242 return XAIE_OK;
243 }
244 void _getReservedRscs(std::vector<XAieUserRsc> &vOutRscs) const {
245 vOutRscs.insert(vOutRscs.end(), vRscs.begin(), vRscs.end());
246 }
247 };
248
254 public:
255 XAieUserEvent() = delete;
256 XAieUserEvent(std::shared_ptr<XAieDevHandle> DevHd,
257 XAie_LocType Loc, XAie_ModuleType Mod):
259 State.Initialized = 1;
260 State.Configured = 1;
261 }
263 XAie_LocType Loc, XAie_ModuleType Mod):
264 XAieUserEvent(Dev.getDevHandle(), Loc, Mod) {}
265
273 AieRC getEvent(XAie_Events &Event) const {
274 AieRC RC = XAIE_OK;
275
276 if (State.Reserved == 0) {
277 Logger::log(LogLevel::FAL_ERROR) << "User Event " << __func__ << " (" <<
278 static_cast<uint32_t>(Loc.Col) << "," << static_cast<uint32_t>(Loc.Row) << ")" <<
279 " resource not resesrved." << std::endl;
280 RC = XAIE_INVALID_ARGS;
281 } else {
282 Event = _getEventFromId(vRscs[0].RscId);
283 }
284 return RC;
285 }
286 private:
287 AieRC _reserve() {
288 AieRC RC;
289 XAieUserRsc Rsc;
290 Rsc.Loc = Loc;
291 Rsc.Mod = Mod;
292 Rsc.RscType = Type;
293 Rsc.RscId = preferredId;
294
295 vRscs.push_back(Rsc);
296 RC = AieHd->rscMgr()->request(*this);
297 if (RC != XAIE_OK) {
298 Logger::log(LogLevel::FAL_WARN) << "userevent " << __func__ << " (" <<
299 (uint32_t)Loc.Col << "," << (uint32_t)Loc.Row << ")" <<
300 " Expect Mod= " << Mod << " resource not available.\n";
301 vRscs.clear();
302 } else {
303 reservedId = vRscs[0].RscId;
304 }
305 return RC;
306 }
307 AieRC _release() {
308 AieRC RC;
309
310 RC = AieHd->rscMgr()->release(*this);
311 vRscs.clear();
312 return RC;
313 }
314 AieRC _start() {
315 // As no hardware config is required for user event
316 // always succeeds.
317 return XAIE_OK;
318 }
319 AieRC _stop() {
320 // As no hardware config is required for user event
321 // always succeeds.
322 return XAIE_OK;
323 }
324
331 uint32_t _getIdFromEvent(XAie_Events Event) const {
332 XAie_Events UserEventStart;
333 XAie_EventGetUserEventBase(AieHd->dev(), Loc, Mod, &UserEventStart);
334
335 return static_cast<uint32_t>(Event - UserEventStart);
336 }
337
344 XAie_Events _getEventFromId(uint32_t RscId) const {
345 XAie_Events UserEventStart;
346 XAie_EventGetUserEventBase(AieHd->dev(), Loc, Mod, &UserEventStart);
347
348 return static_cast<XAie_Events>(static_cast<uint32_t>(UserEventStart) + RscId);
349 }
350 };
351}
static std::ostream & log(LogLevel Lvl=LogLevel::FAL_MAX)
Definition xaiefal-log.hpp:50
AieRC setEvents(const std::vector< XAie_Events > &vInEvents, const std::vector< XAie_EventComboOps > &vInOps)
Definition xaiefal-events.hpp:48
std::vector< XAie_Events > vEvents
Definition xaiefal-events.hpp:142
std::vector< XAie_EventComboOps > vOps
Definition xaiefal-events.hpp:143
XAieComboEvent(std::shared_ptr< XAieDevHandle > DevHd, XAie_LocType Loc, XAie_ModuleType Mod, uint32_t ENum=2)
Definition xaiefal-events.hpp:23
AieRC getEvents(std::vector< XAie_Events > &vOutEvents)
Definition xaiefal-events.hpp:94
XAieComboEvent(XAieDev &Dev, XAie_LocType Loc, XAie_ModuleType Mod, uint32_t ENum=2)
Definition xaiefal-events.hpp:32
AieRC getInputEvents(std::vector< XAie_Events > &vOutEvents, std::vector< XAie_EventComboOps > &vOutOps)
Definition xaiefal-events.hpp:119
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
AieRC getEvent(XAie_Events &Event) const
Definition xaiefal-events.hpp:273
XAieUserEvent(XAieDev &Dev, XAie_LocType Loc, XAie_ModuleType Mod)
Definition xaiefal-events.hpp:262
XAieUserEvent(std::shared_ptr< XAieDevHandle > DevHd, XAie_LocType Loc, XAie_ModuleType Mod)
Definition xaiefal-events.hpp:256
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_COMBOEVENT
Definition xaiefal-rsc-group.hpp:34
@ XAIE_USEREVENT
Definition xaiefal-rsc-group.hpp:29
@ 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