-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Load backend dialects in IRSource
to make sure parse_mlir_module
works for third_party backends
#5146
Merged
Merged
Load backend dialects in IRSource
to make sure parse_mlir_module
works for third_party backends
#5146
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0b43b52
Load backend dialects in 'IRSource' to make sure 'parse_mlir_module' …
anmyachev 5f77793
use 'backend' instead of 'target'
anmyachev 168d3e2
Merge branch 'main' into parse_mlir_module
anmyachev 6dfc3fc
Merge branch 'main' into parse_mlir_module
anmyachev 4dab704
return the comment
anmyachev 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 |
---|---|---|
|
@@ -91,12 +91,17 @@ def parse_options(self): | |
|
||
class IRSource: | ||
|
||
def __init__(self, path, context): | ||
def __init__(self, path, context, target=None): | ||
self.path = path | ||
path = Path(path) | ||
self.ext = path.suffix[1:] | ||
self.src = path.read_text() | ||
ir.load_dialects(context) | ||
if target is None: | ||
target = driver.active.get_current_target() | ||
assert isinstance(target, GPUTarget), "target must be of GPUTarget type" | ||
backend = make_backend(target) | ||
backend.load_dialects(context) | ||
|
||
# We don't have a easy-to-use PTX parser that we can use, so keep that regex for now. | ||
# TODO - replace with a proper parser | ||
|
@@ -223,7 +228,7 @@ def compile(src, target=None, options=None): | |
if ir_source: | ||
assert isinstance(src, str), "source must be either AST or a filepath" | ||
context = ir.context() | ||
src = IRSource(src, context) | ||
src = IRSource(src, context, target) | ||
peterbell10 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
extra_options = src.parse_options() | ||
options = backend.parse_options(dict(options or dict(), **extra_options)) | ||
|
@@ -270,10 +275,7 @@ def compile(src, target=None, options=None): | |
context = ir.context() | ||
ir.load_dialects(context) | ||
backend.load_dialects(context) | ||
else: | ||
# For IRSource, we have already grabbed the context + called ir.load_dialects | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please keep the comment, and just update it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
# just need to load the dialects for the backend. | ||
backend.load_dialects(context) | ||
|
||
codegen_fns = backend.get_codegen_implementation() | ||
module_map = backend.get_module_map() | ||
try: | ||
|
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.
Why the target must be a GPU target?
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 took this check from
compile
function, just in case. However, looking at the code, it seems I can maketarget
(or passingbackend
directly as suggested by @peterbell10 ) non-optional, then there will be no need to haveassert
here. Does it make sense?