Skip to content

Commit

Permalink
changed how the net name match is calculated
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Klix committed Dec 18, 2024
1 parent 3d2a22d commit a30b810
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
49 changes: 47 additions & 2 deletions plugins/machine_learning/src/labels/gate_label.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "hal_core/netlist/gate.h"
#include "hal_core/netlist/net.h"
#include "machine_learning/labels/gate_label.h"
#include "netlist_preprocessing/netlist_preprocessing.h"
#include "nlohmann/json.hpp"

namespace hal
{
Expand Down Expand Up @@ -73,13 +75,56 @@ namespace hal
{
if (g->get_type()->has_property(gtp))
{
if (!g->has_data("preprocessing_information", "multi_bit_indexed_identifiers"))
{
log_error("machine_learning", "unable to find indexed identifiers for gate with ID {}", g->get_id());
continue;
}

const std::string json_string = std::get<1>(g->get_data("preprocessing_information", "multi_bit_indexed_identifiers"));

nlohmann::json j = nlohmann::json::parse(json_string);
std::vector<netlist_preprocessing::indexed_identifier> index_information = j.get<std::vector<netlist_preprocessing::indexed_identifier>>();

// for each pin, only consider the index information with the least distance
std::map<std::string, u32> pin_to_min_distance;
for (const auto& [_name, _index, _origin, pin, _direction, distance] : index_information)
{
if (const auto it = pin_to_min_distance.find(pin); it == pin_to_min_distance.end())
{
pin_to_min_distance.insert({pin, distance});
}
else
{
pin_to_min_distance.at(pin) = std::min(it->second, distance);
}
}

std::map<std::string, std::string> pin_to_net_name;
for (const auto& [name, _index, _origin, pin, _direction, distance] : index_information)
{
if (pin_to_min_distance.at(pin) == distance)
{
pin_to_net_name.insert({pin, name});
}
}

for (const auto& pt : m_pin_types)
{
const auto& pins = g->get_type()->get_pins([&pt](const auto& gt_p) { return gt_p->get_type() == pt; });
for (const auto* p : pins)
{
const auto* ep = (p->get_direction() == PinDirection::input) ? g->get_fan_in_endpoint(p) : g->get_fan_out_endpoint(p);
const auto& net_name = ep->get_net()->get_name();
std::string net_name;
if (const auto it = pin_to_net_name.find(p->get_name()); it != pin_to_net_name.end())
{
net_name = pin_to_net_name.at(p->get_name());
}
else
{
const auto* ep = (p->get_direction() == PinDirection::input) ? g->get_fan_in_endpoint(p) : g->get_fan_out_endpoint(p);
net_name = ep->get_net()->get_name();
}

if (net_name.find(m_key_word) != std::string::npos)
{
return OK(MATCH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ namespace hal
*/
Result<u32> simplify_lut_inits(Netlist* nl);


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

// Overload < operator for strict weak ordering
// Overload < operator for strict weak ordering
bool operator<(const indexed_identifier& other) const;
};

Expand Down

0 comments on commit a30b810

Please sign in to comment.