Skip to content

Commit

Permalink
feat(frontend-python): memory usage per location
Browse files Browse the repository at this point in the history
  • Loading branch information
umut-sahin authored and BourgerieQuentin committed Apr 29, 2024
1 parent 179080a commit 3d338af
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions frontends/concrete-python/concrete/fhe/compilation/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions frontends/concrete-python/concrete/fhe/compilation/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions frontends/concrete-python/tests/compilation/test_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 3d338af

Please sign in to comment.