OpenASIP  2.0
DesignSpaceExplorerPlugin.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2011 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 DesignSpaceExplorerPlugin.cc
26  *
27  * Implementation of DesignSpaceExplorerPlugin class
28  *
29  * @author Jari Mäntyneva 2007 (jari.mantyneva-no.spam-tut.fi)
30  * @author Pekka Jääskeläinen 2011
31  * @note rating: red
32  */
33 
34 #include <map>
35 #include <string>
36 
39 #include "Exception.hh"
40 #include "StringTools.hh"
41 
42 /**
43  * The constructor of the DesignExplorerPlugin class.
44  *
45  * @param dsdb Design space data base to be used with the plugin.
46  * @name pluginName Name of the plugin.
47  */
50 }
51 
52 
53 /**
54  * The destructor.
55  */
57 }
58 
59 
60 /**
61  * Sets the plugin name.
62  *
63  * @param pluginName Name of the plugin.
64  */
65 void
66 DesignSpaceExplorerPlugin::setPluginName(const std::string& pluginName) {
67  pluginName_ = pluginName;
68 }
69 
70 
71 /**
72  * Returns the plugin name.
73  *
74  * @return The plugin name as a string.
75  */
76 std::string
78  return pluginName_;
79 }
80 
81 
82 /**
83  * Gives a plugin parameter value.
84  *
85  * @param name The parameter name.
86  * @param value The value to be set for the parameter.
87  */
88 void
90  const std::string& name, const std::string& value) {
91  PMIt it = parameters_.find(name);
92  if (it == parameters_.end()) {
93  std::string msg = "Plugin has no parameter named: " + name;
94  throw InstanceNotFound(__FILE__, __LINE__, __func__, msg);
95  }
96  it->second.setValue(value);
97 }
98 
99 /**
100  * Tells whether the plugin has the given parameter defined.
101  *
102  * @param paramName Name of the parameter.
103  * @return True if the given parameter is defined, otherwise false.
104  */
105 bool
106 DesignSpaceExplorerPlugin::hasParameter(const std::string& paramName) const {
107  return parameters_.find(paramName)->second.isSet();
108 }
109 
110 
111 /**
112  * Makes a copy of the parameters of the plugin and returns it.
113  *
114  * @return ParameterMap map of the explorer plugin parameters.
115  */
118  return parameters_;
119 }
120 
121 
122 /**
123  * Returns the boolean value of the given parameter if parameter can be
124  * considered as a boolean.
125  *
126  * @param parameter The string to be converted to a boolean value
127  * @return Boolean value of the parameter
128  * @exception IllegalParameters Given parameter could not be considerer as
129  * boolean value
130  */
131 bool
132 DesignSpaceExplorerPlugin::booleanValue(const std::string& parameter) const {
133  std::string lowCase = StringTools::stringToLower(parameter);
134  if (lowCase == "true" || lowCase == "1") {
135  return true;
136  } else if (lowCase == "false" || lowCase == "0") {
137  return false;
138  } else {
139  throw IllegalParameters(__FILE__, __LINE__, __func__);
140  }
141 }
142 
143 /**
144  * Checks that all compulsory parameters are set for the plugin.
145  */
146 void
148  for (PMCIt it = parameters_.begin(); it != parameters_.end(); it++) {
149  if (it->second.isCompulsory() && !it->second.isSet()) {
150  std::string msg = it->second.name() + " parameter is needed.";
151  throw IllegalParameters(__FILE__, __LINE__, __func__, msg);
152  }
153  }
154 }
155 
156 /**
157  * Explores the design space from the starting point machine and returns
158  * best exploring results as configuration IDs.
159  *
160  * Exploring creates new machine configurations (architecture, implementation)
161  * that are ordered so that the best results are first in the result vector.
162  *
163  * @param startPoint Starting point machine configuration for the plugin.
164  * @param maxIter Maximum number of design space points the plugin is allowed to
165  * explore. Default value for maxIter is zero when the iteration number is not
166  * taken into account. In that case the exploration runs indefinetly or stops
167  * at a point defined by the algorithm.
168  * @return Ordered vector of IDs of the best machine configurations where the
169  * target programs can be successfully run. The IDs of the best machine
170  * configurations are first in the result vector. Returns an empty vector if
171  * does not find any possible machine configurations.
172  */
173 std::vector<RowID>
175  const RowID&, const unsigned int&) {
176 
177  std::vector<RowID> result;
178  return result;
179 }
Exception.hh
ExplorerPluginParameter.hh
DesignSpaceExplorerPlugin::booleanValue
virtual bool booleanValue(const std::string &parameter) const
Definition: DesignSpaceExplorerPlugin.cc:132
DesignSpaceExplorerPlugin::checkParameters
void checkParameters() const
Definition: DesignSpaceExplorerPlugin.cc:147
RowID
int RowID
Type definition of row ID in relational databases.
Definition: DBTypes.hh:37
DesignSpaceExplorerPlugin::DesignSpaceExplorerPlugin
DesignSpaceExplorerPlugin()
Definition: DesignSpaceExplorerPlugin.cc:48
DesignSpaceExplorerPlugin::~DesignSpaceExplorerPlugin
virtual ~DesignSpaceExplorerPlugin()
Definition: DesignSpaceExplorerPlugin.cc:56
DesignSpaceExplorerPlugin::pluginName_
std::string pluginName_
the name of the explorer plugin
Definition: DesignSpaceExplorerPlugin.hh:114
DesignSpaceExplorerPlugin::setPluginName
virtual void setPluginName(const std::string &pluginName)
Definition: DesignSpaceExplorerPlugin.cc:66
DesignSpaceExplorerPlugin.hh
StringTools.hh
IllegalParameters
Definition: Exception.hh:113
DesignSpaceExplorerPlugin::parameters_
ParameterMap parameters_
Parameters for the plugin.
Definition: DesignSpaceExplorerPlugin.hh:116
__func__
#define __func__
Definition: Application.hh:67
DesignSpaceExplorerPlugin::giveParameter
virtual void giveParameter(const std::string &name, const std::string &value)
Definition: DesignSpaceExplorerPlugin.cc:89
DesignSpaceExplorerPlugin::explore
virtual std::vector< RowID > explore(const RowID &startPointConfigurationID, const unsigned int &maxIter=0)
Definition: DesignSpaceExplorerPlugin.cc:174
DesignSpaceExplorerPlugin::name
virtual std::string name() const
Definition: DesignSpaceExplorerPlugin.cc:77
DesignSpaceExplorerPlugin::PMCIt
std::map< std::string, ExplorerPluginParameter >::const_iterator PMCIt
Definition: DesignSpaceExplorerPlugin.hh:73
DesignSpaceExplorerPlugin::hasParameter
virtual bool hasParameter(const std::string &paramName) const
Definition: DesignSpaceExplorerPlugin.cc:106
DesignSpaceExplorer
Definition: DesignSpaceExplorer.hh:70
DesignSpaceExplorerPlugin::ParameterMap
std::map< std::string, ExplorerPluginParameter > ParameterMap
Definition: DesignSpaceExplorerPlugin.hh:69
DesignSpaceExplorerPlugin::PMIt
std::map< std::string, ExplorerPluginParameter >::iterator PMIt
Definition: DesignSpaceExplorerPlugin.hh:71
DesignSpaceExplorerPlugin::parameters
ParameterMap parameters() const
Definition: DesignSpaceExplorerPlugin.cc:117
StringTools::stringToLower
static std::string stringToLower(const std::string &source)
Definition: StringTools.cc:160
InstanceNotFound
Definition: Exception.hh:304