Skip to content
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

Merged
merged 13 commits into from
Sep 5, 2018
Merged

Conversation

were
Copy link
Contributor

@were were commented Aug 28, 2018

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.

@tqchen
Copy link
Member

tqchen commented Aug 30, 2018

please request reviews

@tqchen
Copy link
Member

tqchen commented Aug 31, 2018

@nishi-t @eqy please review

=========================
**Author**: `Jian Weng <https://were.github.io>`_

TVM is a framework to abstract the heterogenity of those various machine learning
Copy link
Contributor

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"

**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
Copy link
Contributor

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"

Copy link
Contributor Author

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.


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
Copy link
Contributor

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"

a customized pass in TVM.
Prerequisites
-------------
Before reading this tutorial, we assume readers have already known these well:
Copy link
Contributor

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:"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I insist mine.

Copy link
Contributor

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"

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
Copy link
Contributor

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."

Copy link
Contributor Author

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?

# 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.
Copy link
Contributor

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."

#####################################################################
# Summary
# -------
# This tutorial gives a quick view of writing a customized IR transformation pass:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"quick overview"

# 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"on each IR node."

# 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.
Copy link
Contributor

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 ..."

# - 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
Copy link
Contributor

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."

@xqdan
Copy link
Contributor

xqdan commented Sep 1, 2018

How can I do MergeSeq or MergeNest in python, should we expose these api to python?

@were
Copy link
Contributor Author

were commented Sep 1, 2018

@xqdan Can you make the question more specific?
At the first glance I even suppose this question is not related at all.

@were
Copy link
Contributor Author

were commented Sep 1, 2018

@eqy I resolved your requests!

@xqdan
Copy link
Contributor

xqdan commented Sep 1, 2018

@were that's the problem when I wrote a python pass, we may need more until api for writing a pass.

@were
Copy link
Contributor Author

were commented Sep 1, 2018

@xqdan Can you be more specific? What util (I suppose ur 'until' is typo) do you need?

@xqdan
Copy link
Contributor

xqdan commented Sep 1, 2018

@were I mean we may need more utility functions when writing python pass, eg. MergeNest in c++,
https://github.com/dmlc/tvm/blob/b95b5958913927b90463dddb61eb18ef6e1556f6/src/pass/ir_util.cc#L11

@were
Copy link
Contributor Author

were commented Sep 1, 2018

@xqdan but it is not stmt->stmt mapping at all.

@were
Copy link
Contributor Author

were commented Sep 1, 2018

also, i believe this c++ code can be done in equivalent python in tvm

@xqdan
Copy link
Contributor

xqdan commented Sep 2, 2018

@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.

@xqdan
Copy link
Contributor

xqdan commented Sep 2, 2018

@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.

@were
Copy link
Contributor Author

were commented Sep 2, 2018

@xqdan Eazy! You can just go to the node before which you want to inject to statement and transform it to a block statement.

@were
Copy link
Contributor Author

were commented Sep 3, 2018

@tqchen My changes have been approved.

@yzhliu
Copy link
Member

yzhliu commented Sep 4, 2018

@were could you help to retrigger the CI?

@were
Copy link
Contributor Author

were commented Sep 4, 2018

@yzhliu I have done.

@@ -0,0 +1,153 @@
"""
Copy link
Member

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

@@ -0,0 +1,153 @@
"""
Writing a Customized Pass
=========================
Copy link
Member

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

@were were force-pushed the tutorial branch 2 times, most recently from f126cd1 to edbd878 Compare September 4, 2018 19:49
@were
Copy link
Contributor Author

were commented Sep 4, 2018

@tqchen Done.

@tqchen
Copy link
Member

tqchen commented Sep 4, 2018

@were
Copy link
Contributor Author

were commented Sep 4, 2018

@tqchen Done.

@tqchen tqchen merged commit d173e63 into apache:master Sep 5, 2018
@tqchen
Copy link
Member

tqchen commented Sep 5, 2018

Thanks @were @eqy @xqdan , this is now merged.

ZhennanQin pushed a commit to ZhennanQin/tvm that referenced this pull request Sep 6, 2018
kevinthesun pushed a commit to kevinthesun/tvm that referenced this pull request Sep 6, 2018
@were were deleted the tutorial branch September 10, 2018 01:38
FrozenGene pushed a commit to FrozenGene/tvm that referenced this pull request Dec 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants