OpenASIP 2.2
Loading...
Searching...
No Matches
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>
35#include "ResourceBroker.hh"
36#include "ContainerTools.hh"
37#include "Exception.hh"
38#include "SequenceTools.hh"
39/**
40 * Constructor.
41 */
44
45/**
46 * Destructor.
47 */
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 */
60void
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 */
74void
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 */
101void
102ResourceBuildDirector::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 */
177void
179 for (size_t i = 0; i < brokers_.size(); i++) {
180 brokers_[i]->clear();
181 }
182}
#define __func__
TTAMachine::Machine * machine
the architecture definition of the estimated processor
static bool containsValue(const ContainerType &aContainer, const ElementType &aKey)
std::set< SchedulingResource * > ResourceSet
std::vector< ResourceBroker * > brokers_
Resource brokers.
ResourceMapper mapper_
Resource mapper.
void build(const TTAMachine::Machine &machine)
void addBroker(ResourceBroker &broker)
void print(std::ostream &target_, unsigned int cycles) const
void addResourceMap(const ResourceBroker &broker)
static void deleteAllItems(SequenceType &aSequence)