OpenASIP  2.0
Public Member Functions | Private Attributes | List of all members
MinimalOpSetCheck Class Reference

#include <MinimalOpSetCheck.hh>

Inheritance diagram for MinimalOpSetCheck:
Inheritance graph
Collaboration diagram for MinimalOpSetCheck:
Collaboration graph

Public Member Functions

 MinimalOpSetCheck ()
 
virtual ~MinimalOpSetCheck ()
 
virtual bool check (const TTAMachine::Machine &machine, MachineCheckResults &results) const
 
virtual bool check (const TTAMachine::Machine &machine) const
 
bool checkWithIgnore (const TTAMachine::Machine &machine, const std::set< std::string > &ignoreFUName) const
 
void missingOperations (const TTAMachine::Machine &machine, std::vector< std::string > &missingOps) const
 
void buildMinimalOpSet (const TTAMachine::Machine *machine=NULL)
 
TCETools::CIStringSet minimalOpSet () const
 
virtual bool canFix (const TTAMachine::Machine &mach) const
 
virtual std::string fix (TTAMachine::Machine &machine) const
 
- Public Member Functions inherited from MachineCheck
virtual std::string shortDescription () const
 
virtual std::string description () const
 
virtual ~MachineCheck ()
 

Private Attributes

TCETools::CIStringSet minimalOpSet_
 

Additional Inherited Members

- Protected Member Functions inherited from MachineCheck
 MachineCheck (const std::string &shortDesc_)
 

Detailed Description

MachineCheck to check is the machine fully connected.

Definition at line 53 of file MinimalOpSetCheck.hh.

Constructor & Destructor Documentation

◆ MinimalOpSetCheck()

MinimalOpSetCheck::MinimalOpSetCheck ( )

Definition at line 46 of file MinimalOpSetCheck.cc.

46  :
47  MachineCheck("Common helper functionality for minimal opset checks.") {
49 }

References buildMinimalOpSet().

Here is the call graph for this function:

◆ ~MinimalOpSetCheck()

MinimalOpSetCheck::~MinimalOpSetCheck ( )
virtual

Definition at line 51 of file MinimalOpSetCheck.cc.

51  {
52 }

Member Function Documentation

◆ buildMinimalOpSet()

void MinimalOpSetCheck::buildMinimalOpSet ( const TTAMachine::Machine machine = NULL)

Constructs a minimal opset from a given machine.

Parameters
machineMachine that is used as reference for minimal opset.

Definition at line 255 of file MinimalOpSetCheck.cc.

255  {
256  bool deleteMach = false;
257  if (machine == NULL) {
259  deleteMach = true;
260  }
261 
264  // construct the opset list
265  for (int i = 0; i < fuNav.count(); i++) {
266  TTAMachine::FunctionUnit* fu = fuNav.item(i);
268  }
269 
270  if (deleteMach) {
271  delete machine;
272  machine = NULL;
273  }
274 }

References TTAMachine::Machine::Navigator< ComponentType >::count(), TTAMachine::Machine::functionUnitNavigator(), TTAMachine::Machine::Navigator< ComponentType >::item(), TTAMachine::Machine::loadFromADF(), machine, Environment::minimalADF(), minimalOpSet_, and TTAMachine::FunctionUnit::operationNames().

Referenced by MinimalOpSetCheck().

Here is the call graph for this function:

◆ canFix()

bool MinimalOpSetCheck::canFix ( const TTAMachine::Machine mach) const
virtual

Returns true if the checker can automatically fix the machine to pass the check.

Returns
True, minimal opset can be always added to the machine.

Reimplemented from MachineCheck.

Definition at line 346 of file MinimalOpSetCheck.cc.

346  {
347  return true;
348 }

◆ check() [1/2]

bool MinimalOpSetCheck::check ( const TTAMachine::Machine machine) const
virtual

Checks if machine has all operations in minimal opset.

Parameters
machineMachine to be checked against minimal opset.
Returns
True if minimal operation set was met, false otherwise.

Definition at line 61 of file MinimalOpSetCheck.cc.

