OpenASIP 2.2
Loading...
Searching...
No Matches
AutoSelectImplementationsDialog.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file AutoSelectImplementationsDialog.cc
26 *
27 * Definition of AutoSelectImplementationsDialog class.
28 *
29 * @author Mikko Järvelä 2013 (jarvela7-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include <wx/valgen.h>
34#include <wx/statline.h>
36#include "HDBRegistry.hh"
37#include "WxConversion.hh"
39#include "RegisterFile.hh"
40#include "ErrorDialog.hh"
41#include "ConfirmDialog.hh"
42#include "WarningDialog.hh"
43
44#if wxCHECK_VERSION(3, 0, 0)
45 #define wxOPEN wxFD_OPEN
46 #define wxFILE_MUST_EXIST wxFD_FILE_MUST_EXIST
47#endif
48
49using namespace IDF;
50using namespace TTAMachine;
51using namespace HDB;
52
53BEGIN_EVENT_TABLE(AutoSelectImplementationsDialog, wxDialog)
58
59const std::string AutoSelectImplementationsDialog::defaultHDB_
60 ("asic_130nm_1.5V.hdb");
61
62/**
63 * The Constructor.
64 *
65 * @param parent Parent window of the dialog.
66 * @param machine Current machine.
67 * @param impl Implementation of the machine.
68 */
70 wxWindow* parent,
73 wxDialog(parent, -1, _T("Auto Select Implementations"), wxDefaultPosition),
74 machine_(machine),
75 impl_(impl) {
76
77 createContents(this, true, true);
78
79 hdbChoice_ = dynamic_cast<wxChoice*>(FindWindow(ID_HDB_CHOICE));
80 cboxRF_ = dynamic_cast<wxCheckBox*>(FindWindow(ID_RF));
81 cboxIU_ = dynamic_cast<wxCheckBox*>(FindWindow(ID_IU));
82 cboxFU_ = dynamic_cast<wxCheckBox*>(FindWindow(ID_FU));
83
84 // set all checkboxes as selected
85 cboxRF_->SetValue(true);
86 cboxIU_->SetValue(true);
87 cboxFU_->SetValue(true);
88
89 // add available HDBs to the choice list
91 registry.loadFromSearchPaths();
92 for (int i = 0; i < registry.hdbCount(); i++) {
93 hdbs_.insert(registry.hdbPath(i));
94 }
95 if (!hdbs_.empty()) {
96 std::set<TCEString>::iterator iter = hdbs_.begin();
97 bool defaultHDBFound = false;
98 int selection = 0;
99 for (; iter != hdbs_.end(); iter++) {
100 std::string shortPath = Environment::shortHDBPath(*iter);
101 hdbChoice_->Append(WxConversion::toWxString(shortPath));
102 if (!defaultHDBFound && StringTools::endsWith(*iter, defaultHDB_)) {
103 selection = hdbChoice_->GetCount() - 1;
104 defaultHDBFound = true;
105 }
106 }
107 hdbChoice_->SetSelection(selection);
108 }
109}
110
111/**
112 * The Destructor.
113 */
116
117/**
118 * File dialog for choosing a custom HDB file.
119 */
120void
122
123 wxFileDialog dialog(
124 this, _T("Choose a HDB file containing the implementation"),
125 _T(""), _T(""), _T("HDBs|*.hdb|All files|*.*"),
126 (wxOPEN | wxFILE_MUST_EXIST));
127
128 if (dialog.ShowModal() == wxID_OK) {
129 std::string hdb = std::string(dialog.GetPath().mb_str());
130 hdb = Environment::shortHDBPath(hdb);
131 auto wxHDB = WxConversion::toWxString(hdb);
132 int item = hdbChoice_->FindString(wxHDB);
133 if (item == wxNOT_FOUND) {
134 item = hdbChoice_->Append(wxHDB);
135 }
136 hdbChoice_->Select(item);
137 }
138}
139
140/**
141 * Exit the dialog.
142 */
143void
145 Close();
146}
147
148/**
149 * Searches implementations for empty RF/IU/FU units.
150 *
151 * After search is over and if implementations were found, user is asked
152 * if he/she wants to integrate the found implementations to the current
153 * machine implementation.
154 */
155void
157
158 foundRF_.clear();
159 foundIU_.clear();
160 foundFU_.clear();
161
162 // if none of the check boxes are selected, no point in searching
163 if (!cboxRF_->GetValue() && !cboxIU_->GetValue() && !cboxFU_->GetValue()) {
164 return;
165 }
166
167 // extract path of the HDB file that user has chosen
168 TCEString path = WxConversion::toString(hdbChoice_->GetStringSelection());
169 path = Environment::longHDBPath(path);
170 // make sure the file exists
171 if (!FileSystem::fileExists(path)) {
172 wxString message = _T("Error: path ");
173 message.append(WxConversion::toWxString(path));
174 message.append(_T(" could not be found!\n"));
175 ErrorDialog dialog(this, message);
176 dialog.ShowModal();
177 return;
178 }
179
180 // pass the hdb file to search functions for implementation searching
181 try {
182 HDBManager& hdb = HDBRegistry::instance().hdb(path);
183
184 if (cboxRF_->GetValue()) {
186 }
187 if (cboxIU_->GetValue()) {
189 }
190 if (cboxFU_->GetValue()) {
192 }
193 } catch (Exception& e) {
194 wxString message = _T("");
195 message.append(WxConversion::toWxString(e.errorMessage()));
196 ErrorDialog dialog(this, message);
197 dialog.ShowModal();
198 return;
199 }
200
201 unsigned int rfCount = static_cast<unsigned int>(foundRF_.size());
202 unsigned int iuCount = static_cast<unsigned int>(foundIU_.size());
203 unsigned int fuCount = static_cast<unsigned int>(foundFU_.size());
204
205 // form a message describing how many implementations were found
206 wxString message = _T("");
207 message.append(WxConversion::toWxString(rfCount+iuCount+fuCount));
208 message.append(_T(" implementations were found for "));
209 if (cboxRF_->GetValue()) {
210 message.append(_T("RF ("));
211 message.append(WxConversion::toWxString(rfCount));
212 message.append(_T(")"));
213 }
214 if (cboxIU_->GetValue()) {
215 if (cboxRF_->GetValue()) {
216 message.append(_T(" / "));
217 }
218 message.append(_T("IU ("));
219 message.append(WxConversion::toWxString(iuCount));
220 message.append(_T(")"));
221 }
222 if (cboxFU_->GetValue()) {
223 if (cboxIU_->GetValue() || cboxRF_->GetValue()) {
224 message.append(_T(" / "));
225 }
226 message.append(_T("FU ("));
227 message.append(WxConversion::toWxString(fuCount));
228 message.append(_T(")"));
229 }
230 message.append(_T(" units that have no implementations yet.\n\n"));
231
232 // if no implementations were found, prompt user and exit
233 if ((rfCount+iuCount+fuCount) == 0) {
234 WarningDialog dialog(this, message);
235 dialog.ShowModal();
236 return;
237 }
238
239 message.append(_T("Press Yes to integrate found implementations into"));
240 message.append(_T(" the empty units.\n"));
241
242 // ask if user wants to save the found implementations
243 ConfirmDialog dialog(this, message);
244 if (dialog.ShowModal() != wxID_YES) {
245 return;
246 }
247
248 // add all the newly found implementations to the machine implementation
249
250 // steps: set the new HDB file and ID pair for the unit implementation,
251 // and then add the unit implementation to the machine implementation
252 std::map<const RFImplementationLocation*, HdbIdPair>::iterator itRF;
253 for (itRF = foundRF_.begin(); itRF != foundRF_.end(); ++itRF) {
254 const RFImplementationLocation* unit = itRF->first;
255 HdbIdPair hdbID = itRF->second;
257 hdbID.hdbFile, hdbID.id, unit->unitName());
258 try {
260 } catch (...) {
261 // do nothing if the implementation could not be added
262 }
263 }
264
265 std::map<const RFImplementationLocation*, HdbIdPair>::iterator itIU;
266 for (itIU = foundIU_.begin(); itIU != foundIU_.end(); ++itIU) {
267 const RFImplementationLocation* unit = itIU->first;
268 HdbIdPair hdbID = itIU->second;
270 hdbID.hdbFile, hdbID.id, unit->unitName());
271 try {
273 } catch (...) {
274 // do nothing if the implementation could not be added
275 }
276 }
277
278 std::map<const FUImplementationLocation*, HdbIdPair>::iterator itFU;
279 for (itFU = foundFU_.begin(); itFU != foundFU_.end(); ++itFU) {
280 const FUImplementationLocation* unit = itFU->first;
281 HdbIdPair hdbID = itFU->second;
283 hdbID.hdbFile, hdbID.id, unit->unitName());
284 try {
286 } catch (...) {
287 // do nothing if the implementation could not be added
288 }
289 }
290
291 // exit to update the RF/IU/FU implementation list view for user
292 wxCommandEvent dummy;
293 onClose(dummy);
294}
295
296/**
297 * Function that searches RF implementations from given HDB file.
298 *
299 * @param hdb HDB file from which implementations are searched.
300 */
301void
303
304 // this component searches proper implementations for register files
307 // add the HDB file to selector for searching
308 selector->addHDB(hdb);
309
310 std::map<const RFImplementationLocation*, CostEstimates*> rfImpls;
311 std::map<const RFImplementationLocation*, CostEstimates*>::iterator it;
312
313 // loop through machine's register files
314 int rfCount = machine_.registerFileNavigator().count();
315 for (int i = 0; i < rfCount; ++i) {
317 RegisterFile* rf = dynamic_cast<RegisterFile*>(comp);
318
319 // if register file doesn't have an implementation...
320 if (rf != NULL && !impl_.hasRFImplementation(rf->name())) {
321 // ...try to find one using the selector component
322 rfImpls = selector->rfImplementations(*rf, rf->isUsedAsGuard());
323 it = rfImpls.begin();
324
325 // if an implementation was found, save it into the std::map
326 if (rfImpls.size() > 0 && it->first != NULL) {
327 const RFImplementationLocation* location = it->first;
328 HdbIdPair locationInfo;
329 locationInfo.hdbFile = hdb.fileName();
330 locationInfo.id = location->id();
331
332 foundRF_.insert(
333 std::pair<const RFImplementationLocation*, HdbIdPair>(
334 location, locationInfo));
335 }
336 }
337 }
338
339 delete selector;
340}
341
342/**
343 * Function that searches IU implementations from given HDB file.
344 *
345 * @param hdb HDB file from which implementations are searched.
346 */
347void
349
350 // this component searches proper implementations for immediate units
353 // add the HDB file to selector for searching
354 selector->addHDB(hdb);
355
356 std::map<const RFImplementationLocation*, CostEstimates*> iuImpls;
357 std::map<const RFImplementationLocation*, CostEstimates*>::iterator it;
358
359 // loop through machine's immediate units
360 int iuCount = machine_.immediateUnitNavigator().count();
361 for (int i = 0; i < iuCount; ++i) {
363 ImmediateUnit* iu = dynamic_cast<ImmediateUnit*>(comp);
364
365 // if immediate unit doesn't have an implementation...
366 if (iu != NULL && !impl_.hasIUImplementation(iu->name())) {
367 // ...try to find one using the selector component
368 iuImpls = selector->iuImplementations(*iu);
369 it = iuImpls.begin();
370
371 // if an implementation was found, save it into the std::map
372 if (iuImpls.size() > 0 && it->first != NULL) {
373 const RFImplementationLocation* location = it->first;
374 HdbIdPair locationInfo;
375 locationInfo.hdbFile = hdb.fileName();
376 locationInfo.id = location->id();
377
378 foundIU_.insert(
379 std::pair<const RFImplementationLocation*, HdbIdPair>(
380 location, locationInfo));
381 }
382 }
383 }
384
385 delete selector;
386}
387
388/**
389 * Function that searches FU implementations from given HDB file.
390 *
391 * @param hdb HDB file from which implementations are searched.
392 */
393void
395
396 // this component searches proper implementations for function units
399 // add the HDB file to selector for searching
400 selector->addHDB(hdb);
401
402 std::map<const FUImplementationLocation*, CostEstimates*> fuImpls;
403 std::map<const FUImplementationLocation*, CostEstimates*>::iterator it;
404
405 // loop through machine's function units
406 int fuCount = machine_.functionUnitNavigator().count();
407 for (int i = 0; i < fuCount; ++i) {
409 FunctionUnit* fu = dynamic_cast<FunctionUnit*>(comp);
410
411 // if function unit doesn't have an implementation...
412 if (fu != NULL && !impl_.hasFUImplementation(fu->name())) {
413 // ...try to find one using the selector component
414 fuImpls = selector->fuImplementations(*fu);
415 it = fuImpls.begin();
416
417 // if an implementation was found, save it into the std::map
418 if (fuImpls.size() > 0 && it->first != NULL) {
419 const FUImplementationLocation* location = it->first;
420 HdbIdPair locationInfo;
421 locationInfo.hdbFile = hdb.fileName();
422 locationInfo.id = location->id();
423
424 foundFU_.insert(
425 std::pair<const FUImplementationLocation*, HdbIdPair>(
426 location, locationInfo));
427 }
428 }
429 }
430
431 delete selector;
432}
433
434/**
435 * Creates the dialog widgets.
436 */
437wxSizer*
439 wxWindow *parent,
440 bool call_fit,
441 bool set_sizer) {
442
443 wxFlexGridSizer *item0 = new wxFlexGridSizer( 1, 0, 0 );
444 item0->AddGrowableCol( 0 );
445 item0->AddGrowableRow( 1 );
446
447 wxBoxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
448
449 wxStaticText *itemText = new wxStaticText( parent, ID_TEXT, wxT("HDB file:"), wxDefaultPosition, wxDefaultSize, 0 );
450 item1->Add( itemText, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
451
452 wxString *strs2 = (wxString*) NULL;
453 wxChoice *item2 = new wxChoice( parent, ID_HDB_CHOICE, wxDefaultPosition, wxSize(250,-1), 0, strs2, 0 );
454 item1->Add( item2, 0, wxALIGN_CENTER|wxALL, 5 );
455
456 wxButton *item3 = new wxButton( parent, ID_BROWSE, wxT("Browse..."), wxDefaultPosition, wxDefaultSize, 0 );
457 item1->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 );
458
459 wxButton *buttonFind = new wxButton( parent, ID_FIND, wxT("Find"), wxDefaultPosition, wxDefaultSize, 0 );
460 item1->Add( buttonFind, 0, wxALIGN_CENTER|wxALL, 5 );
461
462 item0->Add( item1, 0, wxALIGN_CENTER|wxALL, 5 );
463
464 wxBoxSizer *cboxSizer = new wxBoxSizer( wxHORIZONTAL );
465
466 wxStaticText *cboxText = new wxStaticText( parent, ID_TEXT, wxT("Do selections for:"), wxDefaultPosition, wxDefaultSize, 0 );
467 cboxSizer->Add( cboxText, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
468
469 wxCheckBox *cboxRF = new wxCheckBox( parent, ID_RF, wxT("Register Files"), wxDefaultPosition, wxDefaultSize, 0 );
470 cboxSizer->Add( cboxRF, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
471
472 wxCheckBox *cboxIU = new wxCheckBox( parent, ID_IU, wxT("Immediate Units"), wxDefaultPosition, wxDefaultSize, 0 );
473 cboxSizer->Add( cboxIU, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
474
475 wxCheckBox *cboxFU = new wxCheckBox( parent, ID_FU, wxT("Function Units"), wxDefaultPosition, wxDefaultSize, 0 );
476 cboxSizer->Add( cboxFU, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
477
478 item0->Add( cboxSizer, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
479
480 wxStaticLine *item5 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL );
481 item0->Add( item5, 0, wxGROW|wxALL, 5 );
482
483 wxBoxSizer *item6 = new wxBoxSizer( wxHORIZONTAL );
484
485 wxButton *closeButton = new wxButton( parent, ID_CLOSE, wxT("Close"), wxDefaultPosition, wxDefaultSize, 0 );
486 item6->Add( closeButton, 0, wxALIGN_CENTER|wxALL, 5 );
487
488 item0->Add( item6, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
489
490
491 if (set_sizer)
492 {
493 parent->SetSizer( item0 );
494 if (call_fit)
495 item0->SetSizeHints( parent );
496 }
497
498 return item0;
499}
END_EVENT_TABLE() using namespace IDF
TTAMachine::Machine * machine
the architecture definition of the estimated processor
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
SimValue dummy(32)
a dummy simvalue which is given for operands that are not bound
wxCheckBox * cboxIU_
Checkbox widget for immediate unit flag.
TTAMachine::Machine & machine_
Machine containing navigators fo RFs, IUs and FUs.
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
wxCheckBox * cboxFU_
Checkbox widget for function unit flag.
std::map< const IDF::UnitImplementationLocation *, HdbIdPair > foundRF_
std::map< const IDF::UnitImplementationLocation *, HdbIdPair > foundIU_
wxChoice * hdbChoice_
Choice selection for list of HDB files.
std::map< const IDF::UnitImplementationLocation *, HdbIdPair > foundFU_
wxCheckBox * cboxRF_
Checkbox widget for register file flag.
std::map< const IDF::FUImplementationLocation *, CostEstimates * > fuImplementations(const TTAMachine::FunctionUnit &fu, double frequencyMHz=0, double maxArea=0)
std::map< const IDF::RFImplementationLocation *, CostEstimates * > rfImplementations(const TTAMachine::RegisterFile &rf, bool guarded=false, double frequencyMHz=0, double maxArea=0)
std::map< const IDF::IUImplementationLocation *, CostEstimates * > iuImplementations(const TTAMachine::ImmediateUnit &iu, double frequencyMHz=0, double maxArea=0)
static TCEString longHDBPath(const TCEString &hdbPath)
static TCEString shortHDBPath(const TCEString &hdbPath)
std::string errorMessage() const
Definition Exception.cc:123
static bool fileExists(const std::string fileName)
std::string fileName() const
static HDBRegistry & instance()
CachedHDBManager & hdb(const std::string fileName)
void loadFromSearchPaths()
std::string hdbPath(unsigned int index)
void addIUImplementation(RFImplementationLocation *implementation)
void addRFImplementation(RFImplementationLocation *implementation)
bool hasIUImplementation(const std::string &unitName) const
bool hasRFImplementation(const std::string &unitName) const
void addFUImplementation(FUImplementationLocation *implementation)
bool hasFUImplementation(const std::string &unitName) const
static bool endsWith(const std::string &source, const std::string &searchString)
virtual TCEString name() const
ComponentType * item(int index) const
virtual RegisterFileNavigator registerFileNavigator() const
Definition Machine.cc:450
virtual FunctionUnitNavigator functionUnitNavigator() const
Definition Machine.cc:380
virtual ImmediateUnitNavigator immediateUnitNavigator() const
Definition Machine.cc:416
virtual bool isUsedAsGuard() const
static wxString toWxString(const std::string &source)
static std::string toString(const wxString &source)
UnitImplementationLocation RFImplementationLocation
UnitImplementationLocation FUImplementationLocation