Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎨 Refactored the technology mapping interface #278

Merged
merged 26 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
162421c
:art: Refactored the technology mapping interface into its own header…
marcelwa Sep 6, 2023
c7723ad
:memo: Added documentation
marcelwa Sep 6, 2023
c7098e0
:art: Addressed `clang-tidy`'s warnings
marcelwa Sep 6, 2023
7de9081
:white_check_mark: Increased test coverage
marcelwa Sep 6, 2023
b6960dd
Merge branch 'main' into tech-mapper
marcelwa Sep 8, 2023
6d5f029
:construction_worker: Updated workflows to disable benchmark compilation
marcelwa Sep 8, 2023
c027c3f
Merge branch 'main' into tech-mapper
marcelwa Sep 8, 2023
bd271ee
Merge branch 'main' into tech-mapper
marcelwa Sep 22, 2023
90cb275
Merge branch 'main' into tech-mapper
marcelwa Sep 23, 2023
ff05d23
:white_check_mark: Disable some tests to see which ones MSVC doesn't …
marcelwa Oct 31, 2023
93570bc
:art: ClangFormat changes
Oct 31, 2023
bb8c88f
Merge branch 'main' into tech-mapper
marcelwa Oct 31, 2023
2e01e43
:white_check_mark: Disabled more tests
marcelwa Nov 2, 2023
d3a9e1b
Merge remote-tracking branch 'origin/tech-mapper' into tech-mapper
marcelwa Nov 2, 2023
3959dc9
:white_check_mark: Disabled more tests
marcelwa Nov 3, 2023
f7f0774
Merge branch 'main' into tech-mapper
marcelwa Apr 27, 2024
f2f0af0
🎨 Incorporated pre-commit fixes
pre-commit-ci[bot] Apr 27, 2024
aa44a2e
:white_check_mark: Reactivated previously failing tests
marcelwa Apr 28, 2024
a4da157
:art: Minor code quality improvements
marcelwa Apr 28, 2024
e1769db
:sparkles: Added Python bindings for technology_mapping
marcelwa Apr 28, 2024
18ca1f2
Merge branch 'main' into tech-mapper
marcelwa Apr 29, 2024
9dc6630
Merge remote-tracking branch 'origin/tech-mapper' into tech-mapper
marcelwa Apr 29, 2024
78d6751
:memo: Added Python documentation for `technology_mapping`
marcelwa Apr 29, 2024
452d44c
:memo: Update pyfiction docstrings
actions-user Apr 29, 2024
1d7dbc4
Merge remote-tracking branch 'origin/tech-mapper' into tech-mapper
marcelwa Apr 29, 2024
555aa2c
:white_check_mark: Fixed tests
marcelwa Apr 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/clang-tidy-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
-DFICTION_CLI=ON
-DFICTION_TEST=ON
-DFICTION_BENCHMARK=OFF
-DFICTION_EXPERIMENTS=ON
-DMOCKTURTLE_EXAMPLES=OFF
build_dir: build
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ jobs:
-DFICTION_ENABLE_PCH=ON
-DFICTION_CLI=ON
-DFICTION_TEST=ON
-DFICTION_BENCHMARK=OFF
-DFICTION_EXPERIMENTS=ON
-DFICTION_Z3=ON
-DFICTION_ENABLE_MUGEN=ON
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ jobs:
-DFICTION_ENABLE_PCH=ON
-DFICTION_CLI=OFF
-DFICTION_TEST=ON
-DFICTION_BENCHMARK=OFF
-DFICTION_Z3=ON
-DFICTION_ENABLE_MUGEN=ON
-DFICTION_PROGRESS_BARS=OFF
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ RUN . venv/bin/activate \
-DFICTION_ENABLE_PCH=ON \
-DFICTION_CLI=ON \
-DFICTION_TEST=OFF \
-DFICTION_BENCHMARK=OFF \
-DFICTION_EXPERIMENTS=OFF \
-DFICTION_Z3=ON \
-DFICTION_ENABLE_MUGEN=OFF \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//
// Created by marcel on 25.01.23.
//

#ifndef PYFICTION_TECHNOLOGY_MAPPING_HPP
#define PYFICTION_TECHNOLOGY_MAPPING_HPP

#include "pyfiction/documentation.hpp"
marcelwa marked this conversation as resolved.
Show resolved Hide resolved
#include "pyfiction/types.hpp"

#include <fiction/algorithms/network_transformation/technology_mapping.hpp>

#include <pybind11/pybind11.h>