61  {
65  // construct the opset list
66  for (int i = 0; i < fuNav.count(); i++) {
67  TTAMachine::FunctionUnit* fu = fuNav.item(i);
68  fu->operationNames(opSet);
69  }
70 
71  // if machines opset is smaller than required opset
72  if (opSet.size() < minimalOpSet_.size()) {
73  return false;
74  }
75 
76  TCETools::CIStringSet::const_iterator first1 = minimalOpSet_.begin();
77  TCETools::CIStringSet::const_iterator last1 = minimalOpSet_.end();
78 
79  TCETools::CIStringSet::iterator first2 = opSet.begin();
80  TCETools::CIStringSet::iterator last2 = opSet.end();
81 
82  // return false if missing operation was found
83  while (first1 != last1 && first2 != last2) {
84  if (*first1 < *first2) {
85  return false;
86  } else if (*first2 < *first1) {
87  ++first2;
88  } else {
89  ++first1;
90  ++first2;
91  }
92  }
93  if (first1 != last1) {
94  return false;
95  }
96  return true;
97 }

References TTAMachine::Machine::Navigator< ComponentType >::count(), TTAMachine::Machine::functionUnitNavigator(), TTAMachine::Machine::Navigator< ComponentType >::item(), machine, minimalOpSet_, and TTAMachine::FunctionUnit::operationNames().

Here is the call graph for this function:

◆ check() [2/2]

bool MinimalOpSetCheck::check ( const TTAMachine::Machine machine,
MachineCheckResults results 
) const
virtual

Checks the machine if it misses operations from the minimal op set.

Parameters
resultsResults of the validation are added to the given instance.

Implements MachineCheck.

Definition at line 106 of file MinimalOpSetCheck.cc.

108  {
109 
110  // construct the opset list
113  TCETools::CIStringSet opSet;
114  for (int i = 0; i < fuNav.count(); i++) {
115  TTAMachine::FunctionUnit* fu = fuNav.item(i);
116  fu->operationNames(opSet);
117  }
118 
119  TCETools::CIStringSet::iterator first1 = minimalOpSet_.begin();
120  TCETools::CIStringSet::iterator last1 = minimalOpSet_.end();
121 
122  TCETools::CIStringSet::iterator first2 = opSet.begin();
123  TCETools::CIStringSet::iterator last2 = opSet.end();
124 
125  std::string eMsg = "Operation missing from the minimal operation set: ";
126 
127  bool errorsAdded = false;
128  // missing opset is the difference towards minimalOpSet_
129  while (first1 != last1 && first2 != last2) {
130  if (*first1 < *first2) {
131  results.addError(*this, eMsg.append(*first1++));
132  errorsAdded = true;
133  } else if (*first2 < *first1) {
134  ++first2;
135  } else {
136  ++first1;
137  ++first2;
138  }
139  }
140  while (first1 != last1) {
141  results.addError(*this, eMsg.append(*first1++));
142  errorsAdded = true;
143  }
144  return !errorsAdded;
145 }

References MachineCheckResults::addError(), TTAMachine::Machine::Navigator< ComponentType >::count(), TTAMachine::Machine::functionUnitNavigator(), TTAMachine::Machine::Navigator< ComponentType >::item(), machine, minimalOpSet_, and TTAMachine::FunctionUnit::operationNames().

Here is the call graph for this function:

◆ checkWithIgnore()

bool MinimalOpSetCheck::checkWithIgnore ( const TTAMachine::Machine machine,
const std::set< std::string > &  ignoreFUName 
) const

Checks if machine has all operations in minimal opset.

Ignores fus with specified names from the check. This is useful with testing if minimal opset requirement breaks if a certain FUs are removed.

Parameters
machineMachine to be checked against minimal opset.
ignoreFUsNames of the fus to be ignored regarding the check.
Returns
True if minimal operation set was met, false otherwise.

Definition at line 159 of file MinimalOpSetCheck.cc.

161  {
162 
165  TCETools::CIStringSet opSet;
166  // construct the opset list
167  for (int i = 0; i < fuNav.count(); i++) {
168  TTAMachine::FunctionUnit* fu = fuNav.item(i);
169  if (ignoreFUName.find(fu->name()) == ignoreFUName.end()) {
170  fu->operationNames(opSet);
171  }
172  }
173 
174  // if machines opset is smaller than required opset
175  if (opSet.size() < minimalOpSet_.size()) {
176  return false;
177  }
178 
179  TCETools::CIStringSet::const_iterator first1 = minimalOpSet_.begin();
180  TCETools::CIStringSet::const_iterator last1 = minimalOpSet_.end();
181 
182  TCETools::CIStringSet::iterator first2 = opSet.begin();
183  TCETools::CIStringSet::iterator last2 = opSet.end();
184 
185  // return false if missing operation was found
186  while (first1 != last1 && first2 != last2) {
187  if (*first1 < *first2) {
188  return false;
189  } else if (*first2 < *first1) {
190  ++first2;
191  } else {
192  ++first1;
193  ++first2;
194  }
195  }
196  if (first1 != last1) {
197  return false;
198  }
199  return true;
200 }

