12 namespace py = pybind11;
16 #ifdef PYBIND11_MODULE
17 PYBIND11_MODULE(module_identification, m)
19 m.doc() =
"Plugin for module classification against a library of predefined types.";
23 py::module m(
"module_identification",
"Plugin for module classification against a library of predefined types.");
26 py::class_<ModuleIdentificationPlugin, RawPtrWrapper<ModuleIdentificationPlugin>,
BasePluginInterface> py_module_identification_plugin(
27 m,
"ModuleIdentificationPlugin", R
"(This class provides an interface to integrate the module identification tool as a plugin within the HAL framework.)");
30 The name of the plugin.
36 Get the name of the plugin.
38 :returns: The name of the plugin.
43 The version of the plugin.
49 Get the version of the plugin.
51 :returns: The version of the plugin.
56 The description of the plugin.
62 Get the description of the plugin.
64 :returns: The description of the plugin.
69 A set of plugin names that this plugin depends on.
75 Get a set of plugin names that this plugin depends on.
77 :returns: A set of plugin names that this plugin depends on.
82 py::class_<module_identification::Configuration> py_configuration(m,
"Configuration", R
"(
83 Configuration for the module identification analysis.
84 This struct holds important parameters that configure the module identification analysis, including netlist to analyze, known registers, candidate types to check, threading options, etc.
87 py_configuration.def(py::init<hal::Netlist*>(), py::arg("nl"), R
"(
88 Constructs a new ModuleIdentification analysis configuration for the given netlist.
90 :param hal_py.Netlist nl: The netlist to be analyzed.
93 py_configuration.def(py::init<>(), R"(
94 Constructs an empty configuration.
98 The netlist to be analyzed.
100 :type: hal_py.Netlist
104 A vector handling possibly known registers.
106 :type: list[list[hal_py.Gate]]
110 CandidateTypes that shall be checked. Defaults to all checkable candidate types.
112 :type: list[module_identification.CandidateType]
116 Maximum number of concurrent threads created during execution. Defaults to 1.
122 Maximum number of control signals to be tested. Defaults to 3.
128 Gates to ignore during processing.
130 :type: list[list[hal_py.Gate]]
134 Base candidates to block during analysis.
136 :type: list[set[hal_py.Gate]]
140 Choose which `MultithreadingPriority` to use for the analysis. Defaults to memory priority
142 :type: module_identification.MultithreadingPriority
146 Set the known registers for prioritization.
148 :param list[list[hal_py.Gate]] registers: The groups provided by a dana run.
149 :returns: The updated module identification configuration.
150 :rtype: module_identification.Configuration
154 Set the maximum number of threads.
156 :param int max_thread_count: The number of threads to be started at max.
157 :returns: The updated module identification configuration.
158 :rtype: module_identification.Configuration
162 Set the maximum number of control signals to be tested.
164 :param int max_control_signals: The number of control signals checked.
165 :returns: The updated module identification configuration.
166 :rtype: module_identification.Configuration
170 Set the multithreading priority type.
172 :param module_identification.MultithreadingPriority priority: The type of multithreading used during execution.
173 :returns: The updated module identification configuration.
174 :rtype: module_identification.Configuration
178 Set the candidate types to be checked.
180 :param list[module_identification.CandidateType] types_to_check: A list of candidate types to be checked for.
181 :returns: The updated module identification configuration.
182 :rtype: module_identification.Configuration
186 Add gates to be ignored during processing.
188 All candidates that are build during the module identification run that contain any gates that overlap with any already classified candidate are discarded to avoid conflicts.
190 :param list[list[hal_py.Gate]] already_classified_candidates: Candidates to be ignored.
191 :returns: The updated module identification configuration.
192 :rtype: module_identification.Configuration
196 Add base candidates to be blocked during analysis.
198 :param list[set[hal_py.Gate]] blocked_base_candidates: Base candidates to be ignored.
199 :returns: The updated module identification configuration.
200 :rtype: module_identification.Configuration
204 py::class_<module_identification::Result> py_result(m,
"Result", R
"(
205 The result of a module identification run containing the candidates.
208 py_result.def(py::init<hal::Netlist*, const std::vector<std::pair<module_identification::BaseCandidate, module_identification::VerifiedCandidate>>&,
const std::string&>(),
211 py::arg(
"timing_stats_json") =
"",
213 Constructor for `Result`.
215 :param hal_py.Netlist nl: The netlist on which module identification has been performed.
216 :param list[tuple(module_identification.BaseCandidate, module_identification.VerifiedCandidate)] result: A vector of pairs containing base candidates and their verified candidates.
217 :param str timing_stats_json: A JSON string containing timing statistics. Defaults to an empty string.
221 Get the netlist on which module identification has been performed.
223 :returns: The netlist.
224 :rtype: hal_py.Netlist
228 Get a map of the candidate IDs to the gates contained inside the verified candidates.
230 This map only contains verified candidates that are fully verified.
231 The ID is only unique for this result.
233 :returns: A map of candidate IDs to a vector of gates.
234 :rtype: dict[int, list[hal_py.Gate]]
238 Get a map of the candidate IDs to the verified candidates.
240 This map only contains verified candidates that are fully verified.
241 The ID is only unique for this result.
243 :returns: A map of candidate IDs to verified candidates.
244 :rtype: dict[int, module_identification.VerifiedCandidate]
248 Get a map of the candidate IDs to the gates contained inside the candidate.
250 This map contains all checked candidates, even the ones not verified.
251 The ID is only unique for this result.
253 :returns: A map of candidate IDs to a vector of gates.
254 :rtype: dict[int, list[hal_py.Gate]]
258 Get a map of the candidate IDs to the candidates.
260 This map contains all checked candidates, even the ones not verified.
261 The ID is only unique for this result.
263 :returns: A map of candidate IDs to candidates.
264 :rtype: dict[int, module_identification.VerifiedCandidate]
268 "get_candidate_gates_by_id",
270 const auto res =
self.get_candidate_gates_by_id(
id);
277 log_error(
"python_context",
"error encountered while getting gates of candidate:\n{}", res.get_error().get());
283 Get the gates of the candidate with the corresponding ID.
285 :param int id: The ID of the requested candidate.
286 :returns: The gates of the candidate on success, ``None`` otherwise.
287 :rtype: list[hal_py.Gate] or None
291 "get_candidate_by_id",
293 const auto res =
self.get_candidate_by_id(
id);
300 log_error(
"python_context",
"error encountered while getting candidate:\n{}", res.get_error().get());
306 Get the candidate with the corresponding ID.
308 :param int id: The ID of the requested candidate.
309 :returns: The verified candidate on success, ``None`` otherwise.
310 :rtype: module_identification.VerifiedCandidate or None
314 Get all gates contained in any of the candidates.
316 :returns: A set of gates.
317 :rtype: set[hal_py.Gate]
321 Get all gates contained in any of the verified candidates.
323 :returns: A set of gates.
324 :rtype: set[hal_py.Gate]
328 "create_modules_in_netlist",
330 const auto res =
self.create_modules_in_netlist();
338 log_error(
"python_context",
"error encountered while merging results:\n{}", res.get_error().get());
343 Creates a HAL module for each candidate of the result.
345 :returns: ```True``` on success, ```False``` otherwise.
350 Get the collected timing information formatted as a JSON string.
352 :returns: A JSON formatted string.
359 const auto res =
self.merge(other, registers);
366 log_error(
"python_context",
"error encountered while merging results:\n{}", res.get_error().get());
371 py::arg(
"registers"),
373 Merges two results by combining the found verified candidates.
375 When both results contain a verified candidate for the same base candidate, the better one is chosen via the same post-processing used in the original module identification process.
376 This requires that the base candidates are identical and that all gates of all candidates still exist in the netlist!
378 :param module_identification.Result other: Another module identification result that is merged with this one.
379 :param list[list[hal_py.Gate]] registers: A list of previously identified register groupings that is used in the post-processing.
380 :returns: The merged module identification result on success, ``None`` otherwise.
381 :rtype: module_identification.Result or None
384 py_result.def_static(
386 For different runs of the plugin figure out in which iteration the plugin found the highest quality result for each candidate.
388 This is used to compare the results of different runs of the plugin and afterwards get a list of base candidates for each execution for which this execution gave the best results.
390 :param list[module_identification.Result] iteration_results: A vector of all the execution results.
391 :param bool create_block_lists: A parameter to determine whether to create allow or block lists.
392 :returns: A vector of allow or block lists for each plugin execution iteration.
393 :rtype: list[list[set[hal_py.Gate]]]
407 log_error(
"python_context",
"error encountered while executing module identification:\n{}", res.get_error().get());
413 Perform a full run of the module identification process on the given netlist with the provided configuration.
415 This function executes the complete module identification process on the specified netlist. It uses the provided configuration to guide the identification process and returns a result object containing information about all analyzed candidates.
417 :param module_identification.Configuration config: The configuration to guide the identification process.
418 :returns: The result of the run containing all computed results and options for further processing on success, ``None`` otherwise.
419 :rtype: module_identification.Result or None
432 log_error(
"python_context",
"error encountered while executing module identification on gates:\n{}", res.get_error().get());
439 Perform a module identification run on the specified gates with the provided configuration.
441 This function executes the module identification process on a specific set of gates. It uses the provided configuration to guide the identification process and returns a result object containing information about all analyzed candidates.
443 :param list[hal_py.Gate] gates: The gates to be analyzed.
444 :param module_identification.Configuration config: The configuration to guide the identification process.
445 :returns: The result of the run containing all computed results and options for further processing on success, ``None`` otherwise.
446 :rtype: module_identification.Result or None
450 py::enum_<module_identification::Architecture> py_architecture(m,
"Architecture", R
"(
451 Defines supported FPGA architectures.
452 This enum specifies the FPGA architectures that are supported by the module identification plugin.
460 py::enum_<module_identification::CandidateType> py_candidate_type(m,
"CandidateType", R
"(
461 Enumeration of the different candidate types for module identification.
462 This enum specifies the types of operations that the module identification process can recognize and verify, such as arithmetic operations and comparisons.
484 py::enum_<module_identification::MultithreadingPriority> py_multithreading_priority(m,
"MultithreadingPriority", R
"(
485 Specifies the strategy for multithreading in the module identification process.
486 This enum class defines the strategies for managing multithreading in the module identification plugin.
487 The strategies determine how resources are allocated and prioritized when performing multithreaded operations.
490 py_multithreading_priority
492 Prioritize time efficiency in multithreading.
493 This option specifies that multithreading should be handled with a priority on time efficiency,
494 aiming to complete tasks as quickly as possible.
497 Prioritize memory efficiency in multithreading.
498 This option specifies that multithreading should be handled with a priority on memory efficiency,
499 aiming to minimize memory usage even if it results in longer execution times.
504 py::class_<module_identification::WordLevelOperation> py_word_level_operation(m,
"WordLevelOperation", R
"(
505 Represents a word-level operation with its operands, control signals, and the operation implemented as a HAL Boolean function.
506 This struct is used to store the information related to a word-level operation, which includes the operands, control signals, and the Boolean function representing the operation.
509 py_word_level_operation.def(py::init<>());
512 A map of operand names to their corresponding Boolean functions.
514 :type: dict[str, hal_py.BooleanFunction]
518 A vector of control signals as Boolean functions.
520 :type: list[hal_py.BooleanFunction]
524 The Boolean function representing the word-level operation.
526 :type: hal_py.BooleanFunction
530 py::class_<module_identification::VerifiedCandidate> py_verified_candidate(m,
"VerifiedCandidate", R
"(
531 This class is used to represent a verified candidate within the module identification process, providing methods for their creation, manipulation, and verification.
535 Merge multiple verified candidates into a single candidate.
537 This function merges a vector of verified candidates into a single candidate.
539 :param list[module_identification.VerifiedCandidate] candidates: A vector of verified candidates to merge.
540 :returns: The merged verified candidate on success.
541 :rtype: module_identification.VerifiedCandidate
545 Get the candidate information as a string.
547 :returns: A string containing the candidate information.
552 Check if the candidate is verified.
554 :returns: ``True`` if the candidate is verified, ``False`` otherwise.
559 Get the name of the candidate that represents the functionality of the candidate.
561 :returns: A string containing the name of the candidate.
566 Get the merged word-level operation for the candidate.
568 The mergred word-level operation includes all word-level oprations that we were able to verify for different control mappings of the candidate.
570 :returns: The merged word-level operation as a Boolean function.
571 :rtype: hal_py.BooleanFunction
575 A vector of operands.
577 :type: list[list[hal_py.Net]]
581 A vector of output nets.
583 :type: list[hal_py.Net]
587 A vector of control signal nets.
589 :type: list[hal_py.Net]
593 A vector of all control mappings covered by this candidate.
595 :type: list[dict[hal_py.Net, hal_py.BooleanFunction.Value]]
599 A map of control signal mappings to their respective word-level operations.
601 :type: dict[dict[hal_py.Net, hal_py.BooleanFunction.Value], hal_py.BooleanFunction]
605 A vector of gates associated with the candidate.
607 :type: list[hal_py.Gate]
611 A vector of base gates associated with the candidate.
613 :type: list[hal_py.Gate]
617 A vector of all input nets to the gate subgraph, regardless of whether they appear in a word-level operation or not.
619 :type: list[hal_py.Net]
623 A vector of all output nets of the subgraph, regardless of whether they appear in a word-level operation or not.
625 :type: list[hal_py.Net]
629 The set of contained candidate types.
631 :type: set[module_identification.CandidateType]
635 Indicates whether the candidate is verified.
This file contains the definition of the Architecture enum for the module identification plugin.
This file contains the enumeration and constants for the candidate types used in the module identific...
std::set< std::string > get_dependencies() const override
Get the plugin dependencies.
std::string get_description() const override
Get a short description of the plugin.
std::string get_name() const override
Get the name of the plugin.
std::string get_version() const override
Get the version of the plugin.
bool is_verified() const
Check if the candidate is verified.
std::string get_name() const
Get the name of the candidate that represents the functionality of the candidate.
BooleanFunction get_merged_word_level_operation() const
Get the merged word-level operation for the candidate.
std::vector< Net * > m_total_output_nets
std::vector< Net * > m_control_signals
std::set< CandidateType > m_types
std::vector< Gate * > m_gates
std::vector< std::map< Net *, BooleanFunction::Value > > m_control_signal_mappings
std::string get_candidate_info() const
Get the candidate information as a string.
std::map< std::map< Net *, BooleanFunction::Value >, BooleanFunction > m_word_level_operations
static hal::Result< VerifiedCandidate > merge(const std::vector< VerifiedCandidate > &candidates)
Merge multiple verified candidates into a single candidate.
std::vector< Net * > m_total_input_nets
std::vector< std::vector< Net * > > m_operands
std::vector< Net * > m_output_nets
std::vector< Gate * > m_base_gates
#define log_error(channel,...)
This file contains the struct Configuration for module identification analysis.
This file contains the function declarations for the Module Identification plugin in hal.
This file contains the enum class for multithreading strategies in the module identification process.
const Module * module(const Gate *g, const NodeBoxes &boxes)
hal::Result< Result > execute(const Configuration &config)
Perform a full run of the module identification process on the given netlist with the provided config...
hal::Result< Result > execute_on_gates(const std::vector< Gate * > &gates, const Configuration &config)
Perform a module identification run on the specified gates with the provided configuration.
@ mixed
Mixed operation, for merged VerifiedCandidates that contain multiple candidate types.
@ addition
Addition operation.
@ signed_less_equal
Signed less-than-or-equal comparison.
@ equal
Equality comparison.
@ negation
Negation operation.
@ less_equal
Less-than-or-equal comparison.
@ less_than
Less-than comparison.
@ counter
Counter operation.
@ subtraction
Subtraction operation.
@ value_check
Value check against a constant operation.
@ absolute
Absolute value operation.
@ constant_multiplication
Constant multiplication operation.
@ signed_less_than
Signed less-than comparison.
@ constant_multiplication_offset
Constant multiplication operation with a constant offset.
@ xilinx_unisim
Xilinx Unisim FPGA architecture.
@ lattice_ice40
Lattice iCE40 FPGA architecture.
@ time_priority
Prioritize time efficiency in multithreading.
@ memory_priority
Prioritize memory efficiency in multithreading.
This file contains the structures and functions related to module identification results.
Configuration for the module identification analysis.
Configuration & with_multithreading_priority(const MultithreadingPriority &priority)
Set the multithreading priority type.
Configuration & with_types_to_check(const std::vector< module_identification::CandidateType > &types_to_check)
Set the candidate types to be checked.
Netlist * m_netlist
The netlist to be analyzed.
Configuration & with_already_classified_candidates(const std::vector< std::vector< Gate * >> &already_classified_candidates)
Add gates to be ignored during processing.
std::vector< std::set< Gate * > > m_blocked_base_candidates
Base candidates to block during analysis.
std::vector< module_identification::CandidateType > m_types_to_check
CandidateTypes that shall be checked. Defaults to all checkable candidate types.
std::vector< std::vector< Gate * > > m_known_registers
A vector handling possibly known registers.
u32 m_max_control_signals
Maximum number of control signals to be tested. Defaults to 3.
Configuration & with_known_registers(const std::vector< std::vector< Gate * >> ®isters)
Set the known registers for prioritization.
Configuration & with_blocked_base_candidates(const std::vector< std::set< Gate * >> &blocked_base_candidates)
Add base candidates to be blocked during analysis.
std::vector< std::vector< Gate * > > m_already_classified_candidates
Gates to ignore during processing.
Configuration & with_max_control_signals(const u32 &max_control_signals)
Set the maximum number of control signals to be tested.
Configuration & with_max_thread_count(const u32 &max_thread_count)
Set the maximum number of threads.
MultithreadingPriority m_multithreading_priority
Choose which MultithreadingPriority to use for the analysis. Defaults to memory priority.
u32 m_max_thread_count
Maximum number of concurrent threads created during execution. Defaults to 1.
The result of a module identification run containing the candidates.
std::map< u32, std::vector< Gate * > > get_candidate_gates() const
Get a map of the candidate IDs to the gates contained inside the candidate.
std::map< u32, VerifiedCandidate > get_candidates() const
Get a map of the candidate IDs to the candidates.
std::set< Gate * > get_all_gates() const
Get all gates contained in any of the candidates.
std::map< u32, std::vector< Gate * > > get_verified_candidate_gates() const
Get a map of the candidate IDs to the gates contained inside the verified candidates.
std::set< Gate * > get_all_verified_gates() const
Get all gates contained in any of the verified candidates.
static std::vector< std::vector< std::set< Gate * > > > assign_base_candidates_to_iterations(const std::vector< Result > &iteration_results, const bool create_block_lists=false)
For different runs of the plugin figure out in which iteration the plugin found the highest quality r...
Netlist * get_netlist() const
Get the netlist on which module identification has been performed.
std::string get_timing_stats() const
Get the collected timing information formatted as a JSON string.
std::map< u32, VerifiedCandidate > get_verified_candidates() const
Get a map of the candidate IDs to the verified candidates.
BooleanFunction operation
The Boolean function representing the word-level operation.
std::map< std::string, BooleanFunction > operands
A map of operand names to their corresponding Boolean functions.
std::vector< BooleanFunction > ctrl_signals
A vector of control signals as Boolean functions.