Skip to content

Commit

Permalink
added alternative gate label method, added cached version to test spe…
Browse files Browse the repository at this point in the history
…ed up netlist abstraction traversal
  • Loading branch information
Simon Klix committed Dec 18, 2024
1 parent 76807b2 commit 3d2a22d
Show file tree
Hide file tree
Showing 7 changed files with 561 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ namespace hal
const std::function<bool(const Gate*)>& target_gate_filter,
const PinDirection& direction,
const bool directed = true,
bool continue_on_match = false,
const bool continue_on_match = false,
const std::function<bool(const Endpoint*, const u32 current_depth)>& exit_endpoint_filter = nullptr,
const std::function<bool(const Endpoint*, const u32 current_depth)>& entry_endpoint_filter = nullptr) const;

Expand All @@ -307,10 +307,56 @@ namespace hal
const std::function<bool(const Gate*)>& target_gate_filter,
const PinDirection& direction,
const bool directed = true,
bool continue_on_match = false,
const bool continue_on_match = false,
const std::function<bool(const Endpoint*, const u32 current_depth)>& exit_endpoint_filter = nullptr,
const std::function<bool(const Endpoint*, const u32 current_depth)>& entry_endpoint_filter = nullptr) const;

/**
* @brief Starting from the given endpoint, traverse the netlist abstraction and return the successor/predecessor gates for which the `target_gate_filter` evaluates to `true`.
* Traverse over gates that do not meet the `target_gate_filter` condition.
* Stop traversal if (1) `continue_on_match` is `false` and the `target_gate_filter` evaluates to `true`, (2) the `exit_endpoint_filter` evaluates to `false` on a fan-in/out endpoint, or (3) the `entry_endpoint_filter` evaluates to `false` on a successor/predecessor endpoint.
* Both the `entry_endpoint_filter` and the `exit_endpoint_filter` may be omitted.
*
* @param[in] endpoint - The starting endpoint.
* @param[in] target_gate_filter - Filter condition that must be met for the target gates.
* @param[in] direction - The direction to search in (`PinDirection::input` or `PinDirection::output`).
* @param[in] directed - Defines whether we are searching on a directed or undirected graph represenation of the netlist.
* @param[in] continue_on_match - Set `true` to continue even if `target_gate_filter` evaluates to `true`, `false` otherwise. Defaults to `false`.
* @param[in] exit_endpoint_filter - Filter condition to stop traversal on a fan-in/out endpoint.
* @param[in] entry_endpoint_filter - Filter condition to stop traversal on a successor/predecessor endpoint.
* @returns OK() and a set of gates fulfilling the `target_gate_filter` condition on success, an error otherwise.
*/
Result<std::vector<std::set<Gate*>>> get_next_matching_gates(const std::vector<Endpoint*>& endpoints,
const std::function<bool(const Gate*)>& target_gate_filter,
const PinDirection& direction,
const bool directed = true,
const bool continue_on_match = false,
const std::function<bool(const Endpoint*, const u32 current_depth)>& exit_endpoint_filter = nullptr,
const std::function<bool(const Endpoint*, const u32 current_depth)>& entry_endpoint_filter = nullptr) const;

/**
* @brief Starting from the given gate, traverse the netlist abstraction and return the successor/predecessor gates for which the `target_gate_filter` evaluates to `true`.
* Traverse over gates that do not meet the `target_gate_filter` condition.
* Stop traversal if (1) `continue_on_match` is `false` and the `target_gate_filter` evaluates to `true`, (2) the `exit_endpoint_filter` evaluates to `false` on a fan-in/out endpoint, or (3) the `entry_endpoint_filter` evaluates to `false` on a successor/predecessor endpoint.
* Both the `entry_endpoint_filter` and the `exit_endpoint_filter` may be omitted.
*
* @param[in] gate - The starting gate.
* @param[in] target_gate_filter - Filter condition that must be met for the target gates.
* @param[in] direction - The direction to search in (`PinDirection::input` or `PinDirection::output`).
* @param[in] directed - Defines whether we are searching on a directed or undirected graph represenation of the netlist.
* @param[in] continue_on_match - Set `true` to continue even if `target_gate_filter` evaluates to `true`, `false` otherwise. Defaults to `false`.
* @param[in] exit_endpoint_filter - Filter condition to stop traversal on a fan-in/out endpoint.
* @param[in] entry_endpoint_filter - Filter condition to stop traversal on a successor/predecessor endpoint.
* @returns OK() and a set of gates fulfilling the `target_gate_filter` condition on success, an error otherwise.
*/
Result<std::vector<std::set<Gate*>>> get_next_matching_gates(const std::vector<Gate*>& gates,
const std::function<bool(const Gate*)>& target_gate_filter,
const PinDirection& direction,
const bool directed = true,
const bool continue_on_match = false,
const std::function<bool(const Endpoint*, const u32 current_depth)>& exit_endpoint_filter = nullptr,
const std::function<bool(const Endpoint*, const u32 current_depth)>& entry_endpoint_filter = nullptr) const;

