torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VirtexE.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 Source for the VirtexE class.
19 #include <iostream>
20 
21 /// \todo Warning: this will need to be moved elsewhere.
25 #include <fstream>
26 
27 
28 namespace torc {
29 namespace bitstream {
30 
31 //#define GENERATE_STATIC_DEVICE_INFO
32 #ifndef GENERATE_STATIC_DEVICE_INFO
33 
34  extern DeviceInfo xcv50e;
35  extern DeviceInfo xcv100e;
36  extern DeviceInfo xcv200e;
37  extern DeviceInfo xcv300e;
38  extern DeviceInfo xcv400e;
39  extern DeviceInfo xcv405e;
40  extern DeviceInfo xcv600e;
41  extern DeviceInfo xcv812e;
42  extern DeviceInfo xcv1000e;
43  extern DeviceInfo xcv1600e;
44  extern DeviceInfo xcv2000e;
45  extern DeviceInfo xcv2600e;
46  extern DeviceInfo xcv3200e;
47 
48  void VirtexE::initializeDeviceInfo(const std::string& inDeviceName) {
49  using namespace torc::common;
50  switch(mDevice) {
51  case eXCV50E: setDeviceInfo(xcv50e); break;
52  case eXCV100E: setDeviceInfo(xcv100e); break;
53  case eXCV200E: setDeviceInfo(xcv200e); break;
54  case eXCV300E: setDeviceInfo(xcv300e); break;
55  case eXCV400E: setDeviceInfo(xcv400e); break;
56  case eXCV405E: setDeviceInfo(xcv405e); break;
57  case eXCV600E: setDeviceInfo(xcv600e); break;
58  case eXCV812E: setDeviceInfo(xcv812e); break;
59  case eXCV1000E: setDeviceInfo(xcv1000e); break;
60  case eXCV1600E: setDeviceInfo(xcv1600e); break;
61  case eXCV2000E: setDeviceInfo(xcv2000e); break;
62  case eXCV2600E: setDeviceInfo(xcv2600e); break;
63  case eXCV3200E: setDeviceInfo(xcv3200e); break;
64  default: break;
65  }
66  }
67 
68 #else
69 
70  void VirtexE::initializeDeviceInfo(const std::string& inDeviceName) {
71 
77 
78  // look up the device tile map
79  torc::architecture::DDB ddb(inDeviceName);
80  const torc::architecture::Tiles& tiles = ddb.getTiles();
81  uint32_t tileCount = tiles.getTileCount();
82  uint16_t rowCount = tiles.getRowCount();
83  uint16_t colCount = tiles.getColCount();
84  ColumnTypeVector columnTypes;
85 
86  // set up the tile index and name mappings, and the index to column def mapping
87  typedef std::map<TileTypeIndex, std::string> TileTypeIndexToName;
88  typedef std::map<std::string, TileTypeIndex> TileTypeNameToIndex;
89  TileTypeIndexToName tileTypeIndexToName;
90  TileTypeNameToIndex tileTypeNameToIndex;
91  TileTypeCount tileTypeCount = tiles.getTileTypeCount();
92  for(TileTypeIndex tileTypeIndex(0); tileTypeIndex < tileTypeCount; tileTypeIndex++) {
93  const std::string tileTypeName = tiles.getTileTypeName(tileTypeIndex);
94  tileTypeIndexToName[tileTypeIndex] = tileTypeName;
95  tileTypeNameToIndex[tileTypeName] = tileTypeIndex;
96  TileTypeNameToColumnType::iterator ttwp = mTileTypeNameToColumnType.find(tileTypeName);
97  TileTypeNameToColumnType::iterator ttwe = mTileTypeNameToColumnType.end();
98  if(ttwp != ttwe) mTileTypeIndexToColumnType[tileTypeIndex] = EColumnType(ttwp->second);
99  }
100 
101  // identify every column that contains known frames
102  columnTypes.resize(colCount);
103  uint32_t frameCount = 0;
104  for(uint32_t blockType = 0; blockType < Virtex::eFarBlockTypeCount; blockType++) {
105  for(TileCol col; col < colCount; col++) {
106  bool found = false;
107  columnTypes[col] = eColumnTypeEmpty;
108  TileTypeIndexToColumnType::iterator ttwe = mTileTypeIndexToColumnType.end();
109  TileTypeIndexToColumnType::iterator ttwp = ttwe;
110  for(TileRow row; row < rowCount; row++) {
111  // look up the tile info
112  const torc::architecture::TileInfo& tileInfo
113  = tiles.getTileInfo(tiles.getTileIndex(row, col));
114  TileTypeIndex tileTypeIndex = tileInfo.getTypeIndex();
115  // determine whether the tile type widths are defined
116  ttwp = mTileTypeIndexToColumnType.find(tileTypeIndex);
117  if(ttwp != ttwe) {
118  uint32_t width = mColumnDefs[ttwp->second][blockType];
119  frameCount += width;
120  //std::cout << " " << tiles.getTileTypeName(tileInfo.getTypeIndex())
121  //<< ": " << width << " (" << frameCount << ")" << std::endl;
122  columnTypes[col] = static_cast<EColumnType>(ttwp->second);
123  found = true;
124  break;
125  }
126  }
127  (void) found;
128  }
129  //std::cout << std::endl;
130  if(blockType == 2) break;
131  }
132 
134  boost::filesystem::path generatedMap = workingPath / (inDeviceName + ".map.csv");
135  std::fstream tilemapStream(generatedMap.string().c_str(), std::ios::out);
136  for(TileRow row; row < rowCount; row++) {
137  for(TileCol col; col < colCount; col++) {
138  const torc::architecture::TileInfo& tileInfo
139  = tiles.getTileInfo(tiles.getTileIndex(row, col));
140  TileTypeIndex tileTypeIndex = tileInfo.getTypeIndex();
141  tilemapStream << tiles.getTileTypeName(tileTypeIndex);
142  if(col + 1 < colCount) tilemapStream << ",";
143  }
144  tilemapStream << std::endl;
145  }
146  tilemapStream.close();
147 
148  // update bitstream device information
149  setDeviceInfo(DeviceInfo(tileCount, rowCount, colCount, columnTypes));
150  // update the frame length
151  }
152 
153 #endif
154 
156 
157  bool debug = 0;
158  int center = 0;
159  int frameIndex = 0;
160  int frameCount = 0;
161  int farMajor = 0;
162  int width = 0;
163  ColumnIndex col;
164  const ColumnTypeVector& columnTypes = mDeviceInfo.getColumnTypes();
165  for(uint32_t i = 0; i < VirtexE::eFarBlockTypeCount; i++) {
166  farMajor = i;
167  mFrameIndexBounds = 0;
168  EFarBlockType blockType = VirtexE::EFarBlockType(i);
169  //Set first frame index to 0
170  uint32_t bitIndex = 0;
171  uint32_t xdlIndex = 0;
172  mBitColumnIndexes[i].push_back(bitIndex);
173  mXdlColumnIndexes[i].push_back(xdlIndex);
174  uint16_t finalColumn = mDeviceInfo.getColCount()-1;
175  uint32_t xdlColumnCount = 0;
176  uint32_t bitColumnCount = 0;
177  // Clock Column at the middle
178  center = mDeviceInfo.getColCount()/2;
179  col = center;
180  prepareFrames(col, frameCount, frameIndex, blockType, farMajor, width);
181  int numBrams = 4;
182  int numIobs = 2;
183  int numClocks = 1;
184  int numClbs = mDeviceInfo.getColCount() - numClocks - numBrams - numIobs;
185  // Extended memory devices have different frame mapping
187  // CLB Columns alternate around the clock column
188  for(int j = 1; j < center; j++) {
189  for(int k = -1; k < 2; k += 2) {
190  col = center - (j * k);
191  if(columnTypes[col] == eColumnTypeClb) {
192  prepareFrames(col, frameCount, frameIndex, blockType, farMajor, width);
193  }
194  //Indexes for Bitstream Columns, only stores non-empty tile types
196  mXdlColumnToBitColumn[xdlColumnCount] = bitColumnCount;
197  bitColumnCount++;
198  bitIndex += width;
199  mBitColumnIndexes[i].push_back(bitIndex);
200  if(col == finalColumn) {
201  bitIndex += mColumnDefs[mDeviceInfo.getColumnTypes()[col]][i];
202  mBitColumnIndexes[i].push_back(bitIndex);
203  }
204  }
205  //Indexes for XDL Columns, stores interconnect and tile indexes for
206  //non-empty tiles
207  xdlIndex += width;
208  mXdlColumnIndexes[i].push_back(xdlIndex);
209  xdlColumnCount++;
210  if(col == finalColumn)
211  {
212  xdlIndex += mColumnDefs[mDeviceInfo.getColumnTypes()[col]][i];
213  mXdlColumnIndexes[i].push_back(xdlIndex);
214  }
215  }
216  }
217  // IOB Columns alternate after the CLB's
218  for(int j = center; j < (center + 1); j++) {
219  for(int k = -1; k < 2; k += 2) {
220  col = center - (j * k);
221  prepareFrames(col, frameCount, frameIndex, blockType, farMajor, width);
222  //Indexes for Bitstream Columns, only stores non-empty tile types
224  mXdlColumnToBitColumn[xdlColumnCount] = bitColumnCount;
225  bitColumnCount++;
226  bitIndex += width;
227  mBitColumnIndexes[i].push_back(bitIndex);
228  if(col == finalColumn) {
229  bitIndex += mColumnDefs[mDeviceInfo.getColumnTypes()[col]][i];
230  mBitColumnIndexes[i].push_back(bitIndex);
231  }
232  }
233  //Indexes for XDL Columns, stores interconnect and tile indexes for
234  //non-empty tiles
235  xdlIndex += width;
236  mXdlColumnIndexes[i].push_back(xdlIndex);
237  xdlColumnCount++;
238  if(col == finalColumn)
239  {
240  xdlIndex += mColumnDefs[mDeviceInfo.getColumnTypes()[col]][i];
241  mXdlColumnIndexes[i].push_back(xdlIndex);
242  }
243  }
244  }
245  // BRAM Columns alternate after the IOB's
246  for(int j = 1; j < center; j++) {
247  for(int k = -1; k < 2; k += 2) {
248  col = center - (j * k);
249  if(columnTypes[col] == eColumnTypeBram) {
250  prepareFrames(col, frameCount, frameIndex, blockType, farMajor, width);
251  }
252  //Indexes for Bitstream Columns, only stores non-empty tile types
254  mXdlColumnToBitColumn[xdlColumnCount] = bitColumnCount;
255  bitColumnCount++;
256  bitIndex += width;
257  mBitColumnIndexes[i].push_back(bitIndex);
258  if(col == finalColumn) {
259  bitIndex += mColumnDefs[mDeviceInfo.getColumnTypes()[col]][i];
260  mBitColumnIndexes[i].push_back(bitIndex);
261  }
262  }
263  //Indexes for XDL Columns, stores interconnect and tile indexes for
264  //non-empty tiles
265  xdlIndex += width;
266  mXdlColumnIndexes[i].push_back(xdlIndex);
267  xdlColumnCount++;
268  if(col == finalColumn)
269  {
270  xdlIndex += mColumnDefs[mDeviceInfo.getColumnTypes()[col]][i];
271  mXdlColumnIndexes[i].push_back(xdlIndex);
272  }
273  }
274  }
275  }
276  else {
277  // CLB and BRAM Columns alternate around the clock column
278  for(int j = 1; j <= (numClbs + numBrams) / 2; j++) {
279  for(int k = -1; k < 2; k += 2) {
280  col = center - (j * k);
281  prepareFrames(col, frameCount, frameIndex, blockType, farMajor, width);
282  //Indexes for Bitstream Columns, only stores non-empty tile types
284  mXdlColumnToBitColumn[xdlColumnCount] = bitColumnCount;
285  bitColumnCount++;
286  bitIndex += width;
287  mBitColumnIndexes[i].push_back(bitIndex);
288  if(col == finalColumn) {
289  bitIndex += mColumnDefs[mDeviceInfo.getColumnTypes()[col]][i];
290  mBitColumnIndexes[i].push_back(bitIndex);
291  }
292  }
293  //Indexes for XDL Columns, stores interconnect and tile indexes for
294  //non-empty tiles
295  xdlIndex += width;
296  mXdlColumnIndexes[i].push_back(xdlIndex);
297  xdlColumnCount++;
298  if(col == finalColumn)
299  {
300  xdlIndex += mColumnDefs[mDeviceInfo.getColumnTypes()[col]][i];
301  mXdlColumnIndexes[i].push_back(xdlIndex);
302  }
303  }
304  }
305  // IOB Columns alternate after the CLB's
306  for(int j = center; j < (center + 1); j++) {
307  for(int k = -1; k < 2; k += 2) {
308  col = center - (j * k);
309  prepareFrames(col, frameCount, frameIndex, blockType, farMajor, width);
310  //Indexes for Bitstream Columns, only stores non-empty tile types
312  mXdlColumnToBitColumn[xdlColumnCount] = bitColumnCount;
313  bitColumnCount++;
314  bitIndex += width;
315  mBitColumnIndexes[i].push_back(bitIndex);
316  if(col == finalColumn) {
317  bitIndex += mColumnDefs[mDeviceInfo.getColumnTypes()[col]][i];
318  mBitColumnIndexes[i].push_back(bitIndex);
319  }
320  }
321  //Indexes for XDL Columns, stores interconnect and tile indexes for
322  //non-empty tiles
323  xdlIndex += width;
324  mXdlColumnIndexes[i].push_back(xdlIndex);
325  xdlColumnCount++;
326  if(col == finalColumn)
327  {
328  xdlIndex += mColumnDefs[mDeviceInfo.getColumnTypes()[col]][i];
329  mXdlColumnIndexes[i].push_back(xdlIndex);
330  }
331  }
332  }
333  }
334  //stores frame index bounds for each block type
336  if(debug) std::cout << "***Block frame index bounds: " << mBlockFrameIndexBounds[i] << std::endl;
337  }
338  //Test to check proper indexing
339  if(debug) {
340  for(uint32_t i = 0; i < Virtex::eFarBlockTypeCount; i++) {
341  for(uint32_t j = 0; j < mBitColumnIndexes[i].size(); j++)
342  std::cout << "Bit Value at index: (" << i << ", " << j << ") : " << mBitColumnIndexes[i][j] << std::endl;
343  for(uint32_t k = 0; k < mXdlColumnIndexes[i].size(); k++)
344  std::cout << "Xdl Value at index: (" << i << ", " << k << ") : " << mXdlColumnIndexes[i][k] << std::endl;
345  }
346  }
347  }
348 
349 } // namespace bitstream
350 }
ColumnDefVector mColumnDefs
Column type widths.
DeviceInfo xcv400e
Encapsulation of a tile row in an unsigned 16-bit integer.
Header for the VirtexE class.
TileTypeNameToColumnType mTileTypeNameToColumnType
uint32_t mFrameIndexBounds
Frame index bounds count.
Definition: Virtex.hpp:220
DeviceInfo xcv600e
Encapsulation of a tile column in an unsigned 16-bit integer.
Device database, including complete wiring and logic support.
Definition: DDB.hpp:42
TileTypeCount getTileTypeCount(void) const
Returns the tile type count for this device.
Definition: Tiles.hpp:151
TileRow getRowCount(void) const
Returns the row count for this device.
Definition: Tiles.hpp:153
DeviceInfo xcv3200e
Header for the DirectoryTree class.
IndexVector mXdlColumnIndexes[Virtex::eFarBlockTypeCount]
Vector to store frame indexes of Bitstream columns.
Definition: Virtex.hpp:216
const TileInfo & getTileInfo(TileIndex inTileIndex) const
Returns the TileInfo object for the specified tile.
Definition: Tiles.hpp:137
virtual void initializeDeviceInfo(const std::string &inDeviceName)
Initialize the device information.
Definition: VirtexE.cpp:48
DeviceInfo xcv405e
TileTypeIndexToColumnType mTileTypeIndexToColumnType
uint16_t getColCount(void) const
Returns the column count.
Definition: DeviceInfo.hpp:114
void prepareFrames(ColumnIndex &inCol, int &inFrameCount, int &inFrameIndex, EFarBlockType &inBlockType, int &inFarMajor, int &inWidth)
Definition: Virtex.cpp:471
TileCount getTileCount(void) const
Returns the tile count for this device.
Definition: Tiles.hpp:149
EDevice mDevice
Bitstream device enumeration.
DeviceInfo xcv50e
std::string string
DeviceInfo xcv2000e
boost::uint32_t uint32_t
Imported type name.
DeviceInfo xcv1000e
uint32_t mBlockFrameIndexBounds[Virtex::eFarBlockTypeCount]
Array to hold frame index boundaries for blocks.
Definition: Virtex.hpp:218
IndexVector mBitColumnIndexes[Virtex::eFarBlockTypeCount]
Vector to store frame indexes of XDL columns.
Definition: Virtex.hpp:214
DeviceInfo mDeviceInfo
Device information.
Tile map, tile type, and wire information for the family and device.
Definition: Tiles.hpp:36
std::map< uint32_t, uint32_t > mXdlColumnToBitColumn
Map of XDL column indexes to bitstream column indexes.
Definition: Virtex.hpp:222
Encapsulation of a tile count in an unsigned 32-bit integer.
Encapsulation of a tile within a device tile map.
Definition: TileInfo.hpp:33
const char * getTileTypeName(TileTypeIndex inTileTypeIndex) const
Returns the tile type name for the given tile type index.
Definition: Tiles.hpp:164
const ColumnTypeVector & getColumnTypes(void) const
Returns the column type vector.
Definition: DeviceInfo.hpp:116
DeviceInfo xcv812e
DeviceInfo xcv1600e
boost::filesystem::path path
const TileTypeIndex & getTypeIndex(void) const
Returns the tile type index for this tile.
Definition: TileInfo.hpp:92
EFarBlockType
Frame Address Register block type constants.
Definition: Virtex.hpp:73
DeviceInfo xcv300e
DeviceInfo xcv200e
static const boost::filesystem::path & getWorkingPath(void)
Returns the absolute path to the working directory.
Encapsulation of a tile type count in an unsigned 16-bit integer.
TileCol getColCount(void) const
Returns the column count for this device.
Definition: Tiles.hpp:155
Encapsulation of a tile type index in an unsigned 16-bit integer.
boost::uint32_t uint32_t
Imported type name.
Definition: Virtex.hpp:49
boost::uint16_t uint16_t
Imported type name.
Header for the DDB class.
Template base for encapsulated integers, to enforce strong typing.
virtual void initializeFrameMaps(void)
Initialize the maps between frame indexes and frame addresses. This is generally only useful for int...
Definition: VirtexE.cpp:155
DeviceInfo xcv100e
void setDeviceInfo(const DeviceInfo &rhs)
Assign static device information for the current bitstream.
TileIndex getTileIndex(TileRow inRow, TileCol inCol) const
Returns the tile index for the given [row,column] pair.
Definition: Tiles.hpp:161
DeviceInfo xcv2600e
EColumnType
Major column types.
Definition: Virtex.hpp:78
Device database types for Xilinx architectures.