Skip to content

poly: add initial lowering for NTT op and add root parameter to rings#642

Merged
copybara-service[bot] merged 1 commit into
google:mainfrom
inbelic:inbelic/ntt-for-loop
Apr 25, 2024
Merged

poly: add initial lowering for NTT op and add root parameter to rings#642
copybara-service[bot] merged 1 commit into
google:mainfrom
inbelic:inbelic/ntt-for-loop

Conversation

@inbelic

@inbelic inbelic commented Apr 24, 2024

Copy link
Copy Markdown
Contributor
- add a standard iterative implementation of the NTT Op
- add testing for lowering and a simple case runner
- add performance test that uses random coefficients to prevent
  optimizations on dense values that artifically improves
  compile/runtime
  • include an optional parameter that computes the 2n-th primitive
    root of a rings ideal degree and its coefficient modulus
  • allow for this to be retrieved from a pre-computed or to be
    user-specified
  • Add a script that will compute the 2n-th roots of unity for the
    specified polynomial degree values and n. The values are only
    outputted if the 2n-th root of unity exists.

Resolve #543

@inbelic

inbelic commented Apr 24, 2024

Copy link
Copy Markdown
Contributor Author

@j2kun Ready for review.

Sorry for letting it grow so much. I should have created a first pull request with the changes adding the root parameter. Will try to reduce the size of commits in the future.

Hmm, I am not able to reproduce the build failure locally. Can take another look when I am more awake.

@inbelic inbelic marked this pull request as ready for review April 24, 2024 04:59
Comment thread include/Dialect/Polynomial/IR/NumberTheory.h Outdated
Comment thread lib/Dialect/Polynomial/IR/PolynomialAttributes.cpp
Comment thread lib/Conversion/PolynomialToStandard/PolynomialToStandard.cpp
@j2kun

j2kun commented Apr 24, 2024

Copy link
Copy Markdown
Collaborator

Hmm, I am not able to reproduce the build failure locally.

I also cannot reproduce the failure locally. I'll take a look at the CI.

Comment thread lib/Conversion/PolynomialToStandard/PolynomialToStandard.cpp Outdated
Comment thread lib/Conversion/PolynomialToStandard/PolynomialToStandard.cpp Outdated
Comment thread lib/Conversion/PolynomialToStandard/PolynomialToStandard.cpp Outdated
Comment thread lib/Conversion/PolynomialToStandard/PolynomialToStandard.cpp Outdated

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

LGTM! Just a few optional improvements. When you're ready please manually squash your commits and I'll get it merged.

@j2kun

j2kun commented Apr 24, 2024

Copy link
Copy Markdown
Collaborator

My guess is that this will fix the build failure:

diff --git a/lib/Dialect/Polynomial/IR/BUILD b/lib/Dialect/Polynomial/IR/BUILD
index 32666254..ac791511 100644
--- a/lib/Dialect/Polynomial/IR/BUILD
+++ b/lib/Dialect/Polynomial/IR/BUILD
@@ -38,12 +38,12 @@ cc_library(
         "PolynomialAttributes.cpp",
     ],
     hdrs = [
-        "@heir//include/Dialect/Polynomial/IR:NumberTheory.h",
         "@heir//include/Dialect/Polynomial/IR:PolynomialAttributes.h",
         "@heir//include/Dialect/Polynomial/IR:PolynomialDialect.h",
         "@heir//include/Dialect/Polynomial/IR:StaticRoots.h",
     ],
     deps = [
+        ":NumberTheory",
         ":Polynomial",
         "@heir//include/Dialect/Polynomial/IR:attributes_inc_gen",
         "@heir//include/Dialect/Polynomial/IR:dialect_inc_gen",

It's weird that I can't reproduce it locally, but I think it may be because I'm using clang + lld and the CI is using gcc + ld. I don't have time to do a detailed test/fix, but just based on my intuition this is the problem: you have the header there but no dependency on the implementation directly on the PolynomialAttributes target.

@inbelic inbelic force-pushed the inbelic/ntt-for-loop branch from 588a0c8 to 4d733af Compare April 24, 2024 22:15
@inbelic

inbelic commented Apr 24, 2024

Copy link
Copy Markdown
Contributor Author

That fixed the issue. I had accidentally added the dep to the PolynomialOp build rule instead of PolynomialAttributes.

Just need to rebase on main again to correct the failing canonicalize_ntt test-case.

  - add a standard iterative implementation of the NTT Op
  - add performance test that uses random coefficients to prevent
    optimizations on dense values that artifically improves
    compile/runtime

  - include an optional parameter that computes the 2n-th primitive
    root of a rings ideal degree and its coefficient modulus
  - add a script that will compute the 2n-th roots of unity for the
    specified polynomial degree values and n. The values are only
    outputted if the 2n-th root of unity exists.
@inbelic inbelic force-pushed the inbelic/ntt-for-loop branch from 4d733af to c943d7f Compare April 24, 2024 23:15
@j2kun j2kun self-requested a review April 25, 2024 13:42
@j2kun j2kun added the pull_ready Indicates whether a PR is ready to pull. The copybara worker will import for internal testing label Apr 25, 2024
@copybara-service copybara-service Bot merged commit abbeec8 into google:main Apr 25, 2024
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.

Write an initial lowering for NTT/INTT using a standard algorithm

2 participants