Skip to content

Experimental - Initial commit for Kerngraph #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

christopherngutierrez
Copy link
Contributor

Proposed changes

Experimental
Kerngraph.py is a command line tool that takes output from kerngen.py through stdin and transform the Pisa for optimization.

This PR is the starting point.

  • Parsing is currently supported for kerngen.py
  • Currently supports the following high ops: Add, Sub, Mul, Muli, and Copy. Future PR will extend to composite high ops such as Relin and Mod.
  • Transformation: loop interchange for RNS and Part are currently supported. Future PR will add loop interchange for Unit support.
  • No graph representation is present at this time. Will add in a future PR.

Types of changes

What types of changes does your code introduce to the Encrypted Computing SDK project?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update (if none of the other choices apply)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating
the PR. If you are unsure about any of them, do not hesitate to ask. We are
here to help! This is simply a reminder of what we are going to look for before
merging your code.

  • I have read the CONTRIBUTING agreement
  • Current formatting and unit tests / base functionality passes locally with my changes
  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

Further comments

As an illustrate example, say that the contents of the file bgv.add.high contains:

CONTEXT BGV 16384 3 2

DATA c 2
DATA a 2
DATA b 2

ADD c a b

which produces the following output from kerngen:

### Context: scheme='BGV' poly_order=16384 key_rns=3 current_rns=2 num_digits=None max_rns=2 ###
### Kernel (0): Add(context=KernelContext(scheme='BGV', poly_order=16384, key_rns=3, current_rns=2, num_digits=None, max_rns=2, label='0'), output=Polys(name=c, parts=2, rns=2), input0=Polys(name=a, parts=2, rns=2), input1=Polys(name=b, parts=2, rns=2)) ###
0, add, c_0_0_0, a_0_0_0, b_0_0_0, 0
0, add, c_0_0_1, a_0_0_1, b_0_0_1, 0
0, add, c_1_0_0, a_1_0_0, b_1_0_0, 0
0, add, c_1_0_1, a_1_0_1, b_1_0_1, 0
0, add, c_0_1_0, a_0_1_0, b_0_1_0, 1
0, add, c_0_1_1, a_0_1_1, b_0_1_1, 1
0, add, c_1_1_0, a_1_1_0, b_1_1_0, 1
0, add, c_1_1_1, a_1_1_1, b_1_1_1, 1

With kerngraph, we can interchange the loop order to produce the following output:

# cat bgv.add.high | ./kerngen.py  | ./kerngraph.py -t add --primary part

0, add, c_0_0_0, a_0_0_0, b_0_0_0, 0
0, add, c_0_0_1, a_0_0_1, b_0_0_1, 0
0, add, c_0_1_0, a_0_1_0, b_0_1_0, 1
0, add, c_0_1_1, a_0_1_1, b_0_1_1, 1
0, add, c_1_0_0, a_1_0_0, b_1_0_0, 0
0, add, c_1_0_1, a_1_0_1, b_1_0_1, 0
0, add, c_1_1_0, a_1_1_0, b_1_1_0, 1
0, add, c_1_1_1, a_1_1_1, b_1_1_1, 1

Note the ordering of the generate pisa commands produced with kerngraph.

faberga
faberga previously approved these changes Jun 6, 2025
Copy link
Collaborator

@faberga faberga left a comment

Choose a reason for hiding this comment

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

LGTM as an experimental feature that we want in the codebase so we can start discussing optimizations and showing people the potential of the various intermediate manipulations/optimizations that can be done.

@faberga
Copy link
Collaborator

faberga commented Jun 6, 2025

Hi, @christopherngutierrez
That looks a good start. after this gets in as an experiment feature, let's have a chat on the semantics of the command line.

kylanerace
kylanerace previously approved these changes Jun 6, 2025
Copy link
Collaborator

@kylanerace kylanerace left a comment

Choose a reason for hiding this comment

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

Looks good from an initial scan. Will attempt with wider variety next week, but doesn't seem breaking.

@kylanerace kylanerace self-requested a review June 10, 2025 00:35
@kylanerace
Copy link
Collaborator

Only change I see would be to match the current file hierarchy on main (e.g. kerngen inside of p-isa_tools, same for functional_modeler, etc.). Just needs to be rebased with main

@faberga
Copy link
Collaborator

