Skip to content

Poulpy Emitter - #3250

Merged
copybara-service[bot] merged 1 commit into
google:mainfrom
martonmoro:poulpy-emitter
Aug 10, 2026
Merged

Poulpy Emitter#3250
copybara-service[bot] merged 1 commit into
google:mainfrom
martonmoro:poulpy-emitter

Conversation

@martonmoro

@martonmoro martonmoro commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Step 3 (Implement Code Generation) from #3096.

Adds lib/Target/Poulpy/{PoulpyEmitter.h,.cpp,BUILD,PoulpyTemplates.h}
and registers the --emit-poulpy translation in heir-translate.

  • ModuleOp printer: Rust prelude, backend detection from
    !poulpy.module argument types, type BE = ...; and derived type
    aliases (Ct/Tsk/Akm)
  • func::FuncOp / func::ReturnOp printers: typed, mutability-aware
    argument list, Result return, zero/one-operand return handling
  • convertType: !poulpy.module, !poulpy.scratch, !poulpy.tensor_key,
    !poulpy.automorphism_key_map, and rank-0
    memref<!poulpy.ciphertext> (&Ct/&mut Ct/Ct depending on position
    and mutation)
  • Argument mutability analysis: decides &Ct vs &mut Ct from which
    values are written by a compute op in the function body
  • Lazy memref.alloc materialization: a fresh ciphertext buffer's
    Rust allocation is synthesized at the first op that writes into
    it, deriving its layout at runtime from a sibling operand
  • Rejects an _assign op whose dst is still unmaterialized, since
    that would silently read uninitialized memory
  • Op printers: add, add_assign, sub, sub_assign, mul, mul_assign,
    rotate, rotate_assign

Adds tests/Emitter/Poulpy/{BUILD,emit_poulpy.mlir,
emit_poulpy_invalid_assign.mlir}. Output has also been verified with
cargo check against the real poulpy 0.7.0 crates, not just
pattern-matched.

@github-actions

Copy link
Copy Markdown

Welcome to HEIR!

Thank you for opening your first pull request! We appreciate you joining our community.

Please note that our contributing policy) requires unrecognized users to meet a maintainer in a non-textual format before their first PR will be reviewed.

If you have already met a maintainer, or you're sure the maintainers know who you are, you can safely ignore this message. Otherwise, a maintainer will likely close this PR shortly.

Don't take it personally! Instead, we welcome you to attend one of our open meetings on our community calendar, schedule a dedicated call with a maintainer, or reach out in the #heir channel on Discord.

We look forward to connecting with you!

@j2kun j2kun left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks pretty good! I think it would be worth sharing a sample of the generated code with @Pro7ech to get a validation check on the API usage and the prelude.

Comment thread lib/Target/Poulpy/PoulpyEmitter.cpp
Comment thread lib/Target/Poulpy/PoulpyEmitter.cpp Outdated
@martonmoro

Copy link
Copy Markdown
Contributor Author

Looks pretty good! I think it would be worth sharing a sample of the generated code with @Pro7ech to get a validation check on the API usage and the prelude.

will do!

@martonmoro
martonmoro marked this pull request as ready for review August 5, 2026 16:41
@j2kun

j2kun commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Please rebase and squash your changes and we can optimistically get it merged pending feedback from Jean-Philippe

@Pro7ech

Pro7ech commented Aug 6, 2026

Copy link
Copy Markdown

I went over the example, the emitted code looks good, assuming that hard-coded randomness was intentional. A future optimization would be to use the <op>_tmp_bytes(...) and <struct>.bytes_of(...) API to assess the scratch space required instead of hard-coding it's size, and borrow the tmp values from it instead of doing heap allocations.

Also, just to avoid ambiguity, in Poulpy Galoiskeys are keyed by their signed Galois element.

@martonmoro

Copy link
Copy Markdown
Contributor Author

Please rebase and squash your changes and we can optimistically get it merged pending feedback from Jean-Philippe

I've squashed the commits. Also i left the randomness as is for now and added a comment so the emitter prints code that can be compiled at this stage.

@j2kun j2kun added the pull_ready Indicates whether a PR is ready to pull. The copybara worker will import for internal testing label Aug 10, 2026
@copybara-service
copybara-service Bot merged commit 3f5a1f7 into google:main Aug 10, 2026
9 of 11 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.

3 participants