From 3d338af27f6c4f1935d625f559e43ffcf01a89bd Mon Sep 17 00:00:00 2001 From: Umut Date: Fri, 26 Apr 2024 12:37:55 +0300 Subject: [PATCH] feat(frontend-python): memory usage per location --- .../concrete-python/concrete/fhe/compilation/circuit.py | 7 +++++++ .../concrete-python/concrete/fhe/compilation/server.py | 7 +++++++ .../concrete-python/tests/compilation/test_circuit.py | 6 ++++++ 3 files changed, 20 insertions(+) diff --git a/frontends/concrete-python/concrete/fhe/compilation/circuit.py b/frontends/concrete-python/concrete/fhe/compilation/circuit.py index d4fc79fb36..95b360d33c 100644 --- a/frontends/concrete-python/concrete/fhe/compilation/circuit.py +++ b/frontends/concrete-python/concrete/fhe/compilation/circuit.py @@ -389,6 +389,13 @@ def complexity(self) -> float: """ return self._property("complexity") # pragma: no cover + @property + def memory_usage_per_location(self) -> Dict[str, int]: + """ + Get the memory usage of operations in the circuit per location. + """ + return self._property("memory_usage_per_location")() # pragma: no cover + # Programmable Bootstrap Statistics @property diff --git a/frontends/concrete-python/concrete/fhe/compilation/server.py b/frontends/concrete-python/concrete/fhe/compilation/server.py index e4e9f631b3..b940676169 100644 --- a/frontends/concrete-python/concrete/fhe/compilation/server.py +++ b/frontends/concrete-python/concrete/fhe/compilation/server.py @@ -430,6 +430,12 @@ def complexity(self) -> float: """ return self._compilation_feedback.complexity + def memory_usage_per_location(self, function: str = "main") -> Dict[str, int]: + """ + Get the memory usage of operations per location. + """ + return self._compilation_feedback.circuit(function).memory_usage_per_location + def size_of_inputs(self, function: str = "main") -> int: """ Get size of the inputs of the compiled program. @@ -770,6 +776,7 @@ def statistics(self) -> Dict: "encrypted_negation_count_per_parameter", "encrypted_negation_count_per_tag", "encrypted_negation_count_per_tag_per_parameter", + "memory_usage_per_location", ] output = {attribute: getattr(self, attribute)() for attribute in attributes} output["size_of_secret_keys"] = self.size_of_secret_keys diff --git a/frontends/concrete-python/tests/compilation/test_circuit.py b/frontends/concrete-python/tests/compilation/test_circuit.py index f9b41206fc..ec05693680 100644 --- a/frontends/concrete-python/tests/compilation/test_circuit.py +++ b/frontends/concrete-python/tests/compilation/test_circuit.py @@ -90,6 +90,12 @@ def f(x, y): assert isinstance(circuit.p_error, float) assert isinstance(circuit.global_p_error, float) + assert isinstance(circuit.memory_usage_per_location, dict) + assert all( + isinstance(key, str) and isinstance(value, int) + for key, value in circuit.memory_usage_per_location.items() + ) + assert circuit.p_error <= p_error assert circuit.global_p_error <= global_p_error