CkPttn 1.2.4
Loading...
Searching...
No Matches
netlist.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include <cstddef> // for size_t
9#include <cstdint> // for uint32_t, uint8_t
10#include <py2cpp/dict.hpp> // for dict
11#include <py2cpp/range.hpp> // for range, _iterator, iterable_wra...
12#include <py2cpp/set.hpp> // for set
13// #include <type_traits> // for move
14#include <vector> // for vector
15
16// using node_t = int;
17
18// struct PartInfo
19// {
20// std::vector<std::uint8_t> part;
21// py::set<node_t> extern_nets;
22// };
23
31template <typename graph_t> struct Netlist {
32 using nodeview_t = typename graph_t::nodeview_t;
33 using node_t = typename graph_t::node_t;
34 using index_t = typename nodeview_t::key_type;
35 // using graph_t = xnetwork::Graph<graph_t>;
36
44 size_t num_modules{};
46 size_t num_nets{};
48 size_t num_pads{};
50 size_t max_degree{};
53 // std::uint8_t cost_model = 0;
55 std::vector<unsigned int> module_weight;
59 py::set<node_t> module_fixed;
60
61 public:
75
83 Netlist(graph_t gr, uint32_t numModules, uint32_t numNets);
84
85 auto begin() const { return this->modules.begin(); }
86
87 auto end() const { return this->modules.end(); }
88
94 auto number_of_modules() const -> size_t { return this->num_modules; }
95
101 auto number_of_nets() const -> size_t { return this->num_nets; }
102
108 auto number_of_nodes() const -> size_t { return this->gr.number_of_nodes(); }
109
110 // /**
111 // * @brief
112 // *
113 // * @return index_t
114 // */
115 // auto number_of_pins() const -> index_t { return
116 // this->gr.number_of_edges(); }
117
123 auto get_max_degree() const -> size_t { return this->max_degree; }
124
130 auto get_max_net_degree() const -> size_t { return this->max_net_degree; }
131
138 auto get_module_weight(const node_t& v) const -> unsigned int {
139 return this->module_weight.empty() ? 1U : this->module_weight[v];
140 }
141
147 auto get_net_weight(const node_t& /*net*/) const -> uint32_t {
148 // return this->net_weight.is_empty() ? 1
149 // :
150 // this->net_weight[this->net_map[net]];
151 return 1U;
152 }
153};
154
155template <typename graph_t>
157 : gr{std::move(gr)},
158 modules{modules},
159 nets{nets},
160 num_modules(modules.size()),
161 num_nets(nets.size()) {
162 this->has_fixed_modules = (!this->module_fixed.empty());
163
164 // Some compilers does not accept py::range()->iterator as a forward
165 // iterator auto deg_cmp = [this](const node_t& v, const node_t& w) ->
166 // index_t {
167 // return this->gr.degree(v) < this->gr.degree(w);
168 // };
169 // const auto result1 =
170 // std::max_element(this->modules.begin(), this->modules.end(),
171 // deg_cmp);
172 // this->max_degree = this->gr.degree(*result1);
173 // const auto result2 =
174 // std::max_element(this->nets.begin(), this->nets.end(), deg_cmp);
175 // this->max_net_degree = this->gr.degree(*result2);
176
177 for (const auto& v : this->modules) {
178 if (this->max_degree < this->gr.degree(v)) {
179 this->max_degree = this->gr.degree(v);
180 }
181 }
182
183 for (const auto& net : this->nets) {
184 if (this->max_net_degree < this->gr.degree(net)) {
185 this->max_net_degree = this->gr.degree(net);
186 }
187 }
188}
189
190template <typename graph_t>
191Netlist<graph_t>::Netlist(graph_t gr, uint32_t numModules, uint32_t numNets)
192 : Netlist{std::move(gr), py::range(numModules), py::range(numModules, numModules + numNets)} {}
193
194#include <xnetwork/classes/graph.hpp> // for Graph, Graph<>::nodeview_t
195
196// using RngIter = decltype(py::range(1));
197using graph_t = xnetwork::SimpleGraph;
198using index_t = uint32_t;
200
209template <typename Node> struct Snapshot {
211 py::set<Node> extern_nets;
213 py::dict<index_t, std::uint8_t> extern_modules;
214};
uint32_t index_t
Definition netlist.hpp:198
xnetwork::SimpleGraph graph_t
Definition netlist.hpp:197
Netlist data structure.
Definition netlist.hpp:31
typename graph_t::nodeview_t nodeview_t
Definition netlist.hpp:32
size_t max_net_degree
Maximum degree among all nets.
Definition netlist.hpp:52
typename nodeview_t::key_type index_t
Definition netlist.hpp:34
bool has_fixed_modules
Flag indicating whether any modules have fixed positions.
Definition netlist.hpp:57
nodeview_t modules
Node view for modules (circuit components)
Definition netlist.hpp:40
size_t max_degree
Maximum degree among all modules.
Definition netlist.hpp:50
auto get_net_weight(const node_t &) const -> uint32_t
Get the net weight.
Definition netlist.hpp:147
auto get_module_weight(const node_t &v) const -> unsigned int
Get the module weight.
Definition netlist.hpp:138
size_t num_pads
Number of pads (I/O nodes)
Definition netlist.hpp:48
size_t num_nets
Number of nets in the netlist.
Definition netlist.hpp:46
typename graph_t::node_t node_t
Definition netlist.hpp:33
auto number_of_nodes() const -> size_t
Get the number of nodes.
Definition netlist.hpp:108
auto get_max_degree() const -> size_t
Get the max degree.
Definition netlist.hpp:123
auto number_of_nets() const -> size_t
Get the number of nets.
Definition netlist.hpp:101
auto end() const
Definition netlist.hpp:87
auto number_of_modules() const -> size_t
Get the number of modules.
Definition netlist.hpp:94
auto begin() const
Definition netlist.hpp:85
size_t num_modules
Number of modules in the netlist.
Definition netlist.hpp:44
graph_t gr
The underlying graph structure.
Definition netlist.hpp:38
py::set< node_t > module_fixed
Set of modules with fixed positions.
Definition netlist.hpp:59
nodeview_t nets
Node view for nets (connections)
Definition netlist.hpp:42
auto get_max_net_degree() const -> size_t
Get the max net degree.
Definition netlist.hpp:130
Netlist(graph_t gr, const nodeview_t &modules, const nodeview_t &nets)
Construct a new Netlist object.
Definition netlist.hpp:156
std::vector< unsigned int > module_weight
Weight for each module.
Definition netlist.hpp:55
Snapshot of partition state for rollback.
Definition netlist.hpp:209
py::set< Node > extern_nets
Set of external nets (nets crossing partition boundaries)
Definition netlist.hpp:211
py::dict< index_t, std::uint8_t > extern_modules
Dictionary mapping external modules to their partition assignments.
Definition netlist.hpp:213