OpenASIP  2.0
ResourceBuildDirector.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 ResourceBuildDirector.cc
26  *
27  * Implementation of ResourceBuildDirector class.
28  *
29  * @author Ari Metsähalme 2006 (ari.metsahalme-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #include <iomanip>
34 #include "ResourceBuildDirector.hh"
35 #include "ResourceBroker.hh"
36 #include "ContainerTools.hh"
37 #include "Exception.hh"
38 #include "SequenceTools.hh"
39 /**
40  * Constructor.
41  */
43 }
44 
45 /**
46  * Destructor.
47  */
50 }
51 
52 /**
53  * Add given broker to the list of brokers responsible for resource
54  * construction.
55  *
56  * The order in which brokers are added is irrelevant.
57  *
58  * @param broker Broker to add.
59  */
60 void
63  throw ObjectAlreadyExists(__FILE__, __LINE__, __func__);
64  } else {
65  brokers_.push_back(&broker);
66  }
67 }
68 
69 /**
70  * Build a complete resource object model for given target processor.
71  *
72  * @machine Machine to build from.
73  */
74 void
76 
77  // build primary resources
78  for (unsigned int i = 0; i < brokers_.size(); i++) {
79  brokers_[i]->buildResources(machine);
81  }
82 
83  // setup dependent and related resource links
84  for (unsigned int i = 0; i < brokers_.size(); i++) {
85  brokers_[i]->setupResourceLinks(mapper_);
86  }
87  for (unsigned int i = 0; i < brokers_.size(); i++) {
88  // broker throws in case problem is found
89  brokers_[i]->validateResources();
90  }
91 }
92 
93 /**
94  * Print resource manager's contents.
95  *
96  * @param target_ Output stream to pring (eg. std::cout).
97  * @param cycles How many cycles to print.
98  *
99  * @machine Machine to build from.
100  */
101 void
102 ResourceBuildDirector::print(std::ostream& target_, unsigned int cycles) const
103 {
104  std::vector<ResourceBroker::ResourceSet> contents;
105  std::vector<ResourceBroker::ResourceSet::iterator> contentIterators;
106 
107  bool finished = false;
108  unsigned int k = 0;
109  unsigned int minWidth = cycles;
110 
111  // determine minimum width for field, it is constrained by cycle count or broker's name
112  for (std::vector<ResourceBroker*>::const_iterator i = brokers_.begin(); i != brokers_.end(); ++i) {
113 
114  std::string name = (*i)->brokerName();
115 
116  if(name.length() > minWidth) {
117  minWidth = name.length();
118  }
119  }
120  minWidth += 1;
121 
122  // print broker names
123  for (std::vector<ResourceBroker*>::const_iterator i = brokers_.begin(); i != brokers_.end(); ++i) {
124  target_ << std::left << std::setw(minWidth);
125  target_ << (*i)->brokerName();
126  }
127  target_ << std::endl;
128 
129  // print broker reservation tables
130  while (!finished) {
131 
132  finished = true;
133  for (std::vector<ResourceBroker*>::const_iterator i = brokers_.begin(); i != brokers_.end(); ++i) {
134 
136  (*i)->resources(c);
137  ResourceBroker::ResourceSet::iterator j = c.begin();
138 
139  if(k >= c.size()) {
140  target_ << std::left << std::setw(minWidth) << ' ';
141  //<<
142 // std::string(cycles, ' ');
143  continue;
144  }
145 
146  std::advance(j, k);
147 
148  if(j == c.end()) {
149 // target_ << std::left << std::setw(minWidth) <<
150 // std::string(cycles, ' ');
151  continue;
152  }
153 
154  finished = false;
155 
156  std::string table = "";
157  for (unsigned int cycle = 0; cycle < cycles; ++cycle)
158  {
159  if((*j)->isAvailable(cycle)) {
160  table += '-';
161  }
162  else {
163  table += '#';
164  std::cerr << (*j) << " " << (*j)->name() << std::endl;
165  }
166  }
167  target_ << std::left << std::setw(minWidth) << table;
168  }
169  target_ << std::endl;
170  k += 1;
171  }
172 }
173 
174 /**
175  * Clears all resources of the resouce manager so that the RM can be reused.
176  */
177 void
179  for (size_t i = 0; i < brokers_.size(); i++) {
180  brokers_[i]->clear();
181  }
182 }
ResourceBuildDirector::~ResourceBuildDirector
virtual ~ResourceBuildDirector()
Definition: ResourceBuildDirector.cc:48
ResourceBuildDirector::brokers_
std::vector< ResourceBroker * > brokers_
Resource brokers.
Definition: ResourceBuildDirector.hh:63
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
Exception.hh
ResourceBuildDirector::clear
void clear()
Definition: ResourceBuildDirector.cc:178
ResourceBuildDirector::mapper_
ResourceMapper mapper_
Resource mapper.
Definition: ResourceBuildDirector.hh:65
ResourceBuildDirector::ResourceBuildDirector
ResourceBuildDirector()
Definition: ResourceBuildDirector.cc:42
SequenceTools.hh
ResourceBroker
Definition: ResourceBroker.hh:61
ResourceBroker::ResourceSet
std::set< SchedulingResource * > ResourceSet
Definition: ResourceBroker.hh:66
SequenceTools::deleteAllItems
static void deleteAllItems(SequenceType &aSequence)
__func__
#define __func__
Definition: Application.hh:67
ResourceBuildDirector::build
void build(const TTAMachine::Machine &machine)
Definition: ResourceBuildDirector.cc:75
ResourceBuildDirector.hh
ResourceBroker.hh
ResourceBuildDirector::addBroker
void addBroker(ResourceBroker &broker)
Definition: ResourceBuildDirector.cc:61
ObjectAlreadyExists
Definition: Exception.hh:1002
ContainerTools::containsValue
static bool containsValue(const ContainerType &aContainer, const ElementType &aKey)
ResourceBuildDirector::print
void print(std::ostream &target_, unsigned int cycles) const
Definition: ResourceBuildDirector.cc:102
ResourceMapper::addResourceMap
void addResourceMap(const ResourceBroker &broker)
Definition: ResourceMapper.cc:60
TTAMachine::Machine
Definition: Machine.hh:73
ContainerTools.hh