torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SegmentsRegressionTest.cpp
Go to the documentation of this file.
1 // Torc - Copyright 2011-2013 University of Southern California. All Rights Reserved.
2 // $HeadURL$
3 // $Id$
4 
5 // This program is free software: you can redistribute it and/or modify it under the terms of the
6 // GNU General Public License as published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
11 // the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program. If
14 // not, see <http://www.gnu.org/licenses/>.
15 
16 /// \file
17 /// \brief Regression test for the Segments class.
18 
19 #include <boost/test/unit_test.hpp>
22 #include "torc/common/Devices.hpp"
25 #include <iostream>
26 #include <iomanip>
27 
28 namespace torc {
29 namespace architecture {
30 
31 BOOST_AUTO_TEST_SUITE(architecture)
32 
33  // functions not tested:
34  // const Segments::IrregularArc* getIrregularArc(TileIndex inTileIndex,
35  // WireIndex inSourceWireIndex, WireIndex inSinkWireIndex);
36  // uint32_t getTotalSegmentCount(void) const;
37  // uint32_t getCompactSegmentCount(void) const;
38  // uint32_t getIrregularArcCount(void) const;
39  // const Segments::SegmentReference& getTilewireSegment(const Tilewire& inTilewire) const;
40  // members not tested:
41  // Array2D<CompactSegmentTilewire> mCompactSegments;
42  // Array2D<IrregularArc> mIrregularArcs;
43  // CompactSegmentCount mCompactSegmentCount;
44  // uint32_t mIrregularArcCount;
45  // uint32_t mTotalWireCount;
46  // uint32_t mTotalSegmentCount;
47 
48 /// \brief Regression test class for segments consistency across all devices.
57  typedef boost::uint64_t uint64_t;
59  const Tiles& mTiles;
61  std::map<Tilewire, CompactSegmentIndex> mUsage;
62  const CompactSegmentIndex cUsagePruned;
63  const CompactSegmentIndex cUsageUndefined;
64  uint64_t mTilewireCount;
66  uint64_t mTilewiresPruned;
69  static uint64_t sTotalTilewireCount;
70  static uint64_t sTotalTilewiresAnalyzed;
71  static uint64_t sTotalTilewiresPruned;
72  static uint64_t sTotalTilewiresUndefined;
73  static uint64_t sTotalTilewireMismatches;
74 public:
75  /// \brief Basic constructor.
76  segments_regression_test_helper(DDB& inDDB) : mDDB(inDDB), mTiles(mDDB.getTiles()),
77  mSegments(mDDB.getSegments()),
78  cUsagePruned(CompactSegmentIndex(CompactSegmentIndex::undefined())),
79  cUsageUndefined(CompactSegmentIndex(static_cast<boost::uint32_t>(-2))), mTilewireCount(0),
80  mTilewiresAnalyzed(0), mTilewiresPruned(0), mTilewiresUndefined(0), mTilewireMismatches(0) {
81  // functions tested during database initialization and deletion:
82  // Segments(void);
83  // size_t readTilewireSegments(DigestStream& inStream);
84  // size_t readSegments(DigestStream& inStream);
85  // size_t readIrregularArcs(DigestStream& inStream);
86  }
87  /// \brief Outputs statistics on segment expansion.
88  static void statistics(void) {
89  std::cerr << "=======================================" << std::endl;
90  std::cerr << "Total tilewire count: " << std::setw(12) << sTotalTilewireCount
91  << std::endl;
92  std::cerr << "Total tilewires analyzed: " << std::setw(12) << sTotalTilewiresAnalyzed
93  << std::endl;
94  std::cerr << "Total tilewires pruned: " << std::setw(12) << sTotalTilewiresPruned
95  << std::endl;
96  std::cerr << "Total tilewires undefined: " << std::setw(12) << sTotalTilewiresUndefined
97  << std::endl;
98  std::cerr << "Total tilewire mismatches: " << std::setw(12) << sTotalTilewireMismatches
99  << std::endl;
100  }
101  /// \brief Analyze segment expansion, and detect any tilewire conflicts.
102  void operator ()(void) {
103  TileCount tileCount = mTiles.getTileCount();
104  mUsage.clear();
105 
106  // members tested:
107  // Array2D<SegmentReference> mTilewireSegments;
108  // clear the usage information for all tilewires
109  for(TileIndex tileIndex; tileIndex < tileCount; tileIndex++) {
110  const Array<SegmentReference>& tilewireSegments
111  = mSegments.mTilewireSegments[tileIndex];
112  WireCount wireCount = WireCount(tilewireSegments.getSize());
113  for(WireIndex wireIndex; wireIndex < wireCount; wireIndex++) {
114  Tilewire tilewire(tileIndex, wireIndex);
115  mUsage[tilewire] = cUsageUndefined;
116  mTilewireCount++;
117  }
118  }
119  // iterate through all tilewires and look for any conflicting segment ownership
120  for(TileIndex tileIndex; tileIndex < tileCount; tileIndex++) {
121  const Array<SegmentReference>& tilewireSegments
122  = mSegments.mTilewireSegments[tileIndex];
123  WireCount wireCount = WireCount(tilewireSegments.getSize());
124  for(WireIndex wireIndex; wireIndex < wireCount; wireIndex++) {
125  Tilewire tilewire(tileIndex, wireIndex);
126  analyzeSegmentTilewire(tilewire);
127  TilewireVector segmentTilewires;
128  mDDB.expandSegment(tilewire, segmentTilewires, DDB::eExpandDirectionNone);
129  TilewireVector::const_iterator p = segmentTilewires.begin();
130  TilewireVector::const_iterator e = segmentTilewires.end();
131  while(p < e) {
132  analyzeSegmentTilewire(*p++);
133  }
134  }
135  }
136  // look for any tilewires without segment definitions
137  for(TileIndex tileIndex; tileIndex < tileCount; tileIndex++) {
138  const Array<SegmentReference>& tilewireSegments
139  = mSegments.mTilewireSegments[tileIndex];
140  WireCount wireCount = WireCount(tilewireSegments.getSize());
141  for(WireIndex wireIndex; wireIndex < wireCount; wireIndex++) {
142  Tilewire tilewire(tileIndex, wireIndex);
143  CompactSegmentIndex usage = mUsage[tilewire];
144  if(usage == cUsageUndefined) {
145  mTilewiresUndefined++;
146  std::cerr << "Undefined: " << tilewire << std::endl;
147  BOOST_CHECK(mUsage[tilewire] != cUsageUndefined);
148  } else if(usage == cUsagePruned) {
149  mTilewiresPruned++;
150  }
151  }
152  }
153  std::cerr << "---------------------------------------" << std::endl;
154  std::cerr << "Tilewire count: " << std::setw(12) << mTilewireCount
155  << std::endl;
156  std::cerr << "Tilewires analyzed: " << std::setw(12) << mTilewiresAnalyzed
157  << std::endl;
158  std::cerr << "Tilewires pruned: " << std::setw(12) << mTilewiresPruned
159  << std::endl;
160  std::cerr << "Tilewires undefined: " << std::setw(12) << mTilewiresUndefined
161  << std::endl;
162  std::cerr << "Tilewire mismatches: " << std::setw(12) << mTilewireMismatches
163  << std::endl;
164  sTotalTilewireCount += mTilewireCount;
165  sTotalTilewiresAnalyzed += mTilewiresAnalyzed;
166  sTotalTilewiresPruned += mTilewiresPruned;
167  sTotalTilewiresUndefined += mTilewiresUndefined;
168  sTotalTilewireMismatches += mTilewireMismatches;
169 
170  // functions tested:
171  // uint32_t getTotalWireCount(void) const;
172  BOOST_CHECK_EQUAL(mTilewireCount - mTilewiresPruned, mSegments.getActualWireCount());
173  BOOST_CHECK(mTilewireMismatches == 0);
174  }
175  /// \brief Verifies and enforces segment ownership of the specified tilewire.
176  void analyzeSegmentTilewire(const Tilewire& inTilewire) {
177  mTilewiresAnalyzed++;
178  // extract the tilewire information
179  TileIndex tileIndex = inTilewire.getTileIndex();
180  WireIndex wireIndex = inTilewire.getWireIndex();
181  const Array<SegmentReference>& tilewireSegments = mSegments.mTilewireSegments[tileIndex];
182  // look up the segment reference information
183  const SegmentReference& segmentReference = tilewireSegments[wireIndex];
184  CompactSegmentIndex compactSegmentIndex = segmentReference.getCompactSegmentIndex();
185  TileIndex anchorTileIndex = segmentReference.getAnchorTileIndex();
186  (void) anchorTileIndex;
187  // look up the current tilewire membership
188  CompactSegmentIndex usageCompactSegmentIndex = mUsage[inTilewire];
189  if(compactSegmentIndex == usageCompactSegmentIndex) {
190  // there has been no change
191  //std::cerr << "Match: " << static_cast<int>(compactSegmentIndex) << " for "
192  // << inTilewire << std::endl;
193  } else if(usageCompactSegmentIndex == cUsageUndefined) {
194  // this wire was not previously defined, so we accept the new value
195  mUsage[inTilewire] = compactSegmentIndex;
196  //std::cerr << "Definition: " << static_cast<int>(compactSegmentIndex) << " for "
197  // << inTilewire << std::endl;
198  } else {
199  mTilewireMismatches++;
200  std::cerr << "Mismatch (" << static_cast<int>(compactSegmentIndex) << " vs. "
201  << static_cast<int>(usageCompactSegmentIndex) << ") for " << inTilewire
202  << std::endl;
203  BOOST_CHECK_EQUAL(static_cast<int>(compactSegmentIndex),
204  static_cast<int>(usageCompactSegmentIndex));
205  }
206  }
207 };
208 
209 /// \brief Total number of tilewires visited.
211 /// \brief Total number of tilewires analyzed (visited or expanded).
213 /// \brief Total number of tilewires pruned from the device (absent from XDLRC).
215 /// \brief Total number of tilewires never defined (sanity check).
217 /// \brief Total number of tilewire mismatches (more than one segment contending for one tilewire).
219 
220 /// \brief Regression test for the Segments class.
221 BOOST_AUTO_TEST_CASE(SegmentsRegressionTest) {
222 
223  // iterate over the devices
225  torc::common::DeviceVector::const_iterator dp = devices.begin();
226  torc::common::DeviceVector::const_iterator de = devices.end();
227  while(dp < de) {
228  const std::string& device = *dp++;
229  if(device.empty()) break;
230  DDB ddb(device);
231  std::cerr << ddb;
232  segments_regression_test_helper segmentTester(ddb);
233  segmentTester();
234  }
236 
237 }
238 
239 BOOST_AUTO_TEST_SUITE_END()
240 
241 } // namespace architecture
242 } // namespace torc
const WireIndex & getWireIndex(void) const
Returns the wire index.
Definition: Tilewire.hpp:66
Encapsulation of a tile index in an unsigned 32-bit integer.
CompactSegmentIndex getCompactSegmentIndex(void) const
Definition: Segments.hpp:82
std::vector< Tilewire > TilewireVector
Vector of Tilewire objects.
Definition: Tilewire.hpp:101
Header for the Segments class.
static uint64_t sTotalTilewireMismatches
Total number of tilewire mismatches (more than one segment contending for one tilewire).
Device database, including complete wiring and logic support.
Definition: DDB.hpp:42
BOOST_AUTO_TEST_CASE(ArcUnitTest)
Unit test for the Arc class.
Definition: ArcUnitTest.cpp:29
void analyzeSegmentTilewire(const Tilewire &inTilewire)
Verifies and enforces segment ownership of the specified tilewire.
static uint64_t sTotalTilewiresPruned
Total number of tilewires pruned from the device (absent from XDLRC).
Header for the DDBStreamHelper class.
Array2D< SegmentReference > mTilewireSegments
The segment references for every wire in every tile.
Definition: Segments.hpp:119
Encapsulation of a wire index in an unsigned 16-bit integer.
static uint64_t sTotalTilewiresAnalyzed
Total number of tilewires analyzed (visited or expanded).
static uint64_t sTotalTilewiresUndefined
Total number of tilewires never defined (sanity check).
TileCount getTileCount(void) const
Returns the tile count for this device.
Definition: Tiles.hpp:149
static uint64_t sTotalTilewireCount
Total number of tilewires visited.
std::string string
uint32_t getActualWireCount(void) const
Return the number of actual wires in the device (unpruned and non-trivial).
Definition: Segments.hpp:168
static const DeviceVector & getSupportedDevices(void)
Returns all devices.
Definition: Devices.hpp:207
Header for torc::physical output stream helpers.
Encapsulation of a device tile and wire pair.
Definition: Tilewire.hpp:39
Regression test class for segments consistency across all devices.
Tile map, tile type, and wire information for the family and device.
Definition: Tiles.hpp:36
Encapsulation of a wire count in an unsigned 16-bit integer.
Encapsulation of a tile count in an unsigned 32-bit integer.
Header for the Devices class.
Encapsulation of a compact segment index in an unsigned 32-bit integer.
static void statistics(void)
Outputs statistics on segment expansion.
Encapsulation of compact segment index and an anchoring tile index.
Definition: Segments.hpp:78
Encapsulation of a tile type index in an unsigned 16-bit integer.
Header for the DDB class.
const TileIndex & getTileIndex(void) const
Returns the tile index.
Definition: Tilewire.hpp:64
std::map< Tilewire, CompactSegmentIndex > mUsage
std::vector< std::string > DeviceVector
Vector of device names.
Definition: Devices.hpp:119
Segment and irregular arc data for the device.
Definition: Segments.hpp:40
Encapsulation of a static array.
Definition: Array.hpp:39
void expandSegment(const Tilewire &inTilewire, TilewireVector &outTilewires, EExpandDirection inExpandDirection=eExpandDirectionNone)
Expands the given tilewire's segment.
Definition: DDB.cpp:154
uint32_t getSize(void) const
Returns the array size.
Definition: Array.hpp:104