mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-09 03:55:04 -05:00
feat(CAPI): expose encrypted signed int in CAPI
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user