From 9c077852bb2ab208b29ad0e409b6e31c52e0c385 Mon Sep 17 00:00:00 2001 From: youben11 Date: Tue, 6 Jun 2023 10:25:27 +0100 Subject: [PATCH] feat(compiler): load lib compilation result from directory --- .../concretelang-c/Support/CompilerEngine.h | 3 +++ .../concretelang/Support/LibrarySupport.h | 22 +++++++++++++++++++ .../lib/Bindings/Rust/src/compiler.rs | 17 ++++++++++++++ .../lib/CAPI/Support/CompilerEngine.cpp | 11 ++++++++++ 4 files changed, 53 insertions(+) diff --git a/compilers/concrete-compiler/compiler/include/concretelang-c/Support/CompilerEngine.h b/compilers/concrete-compiler/compiler/include/concretelang-c/Support/CompilerEngine.h index b6babf215..4ec644a49 100644 --- a/compilers/concrete-compiler/compiler/include/concretelang-c/Support/CompilerEngine.h +++ b/compilers/concrete-compiler/compiler/include/concretelang-c/Support/CompilerEngine.h @@ -216,6 +216,9 @@ MLIR_CAPI_EXPORTED ServerLambda librarySupportLoadServerLambda( MLIR_CAPI_EXPORTED ClientParameters librarySupportLoadClientParameters( LibrarySupport support, LibraryCompilationResult result); +MLIR_CAPI_EXPORTED LibraryCompilationResult +librarySupportLoadCompilationResult(LibrarySupport support); + MLIR_CAPI_EXPORTED CompilationFeedback librarySupportLoadCompilationFeedback( LibrarySupport support, LibraryCompilationResult result); diff --git a/compilers/concrete-compiler/compiler/include/concretelang/Support/LibrarySupport.h b/compilers/concrete-compiler/compiler/include/concretelang/Support/LibrarySupport.h index 2e03a7f7e..3c6eb054c 100644 --- a/compilers/concrete-compiler/compiler/include/concretelang/Support/LibrarySupport.h +++ b/compilers/concrete-compiler/compiler/include/concretelang/Support/LibrarySupport.h @@ -104,6 +104,28 @@ public: return *param; } + std::string getFuncName() { + auto path = CompilerEngine::Library::getClientParametersPath(outputPath); + auto params = ClientParameters::load(path); + if (params.has_error() || params.value().empty()) { + return ""; + } + return params.value().front().functionName; + } + + /// Load the the compilation result if circuit already compiled + llvm::Expected> + loadCompilationResult() { + auto funcName = getFuncName(); + if (funcName.empty()) { + return StreamStringError("couldn't find function name"); + } + auto result = std::make_unique(); + result->outputDirPath = outputPath; + result->funcName = funcName; + return std::move(result); + } + llvm::Expected loadCompilationFeedback(LibraryCompilationResult &result) override { auto path = CompilerEngine::Library::getCompilationFeedbackPath( diff --git a/compilers/concrete-compiler/compiler/lib/Bindings/Rust/src/compiler.rs b/compilers/concrete-compiler/compiler/lib/Bindings/Rust/src/compiler.rs index 8edbf0bc7..ccf7001ce 100644 --- a/compilers/concrete-compiler/compiler/lib/Bindings/Rust/src/compiler.rs +++ b/compilers/concrete-compiler/compiler/lib/Bindings/Rust/src/compiler.rs @@ -548,6 +548,23 @@ impl LibrarySupport { } } + /// Load compilation result from the library support's output directory. + /// + /// This should be used when the output directory already has artefacts from a previous compilation. + pub fn load_compilation_result(&self) -> Result { + unsafe { + let result = + LibraryCompilationResult::wrap(ffi::librarySupportLoadCompilationResult(self._c)); + if result.is_null() { + return Err(CompilerError(format!( + "Error in compiler (check logs for more info): {}", + result.error_msg() + ))); + } + Ok(result) + } + } + /// Run a compiled circuit. pub fn server_lambda_call( &self, diff --git a/compilers/concrete-compiler/compiler/lib/CAPI/Support/CompilerEngine.cpp b/compilers/concrete-compiler/compiler/lib/CAPI/Support/CompilerEngine.cpp index a4f58c998..739022954 100644 --- a/compilers/concrete-compiler/compiler/lib/CAPI/Support/CompilerEngine.cpp +++ b/compilers/concrete-compiler/compiler/lib/CAPI/Support/CompilerEngine.cpp @@ -269,6 +269,17 @@ librarySupportLoadClientParameters(LibrarySupport support, new mlir::concretelang::clientlib::ClientParameters(paramsOrError.get())); } +LibraryCompilationResult +librarySupportLoadCompilationResult(LibrarySupport support) { + auto retOrError = unwrap(support)->loadCompilationResult(); + if (!retOrError) { + return wrap((mlir::concretelang::LibraryCompilationResult *)NULL, + llvm::toString(retOrError.takeError())); + } + return wrap(new mlir::concretelang::LibraryCompilationResult( + *retOrError.get().release())); +} + CompilationFeedback librarySupportLoadCompilationFeedback(LibrarySupport support, LibraryCompilationResult result) {