google / google/heir

Configure OpenFHE for sparse packing properly

Open
#2,709 0 comments 0 reactions 0 assignees View on GitHub
bug dialect: openfhe
Dominant language
MLIR
Stars
906
Forks
171
Avg merge
4d 12h
Merged PRs (30d)
32

Description

In 5bff766e838b5e9b49ed78339aafc8ab5a4b5113 we have the lattigo pipeline properly configure lattigo to use its sparse encoding (when the number of actual used slots `n` divides the max number of slots `N`). In Lattigo you do this by setting `LogDimensions` on a plaintext before encoding, and for bootstrappng this has to be paired with a corresponding setting of `LogSlots` on the bootstrapping params to use sparse bootstrapping.

OpenFHE has a similar situation, but in our current backend we aren't properly configuring the sparse packing, and are instead always assuming a full packing: https://github.com/google/heir/blob/26ef485a8ac9367ed4ff4e4f188d0d0129f1dd0c/lib/Target/OpenFhePke/OpenFhePkeEmitter.cpp#L1942

In OpenFHE the `SetBatchSize` is supposed to be used for this purpose, and now at the end of the pipeline we should have a [requested slot count attribute](https://github.com/google/heir/blob/26ef485a8ac9367ed4ff4e4f188d0d0129f1dd0c/lib/Dialect/ModuleAttributes.h#L25) on the module that corresponds to the actual number of slots needed.

This issue is to use that attribute to properly `SetBatchSize`, and to fix up any lingering assumptions in the OpenFHE emitter; e.g., [explicit cyclic repetition](https://github.com/google/heir/blob/26ef485a8ac9367ed4ff4e4f188d0d0129f1dd0c/lib/Target/OpenFhePke/OpenFhePkeEmitter.cpp#L1649) that should not be necessary if `SetBatchSize` is used properly, as well as various places where we query `GetRingDimension() / 2` to get a slot count. I had originally tried to do this in `5bff766e838b5e9b49ed78339aafc8ab5a4b5113`, and ran into errors that I didn't have time to fix.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.