mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-09 03:55:04 -05:00
fix: forward errors instead of creating new ones
LLVM errors should be handled/consumed. Creating a new one and leaving the previous one alive will crash the compiler. Whenever we don't want a crash (e.g. logging the error is enough), but still wanna continue the execution, we can just consume it.
This commit is contained in:
@@ -37,6 +37,29 @@ def test_compile_and_run(mlir_input, args, expected_result):
|
||||
assert engine.run(*args) == expected_result
|
||||
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"mlir_input, args",
|
||||
[
|
||||
pytest.param(
|
||||
"""
|
||||
func @main(%arg0: !HLFHE.eint<7>, %arg1: i8) -> !HLFHE.eint<7> {
|
||||
%1 = "HLFHE.add_eint_int"(%arg0, %arg1): (!HLFHE.eint<7>, i8) -> (!HLFHE.eint<7>)
|
||||
return %1: !HLFHE.eint<7>
|
||||
}
|
||||
""",
|
||||
(5, 7, 8),
|
||||
id="add_eint_int_invalid_arg_number"
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_compile_and_run_invalid_arg_number(mlir_input, args):
|
||||
engine = CompilerEngine()
|
||||
engine.compile_fhe(mlir_input)
|
||||
with pytest.raises(RuntimeError, match=r"failed pushing integer argument"):
|
||||
engine.run(*args)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"mlir_input, args, expected_result, tab_size",
|
||||
[
|
||||
@@ -59,3 +82,25 @@ def test_compile_and_run_tlu(mlir_input, args, expected_result, tab_size):
|
||||
engine = CompilerEngine()
|
||||
engine.compile_fhe(mlir_input)
|
||||
assert abs(engine.run(*args) - expected_result) / tab_size < 0.1
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"mlir_input",
|
||||
[
|
||||
pytest.param(
|
||||
"""
|
||||
func @test(%arg0: tensor<4x!HLFHE.eint<7>>, %arg1: tensor<4xi8>) -> !HLFHE.eint<7>
|
||||
{
|
||||
%ret = "HLFHE.dot_eint_int"(%arg0, %arg1) :
|
||||
(tensor<4x!HLFHE.eint<7>>, tensor<4xi8>) -> !HLFHE.eint<7>
|
||||
return %ret : !HLFHE.eint<7>
|
||||
}
|
||||
""",
|
||||
id="not @main"
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_compile_invalid(mlir_input):
|
||||
engine = CompilerEngine()
|
||||
with pytest.raises(RuntimeError, match=r"failed compiling"):
|
||||
engine.compile_fhe(mlir_input)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import pytest
|
||||
from mlir.ir import Context
|
||||
from zamalang import register_dialects
|
||||
from zamalang.dialects import hlfhe
|
||||
@@ -8,3 +9,11 @@ def test_eint():
|
||||
register_dialects(ctx)
|
||||
eint = hlfhe.EncryptedIntegerType.get(ctx, 6)
|
||||
assert eint.__str__() == "!HLFHE.eint<6>"
|
||||
|
||||
|
||||
# FIXME: need to handle error on call to hlfhe.EncryptedIntegerType.get and throw an exception to python
|
||||
# def test_invalid_eint():
|
||||
# ctx = Context()
|
||||
# register_dialects(ctx)
|
||||
# with pytest.raises(RuntimeError, match=r"mlir parsing failed"):
|
||||
# eint = hlfhe.EncryptedIntegerType.get(ctx, 16)
|
||||
|
||||
@@ -47,14 +47,14 @@ VALID_INPUTS = [
|
||||
]
|
||||
|
||||
INVALID_INPUTS = [
|
||||
pytest.param("nothing really mlir", id="add_eint_int_cst"),
|
||||
pytest.param("nothing really mlir", id="english sentence"),
|
||||
pytest.param(
|
||||
"""
|
||||
func @test(%arg0: !HLFHE.eint<0>) {
|
||||
return
|
||||
}
|
||||
""",
|
||||
id="add_eint_int_cst",
|
||||
id="eint<0>",
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user