From 4d3055d77a9ad8ba9cf9a01745666381f8002540 Mon Sep 17 00:00:00 2001 From: iopapamanoglou Date: Tue, 12 Nov 2024 08:44:36 +0100 Subject: [PATCH] Max paths heuristic --- src/faebryk/core/cpp/__init__.pyi | 1 + src/faebryk/core/cpp/include/pathfinder/pathfinder.hpp | 4 ++++ src/faebryk/core/cpp/src/main.cpp | 1 + src/faebryk/core/pathfinder.py | 6 ++++-- src/faebryk/libs/util.py | 3 +++ test/core/test_performance.py | 8 ++++++-- 6 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/faebryk/core/cpp/__init__.pyi b/src/faebryk/core/cpp/__init__.pyi index df2d44c0..b3a54a95 100644 --- a/src/faebryk/core/cpp/__init__.pyi +++ b/src/faebryk/core/cpp/__init__.pyi @@ -194,3 +194,4 @@ def find_paths(src: Node, dst: Sequence[Node]) -> tuple[list[Path], list[Counter def print_obj(obj: object) -> None: ... def set_indiv_measure(value: bool) -> None: ... def set_leak_warnings(value: bool) -> None: ... +def set_max_paths(value: int) -> None: ... diff --git a/src/faebryk/core/cpp/include/pathfinder/pathfinder.hpp b/src/faebryk/core/cpp/include/pathfinder/pathfinder.hpp index fd35f990..318645f2 100644 --- a/src/faebryk/core/cpp/include/pathfinder/pathfinder.hpp +++ b/src/faebryk/core/cpp/include/pathfinder/pathfinder.hpp @@ -17,6 +17,10 @@ inline uint32_t MAX_PATHS = 1 << 31; +inline void set_max_paths(uint32_t v) { + MAX_PATHS = v; +} + class PathFinder; struct Filter { diff --git a/src/faebryk/core/cpp/src/main.cpp b/src/faebryk/core/cpp/src/main.cpp index ae5b5491..c81fca45 100644 --- a/src/faebryk/core/cpp/src/main.cpp +++ b/src/faebryk/core/cpp/src/main.cpp @@ -69,6 +69,7 @@ PYMOD(m) { // TODO why this rv_pol needed m.def("find_paths", &find_paths, "src"_a, "dst"_a, nb::rv_policy::reference); m.def("set_indiv_measure", &set_indiv_measure, "value"_a); + m.def("set_max_paths", &set_max_paths, "value"_a); // Graph using GI = GraphInterface; diff --git a/src/faebryk/core/pathfinder.py b/src/faebryk/core/pathfinder.py index 370a7207..0ba1e931 100644 --- a/src/faebryk/core/pathfinder.py +++ b/src/faebryk/core/pathfinder.py @@ -8,16 +8,18 @@ from rich.console import Console from rich.table import Table -from faebryk.core.cpp import Counter, Path, set_indiv_measure +from faebryk.core.cpp import Counter, Path, set_indiv_measure, set_max_paths from faebryk.core.cpp import find_paths as find_paths_cpp from faebryk.core.node import Node -from faebryk.libs.util import ConfigFlag +from faebryk.libs.util import ConfigFlag, ConfigFlagInt # Also in C++ INDIV_MEASURE = ConfigFlag( "INDIV_MEASURE", default=True, descr="Measure individual paths" ) +MAX_PATHS = ConfigFlagInt("MAX_PATHS", default=int(1e5), descr="Max paths to search") set_indiv_measure(bool(INDIV_MEASURE)) +set_max_paths(int(MAX_PATHS)) def find_paths(src: Node, dst: Sequence[Node]) -> Sequence[Path]: diff --git a/src/faebryk/libs/util.py b/src/faebryk/libs/util.py index 75080d70..849645b6 100644 --- a/src/faebryk/libs/util.py +++ b/src/faebryk/libs/util.py @@ -865,6 +865,9 @@ def __init__(self, name: str, default: int = 0, descr: str = "") -> None: def _convert(self, raw_val: str) -> int: return int(raw_val) + def __int__(self) -> int: + return self.get() + def zip_dicts_by_key(*dicts): keys = {k for d in dicts for k in d} diff --git a/test/core/test_performance.py b/test/core/test_performance.py index 727a5f16..ef0fbfa9 100644 --- a/test/core/test_performance.py +++ b/test/core/test_performance.py @@ -12,6 +12,7 @@ from faebryk.core.module import Module from faebryk.core.moduleinterface import ModuleInterface from faebryk.core.node import Node +from faebryk.libs.app.parameters import resolve_dynamic_parameters from faebryk.libs.library import L from faebryk.libs.test.times import Times from faebryk.libs.util import times @@ -237,13 +238,16 @@ def test_mif_connect_hull(self): def test_complex_module(self): timings = Times() - modules = [F.USB2514B, F.RP2040] + modules = [ + F.USB2514B, + F.RP2040, + ] for t in modules: app = t() # noqa: F841 timings.add(f"{t.__name__}: construct") - # resolve_dynamic_parameters(app.get_graph()) + resolve_dynamic_parameters(app.get_graph()) timings.add(f"{t.__name__}: resolve") logger.info(f"\n{timings}")