namespace pyfiction
{

namespace detail
{

template <typename Ntk>
void technology_mapping(pybind11::module& m)
{
using namespace pybind11::literals;

m.def("technology_mapping", &fiction::technology_mapping<Ntk>, "network"_a,
"params"_a = fiction::technology_mapping_params{}, "stats"_a = nullptr, DOC(fiction_technology_mapping));
}

} // namespace detail

inline void technology_mapping(pybind11::module& m)
{
namespace py = pybind11;

py::class_<fiction::technology_mapping_params>(m, "technology_mapping_params",
DOC(fiction_technology_mapping_params))
.def(py::init<>())

.def_readwrite("decay", &fiction::technology_mapping_params::decay,
DOC(fiction_technology_mapping_params_decay))

.def_readwrite("inv", &fiction::technology_mapping_params::inv, DOC(fiction_technology_mapping_params_inv))

.def_readwrite("and2", &fiction::technology_mapping_params::and2, DOC(fiction_technology_mapping_params_and2))
.def_readwrite("nand2", &fiction::technology_mapping_params::nand2,
DOC(fiction_technology_mapping_params_nand2))
.def_readwrite("or2", &fiction::technology_mapping_params::or2, DOC(fiction_technology_mapping_params_or2))
.def_readwrite("nor2", &fiction::technology_mapping_params::nor2, DOC(fiction_technology_mapping_params_nor2))
.def_readwrite("xor2", &fiction::technology_mapping_params::xor2, DOC(fiction_technology_mapping_params_xor2))
.def_readwrite("xnor2", &fiction::technology_mapping_params::xnor2,
DOC(fiction_technology_mapping_params_xnor2))

.def_readwrite("and3", &fiction::technology_mapping_params::and3, DOC(fiction_technology_mapping_params_and3))
.def_readwrite("xor_and", &fiction::technology_mapping_params::xor_and,
DOC(fiction_technology_mapping_params_xor_and))
.def_readwrite("or_and", &fiction::technology_mapping_params::or_and,
DOC(fiction_technology_mapping_params_or_and))
.def_readwrite("onehot", &fiction::technology_mapping_params::onehot,
DOC(fiction_technology_mapping_params_onehot))
.def_readwrite("maj3", &fiction::technology_mapping_params::maj3, DOC(fiction_technology_mapping_params_maj3))
.def_readwrite("gamble", &fiction::technology_mapping_params::gamble,
DOC(fiction_technology_mapping_params_gamble))
.def_readwrite("dot", &fiction::technology_mapping_params::dot, DOC(fiction_technology_mapping_params_dot))
.def_readwrite("mux", &fiction::technology_mapping_params::mux, DOC(fiction_technology_mapping_params_mux))
.def_readwrite("and_xor", &fiction::technology_mapping_params::and_xor,
DOC(fiction_technology_mapping_params_and_xor))

;

py::class_<fiction::technology_mapping_stats>(m, "technology_mapping_stats", DOC(fiction_technology_mapping_stats))
.def(py::init<>())

.def("report", &fiction::technology_mapping_stats::report, DOC(fiction_technology_mapping_stats_report))

;

m.def("and_or_not", &fiction::and_or_not, DOC(fiction_and_or_not));

m.def("and_or_not_maj", &fiction::and_or_not_maj, DOC(fiction_and_or_not_maj));

m.def("all_standard_2_input_functions", &fiction::all_standard_2_input_functions,
DOC(fiction_all_standard_2_input_functions));

m.def("all_standard_3_input_functions", &fiction::all_standard_3_input_functions,
DOC(fiction_all_standard_3_input_functions));

m.def("all_supported_standard_functions", &fiction::all_supported_standard_functions,
DOC(fiction_all_supported_standard_functions));

detail::technology_mapping<py_logic_network>(m);
}

} // namespace pyfiction

#endif // PYFICTION_TECHNOLOGY_MAPPING_HPP
133 changes: 133 additions & 0 deletions bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,41 @@ Parameter ``n``:
Returns:
A vector of all possible edge paths leading from terminals to `v`.)doc";

static const char *__doc_fiction_all_standard_2_input_functions =
R"doc(Auxiliary function to create technology mapping parameters for AND,
OR, NAND, NOR, XOR, XNOR, and NOT gates.

Returns:
Technology mapping parameters.)doc";

static const char *__doc_fiction_all_standard_3_input_functions =
R"doc(Auxiliary function to create technology mapping parameters for AND3,
XOR_AND, OR_AND, ONEHOT, MAJ3, GAMBLE, DOT, MUX, and AND_XOR gates.