/**
* @brief Starting from the given endpoint, traverse the netlist abstraction and return the successor/predecessor gates for which the `target_gate_filter` evaluates to `true`.
* Continue traversal regardless of whether `target_gate_filter` evaluates to `true` or `false`.
Expand All @@ -330,7 +376,7 @@ namespace hal
const std::function<bool(const Gate*)>& target_gate_filter,
const PinDirection& direction,
const bool directed = true,
bool continue_on_mismatch = false,
const bool continue_on_mismatch = false,
const std::function<bool(const Endpoint*, const u32 current_depth)>& exit_endpoint_filter = nullptr,
const std::function<bool(const Endpoint*, const u32 current_depth)>& entry_endpoint_filter = nullptr) const;

Expand All @@ -353,7 +399,7 @@ namespace hal
const std::function<bool(const Gate*)>& target_gate_filter,
const PinDirection& direction,
const bool directed = true,
bool continue_on_mismatch = false,
const bool continue_on_mismatch = false,
const std::function<bool(const Endpoint*, const u32 current_depth)>& exit_endpoint_filter = nullptr,
const std::function<bool(const Endpoint*, const u32 current_depth)>& entry_endpoint_filter = nullptr) const;

Expand Down Expand Up @@ -392,7 +438,28 @@ namespace hal
const std::function<bool(const Gate*)>& target_gate_filter,
const PinDirection& direction,
const bool directed = true,
bool continue_on_match = false,
const bool continue_on_match = false,
const std::function<bool(const Endpoint*, u32 current_depth)>& exit_endpoint_filter = nullptr,
const std::function<bool(const Endpoint*, u32 current_depth)>& entry_endpoint_filter = nullptr) const;

/**
* @brief Internal method to traverse the netlist abstraction and return matching gates based on the provided filters.
*
* @param[in] start - The starting endpoints.
* @param[in] target_gate_filter - Filter condition that must be met for the target gates.
* @param[in] direction - The direction to search in.
* @param[in] directed - Defines whether we are searching on a directed or undirected graph represenation of the netlist.
* @param[in] continue_on_match - Determines whether to continue traversal after a match.
* @param[in] exit_endpoint_filter - Filter condition to stop traversal on a fan-in/out endpoint.
* @param[in] entry_endpoint_filter - Filter condition to stop traversal on a successor/predecessor endpoint.
* @returns OK() and a set of gates fulfilling the `target_gate_filter` condition on success, an error otherwise.
*/
Result<std::set<Gate*>> get_next_matching_gates_internal(const std::vector<Endpoint*>& start,
const std::function<bool(const Gate*)>& target_gate_filter,
const PinDirection& direction,
std::map<std::pair<Endpoint*, u32>, std::set<Gate*>>& cache,
const bool directed = true,
const bool continue_on_match = false,
const std::function<bool(const Endpoint*, u32 current_depth)>& exit_endpoint_filter = nullptr,
const std::function<bool(const Endpoint*, u32 current_depth)>& entry_endpoint_filter = nullptr) const;

Expand All @@ -412,7 +479,7 @@ namespace hal
const std::function<bool(const Gate*)>& target_gate_filter,
const PinDirection& direction,
const bool directed = true,
bool continue_on_mismatch = false,
const bool continue_on_mismatch = false,
const std::function<bool(const Endpoint*, const u32 current_depth)>& exit_endpoint_filter = nullptr,
const std::function<bool(const Endpoint*, const u32 current_depth)>& entry_endpoint_filter = nullptr) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace hal
/* Forward declarations */
class Gate;
enum class GateTypeProperty : int;
enum class PinType : int;

namespace machine_learning
{
Expand Down Expand Up @@ -82,6 +83,34 @@ namespace hal
const std::string m_key_word;
const std::vector<GateTypeProperty> m_applicable_to;
};

/**
* @class NetNameKeyWord
* @brief Labels gate based on whether one of the net names at specified pins includes a keyword or not.
*/
class NetNameKeyWord : public GateLabel
{
public:
/**
* @brief Default constructor.
*/
NetNameKeyWord(const std::string& key_word, const std::vector<PinType>& pin_types, const std::vector<GateTypeProperty>& applicable_to = {})
: m_key_word(key_word), m_pin_types(pin_types), m_applicable_to(applicable_to){};

const std::vector<u32> MATCH = {1, 0, 0};
const std::vector<u32> MISMATCH = {0, 1, 0};
const std::vector<u32> NA = {0, 0, 1};

Result<std::vector<u32>> calculate_label(Context& ctx, const Gate* g) const override;
Result<std::vector<std::vector<u32>>> calculate_labels(Context& ctx, const std::vector<Gate*>& gates) const override;
Result<std::vector<std::vector<u32>>> calculate_labels(Context& ctx) const override;
std::string to_string() const override;

private:
const std::string m_key_word;
const std::vector<PinType> m_pin_types;
const std::vector<GateTypeProperty> m_applicable_to;
};
} // namespace gate_label
} // namespace machine_learning
} // namespace hal
Loading

0 comments on commit 3d2a22d

Please sign in to comment.