References TTAMachine::Machine::Navigator< ComponentType >::count(), TTAMachine::Machine::functionUnitNavigator(), TTAMachine::Machine::Navigator< ComponentType >::item(), machine, minimalOpSet_, TTAMachine::Component::name(), and TTAMachine::FunctionUnit::operationNames().

Referenced by SimpleICOptimizer::removeAllConnections().

Here is the call graph for this function:

◆ fix()

std::string MinimalOpSetCheck::fix ( TTAMachine::Machine mach) const
virtual

Adds FUs to the machine so that it doesn't miss operations anymore.

Check is done against minimal opset.

Parameters
machineMachine to be checked against minimal opset and where FUs are inserted so that minimal opset is fulfilled.
Returns
A short description what was done.

Reimplemented from MachineCheck.

Definition at line 298 of file MinimalOpSetCheck.cc.

298  {
299  std::vector<std::string> missingOps;
300  missingOperations(mach, missingOps);
301 
302  if (missingOps.size() < 1) {
303  const std::string errorMessage = "No missing operations found.";
304  throw InvalidData(
305  __FILE__, __LINE__, __func__, errorMessage);
306  }
307 
308  // go through minimal adf and add FUs that include missing ops
311 
313  minMach->functionUnitNavigator();
314  std::set<std::string> fuAdded;
316 
317  for (unsigned int moi = 0; moi < missingOps.size(); ++moi) {
318  for (int fui = 0; fui < fuNav.count(); ++fui) {
319  TTAMachine::FunctionUnit* fu = fuNav.item(fui);
320  if (fu->hasOperation(missingOps.at(moi))) {
321  if (fuAdded.end() != fuAdded.find(fu->name())) {
322  break;
323  }
324  fuAdded.insert(fu->name());
325  fu->unsetMachine();
326  mach.addFunctionUnit(*fu);
327  // connect the fu
328  for (int op = 0; op < fu->operationPortCount(); ++op) {
329  conCheck.connectFUPort(*fu->operationPort(op));
330  }
331  break;
332  }
333  }
334  }
335  delete minMach;
336  return "Operations were added to fulfill minimal opset requirements.";
337 }

References __func__, TTAMachine::Machine::addFunctionUnit(), FullyConnectedCheck::connectFUPort(), TTAMachine::Machine::Navigator< ComponentType >::count(), TTAMachine::Machine::functionUnitNavigator(), TTAMachine::FunctionUnit::hasOperation(), TTAMachine::Machine::Navigator< ComponentType >::item(), TTAMachine::Machine::loadFromADF(), Environment::minimalADF(), missingOperations(), TTAMachine::Component::name(), TTAMachine::FunctionUnit::operationPort(), TTAMachine::FunctionUnit::operationPortCount(), and TTAMachine::FunctionUnit::unsetMachine().

Referenced by MinimalOpSet::explore().

Here is the call graph for this function:

◆ minimalOpSet()

TCETools::CIStringSet MinimalOpSetCheck::minimalOpSet ( ) const

Returns constructed minimal opset.

Returns
Minimal opset as strings in a set.

Definition at line 283 of file MinimalOpSetCheck.cc.

283  {
284  return minimalOpSet_;
285 }

References minimalOpSet_.

◆ missingOperations()

void MinimalOpSetCheck::missingOperations ( const TTAMachine::Machine machine,
std::vector< std::string > &  missingOps 
) const

Return operations that are missing from a machine.

Returns operations that are missing from a machine compared to the minimal operation set.

Parameters
machineMachine to be checked against minimal opset.
missingOpsVector where missing operation names are to be stored.

Definition at line 213 of file MinimalOpSetCheck.cc.

