fix(python): register hlfhelinalg dialect

This commit is contained in:
youben11
2021-11-03 09:58:23 +01:00
committed by Ayoub Benaissa
parent 5999d402ec
commit 97ee8134ed
10 changed files with 93 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
import pytest
from mlir.ir import Context
from mlir.ir import Context, RankedTensorType, Location
from zamalang import register_dialects
from zamalang.dialects import hlfhe
@@ -12,6 +12,17 @@ def test_eint(width):
assert eint.__str__() == f"!HLFHE.eint<{width}>"
@pytest.mark.parametrize("shape", [(1,), (2,), (1, 1), (1, 2), (2, 1), (3, 3, 3)])
def test_eint_tensor(shape):
with Context() as ctx, Location.unknown(context=ctx):
register_dialects(ctx)
eint = hlfhe.EncryptedIntegerType.get(ctx, 3)
tensor = RankedTensorType.get(shape, eint)
assert (
tensor.__str__() == f"tensor<{'x'.join(map(str, shape))}x!HLFHE.eint<{3}>>"
)
@pytest.mark.parametrize("width", [0, 8, 10, 12])
def test_invalid_eint(width):
ctx = Context()

View File

@@ -44,6 +44,15 @@ VALID_INPUTS = [
""",
id="add_eint_int_cst",
),
pytest.param(
"""
func @main(%a0: tensor<4x!HLFHE.eint<2>>, %a1: tensor<4xi3>) -> tensor<4x!HLFHE.eint<2>> {
%1 = "HLFHELinalg.add_eint_int"(%a0, %a1) : (tensor<4x!HLFHE.eint<2>>, tensor<4xi3>) -> tensor<4x!HLFHE.eint<2>>
return %1: tensor<4x!HLFHE.eint<2>>
}
""",
id="add_eint_int_1D",
),
]
INVALID_INPUTS = [
@@ -56,6 +65,16 @@ INVALID_INPUTS = [
""",
id="eint<0>",
),
pytest.param(
"""
func @main(%a0: tensor<2x2x3x4x!HLFHE.eint<2>>, %a1: tensor<2x2x2x4xi3>) -> tensor<2x2x3x4x!HLFHE.eint<2>> {
// expected-error @+1 {{'HLFHELinalg.add_eint_int' op has the dimension #2 of the operand #1 incompatible with other operands, got 2 expect 1 or 3}}
%1 = "HLFHELinalg.add_eint_int"(%a0, %a1) : (tensor<2x2x3x4x!HLFHE.eint<2>>, tensor<2x2x2x4xi3>) -> tensor<2x2x3x4x!HLFHE.eint<2>>
return %1 : tensor<2x2x3x4x!HLFHE.eint<2>>
}
""",
id="incompatible dimensions",
),
]