Skip to content

Commit a30b810

Browse files
author
Simon Klix
committed
changed how the net name match is calculated
1 parent 3d2a22d commit a30b810

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

plugins/machine_learning/src/labels/gate_label.cpp

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "hal_core/netlist/gate.h"
22
#include "hal_core/netlist/net.h"
33
#include "machine_learning/labels/gate_label.h"
4+
#include "netlist_preprocessing/netlist_preprocessing.h"
5+
#include "nlohmann/json.hpp"
46

57
namespace hal
68
{
@@ -73,13 +75,56 @@ namespace hal
7375
{
7476
if (g->get_type()->has_property(gtp))
7577
{
78+
if (!g->has_data("preprocessing_information", "multi_bit_indexed_identifiers"))
79+
{
80+
log_error("machine_learning", "unable to find indexed identifiers for gate with ID {}", g->get_id());
81+
continue;
82+
}
83+
84+
const std::string json_string = std::get<1>(g->get_data("preprocessing_information", "multi_bit_indexed_identifiers"));
85+
86+
nlohmann::json j = nlohmann::json::parse(json_string);
87+
std::vector<netlist_preprocessing::indexed_identifier> index_information = j.get<std::vector<netlist_preprocessing::indexed_identifier>>();
88+
89+
// for each pin, only consider the index information with the least distance
90+
std::map<std::string, u32> pin_to_min_distance;
91+
for (const auto& [_name, _index, _origin, pin, _direction, distance] : index_information)
92+
{
93+
if (const auto it = pin_to_min_distance.find(pin); it == pin_to_min_distance.end())
94+
{
95+
pin_to_min_distance.insert({pin, distance});
96+
}
97+
else
98+
{
99+
pin_to_min_distance.at(pin) = std::min(it->second, distance);
100+
}
101+
}
102+
103+
std::map<std::string, std::string> pin_to_net_name;
104+
for (const auto& [name, _index, _origin, pin, _direction, distance] : index_information)
105+
{
106+
if (pin_to_min_distance.at(pin) == distance)
107+
{
108+
pin_to_net_name.insert({pin, name});
109+
}
110+
}
111+
76112
for (const auto& pt : m_pin_types)
77113
{
78114
const auto& pins = g->get_type()->get_pins([&pt](const auto& gt_p) { return gt_p->get_type() == pt; });
79115
for (const auto* p : pins)
80116
{
81-
const auto* ep = (p->get_direction() == PinDirection::input) ? g->get_fan_in_endpoint(p) : g->get_fan_out_endpoint(p);
82-
const auto& net_name = ep->get_net()->get_name();
117+
std::string net_name;
118+
if (const auto it = pin_to_net_name.find(p->get_name()); it != pin_to_net_name.end())
119+
{
120+
net_name = pin_to_net_name.at(p->get_name());
121+
}
122+
else
123+
{
124+
const auto* ep = (p->get_direction() == PinDirection::input) ? g->get_fan_in_endpoint(p) : g->get_fan_out_endpoint(p);
125+
net_name = ep->get_net()->get_name();
126+
}
127+
83128
if (net_name.find(m_key_word) != std::string::npos)
84129
{
85130
return OK(MATCH);

plugins/netlist_preprocessing/include/netlist_preprocessing/netlist_preprocessing.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ namespace hal
155155
*/
156156
Result<u32> simplify_lut_inits(Netlist* nl);
157157

158-
159158
/**
160159
* Represents an identifier with an associated index and additional metadata, used for reconstructing and annotating names and indices
161160
* for flip flops in synthesized netlists based on input and output net names as well as gate names.
@@ -185,7 +184,7 @@ namespace hal
185184
PinDirection direction; /**< Direction of the pin. */
186185
u32 distance; /**< Distance to merged net which name this index was derived from. */
187186

188-
// Overload < operator for strict weak ordering
187+
// Overload < operator for strict weak ordering
189188
bool operator<(const indexed_identifier& other) const;
190189
};
191190

0 commit comments

Comments
 (0)