google / heir

A compiler for homomorphic encryption
https://heir.dev/
Apache License 2.0
317 stars 48 forks source link

Handle multi-dimensional tensors in RLWE paths #924

Open asraa opened 2 months ago

asraa commented 2 months ago

I'm filing this issue to track / discuss how to handle multi-dimensional tensors as we go through packing passes and secret-to. I thought we had an issue about this, but I couldn't find one

Background

Right now:

Situation right now

In https://github.com/google/heir/issues/906, @lawrencekhlim is rewriting a linalg.matmul operation into a diagonalized matrix - vector product. Matmul operations expect 2-D inputs, and so we currently are restricting to rewrite matmuls of the form NxN matrix with Nx1 vector. The nx1 vector needs to be rotated, and so obviously we hit an error where tensor_ext rotate expects 1-D tensors only.

What to do

I'm not sure if

(1) We should flatten / reshape the inputs so that the rotated vector becomes 1-D or (2) Generalize rotate op (and tensor_ext canonicalization) to assume only one dimension can have a non-unit dimension

Obviously (2) would complicate implementations a bit, especially to determine the non-unit dimension, but it's slightly more realistic coming from the frontends that we would have tensors in the shape 1xN.

Other than this particular problem, if we have 2-D packing algorithms then we need to be able to operate on multi-dimensional tensors, so this probably isn't the only issue. I know we punted a little on defining rotations for multi-dimensional tensors.

github-actions[bot] commented 2 weeks ago

This issue has 3 outstanding TODOs:

This comment was autogenerated by todo-backlinks