Skip to content

[JaxiteWord] Update lowering and emission for CROSS polynomial APIs - #3251

Open
Zohaib58 wants to merge 10 commits into
google:mainfrom
Zohaib58:emitter-optimization/heir-cross-integration
Open

[JaxiteWord] Update lowering and emission for CROSS polynomial APIs#3251
Zohaib58 wants to merge 10 commits into
google:mainfrom
Zohaib58:emitter-optimization/heir-cross-integration

Conversation

@Zohaib58

@Zohaib58 Zohaib58 commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

This PR updates the JaxiteWord lowering pipeline, crypto-context configuration, and Python emitter to use CROSS’s current level-indexed polynomial APIs.

Changes

  • Updates ciphertext arithmetic, rotation, rescaling, relinearization, encryption, and decryption emission to call the corresponding level-indexed CROSS operations directly.
  • Lowers CKKS ciphertext multiplication to jaxiteword.mul_no_relin, keeping relinearization as an explicit operation.
  • Keeps parameter generation independent of cryptographic keys and passes the public, secret, and evaluation keys during program initialization.
  • Removes multiplication-depth analysis and the obsolete numEvalMult configuration.
  • Adds jaxiteword.add_plain for ciphertext–plaintext addition and ensures that commutative plaintext operations use ciphertext-first operand ordering.
  • Adds Python emission support for signed floor division and func.call.
  • Updates the associated dialect, lowering, crypto-context, emitter, and FileCheck tests.

Zohaib58 added 7 commits July 26, 2026 07:43
…hertext ops

Change jaxiteword.gen_params to take public, secret, and evaluation keys, and
emit them into the generated ckks.CKKSParameters. Update the crypto-context
configuration pass so __generate_crypto_context accepts those three keys and
__configure_crypto_context only takes the crypto context.

Teach LWE-to-JaxiteWord lowering to add crypto context/eval-key arguments to
functions with crypto-typed arguments, update func.call operands for converted
callees, and lower CKKS rotations when a dynamic shift is defined by an arith
constant.

Rework the JaxiteWord Python emitter around tiled Polynomial values:
- emit func.call operations
- add _ensure_poly and _assign_poly helpers
- normalize ciphertext operands before add/sub/mul/square/rotate/rescale/decrypt
- use he_mul[level].mul for relined multiplication
- emit he_rescale for modulus reduction across levels
- implement plaintext add/sub against the c0 limb
- generate rotation keys via key_gen.gen_rotation_key
- store key material in generated CKKS params instead of mutating program init

Update JaxiteWord emitter/configure-context FileCheck tests and add 8x8 matvec
MLIR/Python artifacts for validating the emitted JaxiteWord path.
Use CROSS's level-indexed Polynomial operations directly for add, sub,
multiply, rotation, rescale, relinearization, encryption, and decryption.
Remove legacy layout-normalization templates and raw-array compatibility
glue, and add a context-aware binary emitter helper.

Lower CKKS multiplication to mul_no_relin, remove obsolete multiplication
depth configuration, and emit output_scale in CKKS parameters. Remove
unsupported plaintext add/sub and negate operations, and update tests for
the new CROSS interface.
@Zohaib58 Zohaib58 changed the title Emitter optimization/heir cross integration [JaxiteWord] Align backend with canonical CROSS APIs Jul 26, 2026
@Zohaib58 Zohaib58 changed the title [JaxiteWord] Align backend with canonical CROSS APIs [JaxiteWord] Update lowering and emission for CROSS polynomial APIs Jul 26, 2026

@asraa asraa 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.

thank you! just a few minor comments

let summary = "Homomorphic addition of two ciphertexts";
}

def AddPlainOp : JaxiteWord_Op<"add_plain", [Pure]> {

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.

I know many of the ops in this file are also missing traits, but for the LWE ciphertext/plaintext types, adds should probably expect SameOperandsAndResultRings trait

if (!dynamicShift) {
return failure();
}
auto constOp = dynamicShift.getDefiningOp<arith::ConstantOp>();

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.

you could use a matcher:

IntegerAttr attr;
if (matchPattern(value, m_Constant(&attr))) {

}

bool funcNeedsCryptoContextAndKeys(func::FuncOp funcOp) {
return containsDialects<lwe::LWEDialect, ckks::CKKSDialect, bgv::BGVDialect>(

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.

should you really have bgv dialect here?

@Zohaib58

Copy link
Copy Markdown
Contributor Author

thank you! just a few minor comments

Thanks for the review! I’ve addressed all your comments.

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