# show key sharing effect on a real example
# same partition between padding-TLU and 4bits-TLU
# erase a conversion at the start of rounding to 4 bits
description: cifar-16-1.2.0rc0
program: |
    module {
      func.func @main(%arg0_1_dim: tensor<1x!FHE.esint<13>>) -> tensor<1x10x!FHE.eint<8>> {
        %arg0_cst = arith.constant dense<0> : tensor<1x3x32x32xi14>
        %arg0 = "FHELinalg.add_eint_int"(%arg0_1_dim, %arg0_cst) : (tensor<1x!FHE.esint<13>>, tensor<1x3x32x32xi14>) -> tensor<1x3x32x32x!FHE.esint<13>>
        %cst = arith.constant dense<"[encoded data, 6914 characters]"> : tensor<64x3x3x3xi14>
        %0 = "FHELinalg.conv2d"(%arg0, %cst) {dilations = dense<1> : tensor<2xi64>, group = 1 : i64, padding = dense<0> : tensor<4xi64>, strides = dense<1> : tensor<2xi64>} : (tensor<1x3x32x32x!FHE.esint<13>>, tensor<64x3x3x3xi14>) -> tensor<1x64x30x30x!FHE.esint<13>>
        %1 = "FHELinalg.round"(%0) : (tensor<1x64x30x30x!FHE.esint<13>>) -> tensor<1x64x30x30x!FHE.esint<6>>
        %cst_0 = arith.constant dense<"[encoded data, 921602 characters]"> : tensor<1x64x30x30xindex>
        %cst_1 = arith.constant dense<"[encoded data, 17410 characters]"> : tensor<17x64xi64>
        %2 = "FHELinalg.apply_mapped_lookup_table"(%1, %cst_1, %cst_0) : (tensor<1x64x30x30x!FHE.esint<6>>, tensor<17x64xi64>, tensor<1x64x30x30xindex>) -> tensor<1x64x30x30x!FHE.esint<10>>
        %cst_2 = arith.constant dense<"[encoded data, 147458 characters]"> : tensor<64x64x3x3xi11>
        %3 = "FHELinalg.conv2d"(%2, %cst_2) {dilations = dense<1> : tensor<2xi64>, group = 1 : i64, padding = dense<0> : tensor<4xi64>, strides = dense<1> : tensor<2xi64>} : (tensor<1x64x30x30x!FHE.esint<10>>, tensor<64x64x3x3xi11>) -> tensor<1x64x28x28x!FHE.esint<10>>
        %4 = "FHELinalg.round"(%3) : (tensor<1x64x28x28x!FHE.esint<10>>) -> tensor<1x64x28x28x!FHE.esint<6>>
        %cst_3 = arith.constant dense<"[encoded data, 802818 characters]"> : tensor<1x64x28x28xindex>
        %cst_4 = arith.constant dense<"[encoded data, 19458 characters]"> : tensor<19x64xi64>
        %5 = "FHELinalg.apply_mapped_lookup_table"(%4, %cst_4, %cst_3) : (tensor<1x64x28x28x!FHE.esint<6>>, tensor<19x64xi64>, tensor<1x64x28x28xindex>) -> tensor<1x64x28x28x!FHE.esint<4>>
        %cst_5 = arith.constant dense<"[encoded data, 32770 characters]"> : tensor<64x64x2x2xi5>
        %6 = "FHELinalg.conv2d"(%5, %cst_5) {dilations = dense<1> : tensor<2xi64>, group = 1 : i64, padding = dense<0> : tensor<4xi64>, strides = dense<2> : tensor<2xi64>} : (tensor<1x64x28x28x!FHE.esint<4>>, tensor<64x64x2x2xi5>) -> tensor<1x64x14x14x!FHE.esint<4>>
        %cst_6 = arith.constant dense<[0, 0, 0, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, 0, 0]> : tensor<16xi64>
        %7 = "FHELinalg.apply_lookup_table"(%6, %cst_6) : (tensor<1x64x14x14x!FHE.esint<4>>, tensor<16xi64>) -> tensor<1x64x14x14x!FHE.esint<9>>
        %cst_7 = arith.constant dense<"[encoded data, 294914 characters]"> : tensor<128x64x3x3xi10>
        %8 = "FHELinalg.conv2d"(%7, %cst_7) {dilations = dense<1> : tensor<2xi64>, group = 1 : i64, padding = dense<0> : tensor<4xi64>, strides = dense<1> : tensor<2xi64>} : (tensor<1x64x14x14x!FHE.esint<9>>, tensor<128x64x3x3xi10>) -> tensor<1x128x12x12x!FHE.esint<9>>
        %9 = "FHELinalg.round"(%8) : (tensor<1x128x12x12x!FHE.esint<9>>) -> tensor<1x128x12x12x!FHE.esint<6>>
        %cst_8 = arith.constant dense<"[encoded data, 294914 characters]"> : tensor<1x128x12x12xindex>
        %cst_9 = arith.constant dense<"[encoded data, 47106 characters]"> : tensor<46x64xi64>
        %10 = "FHELinalg.apply_mapped_lookup_table"(%9, %cst_9, %cst_8) : (tensor<1x128x12x12x!FHE.esint<6>>, tensor<46x64xi64>, tensor<1x128x12x12xindex>) -> tensor<1x128x12x12x!FHE.esint<10>>
        %cst_10 = arith.constant dense<"[encoded data, 589826 characters]"> : tensor<128x128x3x3xi11>
        %11 = "FHELinalg.conv2d"(%10, %cst_10) {dilations = dense<1> : tensor<2xi64>, group = 1 : i64, padding = dense<0> : tensor<4xi64>, strides = dense<1> : tensor<2xi64>} : (tensor<1x128x12x12x!FHE.esint<10>>, tensor<128x128x3x3xi11>) -> tensor<1x128x10x10x!FHE.esint<10>>
        %12 = "FHELinalg.round"(%11) : (tensor<1x128x10x10x!FHE.esint<10>>) -> tensor<1x128x10x10x!FHE.esint<6>>
        %cst_11 = arith.constant dense<"[encoded data, 204802 characters]"> : tensor<1x128x10x10xindex>
        %cst_12 = arith.constant dense<"[encoded data, 37890 characters]"> : tensor<37x64xi64>
        %13 = "FHELinalg.apply_mapped_lookup_table"(%12, %cst_12, %cst_11) : (tensor<1x128x10x10x!FHE.esint<6>>, tensor<37x64xi64>, tensor<1x128x10x10xindex>) -> tensor<1x128x10x10x!FHE.esint<4>>
        %cst_13 = arith.constant dense<"[encoded data, 131074 characters]"> : tensor<128x128x2x2xi5>
        %14 = "FHELinalg.conv2d"(%13, %cst_13) {dilations = dense<1> : tensor<2xi64>, group = 1 : i64, padding = dense<0> : tensor<4xi64>, strides = dense<2> : tensor<2xi64>} : (tensor<1x128x10x10x!FHE.esint<4>>, tensor<128x128x2x2xi5>) -> tensor<1x128x5x5x!FHE.esint<4>>
        %15 = "FHELinalg.apply_lookup_table"(%14, %cst_6) : (tensor<1x128x5x5x!FHE.esint<4>>, tensor<16xi64>) -> tensor<1x128x5x5x!FHE.esint<9>>
        %cst_14 = arith.constant dense<"[encoded data, 1179650 characters]"> : tensor<256x128x3x3xi10>
        %16 = "FHELinalg.conv2d"(%15, %cst_14) {dilations = dense<1> : tensor<2xi64>, group = 1 : i64, padding = dense<0> : tensor<4xi64>, strides = dense<1> : tensor<2xi64>} : (tensor<1x128x5x5x!FHE.esint<9>>, tensor<256x128x3x3xi10>) -> tensor<1x256x3x3x!FHE.esint<9>>
        %17 = "FHELinalg.round"(%16) : (tensor<1x256x3x3x!FHE.esint<9>>) -> tensor<1x256x3x3x!FHE.esint<6>>
        %cst_15 = arith.constant dense<"[encoded data, 36866 characters]"> : tensor<1x256x3x3xindex>
        %cst_16 = arith.constant dense<"[encoded data, 89090 characters]"> : tensor<87x64xi64>
        %18 = "FHELinalg.apply_mapped_lookup_table"(%17, %cst_16, %cst_15) : (tensor<1x256x3x3x!FHE.esint<6>>, tensor<87x64xi64>, tensor<1x256x3x3xindex>) -> tensor<1x256x3x3x!FHE.esint<10>>
        %cst_17 = arith.constant dense<"[encoded data, 2359298 characters]"> : tensor<256x256x3x3xi11>
        %19 = "FHELinalg.conv2d"(%18, %cst_17) {dilations = dense<1> : tensor<2xi64>, group = 1 : i64, padding = dense<0> : tensor<4xi64>, strides = dense<1> : tensor<2xi64>} : (tensor<1x256x3x3x!FHE.esint<10>>, tensor<256x256x3x3xi11>) -> tensor<1x256x1x1x!FHE.esint<10>>
        %20 = "FHELinalg.round"(%19) : (tensor<1x256x1x1x!FHE.esint<10>>) -> tensor<1x256x1x1x!FHE.esint<6>>
        %cst_18 = arith.constant dense<"[encoded data, 4098 characters]"> : tensor<1x256x1x1xindex>
        %cst_19 = arith.constant dense<"[encoded data, 57346 characters]"> : tensor<56x64xi64>
        %21 = "FHELinalg.apply_mapped_lookup_table"(%20, %cst_19, %cst_18) : (tensor<1x256x1x1x!FHE.esint<6>>, tensor<56x64xi64>, tensor<1x256x1x1xindex>) -> tensor<1x256x1x1x!FHE.esint<8>>
        %collapsed = tensor.collapse_shape %21 [[0], [1, 2, 3]] : tensor<1x256x1x1x!FHE.esint<8>> into tensor<1x256x!FHE.esint<8>>
        %cst_20 = arith.constant dense<"[encoded data, 524290 characters]"> : tensor<256x512xi9>
        %22 = "FHELinalg.matmul_eint_int"(%collapsed, %cst_20) : (tensor<1x256x!FHE.esint<8>>, tensor<256x512xi9>) -> tensor<1x512x!FHE.esint<8>>
        %23 = "FHELinalg.round"(%22) : (tensor<1x512x!FHE.esint<8>>) -> tensor<1x512x!FHE.esint<6>>
        %cst_21 = arith.constant dense<"[encoded data, 8194 characters]"> : tensor<1x512xindex>
        %cst_22 = arith.constant dense<"[encoded data, 71682 characters]"> : tensor<70x64xi64>
        %24 = "FHELinalg.apply_mapped_lookup_table"(%23, %cst_22, %cst_21) : (tensor<1x512x!FHE.esint<6>>, tensor<70x64xi64>, tensor<1x512xindex>) -> tensor<1x512x!FHE.esint<9>>
        %cst_23 = arith.constant dense<"[encoded data, 1048578 characters]"> : tensor<512x512xi10>
        %25 = "FHELinalg.matmul_eint_int"(%24, %cst_23) : (tensor<1x512x!FHE.esint<9>>, tensor<512x512xi10>) -> tensor<1x512x!FHE.esint<9>>
        %26 = "FHELinalg.round"(%25) : (tensor<1x512x!FHE.esint<9>>) -> tensor<1x512x!FHE.esint<6>>
        %cst_24 = arith.constant dense<"[encoded data, 8194 characters]"> : tensor<1x512xindex>
        %cst_25 = arith.constant dense<"[encoded data, 59394 characters]"> : tensor<58x64xi64>
        %27 = "FHELinalg.apply_mapped_lookup_table"(%26, %cst_25, %cst_24) : (tensor<1x512x!FHE.esint<6>>, tensor<58x64xi64>, tensor<1x512xindex>) -> tensor<1x512x!FHE.esint<10>>
        %cst_26 = arith.constant dense<"[encoded data, 20482 characters]"> : tensor<512x10xi11>
        %28 = "FHELinalg.matmul_eint_int"(%27, %cst_26) : (tensor<1x512x!FHE.esint<10>>, tensor<512x10xi11>) -> tensor<1x10x!FHE.esint<10>>
        %29 = "FHELinalg.round"(%28) : (tensor<1x10x!FHE.esint<10>>) -> tensor<1x10x!FHE.esint<6>>
        %cst_27 = arith.constant dense<[70, 80, 89, 99, 109, 118, 128, 138, 148, 157, 167, 177, 186, 196, 206, 216, 225, 235, 245, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 12, 21, 31, 41, 50, 60]> : tensor<64xi64>
        %30 = "FHELinalg.apply_lookup_table"(%29, %cst_27) : (tensor<1x10x!FHE.esint<6>>, tensor<64xi64>) -> tensor<1x10x!FHE.eint<8>>
        return %30 : tensor<1x10x!FHE.eint<8>>
      }
    }
p-error: 6.3342483999973e-05
tests:
  - inputs:
    - tensor: [1]
      shape: [1]
    outputs:
    - tensor: [1]
      shape: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
