Skip to content

Poulpy Emitter - #3250

Draft
martonmoro wants to merge 28 commits into
google:mainfrom
martonmoro:poulpy-emitter
Draft

Poulpy Emitter#3250
martonmoro wants to merge 28 commits 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
materializeIfPending(dst, module, a, /*useSemanticWidth=*/false,
/*wrapUnnormalized=*/false);

os << variableNames->getNameForValue(module) << ".ckks_mul_into("

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.

It might be worth adding one or two templated emitBinaryOp/emitBinaryAssignOp helper functions to reduce some of the duplication among these printers.

@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!

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