-
Notifications
You must be signed in to change notification settings - Fork 131
Add initial cgra compiler #704
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
base: development
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey Jackson, thanks for the pull request!
I had a read through and left a comments inline but there's a lot of code here so it may take a couple of passes :)
Overall, this looks like a great start. Most of my comments are just small nitpicks. The two main suggestions I have to start with are:
- We'll need some tests of the new environment before we can merge. You can take a look in the
tests/llvm
andtests/gcc
directories for some examples to get you started. The goal is to cover all of the branches in your code, though to start with some simple integration tests are a good start. They help catch regressions (so that I don't accidentally break your code by changing something else), as well as providing usage pointers. - Each environments needs a documentation page to provide context on what it is, the problem that it exposes, the various observation/reward/datasets available, etc. See here for an example. To create one of these pages, take a look in
docs/source/envs
and copy and hack on one of the existing docs.
There also looks like there are code style inconsistencies. Some of these can be addressed automatically by running our pre-commit
hooks. See here to get started.
Looking forward to landing the CGRA env!
Cheers,
Chris
@@ -0,0 +1,25 @@ | |||
# Copyright (c) Facebook, Inc. and its affiliates. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this file needs updating to match the cgra BUILD file
# When this is set, the scheduler will take schedules | ||
# that don't account for delays appropriately, and try | ||
# to stretch them out to account for delays correctly. | ||
# When this is false, the compiler will just reject | ||
# such invalid schedules. | ||
# (when set, something like x + (y * z), scheduled | ||
# as +: PE0 on cycle 0, *: PE1 on cycle 0 is valid). | ||
"IntroduceRequiredDelays": False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this would be useful to expose to the user, we could consider doing so using the session parameter API (nothing actionable for this PR, but maybe add a TODO note
# TODO -- properly load CGRA | ||
return CGRA(5, 5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm :)
else: | ||
return hop in self.schedule[time] | ||
|
||
# A class representing a NOC. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does NOC stand for?
examples/cgra/.gitignore
Outdated
@@ -0,0 +1,2 @@ | |||
rewards.png |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed?
setup.py
Outdated
@@ -146,6 +149,8 @@ def wheel_filename(**kwargs): | |||
"package_data": { | |||
"compiler_gym": [ | |||
"envs/gcc/service/compiler_gym-gcc-service", | |||
# "envs/cgra/service/compiler_gym-cgra-service", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# "envs/cgra/service/compiler_gym-cgra-service", |
Codecov Report
@@ Coverage Diff @@
## development #704 +/- ##
================================================
- Coverage 88.36% 60.78% -27.58%
================================================
Files 125 143 +18
Lines 7565 9000 +1435
================================================
- Hits 6685 5471 -1214
- Misses 880 3529 +2649
Continue to review full report at Codecov.
|
I've updated this pull request with most of the issues raised addressed. Test are not yet added, I will add those shortly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing the comments @j-c-w! I left a few more, but at this point its mostly nitpicks.
The tests & documentation are merge blocking, but this is shaping up well.
Cheers,
Chris
@@ -24,41 +29,26 @@ def __str__(self): | |||
return "Node with name " + self.name + " and op " + str(self.operation) | |||
|
|||
class DFG(object): | |||
def __init__(self, working_directory: Optional[Path] = None, benchmark: Optional[Benchmark] = None, from_json: Optional[Path] = None, from_text: Optional[str] = None): | |||
def __init__(self, working_directory: Optional[Path] = None, from_json: Optional[Path] = None, from_text: Optional[str] = None): | |||
# Copied from here: https://github.com/facebookresearch/CompilerGym/blob/development/examples/loop_optimizations_service/service_py/loops_opt_service.py | |||
# self.inst2vec = _INST2VEC_ENCODER | |||
|
|||
if from_json is not None: | |||
self.load_dfg_from_json(from_json) | |||
elif from_text is not None: | |||
self.load_dfg_from_text(from_text) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need a final else
branch to raise an error if neither is set?
# cross-loop dependencies. | ||
print("Cyclical DFG --- Impossible to do a true BFS") | ||
print("DFG is ", str(self)) | ||
assert False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: don't assert False, raise an exception. Or, if that's not possible, sys.exit(1)
.
""" | ||
This is the most abstract representation of a CGRA ---- | ||
a list of nodes, with an interconnect archtiecture. | ||
|
||
This can be inherited from to make things easier. | ||
""" | ||
class CGRA(object): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docstrings need to be placed directly after the class/function/method declaration:
class CGRA:
"""blah blah"""
...
Don't put the docstring before, and don't use #
comments instead of """
docstrings. This applies several places else in the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: don't subclass object
, it's not necessary (again, applies elsewhere in the PR)
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
CGRACompileSettings = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggesting using pydantic to make this a class. It has a number of advantages: 1) docstrings can be rendered for documentation, (2) type validation and type safety, (3) automatic serialization/deserialization, (4) prevents typos
Here's an example of it in use in CompilerGym:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, love the documentation of the settings, good job 🙂
@@ -0,0 +1,3 @@ | |||
#!/bin/bash | |||
|
|||
python plot_CDFs.py ga_output GA ../relative_placement_output/rp_data RLMap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be a script? 🙂 Or could it just be in a README.md
file for this dir?
Hi @j-c-w! Thank you for your pull request. We require contributors to sign our Contributor License Agreement, and yours needs attention. You currently have a record in our system, but the CLA is no longer valid, and will need to be resubmitted. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
Hi,
This adds a CGRA scheduling environment.
There are two environments that are added: the cgra-v0 environment, which allows for direct placement (as in https://arxiv.org/abs/2205.13675) and the cgra-relative-v0 environment, which allows for relative placement (as in https://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=8509169).
Within examples, a genetic algorithm approach is implemented, which works for the relative environemnt.
The CGRA environment is mostly complete, but currently lacks a way of specifying a CGRA --- this is currently done within compiler_gym. Due to effects on the sizes of observation spaces, it will likely stay this way, but the input format for the CGRAs is the next step to be improved.
Jackson