-
Notifications
You must be signed in to change notification settings - Fork 511
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
Pure python ODS for update_torch_ods.sh #3780
Draft
AmosLewis
wants to merge
1
commit into
llvm:main
Choose a base branch
from
AmosLewis:python_ods
base: main
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.
Draft
Changes from all commits
Commits
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
60 changes: 60 additions & 0 deletions
60
projects/pt1/python/torch_mlir/jit_ir_importer/build_tools/get_registered_ops.py
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,60 @@ | ||
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# Also available under a BSD-style license. See LICENSE. | ||
"""Listing of the JIT operator registry, for use in generating the `torch` dialect. | ||
""" | ||
|
||
|
||
import torch | ||
import torch._C | ||
import pybind11 | ||
|
||
def get_registered_ops(): | ||
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. You can just inline this into registry.py vs having separate. |
||
results = [] | ||
|
||
# Walk the JIT operator registry to find all the ops that we might need | ||
# for introspection / ODS generation. | ||
# This registry contains a superset of the ops available to the dispatcher, | ||
# since the JIT has its own dispatch mechanism that it uses to implement | ||
# "prim" ops and a handful of "aten" ops that are effectively prim ops, such | ||
# as `aten::__is__`. | ||
for schema in torch._C._jit_get_all_schemas(): | ||
record = {} | ||
|
||
record["name"] = schema.name | ||
record["overload_name"] = schema.overload_name | ||
record["is_mutable"] = schema.is_mutable | ||
|
||
arguments = [] | ||
returns = [] | ||
|
||
def add_argument(container, arg): | ||
arg_record = { | ||
"name": arg.name, | ||
"type": arg.type.annotation_str, | ||
"kwarg_only" : arg.kwarg_only, | ||
"is_out": arg.is_out, | ||
} | ||
if arg.default_value: | ||
arg_record["default_value"] = arg.default_value | ||
if arg.alias_info: | ||
alias_info = { | ||
"is_write": arg.alias_info.is_write, | ||
"before_set": [str(symbol) for symbol in arg.alias_info.before_set], | ||
"after_set": [str(symbol) for symbol in arg.alias_info.after_set], | ||
} | ||
arg_record["alias_info"] = alias_info | ||
|
||
container.append(arg_record) | ||
|
||
for argument in schema.arguments: | ||
add_argument(arguments, argument) | ||
for return_arg in schema.returns: | ||
add_argument(returns, return_arg) | ||
|
||
record["arguments"] = arguments | ||
record["returns"] = returns | ||
results.append(record) | ||
|
||
return results |
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
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.
Not sure this is needed.