Skip to content

Add packing design doc to the HEIR website#2296

Merged
copybara-service[bot] merged 1 commit intogoogle:mainfrom
j2kun:packing-design
Oct 16, 2025
Merged

Add packing design doc to the HEIR website#2296
copybara-service[bot] merged 1 commit intogoogle:mainfrom
j2kun:packing-design

Conversation

@j2kun
Copy link
Collaborator

@j2kun j2kun commented Oct 10, 2025

Fixes #1888
Fixes #913

@j2kun j2kun marked this pull request as draft October 10, 2025 03:52
j2kun added a commit to j2kun/heir that referenced this pull request Oct 12, 2025
j2kun added a commit to j2kun/heir that referenced this pull request Oct 13, 2025
j2kun added a commit to j2kun/heir that referenced this pull request Oct 13, 2025
@j2kun j2kun marked this pull request as ready for review October 16, 2025 18:07
@j2kun j2kun requested a review from asraa October 16, 2025 19:10
@j2kun
Copy link
Collaborator Author

j2kun commented Oct 16, 2025

@asraa Ready for review!

Comment on lines +201 to +203
attribute, and produces the same data-semantic type. This is an "entry point"
into the layout system and lowers to a loop that packs the data according to
the layout.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
attribute, and produces the same data-semantic type. This is an "entry point"
into the layout system and lowers to a loop that packs the data according to
the layout.
attribute, and produces the same data-semantic type. This is an "entry point" into the layout system
for cleartext values and lowers to a loop that packs the data according to the layout.

Actually I just wanted to understand this clearly just to double check. Cleartext values that are block args will also be assign_layout'd too right? (i.e. we won't annotate the block arg with a layout)

Copy link
Collaborator Author

@j2kun j2kun Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Blocks" don't have the ability to annotate by themselves, you can only annotate the owning op.

But, for example, cleartext function arguments will be assigned a layout, and it won't be until we add the preprocessing helper that we can move them to the client.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I didn't mean annotate the block arg but annotate the arg on the owning op (the func or generic)

And it seems like the rest of the doc only annotated cleartext func args if they're used in a ctxt op

Comment on lines +295 to +299
The [`layout-optimization`](/docs/passes/#-layout-optimization) pass has two
main goals: to choose better kernels for ops, and to try to eliminate
`convert_layout` ops. It does this by running a backward pass through the IR. If
it encounters an op that is followed by a `convert_layout` op, it attempts to
hoist the `convert_layout` through the op to its arguments.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've also added an initial forward pass too! Ah! I guess I can update that after. But the forward pass would start by pushing the initial default layouts through the ops as much as possible (assuming the cost of the kernel does not increase in doing so).

For example, in the case of the slice insertion, we'll pick the best kernel on the forward pass because it'll be cheaper to choose the slice insertion result to minimize the layout conversion needed to insert the slice.

Honestly, now I'm thinking I should just make that be part of layout-propagation (and modify the assigned destination layout during the forward pass if it only has one use)

Migrate some remaining TODOs to dedicated issues
@j2kun j2kun added the pull_ready Indicates whether a PR is ready to pull. The copybara worker will import for internal testing label Oct 16, 2025
@copybara-service copybara-service bot merged commit fcd3a84 into google:main Oct 16, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pull_ready Indicates whether a PR is ready to pull. The copybara worker will import for internal testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Get a simple MNIST model e2e through a SIMD FHE pipeline Unified notation for representing a packing of tensor data into a set of RLWE ciphertexts

2 participants