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

chore(frontends): enable simultaneous execution and simulation in mod… #1016

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
41 changes: 33 additions & 8 deletions frontends/concrete-python/concrete/fhe/compilation/artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
import shutil
import subprocess
from pathlib import Path
from typing import Callable, Dict, List, Optional, Union
from typing import TYPE_CHECKING, Callable, Dict, List, Optional, Union

from ..representation import Graph

if TYPE_CHECKING:
from .module import ExecutionRt
from .utils import Lazy

DEFAULT_OUTPUT_DIRECTORY: Path = Path(".artifacts")


Expand Down Expand Up @@ -83,7 +87,7 @@ class ModuleDebugArtifacts:

output_directory: Path
mlir_to_compile: Optional[str]
client_parameters: Optional[bytes]
_execution_runtime: Optional["Lazy[ExecutionRt]"]
functions: Dict[str, FunctionDebugArtifacts]

def __init__(
Expand All @@ -93,7 +97,7 @@ def __init__(
):
self.output_directory = Path(output_directory)
self.mlir_to_compile = None
self.client_parameters = None
self._execution_runtime = None
self.functions = (
{name: FunctionDebugArtifacts() for name in function_names} if function_names else {}
)
Expand All @@ -108,15 +112,28 @@ def add_mlir_to_compile(self, mlir: str):
"""
self.mlir_to_compile = mlir

def add_client_parameters(self, client_parameters: bytes):
def add_execution_runtime(self, execution_runtime: "Lazy[ExecutionRt]"):
"""
Add client parameters used.
Add the (lazy) execution runtime to get the client parameters if needed.

Args:
client_parameters (bytes): client parameters
execution_runtime (Lazy[ExecutionRt]):
The lazily initialized execution runtime.
"""

self.client_parameters = client_parameters
self._execution_runtime = execution_runtime

@property
def client_parameters(self) -> Optional[bytes]:
"""
The client parameters associated with the execution runtime.
"""

return (
self._execution_runtime.val.client.specs.client_parameters.serialize()
if self._execution_runtime is not None
else None
)

def export(self):
"""
Expand Down Expand Up @@ -217,9 +234,11 @@ class DebugArtifacts:
"""

module_artifacts: ModuleDebugArtifacts
_client_parameters: Optional[bytes]

def __init__(self, output_directory: Union[str, Path] = DEFAULT_OUTPUT_DIRECTORY):
self.module_artifacts = ModuleDebugArtifacts(["main"], output_directory)
self._client_parameters = None

def add_source_code(self, function: Union[str, Callable]):
"""
Expand Down Expand Up @@ -280,13 +299,19 @@ def add_client_parameters(self, client_parameters: bytes):
client_parameters (bytes): client parameters
"""

self.module_artifacts.add_client_parameters(client_parameters)
self._client_parameters = client_parameters

def export(self):
"""
Export the collected information to `self.output_directory`.
"""

# This is a quick fix before we refactor compiler and module_compiler
# to use the same abstraction.
class _ModuleDebugArtifacts(ModuleDebugArtifacts):
client_parameters = self._client_parameters

self.module_artifacts.__class__ = _ModuleDebugArtifacts
self.module_artifacts.export()

@property
Expand Down
Loading
Loading