1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
|
#ifndef DEDUP_CHIPDB_H
#define DEDUP_CHIPDB_H
#include "RoutingGraph.hpp"
#include <map>
#include <unordered_map>
#include <boost/functional/hash.hpp>
#include <cstdint>
#include <memory>
using namespace std;
namespace Trellis {
namespace DDChipDb {
/*
A deduplicated chip database is a database with the following properties, intended to be used in place-and-route flows.
- All coordinates are relative
- All wire, bel and arc IDs are sequential starting from zero at a location
- Locations with identical wire, bel and arc data once converted to relative coordinates are only stored once
- The database is fully linked: wires contain arcs and bel pins up and downhill, arcs store their up and down wires,
etc
*/
struct RelId
{
Location rel;
int32_t id = -1;
};
inline bool operator<(RelId a, RelId b)
{
return (a.rel < b.rel) || (a.rel == b.rel && a.id < b.id);
}
inline bool operator==(RelId a, RelId b)
{
return (a.rel == b.rel) && (a.id == b.id);
}
inline bool operator!=(RelId a, RelId b)
{
return (a.rel != b.rel) || (a.id != b.id);
}
struct BelPort
{
RelId bel;
ident_t pin = -1;
};
inline bool operator==(const BelPort &a, const BelPort &b)
{
return a.bel == b.bel && a.pin == b.pin;
}
struct BelWire
{
RelId wire;
ident_t pin = -1;
PortDirection dir;
};
inline bool operator==(const BelWire &a, const BelWire &b)
{
return a.wire == b.wire && a.pin == b.pin && a.dir == b.dir;
}
enum ArcClass : int8_t
{
ARC_STANDARD = 0,
ARC_FIXED = 1
};
struct DdArcData
{
RelId srcWire;
RelId sinkWire;
ArcClass cls;
int32_t delay;
ident_t tiletype;
int16_t lutperm_flags;
};
inline bool operator==(const DdArcData &a, const DdArcData &b)
{
return a.srcWire == b.srcWire && a.sinkWire == b.sinkWire && a.cls == b.cls && a.delay == b.delay &&
a.tiletype == b.tiletype && a.lutperm_flags == b.lutperm_flags;
}
struct WireData
{
ident_t name;
set<RelId> arcsDownhill, arcsUphill;
vector<BelPort> belPins;
};
inline bool operator==(const WireData &a, const WireData &b)
{
return a.name == b.name && a.arcsDownhill.size() == b.arcsDownhill.size() &&
equal(a.arcsDownhill.begin(), a.arcsDownhill.end(), b.arcsDownhill.begin())
&& a.arcsUphill.size() == b.arcsUphill.size()
&& equal(a.arcsUphill.begin(), a.arcsUphill.end(), b.arcsUphill.begin())
&& a.belPins.size() == b.belPins.size()
&& equal(a.belPins.begin(), a.belPins.end(), b.belPins.begin());
}
struct BelData
{
ident_t name, type;
int z;
vector<BelWire> wires;
};
inline bool operator==(const BelData &a, const BelData &b)
{
return a.name == b.name && a.type == b.type && a.z == b.z && a.wires.size() == b.wires.size()
&& equal(a.wires.begin(), a.wires.end(), b.wires.begin());
}
typedef pair<uint64_t, uint64_t> checksum_t;
struct LocationData
{
vector<WireData> wires;
vector<DdArcData> arcs;
vector<BelData> bels;
checksum_t checksum() const;
};
inline bool operator==(const LocationData &a, const LocationData &b)
{
return a.wires.size() == b.wires.size() && equal(a.wires.begin(), a.wires.end(), b.wires.begin()) &&
a.arcs.size() == b.arcs.size() && equal(a.arcs.begin(), a.arcs.end(), b.arcs.begin())
&& a.bels.size() == b.bels.size() && equal(a.bels.begin(), a.bels.end(), b.bels.begin());
}
}
}
namespace std {
template<>
struct hash<Trellis::DDChipDb::RelId>
{
std::size_t operator()(const Trellis::DDChipDb::RelId &rid) const noexcept
{
std::size_t seed = 0;
boost::hash_combine(seed, hash<Trellis::Location>()(rid.rel));
boost::hash_combine(seed, hash<int32_t>()(rid.id));
return seed;
}
};
template<>
struct hash<set<Trellis::DDChipDb::RelId>>
{
std::size_t operator()(const set<Trellis::DDChipDb::RelId> &rids) const noexcept
{
std::size_t seed = 0;
for (const auto &rid : rids)
boost::hash_combine(seed, hash<Trellis::DDChipDb::RelId>()(rid));
return seed;
}
};
template<>
struct hash<vector<Trellis::DDChipDb::RelId>>
{
std::size_t operator()(const vector<Trellis::DDChipDb::RelId> &rids) const noexcept
{
std::size_t seed = 0;
for (const auto &rid : rids)
boost::hash_combine(seed, hash<Trellis::DDChipDb::RelId>()(rid));
return seed;
}
};
template<>
struct hash<Trellis::DDChipDb::BelPort>
{
std::size_t operator()(const Trellis::DDChipDb::BelPort &port) const noexcept
{
std::size_t seed = 0;
boost::hash_combine(seed, hash<Trellis::DDChipDb::RelId>()(port.bel));
boost::hash_combine(seed, hash<Trellis::ident_t>()(port.pin));
return seed;
}
};
template<>
struct hash<Trellis::DDChipDb::BelWire>
{
std::size_t operator()(const Trellis::DDChipDb::BelWire &port) const noexcept
{
std::size_t seed = 0;
boost::hash_combine(seed, hash<Trellis::DDChipDb::RelId>()(port.wire));
boost::hash_combine(seed, hash<Trellis::ident_t>()(port.pin));
boost::hash_combine(seed, hash<Trellis::ident_t>()(port.dir));
return seed;
}
};
template<>
struct hash<vector<Trellis::DDChipDb::BelPort>>
{
std::size_t operator()(const vector<Trellis::DDChipDb::BelPort> &bps) const noexcept
{
std::size_t seed = 0;
for (const auto &bp : bps)
boost::hash_combine(seed, hash<Trellis::DDChipDb::BelPort>()(bp));
return seed;
}
};
template<>
struct hash<vector<Trellis::DDChipDb::BelWire>>
{
std::size_t operator()(const vector<Trellis::DDChipDb::BelWire> &bps) const noexcept
{
std::size_t seed = 0;
for (const auto &bp : bps)
boost::hash_combine(seed, hash<Trellis::DDChipDb::BelWire>()(bp));
return seed;
}
};
template<>
struct hash<Trellis::DDChipDb::DdArcData>
{
std::size_t operator()(const Trellis::DDChipDb::DdArcData &arc) const noexcept
{
std::size_t seed = 0;
boost::hash_combine(seed, hash<Trellis::DDChipDb::RelId>()(arc.srcWire));
boost::hash_combine(seed, hash<Trellis::DDChipDb::RelId>()(arc.sinkWire));
boost::hash_combine(seed, hash<int8_t>()(arc.cls));
boost::hash_combine(seed, hash<int32_t>()(arc.delay));
boost::hash_combine(seed, hash<Trellis::ident_t>()(arc.tiletype));
boost::hash_combine(seed, hash<uint16_t>()(arc.lutperm_flags));
return seed;
}
};
template<>
struct hash<Trellis::DDChipDb::WireData>
{
std::size_t operator()(const Trellis::DDChipDb::WireData &wire) const noexcept
{
std::size_t seed = 0;
boost::hash_combine(seed, hash<Trellis::ident_t>()(wire.name));
boost::hash_combine(seed, hash<set<Trellis::DDChipDb::RelId>>()(wire.arcsDownhill));
boost::hash_combine(seed, hash<set<Trellis::DDChipDb::RelId>>()(wire.arcsUphill));
boost::hash_combine(seed, hash<vector<Trellis::DDChipDb::BelPort>>()(wire.belPins));
return seed;
}
};
template<>
struct hash<Trellis::DDChipDb::BelData>
{
std::size_t operator()(const Trellis::DDChipDb::BelData &bel) const noexcept
{
std::size_t seed = 0;
boost::hash_combine(seed, hash<Trellis::ident_t>()(bel.name));
boost::hash_combine(seed, hash<Trellis::ident_t>()(bel.type));
boost::hash_combine(seed, hash<vector<Trellis::DDChipDb::BelWire>>()(bel.wires));
boost::hash_combine(seed, hash<int>()(bel.z));
return seed;
}
};
template<>
struct hash<vector<Trellis::DDChipDb::BelData>>
{
std::size_t operator()(const vector<Trellis::DDChipDb::BelData> &vec) const noexcept
{
std::size_t seed = 0;
for (const auto &item : vec)
boost::hash_combine(seed, hash<Trellis::DDChipDb::BelData>()(item));
return seed;
}
};
template<>
struct hash<vector<Trellis::DDChipDb::DdArcData>>
{
std::size_t operator()(const vector<Trellis::DDChipDb::DdArcData> &vec) const noexcept
{
std::size_t seed = 0;
for (const auto &item : vec)
boost::hash_combine(seed, hash<Trellis::DDChipDb::DdArcData>()(item));
return seed;
}
};
template<>
struct hash<vector<Trellis::DDChipDb::WireData>>
{
std::size_t operator()(const vector<Trellis::DDChipDb::WireData> &vec) const noexcept
{
std::size_t seed = 0;
for (const auto &item : vec)
boost::hash_combine(seed, hash<Trellis::DDChipDb::WireData>()(item));
return seed;
}
};
template<>
struct hash<Trellis::DDChipDb::checksum_t>
{
std::size_t operator()(const Trellis::DDChipDb::checksum_t &cs) const noexcept
{
std::size_t seed = 0;
boost::hash_combine(seed, hash<uint64_t>()(cs.first));
boost::hash_combine(seed, hash<uint64_t>()(cs.second));
return seed;
}
};
template<>
struct hash<Trellis::DDChipDb::LocationData>
{
std::size_t operator()(const Trellis::DDChipDb::LocationData &ld) const noexcept
{
std::size_t seed = 0;
boost::hash_combine(seed, hash<vector<Trellis::DDChipDb::WireData>>()(ld.wires));
boost::hash_combine(seed, hash<vector<Trellis::DDChipDb::DdArcData>>()(ld.arcs));
boost::hash_combine(seed, hash<vector<Trellis::DDChipDb::BelData>>()(ld.bels));
return seed;
}
};
}
namespace Trellis {
class Chip;
namespace DDChipDb {
struct DedupChipdb : public IdStore
{
DedupChipdb();
DedupChipdb(const IdStore &base);
map<checksum_t, LocationData> locationTypes;
map<Location, checksum_t> typeAtLocation;
LocationData get_cs_data(checksum_t id);
};
shared_ptr<DedupChipdb> make_dedup_chipdb(Chip &chip, bool include_lutperm_pips = false, bool split_slice_mode = false);
/*
An optimized chip database is a database with the following properties, intended to be used in place-and-route flows.
- All wire, bel and arc IDs are sequential starting from zero at a location
- Sequential IDs means it is possible to store wires, bels, and arcs in vectors instead of maps
- The database is fully linked: wires contain arcs and bel pins up and downhill, arcs store their up and down wires,
etc
This database is _not_ deduplicated, meaning global data is still stored directly
in this database and relative coordinates are NOT used! Types are reused when
possible.
*/
typedef RelId OptId;
typedef DdArcData OptArcData;
struct OptimizedChipdb : public IdStore
{
OptimizedChipdb();
OptimizedChipdb(const IdStore &base);
map<Location, LocationData> tiles;
};
shared_ptr<OptimizedChipdb> make_optimized_chipdb(Chip &chip, bool include_lutperm_pips = false, bool split_slice_mode = false);
}
}
#endif
|