Skip to content
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

Feat/synth extension #773

Closed
wants to merge 5 commits into from
Closed

Feat/synth extension #773

wants to merge 5 commits into from

Conversation

rudy-6-4
Copy link
Contributor

@rudy-6-4 rudy-6-4 commented Apr 3, 2024

No description provided.

@cla-bot cla-bot bot added the cla-signed label Apr 3, 2024
@rudy-6-4
Copy link
Contributor Author

rudy-6-4 commented Apr 3, 2024

Note: the last 2 commits on bit extracts will be merged in separate PR on main before this one

@rudy-6-4 rudy-6-4 force-pushed the feat/synth-extension branch 2 times, most recently from 5d887f6 to a0c074e Compare April 3, 2024 12:54
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: 14c3890 Previous: aa3b4fa Ratio
v0 PBS table generation 58646381 ns/iter (± 536829) 58897620 ns/iter (± 468377) 1.00
v0 PBS simulate dag table generation 37026176 ns/iter (± 361634) 36877868 ns/iter (± 372726) 1.00
v0 WoP-PBS table generation 66912243 ns/iter (± 870763) 66672339 ns/iter (± 2268730) 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@rudy-6-4 rudy-6-4 force-pushed the feat/synth-extension branch 2 times, most recently from 14c3890 to 7e8d75c Compare April 3, 2024 15:45
Copy link
Contributor

@umut-sahin umut-sahin left a comment

Choose a reason for hiding this comment

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

Do we support synthesis outside direct circuits (i.e., with inputsets)?

Also, I don't think the actual implementation should happen on the graph level. I think it'd be better if we leave it to MLIR generation for a few reasons:

  • We would be able to use it during conversion ourselves (with the current implementation, we can't do it easily since it happens during tracing)
  • We would be able to support it without giving explicit types (since the actual conversion would happen after bounds measurement, we can measure the bounds, assign bit-widths, and then interact with verilog during MLIR generation to work on correct bit widths directly, without use needing to give to us explicitly)

What we can do instead is this:

  • trace synthesis functionality into a single node:
%0 = x                                                 # EncryptedTensor<uint3, shape=(4,)>        ∈ [0, 7]
%1 = synthesis.expression((a >= 0) ? a : 0)(%0)        # EncryptedTensor<uint3, shape=(4,)>        ∈ [0, 7]
return %1
  • during bounds measurement, we would just evaluate the expression using verilog
  • in mlir conversion, when we see a synthesis node, we would generate the actual operations we need to perform and convert them directly to MLIR.
  • since we know the bit widths, user doesn't need to specify it explicitly
  • and we can use it in our own conversion logic

I know it's a big change, but a very useful one IMO.


import numpy as np

VERBOSE = False
Copy link
Contributor

Choose a reason for hiding this comment

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

This won't be in the merged PR right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Or at least be configurable with env variables?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No but it's not meant for end user but dev.

Comment on lines +68 to +102
def yosys_script(abc_path, verilog_path, json_path, dot_file, no_clean_up=False):
"""Generate `yosys` scripts."""
no_cleanup = "-nocleanup -showtmp" if no_clean_up else ""
return f"""
echo on
read -sv {verilog_path};
prep
techmap
log Synthesis with ABC: {abc_path}
abc {no_cleanup} -script {abc_path}
write_json {json_path}
""" + (
"" if not dot_file else "show -stretch"
)


def abc_script(lut_cost_path):
"""Generate `abc` scripts."""
return f"""
# & avoid a bug when cleaning tmp
read_lut {lut_cost_path}
print_lut
strash
&get -n
&fraig -x
&put
scorr
dc2
dretime
strash
dch -f
if
mfs2
#lutpack
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Some documentation would be nice 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have noclear idea what theses lines do, it's the default abc script (Ill check), I just made it explicit to be able to modify it.

abc_file, lut_costs_file, yosys_file, verilog_file, verilog_content, json_file, dot_file=True
):
"""Run the yosys script using a subprocess based on the inputs/outpus files."""
tmpdir_prefix = Path.home() / ".cache" / "concrete-python" / "synthesis"
Copy link
Contributor

Choose a reason for hiding this comment

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

If it's truly temporary, we should use /tmp.

Copy link
Contributor

Choose a reason for hiding this comment

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

Same with others.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, the intend is that at some point it will be a real cache, so we don't need to resynthetize the same stuff again and again.

)


YOSIS_EXE_NAME = "yowasp-yosys"

Choose a reason for hiding this comment

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

It's Yosys, not Yosis.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thx I have corrected in the new PR

@rudy-6-4
Copy link
Contributor Author

#1026

@rudy-6-4 rudy-6-4 closed this Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants