-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[Tutorial] tutorial to writing a costumized pass #1671
Conversation
please request reviews |
tutorials/language/pass.py
Outdated
========================= | ||
**Author**: `Jian Weng <https://were.github.io>`_ | ||
|
||
TVM is a framework to abstract the heterogenity of those various machine learning |
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.
"that abstracts away the heterogeneity of machine learning accelerators"
tutorials/language/pass.py
Outdated
**Author**: `Jian Weng <https://were.github.io>`_ | ||
|
||
TVM is a framework to abstract the heterogenity of those various machine learning | ||
accelerators. Sometimes users may want to customized some analysis and IR transformation |
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.
"customize some analysis and IR transformations"
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.
Sorry. I did not look at this carefully.
tutorials/language/pass.py
Outdated
|
||
TVM is a framework to abstract the heterogenity of those various machine learning | ||
accelerators. Sometimes users may want to customized some analysis and IR transformation | ||
to adopt TVM to their own specialized hardware. This tutorial helps users write |
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.
"to adapt TVM to their own specialized hardware"
tutorials/language/pass.py
Outdated
a customized pass in TVM. | ||
Prerequisites | ||
------------- | ||
Before reading this tutorial, we assume readers have already known these well: |
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.
"we assume readers already have good knowledge of these topics:"
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 insist mine.
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.
We can write "we assume readers already know these topics well"
tutorials/language/pass.py
Outdated
Prerequisites | ||
------------- | ||
Before reading this tutorial, we assume readers have already known these well: | ||
- Writing an algorithm in TVM and schedule it. If not, you should go through other |
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.
"Writing an algorithm in TVM and scheduling it. Otherwise, see example tutorials such as GEMM on CPU."
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.
How can I use the relative path to ref this link?
tutorials/language/pass.py
Outdated
# Phase 0 generates the raw IR and loop levels; phase 1 flattens the storage; phase 2 transforms | ||
# the loop levels, like unroll, vectorization and threading; phase 3 does some cleanup work. | ||
# | ||
# Thus, we believe after phase 1 is a good place to put this transformation pass. |
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.
"A good place to put this transformation pass is just after phase 1."
tutorials/language/pass.py
Outdated
##################################################################### | ||
# Summary | ||
# ------- | ||
# This tutorial gives a quick view of writing a customized IR transformation pass: |
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.
"quick overview"
tutorials/language/pass.py
Outdated
# Summary | ||
# ------- | ||
# This tutorial gives a quick view of writing a customized IR transformation pass: | ||
# - Use ``tvm.ir_pass.PostOrderVisit`` to gather information of each IR nodes. |
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.
"on each IR node."
tutorials/language/pass.py
Outdated
# This tutorial gives a quick view of writing a customized IR transformation pass: | ||
# - Use ``tvm.ir_pass.PostOrderVisit`` to gather information of each IR nodes. | ||
# - Use ``tvm.ir_pass.IRTransform`` to transform IR nodes. | ||
# - Wrap up two above to write a ``stmt->stmt`` function. |
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.
"wrap the two above in a ? stmt->stmt
..."
tutorials/language/pass.py
Outdated
# - Use ``tvm.ir_pass.PostOrderVisit`` to gather information of each IR nodes. | ||
# - Use ``tvm.ir_pass.IRTransform`` to transform IR nodes. | ||
# - Wrap up two above to write a ``stmt->stmt`` function. | ||
# - Use ``tvm.build_config`` to glue this function to TVM lower pass |
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.
"to a TVM lower pass."
How can I do MergeSeq or MergeNest in python, should we expose these api to python? |
@xqdan Can you make the question more specific? |
@eqy I resolved your requests! |
@were that's the problem when I wrote a python pass, we may need more until api for writing a pass. |
@xqdan Can you be more specific? What util (I suppose ur 'until' is typo) do you need? |
@were I mean we may need more utility functions when writing python pass, eg. MergeNest in c++, |
@xqdan but it is not |
also, i believe this c++ code can be done in equivalent python in tvm |
@were consider you want to insert two new stmts before a stmt, and one new stmt after it, how do you do that? that's usual requirement when you writing a pass. |
@were actually it's stmt -> stmt, because stmt can be big, can be small, the whole AST can be a stmt, which also can be divided into small ones anything we have had in c++, we can register them to python, you need not to implement again in python. |
@xqdan Eazy! You can just go to the node before which you want to inject to statement and transform it to a block statement. |
@tqchen My changes have been approved. |
@were could you help to retrigger the CI? |
@yzhliu I have done. |
tutorials/language/pass.py
Outdated
@@ -0,0 +1,153 @@ | |||
""" |
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.
pass -> low_level_custom_pass.py
tutorials/language/pass.py
Outdated
@@ -0,0 +1,153 @@ | |||
""" | |||
Writing a Customized Pass | |||
========================= |
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.
Let us put it under tutorials/dev
f126cd1
to
edbd878
Compare
@tqchen Done. |
need to update ordering here |
@tqchen Done. |
Thanks for contributing to TVM! Please refer to guideline https://docs.tvm.ai/contribute/ for useful information and tips. After the pull request is submitted, please request code reviews from others in the community.