-
Notifications
You must be signed in to change notification settings - Fork 129
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
Interfaces to generalize noise calculation in FHE/FHELinalg ops #416
Conversation
Thank you for your pull request. We require contributors to sign our Contributor License Agreement / Terms and Conditions, and we don't seem to have the users @mkmks on file. In order for us to review and merge your code, please sign:
If you already signed one of this document, just wait to be added to the bot config. |
12301d2
to
0140a76
Compare
Thank you for your pull request. We require contributors to sign our Contributor License Agreement / Terms and Conditions, and we don't seem to have the users @mkmks on file. In order for us to review and merge your code, please sign:
If you already signed one of this document, just wait to be added to the bot config. |
0140a76
to
e3bddf3
Compare
Thank you for your pull request. We require contributors to sign our Contributor License Agreement / Terms and Conditions, and we don't seem to have the users @mkmks on file. In order for us to review and merge your code, please sign:
If you already signed one of this document, just wait to be added to the bot config. |
e3bddf3
to
c477308
Compare
Thank you for your pull request. We require contributors to sign our Contributor License Agreement / Terms and Conditions, and we don't seem to have the users @mkmks on file. In order for us to review and merge your code, please sign:
If you already signed one of this document, just wait to be added to the bot config. |
c477308
to
015e3d7
Compare
Thank you for your pull request. We require contributors to sign our Contributor License Agreement / Terms and Conditions, and we don't seem to have the users @mkmks on file. In order for us to review and merge your code, please sign:
If you already signed one of this document, just wait to be added to the bot config. |
015e3d7
to
42a39a8
Compare
Thank you for your pull request. We require contributors to sign our Contributor License Agreement / Terms and Conditions, and we don't seem to have the users @mkmks on file. In order for us to review and merge your code, please sign:
If you already signed one of this document, just wait to be added to the bot config. |
42a39a8
to
e46cf4d
Compare
Thank you for your pull request. We require contributors to sign our Contributor License Agreement / Terms and Conditions, and we don't seem to have the users @mkmks on file. In order for us to review and merge your code, please sign:
If you already signed one of this document, just wait to be added to the bot config. |
compilers/concrete-compiler/compiler/include/concretelang/Dialect/FHELinalg/IR/FHELinalgOps.td
Outdated
Show resolved
Hide resolved
compilers/concrete-compiler/compiler/include/concretelang/Dialect/FHELinalg/IR/FHELinalgOps.td
Outdated
Show resolved
Hide resolved
compilers/concrete-compiler/compiler/include/concretelang/Dialect/FHELinalg/IR/FHELinalgOps.td
Outdated
Show resolved
Hide resolved
compilers/concrete-compiler/compiler/lib/Dialect/FHE/Analysis/MANP.cpp
Outdated
Show resolved
Hide resolved
} | ||
|
||
return llvm::APInt{1, 1, false}; | ||
} | ||
|
||
/// Calculates the squared Minimal Arithmetic Noise Padding of an | ||
/// `FHELinalg.dot_eint_eint` operation. | ||
static llvm::APInt getSqMANP(mlir::concretelang::FHELinalg::DotEint op, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is not yet ported to the interface mechanism but there are no hard reason?
compilers/concrete-compiler/compiler/lib/Dialect/FHE/Analysis/MANP.cpp
Outdated
Show resolved
Hide resolved
static llvm::APInt getSqMANP(mlir::tensor::FromElementsOp op, | ||
llvm::ArrayRef<const MANPLattice *> operandMANPs) { | ||
static std::optional<llvm::APInt> | ||
getSqMANP(mlir::tensor::FromElementsOp op, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I see you dan't use the interfaces mechanism for ops that we don't define, maybe there are a way to attach interface to ops like in the bufferization mechanism (maybe @andidr you know how to achieve that).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its is possible to do that with external models. The file compilers/concrete-compiler/compiler/lib/Dialect/Concrete/Transforms/BufferizableOpInterfaceImpl.cpp
shows this for BufferizableOpInterface
. You just need to ensure that the code attaching the interface is executed at the beginning (e.g., by adding something to CompilationContext::getMLIRContext()
in compilers/concrete-compiler/compiler/lib/Support/CompilerEngine.cpp
).
@cla-bot check |
The cla-bot has been summoned, and re-checked this pull request! |
e46cf4d
to
70f88d7
Compare
2714a6d
to
272b1d9
Compare
@slab-ci concrete-python-test |
Failed to run command: command 'concrete-python-test' not found in config file |
@slab-ci concrete-python-tests-linux |
ee46150
to
ba396d4
Compare
@slab-ci concrete-python-tests-linux |
@slab-ci compiler-cpu-build |
1 similar comment
@slab-ci compiler-cpu-build |
Instead of having one `getSQManp` implementation per op with a lot of repetition, the noise calculation is now modular. - Ops that implements`UnaryEint`/`BinaryInt`/`BinaryEint` interfaces share the operand noise presence check. - For many scalar ops no further calculation is needed. If it's not the case, an op can override `sqMANP`. - Integer operand types lookups are abstracted into `BinaryInt::operandIntType()` - Finding largest operand value for a type is abstracted into `BinaryInt::operandMaxConstant` - Noise calculation for matmul ops is simplified and it's now general enough to work for `matmul_eint_int`, `matmul_int_eint` and `dot_eint_int` at once.
ba396d4
to
734f986
Compare
Instead of having one
getSQManp
implementation per op with a lot of repetition, the noise calculation is now modular.UnaryEint
/BinaryInt
/BinaryEint
interfaces share the operand noise presence check.sqMANP
.BinaryInt::operandIntType()
BinaryInt::operandMaxConstant
matmul_eint_int
,matmul_int_eint
anddot_eint_int
at once.Unless a
sqMANP
implementation is very short, the bulk of the noise calculation is moved to pure functions that don't accessOpState
directly (such assqMANP_matmul
). AsqMANP
implementation is, thus, responsible to pass the necessary information fromOpState
through parameters. This was done to make it explicit that only a small part ofOpState
is needed for calculating noise, which helped, for example, generalizingmatmul_eint_int
,matmul_int_eint
anddot_eint_int
to a singlesqMANP_matmul
.I have a hunch that
sqMANP_conv2d
could also be expressed throughsqMANP_matmul
(or it can be generalized to express sqMANP_conv2d`) but I haven't done so yet.In the future, one could also find a way to declare
mlir::tensor
ops as implementingUnaryEint
/BinaryInt
/BinaryEint
to throw away even more boilerplate. But there doesn't seem to be a way to that through ODS, so I gave up on it for the time being.