|
| 1 | +#pragma once |
| 2 | + |
| 3 | +/** @file Nested parallel case for NetlistRouter */ |
| 4 | +#include "netlist_routers.h" |
| 5 | +#include "vtr_optional.h" |
| 6 | +#include "vtr_thread_pool.h" |
| 7 | +#include <unordered_map> |
| 8 | + |
| 9 | +/* Add cmd line option for this later */ |
| 10 | +constexpr int MAX_THREADS = 4; |
| 11 | + |
| 12 | +/** Nested parallel impl for NetlistRouter. |
| 13 | + * |
| 14 | + * Calls a parallel ConnectionRouter for route_net to extract even more parallelism. |
| 15 | + * The main reason why this is a different router instead of templating NetlistRouter |
| 16 | + * on ConnectionRouter is this router does not use TBB. The scheduling performance is |
| 17 | + * worse, but it can wait in individual tasks now (which is not possible with TBB). |
| 18 | + * |
| 19 | + * Holds enough context members to glue together ConnectionRouter and net routing functions, |
| 20 | + * such as \ref route_net. Keeps the members in thread-local storage where needed, |
| 21 | + * i.e. ConnectionRouters and RouteIterResults-es. |
| 22 | + * See \ref route_net. */ |
| 23 | +template<typename HeapType> |
| 24 | +class NestedNetlistRouter : public NetlistRouter { |
| 25 | + public: |
| 26 | + NestedNetlistRouter( |
| 27 | + const Netlist<>& net_list, |
| 28 | + const RouterLookahead* router_lookahead, |
| 29 | + const t_router_opts& router_opts, |
| 30 | + CBRR& connections_inf, |
| 31 | + NetPinsMatrix<float>& net_delay, |
| 32 | + const ClusteredPinAtomPinsLookup& netlist_pin_lookup, |
| 33 | + std::shared_ptr<SetupHoldTimingInfo> timing_info, |
| 34 | + NetPinTimingInvalidator* pin_timing_invalidator, |
| 35 | + route_budgets& budgeting_inf, |
| 36 | + const RoutingPredictor& routing_predictor, |
| 37 | + const vtr::vector<ParentNetId, std::vector<std::unordered_map<RRNodeId, int>>>& choking_spots, |
| 38 | + bool is_flat) |
| 39 | + : _net_list(net_list) |
| 40 | + , _router_lookahead(router_lookahead) |
| 41 | + , _router_opts(router_opts) |
| 42 | + , _connections_inf(connections_inf) |
| 43 | + , _net_delay(net_delay) |
| 44 | + , _netlist_pin_lookup(netlist_pin_lookup) |
| 45 | + , _timing_info(timing_info) |
| 46 | + , _pin_timing_invalidator(pin_timing_invalidator) |
| 47 | + , _budgeting_inf(budgeting_inf) |
| 48 | + , _routing_predictor(routing_predictor) |
| 49 | + , _choking_spots(choking_spots) |
| 50 | + , _is_flat(is_flat) |
| 51 | + , _thread_pool(MAX_THREADS) {} |
| 52 | + ~NestedNetlistRouter() {} |
| 53 | + |
| 54 | + /** Run a single iteration of netlist routing for this->_net_list. This usually means calling |
| 55 | + * \ref route_net for each net, which will handle other global updates. |
| 56 | + * \return RouteIterResults for this iteration. */ |
| 57 | + RouteIterResults route_netlist(int itry, float pres_fac, float worst_neg_slack); |
| 58 | + /** Inform the PartitionTree of the nets with updated bounding boxes */ |
| 59 | + void handle_bb_updated_nets(const std::vector<ParentNetId>& nets); |
| 60 | + |
| 61 | + /** Set rcv_enabled for each ConnectionRouter this is managing */ |
| 62 | + void set_rcv_enabled(bool x); |
| 63 | + /** Set timing_info for each ConnectionRouter this is managing */ |
| 64 | + void set_timing_info(std::shared_ptr<SetupHoldTimingInfo> timing_info); |
| 65 | + |
| 66 | + private: |
| 67 | + /** Route all nets in a PartitionTree node and add its children to the task queue. */ |
| 68 | + void route_partition_tree_node(PartitionTreeNode& node); |
| 69 | + |
| 70 | + ConnectionRouter<HeapType> _make_router(const RouterLookahead* router_lookahead, bool is_flat) { |
| 71 | + auto& device_ctx = g_vpr_ctx.device(); |
| 72 | + auto& route_ctx = g_vpr_ctx.mutable_routing(); |
| 73 | + |
| 74 | + return ConnectionRouter<HeapType>( |
| 75 | + device_ctx.grid, |
| 76 | + *router_lookahead, |
| 77 | + device_ctx.rr_graph.rr_nodes(), |
| 78 | + &device_ctx.rr_graph, |
| 79 | + device_ctx.rr_rc_data, |
| 80 | + device_ctx.rr_graph.rr_switch(), |
| 81 | + route_ctx.rr_node_route_inf, |
| 82 | + is_flat); |
| 83 | + } |
| 84 | + |
| 85 | + /* Context fields. Most of them will be forwarded to route_net (see route_net.tpp) */ |
| 86 | + const Netlist<>& _net_list; |
| 87 | + const RouterLookahead* _router_lookahead; |
| 88 | + const t_router_opts& _router_opts; |
| 89 | + CBRR& _connections_inf; |
| 90 | + NetPinsMatrix<float>& _net_delay; |
| 91 | + const ClusteredPinAtomPinsLookup& _netlist_pin_lookup; |
| 92 | + std::shared_ptr<SetupHoldTimingInfo> _timing_info; |
| 93 | + NetPinTimingInvalidator* _pin_timing_invalidator; |
| 94 | + route_budgets& _budgeting_inf; |
| 95 | + const RoutingPredictor& _routing_predictor; |
| 96 | + const vtr::vector<ParentNetId, std::vector<std::unordered_map<RRNodeId, int>>>& _choking_spots; |
| 97 | + bool _is_flat; |
| 98 | + |
| 99 | + /** Cached routing parameters for current iteration (inputs to \see route_netlist()) */ |
| 100 | + int _itry; |
| 101 | + float _pres_fac; |
| 102 | + float _worst_neg_slack; |
| 103 | + |
| 104 | + /** The partition tree. Holds the groups of nets for each partition */ |
| 105 | + vtr::optional<PartitionTree> _tree; |
| 106 | + |
| 107 | + /** Thread pool for parallel routing. See vtr_thread_pool.h for implementation */ |
| 108 | + vtr::thread_pool _thread_pool; |
| 109 | + |
| 110 | + /* Thread-local storage. |
| 111 | + * These are maps because thread::id is a random integer instead of 1, 2, ... */ |
| 112 | + std::unordered_map<std::thread::id, ConnectionRouter<HeapType>> _routers_th; |
| 113 | + std::unordered_map<std::thread::id, RouteIterResults> _results_th; |
| 114 | + std::mutex _storage_mutex; |
| 115 | + |
| 116 | + /** Get a thread-local ConnectionRouter. We lock the id->router lookup, but this is |
| 117 | + * accessed once per partition so the overhead should be small */ |
| 118 | + ConnectionRouter<HeapType>& get_thread_router() { |
| 119 | + auto id = std::this_thread::get_id(); |
| 120 | + std::lock_guard<std::mutex> lock(_storage_mutex); |
| 121 | + if (!_routers_th.count(id)) { |
| 122 | + _routers_th.emplace(id, _make_router(_router_lookahead, _is_flat)); |
| 123 | + } |
| 124 | + return _routers_th.at(id); |
| 125 | + } |
| 126 | + |
| 127 | + RouteIterResults& get_thread_results() { |
| 128 | + auto id = std::this_thread::get_id(); |
| 129 | + std::lock_guard<std::mutex> lock(_storage_mutex); |
| 130 | + return _results_th[id]; |
| 131 | + } |
| 132 | +}; |
| 133 | + |
| 134 | +#include "NestedNetlistRouter.tpp" |
0 commit comments