mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-08 11:35:02 -05:00
feat(compiler): load lib compilation result from directory
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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<std::unique_ptr<LibraryCompilationResult>>
|
||||
loadCompilationResult() {
|
||||
auto funcName = getFuncName();
|
||||
if (funcName.empty()) {
|
||||
return StreamStringError("couldn't find function name");
|
||||
}
|
||||
auto result = std::make_unique<LibraryCompilationResult>();
|
||||
result->outputDirPath = outputPath;
|
||||
result->funcName = funcName;
|
||||
return std::move(result);
|
||||
}
|
||||
|
||||
llvm::Expected<CompilationFeedback>
|
||||
loadCompilationFeedback(LibraryCompilationResult &result) override {
|
||||
auto path = CompilerEngine::Library::getCompilationFeedbackPath(
|
||||
|
||||
@@ -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<LibraryCompilationResult, CompilerError> {
|
||||
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,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user