-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
linalg.matmul E2E #1079
Comments
Right now the end to end pipelines require you to hard-code the ciphertext size (we haven't yet broached how to automatically pick ciphertext sizes, since that is intertwined with questions about packing), so it would be
I can run this and get openfhe dialect output. You still need to run it through heir/tests/Examples/openfhe/BUILD Lines 68 to 76 in b534de6
|
ICYMI, we do have a tutorial that shows most of this here: https://heir.dev/docs/getting_started/#using-heir It uses openfhe with BGV, not CKKS, but the difference should be that extra |
Thank you Jeremy! The MLIR I originally posted successfully lowers to a cpp and h file with that pipeline. Starting from a slightly different point, tensorflow converts a module {
func.func @main(%arg0: tensor<1x4xf32>) -> tensor<1x4xf32> attributes {allow_soft_placement = false} {
%cst = stablehlo.constant dense<[[0.433081806, -0.279845297, 0.144051015, 0.631222903], [-0.708569884, 0.407131732, 0.0975818634, 0.0837838649], [-0.0765365362, -0.256991029, 0.505359352, 0.197199166], [-2.625500e-01, 0.420378864, -0.273303688, 0.682159721]]> : tensor<4x4xf32>
%0 = stablehlo.dot %arg0, %cst, precision = [DEFAULT, DEFAULT] : (tensor<1x4xf32>, tensor<4x4xf32>) -> tensor<1x4xf32>
return %0 : tensor<1x4xf32>
}
} From here, I am running the following passes:
This yields (collapsed for brevity): after `--linalg-to-tensor-ext`module {
func.func @main(%arg0: !secret.secret<tensor<1x4xf32>>) -> !secret.secret<tensor<1x4xf32>> attributes {allow_soft_placement = false} {
%c1 = arith.constant 1 : index
%cst = arith.constant dense<[[0.433081806, 0.407131732, 0.505359352, 0.682159721], [-0.708569884, -0.256991029, -0.273303688, 0.631222903], [-0.0765365362, 0.420378864, 0.144051015, 0.0837838649], [-2.625500e-01, -0.279845297, 0.0975818634, 0.197199166]]> : tensor<4x4xf32>
%cst_0 = arith.constant 0.000000e+00 : f32
%0 = secret.generic ins(%arg0 : !secret.secret<tensor<1x4xf32>>) {
^bb0(%arg1: tensor<1x4xf32>):
%1 = tensor.empty() : tensor<1x4xf32>
%2 = linalg.fill ins(%cst_0 : f32) outs(%1 : tensor<1x4xf32>) -> tensor<1x4xf32>
%3:2 = affine.for %arg2 = 0 to 3 iter_args(%arg3 = %2, %arg4 = %arg1) -> (tensor<1x4xf32>, tensor<1x4xf32>) {
%extracted_slice_1 = tensor.extract_slice %cst[%arg2, 0] [1, 4] [1, 1] : tensor<4x4xf32> to tensor<1x4xf32>
%6 = arith.mulf %arg4, %extracted_slice_1 : tensor<1x4xf32>
%7 = arith.addf %arg3, %6 : tensor<1x4xf32>
%8 = tensor_ext.rotate %arg4, %c1 : tensor<1x4xf32>, index
affine.yield %7, %8 : tensor<1x4xf32>, tensor<1x4xf32>
}
%extracted_slice = tensor.extract_slice %cst[3, 0] [1, 4] [1, 1] : tensor<4x4xf32> to tensor<1x4xf32>
%4 = arith.mulf %3#1, %extracted_slice : tensor<1x4xf32>
%5 = arith.addf %3#0, %4 : tensor<1x4xf32>
secret.yield %5 : tensor<1x4xf32>
} -> !secret.secret<tensor<1x4xf32>>
return %0 : !secret.secret<tensor<1x4xf32>>
}
} From here, 03_linalg_to_tensor_ext.mlir:6:10: error: failed to legalize operation 'secret.generic' that was explicitly marked illegal
%0 = secret.generic ins(%arg0 : !secret.secret<tensor<1x4xf32>>) {
^
03_linalg_to_tensor_ext.mlir:6:10: note: see current operation:
%12 = "secret.generic"(%11) ({
^bb0(%arg16: tensor<1x4xf32>):
%35 = "linalg.fill"(%9, %arg16) <{operandSegmentSizes = array<i32: 1, 1>}> ({
^bb0(%arg17: f32, %arg18: f32):
"linalg.yield"(%arg17) : (f32) -> ()
}) : (f32, tensor<1x4xf32>) -> tensor<1x4xf32>
"secret.yield"(%35) : (tensor<1x4xf32>) -> ()
}) : (!secret.secret<tensor<1x4xf32>>) -> !secret.secret<tensor<1x4xf32>> The only difference I notice between this and my first MLIR example is the |
As far as I am aware, the only special purpose linalg op we lower in that pass is matmul, and we don't yet support lowering You could try
As a side note, you should be able to run the @asraa what do you think about taking the output from |
I tried
could you give the IR just after |
Well we can't lower linalg fully before running the halevi shoup pass (linalg-to-tensor-ext) so maybe another option is adding the BufferizableOpInterface to our tensor ext ops... |
Context
Suppose I have the following code (essentially this test file pre-secretization):
I'm trying to run the following:
Here's the output I get:
Question
Is there something I should be doing regarding cipher text dimension or flattening tensors before running this pipeline?
The text was updated successfully, but these errors were encountered: