feat(CAPI): expose encrypted signed int in CAPI

This commit is contained in:
youben11
2022-11-14 14:46:14 +01:00
committed by Ayoub Benaissa
parent 0a57af37af
commit 5576d1d176
2 changed files with 29 additions and 9 deletions

View File

@@ -29,6 +29,13 @@ fheEncryptedIntegerTypeGetChecked(MlirContext context, unsigned width);
/// If the type is an EncryptedInteger
MLIR_CAPI_EXPORTED bool fheTypeIsAnEncryptedIntegerType(MlirType);
/// Creates an encrypted signed integer type of `width` bits
MLIR_CAPI_EXPORTED MlirTypeOrError
fheEncryptedSignedIntegerTypeGetChecked(MlirContext context, unsigned width);
/// If the type is an EncryptedSignedInteger
MLIR_CAPI_EXPORTED bool fheTypeIsAnEncryptedSignedIntegerType(MlirType);
#ifdef __cplusplus
}
#endif

View File

@@ -24,12 +24,8 @@ MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(FHE, fhe, FHEDialect)
// Type API.
//===----------------------------------------------------------------------===//
bool fheTypeIsAnEncryptedIntegerType(MlirType type) {
return unwrap(type).isa<EncryptedIntegerType>();
}
MlirTypeOrError fheEncryptedIntegerTypeGetChecked(MlirContext ctx,
unsigned width) {
template <typename T>
MlirTypeOrError IntegerTypeGetChecked(MlirContext ctx, unsigned width) {
MlirTypeOrError type = {{NULL}, false};
auto catchError = [&]() -> mlir::InFlightDiagnostic {
type.isError = true;
@@ -40,11 +36,28 @@ MlirTypeOrError fheEncryptedIntegerTypeGetChecked(MlirContext ctx,
return engine.emit(mlir::UnknownLoc::get(unwrap(ctx)),
mlir::DiagnosticSeverity::Warning);
};
EncryptedIntegerType eint =
EncryptedIntegerType::getChecked(catchError, unwrap(ctx), width);
T integerType = T::getChecked(catchError, unwrap(ctx), width);
if (type.isError) {
return type;
}
type.type = wrap(eint);
type.type = wrap(integerType);
return type;
}
bool fheTypeIsAnEncryptedIntegerType(MlirType type) {
return unwrap(type).isa<EncryptedIntegerType>();
}
MlirTypeOrError fheEncryptedIntegerTypeGetChecked(MlirContext ctx,
unsigned width) {
return IntegerTypeGetChecked<EncryptedIntegerType>(ctx, width);
}
bool fheTypeIsAnEncryptedSignedIntegerType(MlirType type) {
return unwrap(type).isa<EncryptedSignedIntegerType>();
}
MlirTypeOrError fheEncryptedSignedIntegerTypeGetChecked(MlirContext ctx,
unsigned width) {
return IntegerTypeGetChecked<EncryptedSignedIntegerType>(ctx, width);
}