-
Notifications
You must be signed in to change notification settings - Fork 24
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
Add blackbox and stub passes #702
Open
rsetaluri
wants to merge
5
commits into
master
Choose a base branch
from
add-stub-pass
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from typing import Iterable | ||
|
||
from magma.circuit import CircuitKind | ||
from magma.passes.passes import CircuitPass | ||
|
||
|
||
class BlackBoxPass(CircuitPass): | ||
def __init__(self, main: CircuitKind, black_boxes: Iterable[CircuitKind]): | ||
super().__init__(main) | ||
self._black_boxes = set(black_boxes) | ||
|
||
def __call__(self, cls): | ||
try: | ||
self._black_boxes.remove(cls) | ||
except KeyError: | ||
return # @cls not in black_boxes, don't need to do anything | ||
cls._is_definition = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from typing import Iterable | ||
|
||
from magma.circuit import CircuitKind | ||
from magma.passes.passes import CircuitPass | ||
|
||
|
||
def _drive_if_undriven_input(port): | ||
if port.is_mixed(): | ||
for p in port: | ||
_drive_if_undriven_input(p) | ||
return | ||
# NOTE(rsetaluri): This may override previously wired inputs, resulting in a | ||
# warning. In this case, this warning is benign. | ||
if port.is_input(): | ||
port.undriven() | ||
|
||
|
||
class StubPass(CircuitPass): | ||
def __init__(self, main: CircuitKind, stubs: Iterable[CircuitKind]): | ||
super().__init__(main) | ||
self._stubs = set(stubs) | ||
|
||
def __call__(self, cls): | ||
try: | ||
self._stubs.remove(cls) | ||
except KeyError: | ||
return # @cls not in stubs, don't need to do anything | ||
with cls.open(): | ||
for port in cls.interface.ports.values(): | ||
_drive_if_undriven_input(port) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{"top":"global._Top", | ||
"namespaces":{ | ||
"global":{ | ||
"modules":{ | ||
"_Foo":{ | ||
"type":["Record",[ | ||
["I","BitIn"], | ||
["O","Bit"] | ||
]] | ||
}, | ||
"_Top":{ | ||
"type":["Record",[ | ||
["I","BitIn"], | ||
["O","Bit"] | ||
]], | ||
"instances":{ | ||
"_Foo_inst0":{ | ||
"modref":"global._Foo" | ||
} | ||
}, | ||
"connections":[ | ||
["self.I","_Foo_inst0.I"], | ||
["self.O","_Foo_inst0.O"] | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{"top":"global._Top", | ||
"namespaces":{ | ||
"global":{ | ||
"modules":{ | ||
"_Foo":{ | ||
"type":["Record",[ | ||
["I","BitIn"], | ||
["O","Bit"] | ||
]], | ||
"connections":[ | ||
["self.O","self.I"] | ||
] | ||
}, | ||
"_Top":{ | ||
"type":["Record",[ | ||
["I","BitIn"], | ||
["O","Bit"] | ||
]], | ||
"instances":{ | ||
"_Foo_inst0":{ | ||
"modref":"global._Foo" | ||
} | ||
}, | ||
"connections":[ | ||
["self.I","_Foo_inst0.I"], | ||
["self.O","_Foo_inst0.O"] | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{"top":"global._Top", | ||
"namespaces":{ | ||
"global":{ | ||
"modules":{ | ||
"_Foo":{ | ||
"type":["Record",[ | ||
["I","BitIn"], | ||
["O","Bit"] | ||
]], | ||
"instances":{ | ||
"corebit_undriven_inst0":{ | ||
"modref":"corebit.undriven" | ||
} | ||
}, | ||
"connections":[ | ||
["self.O","corebit_undriven_inst0.out"] | ||
] | ||
}, | ||
"_Top":{ | ||
"type":["Record",[ | ||
["I","BitIn"], | ||
["O","Bit"] | ||
]], | ||
"instances":{ | ||
"_Foo_inst0":{ | ||
"modref":"global._Foo" | ||
} | ||
}, | ||
"connections":[ | ||
["self.I","_Foo_inst0.I"], | ||
["self.O","_Foo_inst0.O"] | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{"top":"global._Top", | ||
"namespaces":{ | ||
"global":{ | ||
"modules":{ | ||
"_Foo":{ | ||
"type":["Record",[ | ||
["I","BitIn"], | ||
["O","Bit"] | ||
]], | ||
"connections":[ | ||
["self.O","self.I"] | ||
] | ||
}, | ||
"_Top":{ | ||
"type":["Record",[ | ||
["I","BitIn"], | ||
["O","Bit"] | ||
]], | ||
"instances":{ | ||
"_Foo_inst0":{ | ||
"modref":"global._Foo" | ||
} | ||
}, | ||
"connections":[ | ||
["self.I","_Foo_inst0.I"], | ||
["self.O","_Foo_inst0.O"] | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import pytest | ||
|
||
import magma as m | ||
from magma.passes.black_box import BlackBoxPass | ||
from magma.testing import check_files_equal | ||
|
||
|
||
# NOTE(rsetaluri): We need this fixture per function, since each function may | ||
# run a pass to modify the circuits. However, the setup is identical for each so | ||
# we reuse this fixture across all the test. | ||
@pytest.fixture(scope="function") | ||
def ckts(): | ||
|
||
class _Foo(m.Circuit): | ||
io = m.IO(I=m.In(m.Bit), O=m.Out(m.Bit)) | ||
io.O @= io.I | ||
|
||
|
||
class _Bar(m.Circuit): | ||
io = m.IO(I=m.In(m.Bit), O=m.Out(m.Bit)) | ||
io.O @= io.I | ||
|
||
|
||
class _Top(m.Circuit): | ||
io = m.IO(I=m.In(m.Bit), O=m.Out(m.Bit)) | ||
io.O @= _Foo()(io.I) | ||
|
||
return (_Foo, _Bar, _Top) | ||
|
||
|
||
def test_noop(ckts): | ||
_Foo, _Bar, _Top = ckts | ||
m.compile("build/test_passes_black_box_noop", _Top, output="coreir") | ||
assert check_files_equal(__file__, | ||
f"build/test_passes_black_box_noop.json", | ||
f"gold/test_passes_black_box_noop.json") | ||
|
||
|
||
def test_basic(ckts): | ||
_Foo, _Bar, _Top = ckts | ||
BlackBoxPass(_Top, (_Foo,)).run() | ||
m.compile("build/test_passes_black_box_basic", _Top, output="coreir") | ||
assert check_files_equal(__file__, | ||
f"build/test_passes_black_box_basic.json", | ||
f"gold/test_passes_black_box_basic.json") | ||
|
||
|
||
def test_unused(ckts): | ||
_Foo, _Bar, _Top = ckts | ||
BlackBoxPass(_Top, (_Bar,)).run() | ||
m.compile("build/test_passes_black_box_unused", _Top, output="coreir") | ||
assert check_files_equal(__file__, | ||
f"build/test_passes_black_box_unused.json", | ||
f"gold/test_passes_black_box_noop.json") | ||
|
||
|
||
def test_compiler_args(ckts): | ||
_Foo, _Bar, _Top = ckts | ||
m.compile("build/test_passes_black_box_compiler_args", _Top, | ||
output="coreir", black_boxes=(_Foo,)) | ||
assert check_files_equal(__file__, | ||
f"build/test_passes_black_box_compiler_args.json", | ||
f"gold/test_passes_black_box_basic.json") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{"top":"global._Top", | ||
"namespaces":{ | ||
"global":{ | ||
"modules":{ | ||
"_Foo":{ | ||
"type":["Record",[ | ||
["I","BitIn"], | ||
["O","Bit"] | ||
]], | ||
"connections":[ | ||
["self.O","self.I"] | ||
] | ||
}, | ||
"_Top":{ | ||
"type":["Record",[ | ||
["I","BitIn"], | ||
["O","Bit"] | ||
]], | ||
"instances":{ | ||
"_Foo_inst0":{ | ||
"modref":"global._Foo" | ||
} | ||
}, | ||
"connections":[ | ||
["self.I","_Foo_inst0.I"], | ||
["self.O","_Foo_inst0.O"] | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Perhaps we should disable warnings in this pass? One simple way would be to set a magma "global" that disables warning reporting, which we can enable/disable in this pass. A more fine-grained way might be to pass a flag through undriven that says ignore drivers or something. Ideally we can avoid generating warnings internally, even if they are benign