Returns:
Technology mapping parameters.)doc";

static const char *__doc_fiction_all_supported_standard_functions =
R"doc(Auxiliary function to create technology mapping parameters for all
supported standard functions.

Returns:
Technology mapping parameters.)doc";

static const char *__doc_fiction_and_or_not =
R"doc(Auxiliary function to create technology mapping parameters for AND,
OR, and NOT gates.

Returns:
Technology mapping parameters.)doc";

static const char *__doc_fiction_and_or_not_maj =
R"doc(Auxiliary function to create technology mapping parameters for AND,
OR, NOT, and MAJ gates.

Returns:
Technology mapping parameters.)doc";

static const char *__doc_fiction_apply_gate_library =
R"doc(Applies a gate library to a given gate-level layout and, thereby,
creates and returns a cell-level layout. The gate library type should
Expand Down Expand Up @@ -6412,6 +6447,36 @@ Parameter ``param``:
Returns:
The string representation of the sweep parameter.)doc";

static const char *__doc_fiction_detail_technology_mapping_impl = R"doc()doc";

static const char *__doc_fiction_detail_technology_mapping_impl_ntk = R"doc(Input network to be mapped.)doc";

static const char *__doc_fiction_detail_technology_mapping_impl_params = R"doc(Technology mapping parameters.)doc";

static const char *__doc_fiction_detail_technology_mapping_impl_perform_mapping =
R"doc(Perform technology mapping with the given number of inputs.

Template parameter ``NumInp``:
Maximum input number of the gates in the technology library.

Parameter ``gates``:
Technology library.

Returns:
Mapped network.)doc";

static const char *__doc_fiction_detail_technology_mapping_impl_run = R"doc()doc";

static const char *__doc_fiction_detail_technology_mapping_impl_set_up_gates =
R"doc(Create a mockturtle gate library from the given parameters.

Returns:
A vector of mockturtle gates.)doc";

static const char *__doc_fiction_detail_technology_mapping_impl_stats = R"doc(Technology mapping statistics.)doc";

static const char *__doc_fiction_detail_technology_mapping_impl_technology_mapping_impl = R"doc()doc";

static const char *__doc_fiction_detail_to_hex =
R"doc(Utility function to transform a Cartesian tile into a hexagonal one.

Expand Down Expand Up @@ -14558,6 +14623,74 @@ static const char *__doc_fiction_technology_dot_drawer_node_label = R"doc()doc";

static const char *__doc_fiction_technology_dot_drawer_node_label_callback = R"doc()doc";

static const char *__doc_fiction_technology_mapping =
R"doc(Performs technology mapping on the given network. Technology mapping
is the process of replacing the gates in a network with gates from a
given technology library. This function utilizes `mockturtle::map` to
perform the technology mapping. This function is a wrapper around that
interface to provide a more convenient usage.

Template parameter ``Ntk``:
Input logic network type.

Parameter ``ntk``:
Input logic network.

Parameter ``params``:
Technology mapping parameters.

Parameter ``pst``:
Technology mapping statistics.

Returns:
Mapped network exclusively using gates from the provided library.)doc";

static const char *__doc_fiction_technology_mapping_params = R"doc()doc";

static const char *__doc_fiction_technology_mapping_params_and2 = R"doc(2-input AND gate.)doc";

static const char *__doc_fiction_technology_mapping_params_and3 = R"doc(3-input AND gate.)doc";

static const char *__doc_fiction_technology_mapping_params_and_xor = R"doc(3-input AND-XOR gate.)doc";

static const char *__doc_fiction_technology_mapping_params_decay =
R"doc(Enforce the application of at least one constant input to three-input
gates.)doc";

static const char *__doc_fiction_technology_mapping_params_dot = R"doc(3-input DOT gate.)doc";

static const char *__doc_fiction_technology_mapping_params_gamble = R"doc(3-input GAMBLE gate.)doc";

static const char *__doc_fiction_technology_mapping_params_inv = R"doc()doc";

static const char *__doc_fiction_technology_mapping_params_maj3 = R"doc(3-input MAJ gate.)doc";

static const char *__doc_fiction_technology_mapping_params_mapper_params = R"doc(mockturtle's mapper parameters.)doc";

static const char *__doc_fiction_technology_mapping_params_mux = R"doc(3-input MUX gate.)doc";

static const char *__doc_fiction_technology_mapping_params_nand2 = R"doc(2-input NAND gate.)doc";