215  {
216 
217  // construct the opset list
220  TCETools::CIStringSet opSet;
221  for (int i = 0; i < fuNav.count(); i++) {
222  TTAMachine::FunctionUnit* fu = fuNav.item(i);
223  fu->operationNames(opSet);
224  }
225 
226  TCETools::CIStringSet::const_iterator first1 = minimalOpSet_.begin();
227  TCETools::CIStringSet::const_iterator last1 = minimalOpSet_.end();
228 
229  TCETools::CIStringSet::iterator first2 = opSet.begin();
230  TCETools::CIStringSet::iterator last2 = opSet.end();
231 
232  // missing opset is the difference towards minimalOpSet_
233  while (first1 != last1 && first2 != last2) {
234  if (*first1 < *first2) {
235  missingOps.push_back(*first1++);
236  } else if (*first2 < *first1) {
237  ++first2;
238  } else {
239  ++first1;
240  ++first2;
241  }
242  }
243  while (first1 != last1) {
244  missingOps.push_back(*first1++);
245  }
246 }

References TTAMachine::Machine::Navigator< ComponentType >::count(), TTAMachine::Machine::functionUnitNavigator(), TTAMachine::Machine::Navigator< ComponentType >::item(), machine, minimalOpSet_, and TTAMachine::FunctionUnit::operationNames().

Referenced by ProgrammabilityValidator::checkPrimitiveSet(), MinimalOpSet::explore(), and fix().

Here is the call graph for this function:

Member Data Documentation

◆ minimalOpSet_

TCETools::CIStringSet MinimalOpSetCheck::minimalOpSet_
private

The documentation for this class was generated from the following files:
MachineCheck::MachineCheck
MachineCheck(const std::string &shortDesc_)
Definition: MachineCheck.cc:41
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
TTAMachine::FunctionUnit::unsetMachine
virtual void unsetMachine()
Definition: FunctionUnit.cc:648
Environment::minimalADF
static std::string minimalADF()
Definition: Environment.cc:901
MachineCheckResults::addError
void addError(const MachineCheck &check, const std::string &errorMsg)
Definition: MachineCheckResults.cc:85
TTAMachine::Machine::Navigator::count
int count() const
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
InvalidData
Definition: Exception.hh:149
__func__
#define __func__
Definition: Application.hh:67
TTAMachine::Machine::functionUnitNavigator
virtual FunctionUnitNavigator functionUnitNavigator() const
Definition: Machine.cc:380
TCETools::CIStringSet
std::set< TCEString, CaseInsensitiveCmp > CIStringSet
Definition: CIStringSet.hh:49
TTAMachine::FunctionUnit::hasOperation
virtual bool hasOperation(const std::string &name) const
Definition: FunctionUnit.cc:330
TTAMachine::FunctionUnit::operationPortCount
virtual int operationPortCount() const
Definition: FunctionUnit.cc:182
MinimalOpSetCheck::minimalOpSet_
TCETools::CIStringSet minimalOpSet_
Definition: MinimalOpSetCheck.hh:80
TTAMachine::Machine::addFunctionUnit
virtual void addFunctionUnit(FunctionUnit &unit)
Definition: Machine.cc:202
FullyConnectedCheck
Definition: FullyConnectedCheck.hh:51
MinimalOpSetCheck::buildMinimalOpSet
void buildMinimalOpSet(const TTAMachine::Machine *machine=NULL)
Definition: MinimalOpSetCheck.cc:255
FullyConnectedCheck::connectFUPort
void connectFUPort(TTAMachine::FUPort &port) const
Definition: FullyConnectedCheck.cc:497
TTAMachine::Machine::Navigator::item
ComponentType * item(int index) const
MinimalOpSetCheck::missingOperations
void missingOperations(const TTAMachine::Machine &machine, std::vector< std::string > &missingOps) const
Definition: MinimalOpSetCheck.cc:213
TTAMachine::FunctionUnit::operationPort
virtual FUPort * operationPort(const std::string &name) const
Definition: FunctionUnit.cc:224
TTAMachine::Machine::Navigator
Definition: Machine.hh:186
TTAMachine::Machine
Definition: Machine.hh:73
TTAMachine::Machine::loadFromADF
static Machine * loadFromADF(const std::string &adfFileName)
Definition: Machine.cc:905
TTAMachine::FunctionUnit::operationNames
virtual void operationNames(TCETools::CIStringSet &opNames) const
Definition: FunctionUnit.cc:428