faberga commented Jun 10, 2025

Hi @christopherngutierrez and @kylanerace
I agree with Kylan, it does need rebasing to fix the conflicts with the directory hierarchy.

@faberga faberga self-requested a review June 10, 2025 09:03
dependabot bot and others added 12 commits June 10, 2025 15:53
Updates the requirements on [pydantic](https://github.com/pydantic/pydantic) to permit the latest version.
- [Release notes](https://github.com/pydantic/pydantic/releases)
- [Changelog](https://github.com/pydantic/pydantic/blob/v1.10.22/HISTORY.md)
- [Commits](pydantic/pydantic@v1.10.13...v1.10.22)

---
updated-dependencies:
- dependency-name: pydantic
  dependency-version: 1.10.22
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Update Documentation to match the change of repository name.

Signed-off-by: Flavio Bergamaschi <[email protected]>
* new repository structure
* documentation update

---------

Signed-off-by: Flavio Bergamaschi <[email protected]>
* Reference implementation of the HERACLES Assembler tools
---------

Signed-off-by: Flavio Bergamaschi <[email protected]>

Co-authored-by: Flavio Bergamaschi <[email protected]>
Co-authored-by: Ernesto Zamora Ramos <[email protected]>
Co-authored-by: Chris Wilkerson <[email protected]>
Co-authored-by: Jose Rojas Chaves <[email protected]>
Co-authored-by: Kylan Race <[email protected]>
Co-authored-by: Christopher Gutierrez <[email protected]>
Co-authored-by: Hamish Hunt <[email protected]>
Co-authored-by: Jack Crawford <[email protected]>
Co-authored-by: Minxuan Zhou <[email protected]>
Co-authored-by: Wen Wang <[email protected]>
Co-authored-by: Adish Vartak <[email protected]>
Co-authored-by: Michael Steiner <[email protected]>
Co-authored-by: Avinash Alevoor <[email protected]>
Co-authored-by: Rashmi Agrawal <[email protected]>
Bumps the pip group with 3 updates in the /assembler_tools/hec-assembler-tools directory: [fonttools](https://github.com/fonttools/fonttools), [pillow](https://github.com/python-pillow/Pillow) and [zipp](https://github.com/jaraco/zipp).


Updates `fonttools` from 4.39.0 to 4.43.0
- [Release notes](https://github.com/fonttools/fonttools/releases)
- [Changelog](https://github.com/fonttools/fonttools/blob/main/NEWS.rst)
- [Commits](fonttools/fonttools@4.39.0...4.43.0)

Updates `pillow` from 10.0.1 to 10.3.0
- [Release notes](https://github.com/python-pillow/Pillow/releases)
- [Changelog](https://github.com/python-pillow/Pillow/blob/main/CHANGES.rst)
- [Commits](python-pillow/Pillow@10.0.1...10.3.0)

Updates `zipp` from 3.15.0 to 3.19.1
- [Release notes](https://github.com/jaraco/zipp/releases)
- [Changelog](https://github.com/jaraco/zipp/blob/main/NEWS.rst)
- [Commits](jaraco/zipp@v3.15.0...v3.19.1)

---
updated-dependencies:
- dependency-name: fonttools
  dependency-version: 4.43.0
  dependency-type: direct:production
  dependency-group: pip
- dependency-name: pillow
  dependency-version: 10.3.0
  dependency-type: direct:production
  dependency-group: pip
- dependency-name: zipp
  dependency-version: 3.19.1
  dependency-type: direct:production
  dependency-group: pip
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Update dependabot rules for the weekly runs
* Enabling configurable mem specifications
* Adding documentation
Fixes two configuration files which contain the incorrect path to kerngen: .pre-commit-config.yaml and pytest.ini.
Fixes suggested bank error

Co-authored-by: Kylan Race <[email protected]>
Co-authored-by: Flavio Bergamaschi <[email protected]>
Copy link
Collaborator

@kylanerace kylanerace left a comment

Choose a reason for hiding this comment

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

LGTM

@christopherngutierrez christopherngutierrez merged commit b3eb8ff into main Jun 11, 2025
8 checks passed
@christopherngutierrez christopherngutierrez deleted the experimental/christopherngutierrez/kerngraph-parser branch June 11, 2025 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Experimental
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants