Skip to content

Commit 3d2a22d

Browse files
author
Simon Klix
committed
added alternative gate label method, added cached version to test speed up netlist abstraction traversal
1 parent 76807b2 commit 3d2a22d

File tree

7 files changed

+561
-16
lines changed

7 files changed

+561
-16
lines changed

include/hal_core/netlist/decorators/netlist_abstraction_decorator.h

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ namespace hal
284284
const std::function<bool(const Gate*)>& target_gate_filter,
285285
const PinDirection& direction,
286286
const bool directed = true,
287-
bool continue_on_match = false,
287+
const bool continue_on_match = false,
288288
const std::function<bool(const Endpoint*, const u32 current_depth)>& exit_endpoint_filter = nullptr,
289289
const std::function<bool(const Endpoint*, const u32 current_depth)>& entry_endpoint_filter = nullptr) const;
290290

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

314+
/**
315+
* @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`.
316+
* Traverse over gates that do not meet the `target_gate_filter` condition.
317+
* 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.
318+
* Both the `entry_endpoint_filter` and the `exit_endpoint_filter` may be omitted.
319+
*
320+
* @param[in] endpoint - The starting endpoint.
321+
* @param[in] target_gate_filter - Filter condition that must be met for the target gates.
322+
* @param[in] direction - The direction to search in (`PinDirection::input` or `PinDirection::output`).
323+
* @param[in] directed - Defines whether we are searching on a directed or undirected graph represenation of the netlist.
324+
* @param[in] continue_on_match - Set `true` to continue even if `target_gate_filter` evaluates to `true`, `false` otherwise. Defaults to `false`.
325+
* @param[in] exit_endpoint_filter - Filter condition to stop traversal on a fan-in/out endpoint.
326+
* @param[in] entry_endpoint_filter - Filter condition to stop traversal on a successor/predecessor endpoint.
327+
* @returns OK() and a set of gates fulfilling the `target_gate_filter` condition on success, an error otherwise.
328+
*/
329+
Result<std::vector<std::set<Gate*>>> get_next_matching_gates(const std::vector<Endpoint*>& endpoints,
330+
const std::function<bool(const Gate*)>& target_gate_filter,
331+
const PinDirection& direction,
332+
const bool directed = true,
333+
const bool continue_on_match = false,
334+
const std::function<bool(const Endpoint*, const u32 current_depth)>& exit_endpoint_filter = nullptr,
335+
const std::function<bool(const Endpoint*, const u32 current_depth)>& entry_endpoint_filter = nullptr) const;
336+
337+
/**
338+
* @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`.
339+
* Traverse over gates that do not meet the `target_gate_filter` condition.
340+
* 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.
341+
* Both the `entry_endpoint_filter` and the `exit_endpoint_filter` may be omitted.
342+
*
343+
* @param[in] gate - The starting gate.
344+
* @param[in] target_gate_filter - Filter condition that must be met for the target gates.
345+
* @param[in] direction - The direction to search in (`PinDirection::input` or `PinDirection::output`).
346+
* @param[in] directed - Defines whether we are searching on a directed or undirected graph represenation of the netlist.
347+
* @param[in] continue_on_match - Set `true` to continue even if `target_gate_filter` evaluates to `true`, `false` otherwise. Defaults to `false`.
348+
* @param[in] exit_endpoint_filter - Filter condition to stop traversal on a fan-in/out endpoint.
349+
* @param[in] entry_endpoint_filter - Filter condition to stop traversal on a successor/predecessor endpoint.
350+
* @returns OK() and a set of gates fulfilling the `target_gate_filter` condition on success, an error otherwise.
351+
*/
352+
Result<std::vector<std::set<Gate*>>> get_next_matching_gates(const std::vector<Gate*>& gates,
353+
const std::function<bool(const Gate*)>& target_gate_filter,
354+
const PinDirection& direction,
355+
const bool directed = true,
356+
const bool continue_on_match = false,
357+
const std::function<bool(const Endpoint*, const u32 current_depth)>& exit_endpoint_filter = nullptr,
358+
const std::function<bool(const Endpoint*, const u32 current_depth)>& entry_endpoint_filter = nullptr) const;
359+
314360
/**
315361
* @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`.
316362
* Continue traversal regardless of whether `target_gate_filter` evaluates to `true` or `false`.
@@ -330,7 +376,7 @@ namespace hal
330376
const std::function<bool(const Gate*)>& target_gate_filter,
331377
const PinDirection& direction,
332378
const bool directed = true,
333-
bool continue_on_mismatch = false,
379+
const bool continue_on_mismatch = false,
334380
const std::function<bool(const Endpoint*, const u32 current_depth)>& exit_endpoint_filter = nullptr,
335381
const std::function<bool(const Endpoint*, const u32 current_depth)>& entry_endpoint_filter = nullptr) const;
336382

@@ -353,7 +399,7 @@ namespace hal
353399
const std::function<bool(const Gate*)>& target_gate_filter,
354400
const PinDirection& direction,
355401
const bool directed = true,
356-
bool continue_on_mismatch = false,
402+
const bool continue_on_mismatch = false,
357403
const std::function<bool(const Endpoint*, const u32 current_depth)>& exit_endpoint_filter = nullptr,
358404
const std::function<bool(const Endpoint*, const u32 current_depth)>& entry_endpoint_filter = nullptr) const;
359405

@@ -392,7 +438,28 @@ namespace hal
392438
const std::function<bool(const Gate*)>& target_gate_filter,
393439
const PinDirection& direction,
394440
const bool directed = true,
395-
bool continue_on_match = false,
441+
const bool continue_on_match = false,
442+
const std::function<bool(const Endpoint*, u32 current_depth)>& exit_endpoint_filter = nullptr,
443+
const std::function<bool(const Endpoint*, u32 current_depth)>& entry_endpoint_filter = nullptr) const;
444+
445+
/**
446+
* @brief Internal method to traverse the netlist abstraction and return matching gates based on the provided filters.
447+
*
448+
* @param[in] start - The starting endpoints.
449+
* @param[in] target_gate_filter - Filter condition that must be met for the target gates.
450+
* @param[in] direction - The direction to search in.
451+
* @param[in] directed - Defines whether we are searching on a directed or undirected graph represenation of the netlist.
452+
* @param[in] continue_on_match - Determines whether to continue traversal after a match.
453+
* @param[in] exit_endpoint_filter - Filter condition to stop traversal on a fan-in/out endpoint.
454+
* @param[in] entry_endpoint_filter - Filter condition to stop traversal on a successor/predecessor endpoint.
455+
* @returns OK() and a set of gates fulfilling the `target_gate_filter` condition on success, an error otherwise.
456+
*/
457+
Result<std::set<Gate*>> get_next_matching_gates_internal(const std::vector<Endpoint*>& start,
458+
const std::function<bool(const Gate*)>& target_gate_filter,
459+
const PinDirection& direction,
460+
std::map<std::pair<Endpoint*, u32>, std::set<Gate*>>& cache,
461+
const bool directed = true,
462+
const bool continue_on_match = false,
396463
const std::function<bool(const Endpoint*, u32 current_depth)>& exit_endpoint_filter = nullptr,
397464
const std::function<bool(const Endpoint*, u32 current_depth)>& entry_endpoint_filter = nullptr) const;
398465

