feat(compiler): load lib compilation result from directory

This commit is contained in:
youben11
2023-06-06 10:25:27 +01:00
committed by Ayoub Benaissa
parent c8cc8a811d
commit 9c077852bb
4 changed files with 53 additions and 0 deletions

View File

@@ -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);

View File

@@ -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(

View File

@@ -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,

View File

@@ -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) {