feat(compiler): HLFHE.apply_lookup_table (#54)

This commit is contained in:
Quentin Bourgerie
2021-07-19 11:57:21 +02:00
parent ea77ee696a
commit cb635f8a55
4 changed files with 54 additions and 1 deletions

View File

@@ -51,6 +51,16 @@ def MulEintIntOp : HLFHE_Op<"mul_eint_int"> {
];
}
def ApplyLookupTable : HLFHE_Op<"apply_lookup_table"> {
let arguments = (ins EncryptedIntegerType:$ct,
MemRefOf<[AnyInteger]>:$l_cst);
let results = (outs EncryptedIntegerType);
let verifier = [{
return ::mlir::zamalang::HLFHE::verifyApplyLookupTable(*this);
}];
}
// Tensor operations
// Dot product

View File

@@ -1,13 +1,42 @@
#include "mlir/IR/Region.h"
#include "mlir/IR/TypeUtilities.h"
#include "zamalang/Dialect/HLFHE/IR/HLFHEOps.h"
#include "zamalang/Dialect/HLFHE/IR/HLFHETypes.h"
#include <mlir/IR/TypeUtilities.h>
namespace mlir {
namespace zamalang {
namespace HLFHE {
using mlir::zamalang::HLFHE::ApplyLookupTable;
using mlir::zamalang::HLFHE::EncryptedIntegerType;
::mlir::LogicalResult verifyApplyLookupTable(ApplyLookupTable &op) {
auto ct = op.ct().getType().cast<EncryptedIntegerType>();
auto l_cst = op.l_cst().getType().cast<MemRefType>();
auto result = op.getResult().getType().cast<EncryptedIntegerType>();
// Check the shape of l_cst argument
auto width = ct.getWidth();
auto lCstShape = l_cst.getShape();
mlir::SmallVector<int64_t, 1> expectedShape{1 << width};
if (!l_cst.hasStaticShape(expectedShape)) {
op.emitOpError() << " should have as `l_cst` argument a shape of one "
"dimension equals to 2^p, where p is the width of the "
"`ct` argument.";
return mlir::failure();
}
// Check the witdh of the encrypted integer and the integer of the tabulated
// lambda are equals
if (ct.getWidth() != l_cst.getElementType().cast<IntegerType>().getWidth()) {
op.emitOpError()
<< " should have equals width beetwen the encrypted integer result and "
"integers of the `tabulated_lambda` argument";
return mlir::failure();
}
return mlir::success();
}
void Dot::getEffects(
SmallVectorImpl<SideEffects::EffectInstance<MemoryEffects::Effect>>
&effects) {

View File

@@ -0,0 +1,7 @@
// RUN: not zamacompiler %s 2>&1| FileCheck %s
// CHECK-LABEL: error: 'HLFHE.apply_lookup_table' op should have as `l_cst` argument a shape of one dimension equals to 2^p, where p is the width of the `ct` argument.
func @apply_lookup_table(%arg0: !HLFHE.eint<2>, %arg1: memref<8xi3>) -> !HLFHE.eint<2> {
%1 = "HLFHE.apply_lookup_table"(%arg0, %arg1): (!HLFHE.eint<2>, memref<8xi3>) -> (!HLFHE.eint<2>)
return %1: !HLFHE.eint<2>
}

View File

@@ -0,0 +1,7 @@
// RUN: not zamacompiler %s 2>&1| FileCheck %s
// CHECK-LABEL: error: 'HLFHE.apply_lookup_table' op should have equals width beetwen the encrypted integer result and integers of the `tabulated_lambda` argument
func @apply_lookup_table(%arg0: !HLFHE.eint<2>, %arg1: memref<4xi3>) -> !HLFHE.eint<2> {
%1 = "HLFHE.apply_lookup_table"(%arg0, %arg1): (!HLFHE.eint<2>, memref<4xi3>) -> (!HLFHE.eint<2>)
return %1: !HLFHE.eint<2>
}