@@ -412,7 +479,7 @@ namespace hal
412479
const std::function<bool(const Gate*)>& target_gate_filter,
413480
const PinDirection& direction,
414481
const bool directed = true,
415-
bool continue_on_mismatch = false,
482+
const bool continue_on_mismatch = false,
416483
const std::function<bool(const Endpoint*, const u32 current_depth)>& exit_endpoint_filter = nullptr,
417484
const std::function<bool(const Endpoint*, const u32 current_depth)>& entry_endpoint_filter = nullptr) const;
418485

plugins/machine_learning/include/machine_learning/labels/gate_label.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace hal
1717
/* Forward declarations */
1818
class Gate;
1919
enum class GateTypeProperty : int;
20+
enum class PinType : int;
2021

2122
namespace machine_learning
2223
{
@@ -82,6 +83,34 @@ namespace hal
8283
const std::string m_key_word;
8384
const std::vector<GateTypeProperty> m_applicable_to;
8485
};
86+
87+
/**
88+
* @class NetNameKeyWord
89+
* @brief Labels gate based on whether one of the net names at specified pins includes a keyword or not.
90+
*/
91+
class NetNameKeyWord : public GateLabel
92+
{
93+
public:
94+
/**
95+
* @brief Default constructor.
96+
*/
97+
NetNameKeyWord(const std::string& key_word, const std::vector<PinType>& pin_types, const std::vector<GateTypeProperty>& applicable_to = {})
98+
: m_key_word(key_word), m_pin_types(pin_types), m_applicable_to(applicable_to){};
99+
100+
const std::vector<u32> MATCH = {1, 0, 0};
101+
const std::vector<u32> MISMATCH = {0, 1, 0};
102+
const std::vector<u32> NA = {0, 0, 1};
103+
104+
Result<std::vector<u32>> calculate_label(Context& ctx, const Gate* g) const override;
105+
Result<std::vector<std::vector<u32>>> calculate_labels(Context& ctx, const std::vector<Gate*>& gates) const override;
106+
Result<std::vector<std::vector<u32>>> calculate_labels(Context& ctx) const override;
107+
std::string to_string() const override;
108+
109+
private:
110+
const std::string m_key_word;
111+
const std::vector<PinType> m_pin_types;
112+
const std::vector<GateTypeProperty> m_applicable_to;
113+
};
85114
} // namespace gate_label
86115
} // namespace machine_learning
87116
} // namespace hal

0 commit comments

Comments
 (0)