static const char *__doc_fiction_technology_mapping_params_nor2 = R"doc(2-input NOR gate.)doc";

static const char *__doc_fiction_technology_mapping_params_onehot = R"doc(3-input ONEHOT gate.)doc";

static const char *__doc_fiction_technology_mapping_params_or2 = R"doc(2-input OR gate.)doc";

static const char *__doc_fiction_technology_mapping_params_or_and = R"doc(3-input OR-AND gate.)doc";

static const char *__doc_fiction_technology_mapping_params_xnor2 = R"doc(2-input XNOR gate.)doc";

static const char *__doc_fiction_technology_mapping_params_xor2 = R"doc(2-input XOR gate.)doc";

static const char *__doc_fiction_technology_mapping_params_xor_and = R"doc(3-input XOR-AND gate.)doc";

static const char *__doc_fiction_technology_mapping_stats = R"doc(Statistics for technology mapping.)doc";

static const char *__doc_fiction_technology_mapping_stats_mapper_stats = R"doc(Statistics for mockturtle's mapper.)doc";

static const char *__doc_fiction_technology_mapping_stats_report = R"doc(Report statistics.)doc";

static const char *__doc_fiction_technology_network =
R"doc(A `mockturtle` logic network type that extends `klut_network`. It
reimplements all node creation functions to disable structural
Expand Down
2 changes: 2 additions & 0 deletions bindings/pyfiction/pyfiction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "pyfiction/algorithms/network_transformation/fanout_substitution.hpp"
marcelwa marked this conversation as resolved.
Show resolved Hide resolved
#include "pyfiction/algorithms/network_transformation/network_balancing.hpp"
#include "pyfiction/algorithms/network_transformation/technology_mapping.hpp"
#include "pyfiction/algorithms/path_finding/a_star.hpp"
#include "pyfiction/algorithms/path_finding/distance.hpp"
#include "pyfiction/algorithms/path_finding/enumerate_all_paths.hpp"
Expand Down Expand Up @@ -145,6 +146,7 @@ PYBIND11_MODULE(pyfiction, m)
*/
pyfiction::fanout_substitution(m);
pyfiction::network_balancing(m);
pyfiction::technology_mapping(m);
marcelwa marked this conversation as resolved.
Show resolved Hide resolved
/**
* Algorithms: Path Finding
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ def test_substitution(self):
self.assertEqual(substituted_breadth.num_gates(), 6)
self.assertTrue(is_fanout_substituted(substituted_breadth, breadth_params))

threashold_params = fanout_substitution_params()
threashold_params.threshold = 2
substituted_threshold = fanout_substitution(network, threashold_params)
threshold_params = fanout_substitution_params()
threshold_params.threshold = 2
substituted_threshold = fanout_substitution(network, threshold_params)
self.assertEqual(substituted_threshold.num_gates(), 5)
self.assertTrue(is_fanout_substituted(substituted_threshold, threashold_params))
self.assertTrue(is_fanout_substituted(substituted_threshold, threshold_params))
self.assertFalse(is_fanout_substituted(substituted_threshold, depth_params))
self.assertFalse(is_fanout_substituted(substituted_threshold, breadth_params))

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from mnt.pyfiction import *
import unittest
import os

dir_path = os.path.dirname(os.path.realpath(__file__))


class TestTechnologyMapping(unittest.TestCase):
def test_mapping_default(self):
network = read_technology_network(dir_path + "/../../resources/mux21.v")
self.assertEqual(network.num_gates(), 5)

mapped_network = technology_mapping(network)

self.assertEqual(equivalence_checking(network, mapped_network), eq_type.NO)

def test_mapping_with_parameters(self):
network = read_technology_network(dir_path + "/../../resources/mux21.v")

for params in [and_or_not(), and_or_not_maj(), all_standard_2_input_functions(),
all_standard_3_input_functions(),
all_supported_standard_functions()]:
mapped_network = technology_mapping(network, params)

self.assertEqual(equivalence_checking(network, mapped_network), eq_type.STRONG)

def test_mapping_with_stats(self):
network = read_technology_network(dir_path + "/../../resources/mux21.v")

for params in [and_or_not(), and_or_not_maj(), all_standard_2_input_functions(),
all_standard_3_input_functions(),
all_supported_standard_functions()]:
stats = technology_mapping_stats()
mapped_network = technology_mapping(network, params=params, stats=stats)

self.assertEqual(equivalence_checking(network, mapped_network), eq_type.STRONG)


if __name__ == '__main__':
unittest.main()
Loading
Loading