feat: Runtime library

This commit is contained in:
youben11
2021-08-27 12:38:15 +01:00
committed by Quentin Bourgerie
parent ea3c940f4a
commit de81ac3f3e
7 changed files with 109 additions and 1 deletions

View File

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

View 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

View 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

View File

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

View File

@@ -0,0 +1,4 @@
add_library(ZamalangRuntime SHARED
context.c
wrappers.c
)

View 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;
}

View 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);
}