mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-09 03:55:04 -05:00
feat: Runtime library
This commit is contained in:
committed by
Quentin Bourgerie
parent
ea3c940f4a
commit
de81ac3f3e
@@ -1,6 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
project(zamacompiler LANGUAGES CXX)
|
||||
project(zamacompiler LANGUAGES C CXX)
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
|
||||
30
compiler/include/zamalang/Runtime/context.h
Normal file
30
compiler/include/zamalang/Runtime/context.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef ZAMALANG_RUNTIME_CONTEXT_H
|
||||
#define ZAMALANG_RUNTIME_CONTEXT_H
|
||||
|
||||
#include "concrete-ffi.h"
|
||||
|
||||
typedef struct RuntimeContext {
|
||||
struct LweKeyswitchKey_u64 *ksk;
|
||||
struct LweBootstrapKey_u64 *bsk;
|
||||
} RuntimeContext;
|
||||
|
||||
extern RuntimeContext *globalRuntimeContext;
|
||||
|
||||
RuntimeContext *createRuntimeContext(LweKeyswitchKey_u64 *ksk,
|
||||
LweBootstrapKey_u64 *bsk);
|
||||
|
||||
void setGlobalRuntimeContext(RuntimeContext *context);
|
||||
|
||||
RuntimeContext *getGlobalRuntimeContext();
|
||||
|
||||
LweKeyswitchKey_u64 *getGlobalKeyswitchKey();
|
||||
|
||||
LweBootstrapKey_u64 *getGlobalBootstrapKey();
|
||||
|
||||
LweKeyswitchKey_u64 *getKeyswitckKeyFromContext(RuntimeContext *context);
|
||||
|
||||
LweBootstrapKey_u64 *getBootstrapKeyFromContext(RuntimeContext *context);
|
||||
|
||||
bool checkError(int *err);
|
||||
|
||||
#endif
|
||||
10
compiler/include/zamalang/Runtime/wrappers.h
Normal file
10
compiler/include/zamalang/Runtime/wrappers.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef ZAMALANG_RUNTIME_WRAPPERS_H
|
||||
#define ZAMALANG_RUNTIME_WRAPPERS_H
|
||||
|
||||
#include "concrete-ffi.h"
|
||||
|
||||
ForeignPlaintextList_u64 *runtime_foreign_plaintext_list_u64(
|
||||
int *err, uint64_t *allocated, uint64_t *aligned, uint64_t offset,
|
||||
uint64_t size_dim0, uint64_t stride_dim0, uint64_t size);
|
||||
|
||||
#endif
|
||||
@@ -1,6 +1,7 @@
|
||||
add_subdirectory(Dialect)
|
||||
add_subdirectory(Conversion)
|
||||
add_subdirectory(Support)
|
||||
add_subdirectory(Runtime)
|
||||
|
||||
# CAPI needed only for python bindings
|
||||
if (ZAMALANG_BINDINGS_PYTHON_ENABLED)
|
||||
|
||||
4
compiler/lib/Runtime/CMakeLists.txt
Normal file
4
compiler/lib/Runtime/CMakeLists.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
add_library(ZamalangRuntime SHARED
|
||||
context.c
|
||||
wrappers.c
|
||||
)
|
||||
51
compiler/lib/Runtime/context.c
Normal file
51
compiler/lib/Runtime/context.c
Normal file
@@ -0,0 +1,51 @@
|
||||
#include "zamalang/Runtime/context.h"
|
||||
#include <stdio.h>
|
||||
|
||||
RuntimeContext *globalRuntimeContext;
|
||||
|
||||
RuntimeContext *createRuntimeContext(LweKeyswitchKey_u64 *ksk,
|
||||
LweBootstrapKey_u64 *bsk) {
|
||||
RuntimeContext *context = (RuntimeContext *)malloc(sizeof(RuntimeContext));
|
||||
context->ksk = ksk;
|
||||
context->bsk = bsk;
|
||||
return context;
|
||||
}
|
||||
|
||||
void setGlobalRuntimeContext(RuntimeContext *context) {
|
||||
globalRuntimeContext = context;
|
||||
}
|
||||
|
||||
RuntimeContext *getGlobalRuntimeContext() { return globalRuntimeContext; }
|
||||
|
||||
LweKeyswitchKey_u64 *getGlobalKeyswitchKey() {
|
||||
return globalRuntimeContext->ksk;
|
||||
}
|
||||
|
||||
LweBootstrapKey_u64 *getGlobalBootstrapKey() {
|
||||
return globalRuntimeContext->bsk;
|
||||
}
|
||||
|
||||
LweKeyswitchKey_u64 *getKeyswitckKeyFromContext(RuntimeContext *context) {
|
||||
return context->ksk;
|
||||
}
|
||||
|
||||
LweBootstrapKey_u64 *getBootstrapKeyFromContext(RuntimeContext *context) {
|
||||
return context->bsk;
|
||||
}
|
||||
|
||||
bool checkError(int *err) {
|
||||
switch (*err) {
|
||||
case ERR_INDEX_OUT_OF_BOUND:
|
||||
fprintf(stderr, "Runtime: index out of bound");
|
||||
break;
|
||||
case ERR_NULL_POINTER:
|
||||
fprintf(stderr, "Runtime: null pointer");
|
||||
break;
|
||||
case ERR_SIZE_MISMATCH:
|
||||
fprintf(stderr, "Runtime: size mismatch");
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
12
compiler/lib/Runtime/wrappers.c
Normal file
12
compiler/lib/Runtime/wrappers.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "zamalang/Runtime/wrappers.h"
|
||||
#include <stdio.h>
|
||||
|
||||
ForeignPlaintextList_u64 *runtime_foreign_plaintext_list_u64(
|
||||
int *err, uint64_t *allocated, uint64_t *aligned, uint64_t offset,
|
||||
uint64_t size_dim0, uint64_t stride_dim0, uint64_t size) {
|
||||
if (stride_dim0 != 1) {
|
||||
fprintf(stderr, "Runtime: stride not equal to 1, check "
|
||||
"runtime_foreign_plaintext_list_u64");
|
||||
}
|
||||
return foreign_plaintext_list_u64(err, aligned + offset, size);
|
||||
}
|
||||
Reference in New Issue
Block a user