Skip to content

Rotom: Roll arguments can name a whole tensor axis - #3174

Open
edwjchen wants to merge 1 commit into
google:mainfrom
edwjchen:rotom-pr-03
Open

Rotom: Roll arguments can name a whole tensor axis#3174
edwjchen wants to merge 1 commit into
google:mainfrom
edwjchen:rotom-pr-03

Conversation

@edwjchen

@edwjchen edwjchen commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Part 3 of #2980 and stacked on #3170

A Rotom roll decorates a layout: roll(from, by) rewrites the from index by subtracting the by argument's index. Until now a roll argument could only be a piece, a position in the dims list. This PR lets it also be a whole tensor axis, spelled axis N and stored as -(axis+1) in the flat rolls array.

// Piece arguments: Halevi-Shoup diagonal of a 4x4 matrix, slot j of
// ciphertext i holds A[i, (j - i) mod 4].
#diag  = #rotom.layout<n = 4, rolls = [(1, 0)], dims = [[0:4:1] | [1:4:1]]>

// Axis 1 is split across two pieces, so the whole-axis roll names it.
// How to read this: `axis 1` refers to `[1:4:4], [1:4:1]` and `2` refers to piece 2 or `[0:16:1]`
#split = #rotom.layout<n = 16, rolls = [(axis 1, 2)],
                       dims = [[1:4:4], [1:4:1] | [0:16:1]]>
  • Piece FROM rewrites only that piece's mixed-radix digit, leaving the axis's other digits untouched. This is the original per-piece reading, now materialized correctly on split axes (no borrow leaks across digits).
  • Axis FROM rewrites the whole axis index modulo its full extent; each piece then takes its digit of the rolled index, so the shift borrows across digits.

@j2kun

j2kun commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

@edwjchen Could you rebase this one?

@j2kun
j2kun self-requested a review July 16, 2026 21:36
Comment thread lib/Dialect/Rotom/IR/RotomAttributes.td
Comment thread lib/Dialect/Rotom/IR/RotomAttributes.td Outdated
Comment thread lib/Dialect/Rotom/IR/RotomAttributes.td Outdated
Comment thread lib/Dialect/Rotom/IR/RotomAttributes.cpp Outdated
Comment thread lib/Dialect/Rotom/Utils/RotomTensorExtLayoutLowering.cpp Outdated
Comment thread lib/Dialect/Rotom/Utils/RotomTensorExtLayoutLowering.h Outdated
@edwjchen edwjchen changed the title Rotom: Exposing BSGS into the Roll semantics. Rotom: Roll Arguments Can Name a Whole Tensor Axis Aug 2, 2026
@edwjchen edwjchen changed the title Rotom: Roll Arguments Can Name a Whole Tensor Axis Rotom: Roll arguments can name a whole tensor axis Aug 2, 2026
@edwjchen
edwjchen force-pushed the rotom-pr-03 branch 2 times, most recently from 0bb5a0c to 187f110 Compare August 2, 2026 22:20
@edwjchen
edwjchen marked this pull request as draft August 3, 2026 07:28
@edwjchen
edwjchen force-pushed the rotom-pr-03 branch 3 times, most recently from 886dccf to 5530486 Compare August 10, 2026 04:31
@edwjchen
edwjchen marked this pull request as ready for review August 10, 2026 05:16
A roll argument is now either a piece -- a dims-list position, the
original Rotom reading -- or a whole tensor axis, spelled 'axis N' and
stored as -(axis+1) in the flat rolls array. An axis argument is legal
only when the axis is packed as more than one piece; the piece spelling
is canonical for an unsplit axis, where the two coincide.

A piece FROM rewrites only the part of the axis index that piece reads
-- the original per-piece semantics, now materialized correctly on split
axes, where nothing carries from one piece into the next. An axis FROM
rewrites the whole axis index modulo its full extent, each piece then
taking its part of the rolled index: that carry across pieces is what
diagonal packings over a split axis need, and no combination of piece
rolls can express it. A BY piece of a split axis shifts by that piece's
part of the axis's current (possibly already-rolled) expression.

Rolls stay a pure packing description: a roll shifts by exactly its BY
argument's index, and a layout describes its value's packed bytes in
full. Kernel schedules that shift by a MULTIPLE of a piece's offset --
the baby-step/giant-step giant shift -- are not layout vocabulary and
are not folded into any value's packing; the kernel emits them as
rotations of its coefficient operand, which for plaintext weights a
backend folds into the encoded constants.

The BSGS diagonal packing is then an ordinary layout:

  #rotom.layout<n = 16, rolls = [(axis 1, 2)],
                dims = [[1:4:4], [1:4:1] | [0:16:1]]>

where the roll diagonalizes the whole split k against i (ciphertext
(g, b) holds the parts of (k - i) mod 16).
@edwjchen
edwjchen force-pushed the rotom-pr-03 branch 2 times, most recently from 773b8db to ab081b8 Compare August 28, 2026 19:01
@edwjchen
edwjchen force-pushed the rotom-pr-03 branch 2 times, most recently from 8e900c0 to a011181 Compare August 29, 2026 04:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants