You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2021/10/19 07:02:19 UTC

[GitHub] [tvm] Hzfengsy opened a new pull request #9315: [TensorIR][Tutorial] Blitz course

Hzfengsy opened a new pull request #9315:
URL: https://github.com/apache/tvm/pull/9315


   This is the blitz course to TensorIR and IRModule. 
   
   Please see the demo web page at: http://tmp.syfeng.net:9090/tutorial/tensor_ir_blitz_course.html
   
   cc @junrushao1994 @tqchen 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] Hzfengsy commented on pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
Hzfengsy commented on pull request #9315:
URL: https://github.com/apache/tvm/pull/9315#issuecomment-952546817


   All comments are addressed. Let's merge it quickly if there is no more comments


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] Hzfengsy commented on a change in pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
Hzfengsy commented on a change in pull request #9315:
URL: https://github.com/apache/tvm/pull/9315#discussion_r733646399



##########
File path: gallery/tutorial/tensor_ir_blitz_course.py
##########
@@ -0,0 +1,135 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+.. _tir_blitz:
+
+Blitz Course to TensorIR
+========================
+**Author**: `Siyuan Feng <https://github.com/Hzfengsy>`_
+
+TensorIR is a domain specific languages for deep learning programs serving two broad purposes:
+
+- An implement for transforming and optimizing programs on various hardware backends.
+
+- An abstraction for automatic tensorized program optimization.
+
+"""
+
+import tvm
+from tvm.script import tir as T
+import numpy as np
+
+################################################################################################
+# IRModule
+# --------
+# An IRModule is the central data structure in TensorIR, which contains deep learning programs.

Review comment:
       A bad news: relay function is not supported by TVMScript for now. :(




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] junrushao1994 commented on pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
junrushao1994 commented on pull request #9315:
URL: https://github.com/apache/tvm/pull/9315#issuecomment-946943591


   We might want an overall introduction of the tutorial somewhere near the beginning of this article. like, the purpose of this article is to blah


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] areusch commented on pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
areusch commented on pull request #9315:
URL: https://github.com/apache/tvm/pull/9315#issuecomment-946960303


   it would probably also be good to state why you might want to use TensorIR instead of other scheduling methods


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] jroesch commented on pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
jroesch commented on pull request #9315:
URL: https://github.com/apache/tvm/pull/9315#issuecomment-946984602


   > it would probably also be good to state why you might want to use TensorIR instead of other scheduling methods
   
   Yeah I think one piece of general feedback is more commentary in the tutorial would be helpful to explain context. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] MasterJH5574 commented on a change in pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
MasterJH5574 commented on a change in pull request #9315:
URL: https://github.com/apache/tvm/pull/9315#discussion_r735779089



##########
File path: gallery/tutorial/tensor_ir_blitz_course.py
##########
@@ -0,0 +1,191 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+.. _tir_blitz:
+
+Blitz Course to TensorIR
+========================
+**Author**: `Siyuan Feng <https://github.com/Hzfengsy>`_
+
+TensorIR is a domain specific language for deep learning programs serving two broad purposes:
+
+- An implementation for transforming and optimizing programs on various hardware backends.
+
+- An abstraction for automatic tensorized program optimization.
+
+"""
+
+import tvm
+from tvm.ir.module import IRModule
+from tvm.script import tir as T
+import numpy as np
+
+################################################################################################
+# IRModule
+# --------
+# An IRModule is the central data structure in TVM, which contains deep learning programs.
+# It is the basic object of interest of IR transformation and model building.
+#
+# .. image:: https://raw.githubusercontent.com/Hzfengsy/web-data/main/images/design/tvm_life_of_irmodule.png
+#    :align: center
+#    :width: 85%
+#
+# This is the life cycle of an IRModule, which can be created from TVM Script. TensorIR schedule
+# primitives and passes are two major ways to transform an IRModule. Also, a sequence of
+# transformations on an IRModule is acceptable. Note that we can print an IRModule at **ANY** stage
+# to TVMScript. After all transformations and optimizations are complete, we can build the IRModule
+# to a runnable module to deploy on target devices.
+#
+# Based on the design of TensorIR and IRModule, we are able to create a new programming method:
+#
+# 1. Write a program by TVMScript in a python-AST based syntax.
+#
+# 2. Transform and optimize a program with python api.
+#
+# 3. Interactively inspect and try the performance with an imperative style transformation API.
+
+
+################################################################################################
+# Create an IRModule
+# ------------------
+# IRModule can be created by writing TVMScript, which is a round-trippable syntax for TVM IR.
+#
+# Different than creating an computational expression by Tensor Expression
+# (:ref:`tutorial-tensor-expr-get-started`). TensorIR allow user to  programs through tvm script,
+# a language embedded in python AST. The new method makes it possible to write complex programs
+# and further schedule and optimize it.
+#
+# Following is an simple example for vector addition.

Review comment:
       ```suggestion
   # Following is a simple example for vector addition.
   ```

##########
File path: gallery/tutorial/tensor_ir_blitz_course.py
##########
@@ -0,0 +1,191 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+.. _tir_blitz:
+
+Blitz Course to TensorIR
+========================
+**Author**: `Siyuan Feng <https://github.com/Hzfengsy>`_
+
+TensorIR is a domain specific language for deep learning programs serving two broad purposes:
+
+- An implementation for transforming and optimizing programs on various hardware backends.
+
+- An abstraction for automatic tensorized program optimization.
+
+"""
+
+import tvm
+from tvm.ir.module import IRModule
+from tvm.script import tir as T
+import numpy as np
+
+################################################################################################
+# IRModule
+# --------
+# An IRModule is the central data structure in TVM, which contains deep learning programs.
+# It is the basic object of interest of IR transformation and model building.
+#
+# .. image:: https://raw.githubusercontent.com/Hzfengsy/web-data/main/images/design/tvm_life_of_irmodule.png
+#    :align: center
+#    :width: 85%
+#
+# This is the life cycle of an IRModule, which can be created from TVM Script. TensorIR schedule
+# primitives and passes are two major ways to transform an IRModule. Also, a sequence of
+# transformations on an IRModule is acceptable. Note that we can print an IRModule at **ANY** stage
+# to TVMScript. After all transformations and optimizations are complete, we can build the IRModule
+# to a runnable module to deploy on target devices.
+#
+# Based on the design of TensorIR and IRModule, we are able to create a new programming method:
+#
+# 1. Write a program by TVMScript in a python-AST based syntax.
+#
+# 2. Transform and optimize a program with python api.
+#
+# 3. Interactively inspect and try the performance with an imperative style transformation API.
+
+
+################################################################################################
+# Create an IRModule
+# ------------------
+# IRModule can be created by writing TVMScript, which is a round-trippable syntax for TVM IR.
+#
+# Different than creating an computational expression by Tensor Expression
+# (:ref:`tutorial-tensor-expr-get-started`). TensorIR allow user to  programs through tvm script,

Review comment:
       ```suggestion
   # Different than creating an computational expression by Tensor Expression
   # (:ref:`tutorial-tensor-expr-get-started`), TensorIR allow user to  programs through tvm script,
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] yzh119 commented on a change in pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
yzh119 commented on a change in pull request #9315:
URL: https://github.com/apache/tvm/pull/9315#discussion_r735868972



##########
File path: gallery/tutorial/tensor_ir_blitz_course.py
##########
@@ -0,0 +1,191 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+.. _tir_blitz:
+
+Blitz Course to TensorIR
+========================
+**Author**: `Siyuan Feng <https://github.com/Hzfengsy>`_
+
+TensorIR is a domain specific language for deep learning programs serving two broad purposes:
+
+- An implementation for transforming and optimizing programs on various hardware backends.
+
+- An abstraction for automatic tensorized program optimization.
+
+"""
+
+import tvm
+from tvm.ir.module import IRModule
+from tvm.script import tir as T
+import numpy as np
+
+################################################################################################
+# IRModule
+# --------
+# An IRModule is the central data structure in TVM, which contains deep learning programs.
+# It is the basic object of interest of IR transformation and model building.
+#
+# .. image:: https://raw.githubusercontent.com/Hzfengsy/web-data/main/images/design/tvm_life_of_irmodule.png
+#    :align: center
+#    :width: 85%
+#
+# This is the life cycle of an IRModule, which can be created from TVM Script. TensorIR schedule
+# primitives and passes are two major ways to transform an IRModule. Also, a sequence of
+# transformations on an IRModule is acceptable. Note that we can print an IRModule at **ANY** stage
+# to TVMScript. After all transformations and optimizations are complete, we can build the IRModule
+# to a runnable module to deploy on target devices.
+#
+# Based on the design of TensorIR and IRModule, we are able to create a new programming method:
+#
+# 1. Write a program by TVMScript in a python-AST based syntax.
+#
+# 2. Transform and optimize a program with python api.
+#
+# 3. Interactively inspect and try the performance with an imperative style transformation API.
+
+
+################################################################################################
+# Create an IRModule
+# ------------------
+# IRModule can be created by writing TVMScript, which is a round-trippable syntax for TVM IR.
+#
+# Different than creating an computational expression by Tensor Expression
+# (:ref:`tutorial-tensor-expr-get-started`). TensorIR allow user to  programs through tvm script,
+# a language embedded in python AST. The new method makes it possible to write complex programs

Review comment:
       I'm not sure if we need to emphasize AST because it's not exposed to user.

##########
File path: gallery/tutorial/tensor_ir_blitz_course.py
##########
@@ -0,0 +1,191 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+.. _tir_blitz:
+
+Blitz Course to TensorIR
+========================
+**Author**: `Siyuan Feng <https://github.com/Hzfengsy>`_
+
+TensorIR is a domain specific language for deep learning programs serving two broad purposes:
+
+- An implementation for transforming and optimizing programs on various hardware backends.
+
+- An abstraction for automatic tensorized program optimization.
+
+"""
+
+import tvm
+from tvm.ir.module import IRModule
+from tvm.script import tir as T
+import numpy as np
+
+################################################################################################
+# IRModule
+# --------
+# An IRModule is the central data structure in TVM, which contains deep learning programs.
+# It is the basic object of interest of IR transformation and model building.
+#
+# .. image:: https://raw.githubusercontent.com/Hzfengsy/web-data/main/images/design/tvm_life_of_irmodule.png
+#    :align: center
+#    :width: 85%
+#
+# This is the life cycle of an IRModule, which can be created from TVM Script. TensorIR schedule
+# primitives and passes are two major ways to transform an IRModule. Also, a sequence of
+# transformations on an IRModule is acceptable. Note that we can print an IRModule at **ANY** stage
+# to TVMScript. After all transformations and optimizations are complete, we can build the IRModule
+# to a runnable module to deploy on target devices.
+#
+# Based on the design of TensorIR and IRModule, we are able to create a new programming method:
+#
+# 1. Write a program by TVMScript in a python-AST based syntax.
+#
+# 2. Transform and optimize a program with python api.
+#
+# 3. Interactively inspect and try the performance with an imperative style transformation API.
+
+
+################################################################################################
+# Create an IRModule
+# ------------------
+# IRModule can be created by writing TVMScript, which is a round-trippable syntax for TVM IR.
+#
+# Different than creating an computational expression by Tensor Expression
+# (:ref:`tutorial-tensor-expr-get-started`). TensorIR allow user to  programs through tvm script,

Review comment:
       allow user to programs -> allow user to program?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] YuchenJin commented on a change in pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
YuchenJin commented on a change in pull request #9315:
URL: https://github.com/apache/tvm/pull/9315#discussion_r732416090



##########
File path: gallery/tutorial/tensor_ir_blitz_course.py
##########
@@ -0,0 +1,135 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+.. _tir_blitz:
+
+Blitz Course to TensorIR
+========================
+**Author**: `Siyuan Feng <https://github.com/Hzfengsy>`_
+
+TensorIR is a domain specific languages for deep learning programs serving two broad purposes:
+
+- An implement for transforming and optimizing programs on various hardware backends.
+
+- An abstraction for automatic tensorized program optimization.
+
+"""
+
+import tvm
+from tvm.script import tir as T
+import numpy as np
+
+################################################################################################
+# IRModule
+# --------
+# An IRModule is the central data structure in TensorIR, which contains deep learning programs.
+# It is the basic object of interest of IR transformation and model building.
+#
+
+
+################################################################################################
+# Create an IRModule
+# ------------------
+# IRModule can be created by writing TVMScript, which is a script syntax for TVM IR. (see the ref)

Review comment:
       Did you miss adding the link to the ref?

##########
File path: gallery/tutorial/tensor_ir_blitz_course.py
##########
@@ -0,0 +1,135 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+.. _tir_blitz:
+
+Blitz Course to TensorIR
+========================
+**Author**: `Siyuan Feng <https://github.com/Hzfengsy>`_
+
+TensorIR is a domain specific languages for deep learning programs serving two broad purposes:
+
+- An implement for transforming and optimizing programs on various hardware backends.
+
+- An abstraction for automatic tensorized program optimization.
+
+"""
+
+import tvm
+from tvm.script import tir as T
+import numpy as np
+
+################################################################################################
+# IRModule
+# --------
+# An IRModule is the central data structure in TensorIR, which contains deep learning programs.
+# It is the basic object of interest of IR transformation and model building.
+#
+
+
+################################################################################################
+# Create an IRModule
+# ------------------
+# IRModule can be created by writing TVMScript, which is a script syntax for TVM IR. (see the ref)
+# Here is a simple module for vector add.
+#
+
+
+@tvm.script.ir_module
+class MyModule:
+    @T.prim_func
+    def main(a: T.handle, b: T.handle):
+        # We exchange data between function by handles, which are similar to pointer.
+        T.func_attr({"global_symbol": "main", "tir.noalias": True})
+        # Create buffer from handles.
+        A = T.match_buffer(a, (8,), dtype="float32")
+        B = T.match_buffer(b, (8,), dtype="float32")
+        for i in range(8):
+            # A block is an abstraction for computation.
+            with T.block("B"):
+                # Define a spatial block iterator and bind it to value i.
+                vi = T.axis.spatial(8, i)
+                B[vi] = A[vi] + 1.0
+
+
+ir_module = MyModule
+print(type(ir_module))
+print(ir_module.script())
+
+################################################################################################
+# Build and Run an IRModule
+# -------------------------
+# We can build the IRModule into a runnable module with specific target backends.
+#
+
+mod = tvm.build(ir_module, target="llvm")  # The module for CPU backends.
+print(type(mod))
+
+################################################################################################
+# Prepare the input array and output array, then run the module.
+#
+
+a = tvm.nd.array(np.arange(8).astype("float32"))
+b = tvm.nd.array(np.zeros((8,)).astype("float32"))
+mod(a, b)
+print(a)
+print(b)
+
+
+################################################################################################
+# Transform an IRModule
+# ---------------------
+# The IRModule is the central data structure for program optimization, which can be transformed
+# by :code:`Schedule`.
+# Schedule is consist of primitives. Each primitive does a simple job on IR transformation,
+# such as loop tiling or make computation parallel. (Please see ref)

Review comment:
       Did you miss the ref?

##########
File path: gallery/tutorial/tensor_ir_blitz_course.py
##########
@@ -0,0 +1,135 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+.. _tir_blitz:
+
+Blitz Course to TensorIR
+========================
+**Author**: `Siyuan Feng <https://github.com/Hzfengsy>`_
+
+TensorIR is a domain specific languages for deep learning programs serving two broad purposes:
+
+- An implement for transforming and optimizing programs on various hardware backends.
+
+- An abstraction for automatic tensorized program optimization.
+
+"""
+
+import tvm
+from tvm.script import tir as T
+import numpy as np
+
+################################################################################################
+# IRModule
+# --------
+# An IRModule is the central data structure in TensorIR, which contains deep learning programs.

Review comment:
       Thanks @Hzfengsy, would it be more precise to say IRModule is the central data structure in TVM (instead of TensorIR)? Might be worth mentioning it can contain a collection of functions including `relay::Function` and `tir::PrimFunc` (since you use `@T.prim_func` in the following code snippets).




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] tqchen commented on pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
tqchen commented on pull request #9315:
URL: https://github.com/apache/tvm/pull/9315#issuecomment-950987518


   @YuchenJin @masahi @MasterJH5574 please take another look and https://tvm.apache.org/docs/contribute/code_review.html#approve-and-request-changes-explicitly


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] quic-sanirudh commented on pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
quic-sanirudh commented on pull request #9315:
URL: https://github.com/apache/tvm/pull/9315#issuecomment-950078661


   > I agree with @quic-sanirudh that printing things as T by default might be better. We can do that as a separate PR
   
   Thanks for the reply and confirmation @tqchen. Changing the printer to print as T by default seems like a simple enough change. Shall I go ahead and raise a PR to do that, or do we need to go through an RFC process for that? 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] masahi commented on a change in pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
masahi commented on a change in pull request #9315:
URL: https://github.com/apache/tvm/pull/9315#discussion_r733228365



##########
File path: gallery/tutorial/tensor_ir_blitz_course.py
##########
@@ -0,0 +1,135 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+.. _tir_blitz:
+
+Blitz Course to TensorIR
+========================
+**Author**: `Siyuan Feng <https://github.com/Hzfengsy>`_
+
+TensorIR is a domain specific languages for deep learning programs serving two broad purposes:
+
+- An implement for transforming and optimizing programs on various hardware backends.

Review comment:
       Typo




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] tqchen edited a comment on pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
tqchen edited a comment on pull request #9315:
URL: https://github.com/apache/tvm/pull/9315#issuecomment-949873841


   I agree with @quic-sanirudh that printing things as T by default might be better. We can do that as a separate PR


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] Hzfengsy commented on a change in pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
Hzfengsy commented on a change in pull request #9315:
URL: https://github.com/apache/tvm/pull/9315#discussion_r736354761



##########
File path: gallery/tutorial/tensor_ir_blitz_course.py
##########
@@ -0,0 +1,191 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+.. _tir_blitz:
+
+Blitz Course to TensorIR
+========================
+**Author**: `Siyuan Feng <https://github.com/Hzfengsy>`_
+
+TensorIR is a domain specific language for deep learning programs serving two broad purposes:
+
+- An implementation for transforming and optimizing programs on various hardware backends.
+
+- An abstraction for automatic tensorized program optimization.
+
+"""
+
+import tvm
+from tvm.ir.module import IRModule
+from tvm.script import tir as T
+import numpy as np
+
+################################################################################################
+# IRModule
+# --------
+# An IRModule is the central data structure in TVM, which contains deep learning programs.
+# It is the basic object of interest of IR transformation and model building.
+#
+# .. image:: https://raw.githubusercontent.com/Hzfengsy/web-data/main/images/design/tvm_life_of_irmodule.png
+#    :align: center
+#    :width: 85%
+#
+# This is the life cycle of an IRModule, which can be created from TVM Script. TensorIR schedule
+# primitives and passes are two major ways to transform an IRModule. Also, a sequence of
+# transformations on an IRModule is acceptable. Note that we can print an IRModule at **ANY** stage
+# to TVMScript. After all transformations and optimizations are complete, we can build the IRModule
+# to a runnable module to deploy on target devices.
+#
+# Based on the design of TensorIR and IRModule, we are able to create a new programming method:
+#
+# 1. Write a program by TVMScript in a python-AST based syntax.
+#
+# 2. Transform and optimize a program with python api.
+#
+# 3. Interactively inspect and try the performance with an imperative style transformation API.
+
+
+################################################################################################
+# Create an IRModule
+# ------------------
+# IRModule can be created by writing TVMScript, which is a round-trippable syntax for TVM IR.
+#
+# Different than creating an computational expression by Tensor Expression
+# (:ref:`tutorial-tensor-expr-get-started`). TensorIR allow user to  programs through tvm script,
+# a language embedded in python AST. The new method makes it possible to write complex programs

Review comment:
       I think it's not a big problem




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] tqchen commented on a change in pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
tqchen commented on a change in pull request #9315:
URL: https://github.com/apache/tvm/pull/9315#discussion_r734565993



##########
File path: gallery/tutorial/tensor_ir_blitz_course.py
##########
@@ -0,0 +1,183 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+.. _tir_blitz:
+
+Blitz Course to TensorIR
+========================
+**Author**: `Siyuan Feng <https://github.com/Hzfengsy>`_
+
+TensorIR is a domain specific languages for deep learning programs serving two broad purposes:
+
+- An implementation for transforming and optimizing programs on various hardware backends.
+
+- An abstraction for automatic tensorized program optimization.
+
+"""
+
+import tvm
+from tvm.ir.module import IRModule
+from tvm.script import tir as T
+import numpy as np
+
+################################################################################################
+# IRModule
+# --------
+# An IRModule is the central data structure in TVM, which contains deep learning programs.
+# It is the basic object of interest of IR transformation and model building.
+#
+# .. image:: https://raw.githubusercontent.com/Hzfengsy/web-data/main/images/design/tvm_life_of_irmodule.png
+#    :align: center
+#    :width: 85%
+#
+# This is the life cycle of an IRModule, which can be created from TVM Script. TensorIR schedule
+# primitives and passes are two major ways to transform an IRModule. Also, a sequence of
+# transformations on an IRModule is acceptable. Note that we can print an IRModule at **ANY** stage
+# to TVMScript. After all transformations and optimizations are complete, we can build the IRModule
+# to a runnable module to deploy on target devices.
+#
+# Based on the design of TensorIR and IRModule, we are able to create a new programming method:
+#
+# 1. Write a program by TVMScript (just like write python codes)

Review comment:
       just like python code => in an python-AST based syntax

##########
File path: gallery/tutorial/tensor_ir_blitz_course.py
##########
@@ -0,0 +1,183 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+.. _tir_blitz:
+
+Blitz Course to TensorIR
+========================
+**Author**: `Siyuan Feng <https://github.com/Hzfengsy>`_
+
+TensorIR is a domain specific languages for deep learning programs serving two broad purposes:
+
+- An implementation for transforming and optimizing programs on various hardware backends.
+
+- An abstraction for automatic tensorized program optimization.
+
+"""
+
+import tvm
+from tvm.ir.module import IRModule
+from tvm.script import tir as T
+import numpy as np
+
+################################################################################################
+# IRModule
+# --------
+# An IRModule is the central data structure in TVM, which contains deep learning programs.
+# It is the basic object of interest of IR transformation and model building.
+#
+# .. image:: https://raw.githubusercontent.com/Hzfengsy/web-data/main/images/design/tvm_life_of_irmodule.png
+#    :align: center
+#    :width: 85%
+#
+# This is the life cycle of an IRModule, which can be created from TVM Script. TensorIR schedule
+# primitives and passes are two major ways to transform an IRModule. Also, a sequence of
+# transformations on an IRModule is acceptable. Note that we can print an IRModule at **ANY** stage
+# to TVMScript. After all transformations and optimizations are complete, we can build the IRModule
+# to a runnable module to deploy on target devices.
+#
+# Based on the design of TensorIR and IRModule, we are able to create a new programming method:
+#
+# 1. Write a program by TVMScript (just like write python codes)
+#
+# 2. Transform and optimize a program with python api (by schedule primitives and passes)
+#
+# 3. Interactively inspect and try the performance (print or build at any stage of IRModule)
+
+
+################################################################################################
+# Create an IRModule
+# ------------------
+# IRModule can be created by writing TVMScript, which is a round-trippable syntax for TVM IR.
+#
+# Different than creating an computational expression by Tensor Expression
+# (:ref:`tutorial-tensor-expr-get-started`). TensorIR allow user to write native programs, which
+# is similar with writing a Python program with for loops and computational body. The new method
+# makes it possible to write complex programs and further schedule and optimize it.
+#
+# Following is an simple example for vector addition.
+#
+
+
+@tvm.script.ir_module
+class MyModule:
+    @T.prim_func
+    def main(a: T.handle, b: T.handle):
+        # We exchange data between function by handles, which are similar to pointer.
+        T.func_attr({"global_symbol": "main", "tir.noalias": True})
+        # Create buffer from handles.
+        A = T.match_buffer(a, (8,), dtype="float32")
+        B = T.match_buffer(b, (8,), dtype="float32")
+        for i in range(8):
+            # A block is an abstraction for computation.
+            with T.block("B"):
+                # Define a spatial block iterator and bind it to value i.
+                vi = T.axis.spatial(8, i)
+                B[vi] = A[vi] + 1.0
+
+
+ir_module = MyModule
+print(type(ir_module))
+print(ir_module.script())
+
+################################################################################################
+# Besides, Tensor Expression (TE) is a really good abstraction for simple operators. TensorIR still
+# allow users to create IRModule from TE.
+#
+
+from tvm import te
+
+A = te.placeholder((8,), dtype="float32", name="A")
+B = te.compute((8,), lambda *i: A(*i) + 1.0, name="B")
+func = te.create_prim_func([A, B])
+ir_module_1 = IRModule({"main": func})
+print(ir_module_1.script())
+
+
+################################################################################################
+# Build and Run an IRModule
+# -------------------------
+# We can build the IRModule into a runnable module with specific target backends.
+#
+
+mod = tvm.build(ir_module, target="llvm")  # The module for CPU backends.
+print(type(mod))
+
+################################################################################################
+# Prepare the input array and output array, then run the module.
+#
+
+a = tvm.nd.array(np.arange(8).astype("float32"))
+b = tvm.nd.array(np.zeros((8,)).astype("float32"))
+mod(a, b)
+print(a)
+print(b)
+
+
+################################################################################################
+# Transform an IRModule
+# ---------------------
+# The IRModule is the central data structure for program optimization, which can be transformed
+# by :code:`Schedule`.
+# Schedule consists of primitives. Each primitive does a simple job on IR transformation,

Review comment:
       A schedule contains multiple primitive methods to interactively transform the program.  Each primitive transforms the program in certain ways to bring additional performance optimizations. 

##########
File path: gallery/tutorial/tensor_ir_blitz_course.py
##########
@@ -0,0 +1,183 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+.. _tir_blitz:
+
+Blitz Course to TensorIR
+========================
+**Author**: `Siyuan Feng <https://github.com/Hzfengsy>`_
+
+TensorIR is a domain specific languages for deep learning programs serving two broad purposes:
+
+- An implementation for transforming and optimizing programs on various hardware backends.
+
+- An abstraction for automatic tensorized program optimization.
+
+"""
+
+import tvm
+from tvm.ir.module import IRModule
+from tvm.script import tir as T
+import numpy as np
+
+################################################################################################
+# IRModule
+# --------
+# An IRModule is the central data structure in TVM, which contains deep learning programs.
+# It is the basic object of interest of IR transformation and model building.
+#
+# .. image:: https://raw.githubusercontent.com/Hzfengsy/web-data/main/images/design/tvm_life_of_irmodule.png
+#    :align: center
+#    :width: 85%
+#
+# This is the life cycle of an IRModule, which can be created from TVM Script. TensorIR schedule
+# primitives and passes are two major ways to transform an IRModule. Also, a sequence of
+# transformations on an IRModule is acceptable. Note that we can print an IRModule at **ANY** stage
+# to TVMScript. After all transformations and optimizations are complete, we can build the IRModule
+# to a runnable module to deploy on target devices.
+#
+# Based on the design of TensorIR and IRModule, we are able to create a new programming method:
+#
+# 1. Write a program by TVMScript (just like write python codes)
+#
+# 2. Transform and optimize a program with python api (by schedule primitives and passes)

Review comment:
       we can safely remove `(by schedule primitives and passes)` as they are not yet defined here.

##########
File path: gallery/tutorial/tensor_ir_blitz_course.py
##########
@@ -0,0 +1,183 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+.. _tir_blitz:
+
+Blitz Course to TensorIR
+========================
+**Author**: `Siyuan Feng <https://github.com/Hzfengsy>`_
+
+TensorIR is a domain specific languages for deep learning programs serving two broad purposes:
+
+- An implementation for transforming and optimizing programs on various hardware backends.
+
+- An abstraction for automatic tensorized program optimization.
+
+"""
+
+import tvm
+from tvm.ir.module import IRModule
+from tvm.script import tir as T
+import numpy as np
+
+################################################################################################
+# IRModule
+# --------
+# An IRModule is the central data structure in TVM, which contains deep learning programs.
+# It is the basic object of interest of IR transformation and model building.
+#
+# .. image:: https://raw.githubusercontent.com/Hzfengsy/web-data/main/images/design/tvm_life_of_irmodule.png
+#    :align: center
+#    :width: 85%
+#
+# This is the life cycle of an IRModule, which can be created from TVM Script. TensorIR schedule
+# primitives and passes are two major ways to transform an IRModule. Also, a sequence of
+# transformations on an IRModule is acceptable. Note that we can print an IRModule at **ANY** stage
+# to TVMScript. After all transformations and optimizations are complete, we can build the IRModule
+# to a runnable module to deploy on target devices.
+#
+# Based on the design of TensorIR and IRModule, we are able to create a new programming method:
+#
+# 1. Write a program by TVMScript (just like write python codes)
+#
+# 2. Transform and optimize a program with python api (by schedule primitives and passes)
+#
+# 3. Interactively inspect and try the performance (print or build at any stage of IRModule)
+
+
+################################################################################################
+# Create an IRModule
+# ------------------
+# IRModule can be created by writing TVMScript, which is a round-trippable syntax for TVM IR.
+#
+# Different than creating an computational expression by Tensor Expression
+# (:ref:`tutorial-tensor-expr-get-started`). TensorIR allow user to write native programs, which
+# is similar with writing a Python program with for loops and computational body. The new method
+# makes it possible to write complex programs and further schedule and optimize it.
+#
+# Following is an simple example for vector addition.
+#
+
+
+@tvm.script.ir_module
+class MyModule:
+    @T.prim_func
+    def main(a: T.handle, b: T.handle):
+        # We exchange data between function by handles, which are similar to pointer.
+        T.func_attr({"global_symbol": "main", "tir.noalias": True})
+        # Create buffer from handles.
+        A = T.match_buffer(a, (8,), dtype="float32")
+        B = T.match_buffer(b, (8,), dtype="float32")
+        for i in range(8):
+            # A block is an abstraction for computation.
+            with T.block("B"):
+                # Define a spatial block iterator and bind it to value i.
+                vi = T.axis.spatial(8, i)
+                B[vi] = A[vi] + 1.0
+
+
+ir_module = MyModule
+print(type(ir_module))
+print(ir_module.script())
+
+################################################################################################
+# Besides, Tensor Expression (TE) is a really good abstraction for simple operators. TensorIR still
+# allow users to create IRModule from TE.
+#
+
+from tvm import te
+
+A = te.placeholder((8,), dtype="float32", name="A")
+B = te.compute((8,), lambda *i: A(*i) + 1.0, name="B")
+func = te.create_prim_func([A, B])
+ir_module_1 = IRModule({"main": func})
+print(ir_module_1.script())
+
+
+################################################################################################
+# Build and Run an IRModule
+# -------------------------
+# We can build the IRModule into a runnable module with specific target backends.
+#
+
+mod = tvm.build(ir_module, target="llvm")  # The module for CPU backends.
+print(type(mod))
+
+################################################################################################
+# Prepare the input array and output array, then run the module.
+#
+
+a = tvm.nd.array(np.arange(8).astype("float32"))
+b = tvm.nd.array(np.zeros((8,)).astype("float32"))
+mod(a, b)
+print(a)
+print(b)
+
+
+################################################################################################
+# Transform an IRModule
+# ---------------------
+# The IRModule is the central data structure for program optimization, which can be transformed
+# by :code:`Schedule`.
+# Schedule consists of primitives. Each primitive does a simple job on IR transformation,
+# such as loop tiling or make computation parallel.
+#
+# .. image:: https://raw.githubusercontent.com/Hzfengsy/web-data/main/images/design/tvm_tensor_ir_opt_flow.png
+#    :align: center
+#    :width: 100%
+#
+# The image above is a typical workflow for optimization a tensor program. First, we need to create
+# schedule on the initial IRModule created from either TVMScript or Tensor Expression. Then, a
+# sequence of schedule primitives will help to improve the performance. And at last, we can lower
+# and build it into a runnable module.
+#
+# Here we just demostrate a very simple tranformation. First we create schedule on the input ir_module.
+
+sch = tvm.tir.Schedule(ir_module)
+print(type(sch))
+
+################################################################################################
+# Tile the loops 8 into 3 loops and print the result.
+
+# Get block by its name
+block_b = sch.get_block("B")
+# Get loops surronding the block
+(i,) = sch.get_loops(block_b)
+# Tile the loop nesting.
+i_0, i_1, i_2 = sch.split(i, factors=[2, 2, 2])

Review comment:
       consider also show reorder

##########
File path: gallery/tutorial/tensor_ir_blitz_course.py
##########
@@ -0,0 +1,183 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+.. _tir_blitz:
+
+Blitz Course to TensorIR
+========================
+**Author**: `Siyuan Feng <https://github.com/Hzfengsy>`_
+
+TensorIR is a domain specific languages for deep learning programs serving two broad purposes:
+
+- An implementation for transforming and optimizing programs on various hardware backends.
+
+- An abstraction for automatic tensorized program optimization.
+
+"""
+
+import tvm
+from tvm.ir.module import IRModule
+from tvm.script import tir as T
+import numpy as np
+
+################################################################################################
+# IRModule
+# --------
+# An IRModule is the central data structure in TVM, which contains deep learning programs.
+# It is the basic object of interest of IR transformation and model building.
+#
+# .. image:: https://raw.githubusercontent.com/Hzfengsy/web-data/main/images/design/tvm_life_of_irmodule.png
+#    :align: center
+#    :width: 85%
+#
+# This is the life cycle of an IRModule, which can be created from TVM Script. TensorIR schedule
+# primitives and passes are two major ways to transform an IRModule. Also, a sequence of
+# transformations on an IRModule is acceptable. Note that we can print an IRModule at **ANY** stage
+# to TVMScript. After all transformations and optimizations are complete, we can build the IRModule
+# to a runnable module to deploy on target devices.
+#
+# Based on the design of TensorIR and IRModule, we are able to create a new programming method:
+#
+# 1. Write a program by TVMScript (just like write python codes)
+#
+# 2. Transform and optimize a program with python api (by schedule primitives and passes)
+#
+# 3. Interactively inspect and try the performance (print or build at any stage of IRModule)

Review comment:
       Interactively inspect and try the performance with an imperative style transformation API.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] tqchen commented on a change in pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
tqchen commented on a change in pull request #9315:
URL: https://github.com/apache/tvm/pull/9315#discussion_r734574998



##########
File path: gallery/tutorial/tensor_ir_blitz_course.py
##########
@@ -0,0 +1,183 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+.. _tir_blitz:
+
+Blitz Course to TensorIR
+========================
+**Author**: `Siyuan Feng <https://github.com/Hzfengsy>`_
+
+TensorIR is a domain specific languages for deep learning programs serving two broad purposes:
+
+- An implementation for transforming and optimizing programs on various hardware backends.
+
+- An abstraction for automatic tensorized program optimization.
+
+"""
+
+import tvm
+from tvm.ir.module import IRModule
+from tvm.script import tir as T
+import numpy as np
+
+################################################################################################
+# IRModule
+# --------
+# An IRModule is the central data structure in TVM, which contains deep learning programs.
+# It is the basic object of interest of IR transformation and model building.
+#
+# .. image:: https://raw.githubusercontent.com/Hzfengsy/web-data/main/images/design/tvm_life_of_irmodule.png
+#    :align: center
+#    :width: 85%
+#
+# This is the life cycle of an IRModule, which can be created from TVM Script. TensorIR schedule
+# primitives and passes are two major ways to transform an IRModule. Also, a sequence of
+# transformations on an IRModule is acceptable. Note that we can print an IRModule at **ANY** stage
+# to TVMScript. After all transformations and optimizations are complete, we can build the IRModule
+# to a runnable module to deploy on target devices.
+#
+# Based on the design of TensorIR and IRModule, we are able to create a new programming method:
+#
+# 1. Write a program by TVMScript (just like write python codes)
+#
+# 2. Transform and optimize a program with python api (by schedule primitives and passes)
+#
+# 3. Interactively inspect and try the performance (print or build at any stage of IRModule)
+
+
+################################################################################################
+# Create an IRModule
+# ------------------
+# IRModule can be created by writing TVMScript, which is a round-trippable syntax for TVM IR.
+#
+# Different than creating an computational expression by Tensor Expression

Review comment:
       avoid mentioning TE tutorial for now since that can change in the future. We can just directly say TensorIR allow users to write programs through tvm script, a language embedded in python AST




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] Hzfengsy commented on pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
Hzfengsy commented on pull request #9315:
URL: https://github.com/apache/tvm/pull/9315#issuecomment-950107335


   I totally agree with @quic-sanirudh. `T` would be much easier when we do round-trips. And we may move towards it.
   
   The only concern is that `T` is a alias of `tir`, which makes no sense without `from tvm.script import tir as T`. So I guess we may print `from tvm.script import tir as T` at the start of script if we want to use `T` (or any other alias different from `tir`) as default.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] MasterJH5574 commented on a change in pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
MasterJH5574 commented on a change in pull request #9315:
URL: https://github.com/apache/tvm/pull/9315#discussion_r736091392



##########
File path: gallery/tutorial/tensor_ir_blitz_course.py
##########
@@ -0,0 +1,191 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+.. _tir_blitz:
+
+Blitz Course to TensorIR
+========================
+**Author**: `Siyuan Feng <https://github.com/Hzfengsy>`_
+
+TensorIR is a domain specific language for deep learning programs serving two broad purposes:
+
+- An implementation for transforming and optimizing programs on various hardware backends.
+
+- An abstraction for automatic tensorized program optimization.
+
+"""
+
+import tvm
+from tvm.ir.module import IRModule
+from tvm.script import tir as T
+import numpy as np
+
+################################################################################################
+# IRModule
+# --------
+# An IRModule is the central data structure in TVM, which contains deep learning programs.
+# It is the basic object of interest of IR transformation and model building.
+#
+# .. image:: https://raw.githubusercontent.com/Hzfengsy/web-data/main/images/design/tvm_life_of_irmodule.png
+#    :align: center
+#    :width: 85%
+#
+# This is the life cycle of an IRModule, which can be created from TVM Script. TensorIR schedule
+# primitives and passes are two major ways to transform an IRModule. Also, a sequence of
+# transformations on an IRModule is acceptable. Note that we can print an IRModule at **ANY** stage
+# to TVMScript. After all transformations and optimizations are complete, we can build the IRModule
+# to a runnable module to deploy on target devices.
+#
+# Based on the design of TensorIR and IRModule, we are able to create a new programming method:
+#
+# 1. Write a program by TVMScript in a python-AST based syntax.
+#
+# 2. Transform and optimize a program with python api.
+#
+# 3. Interactively inspect and try the performance with an imperative style transformation API.
+
+
+################################################################################################
+# Create an IRModule
+# ------------------
+# IRModule can be created by writing TVMScript, which is a round-trippable syntax for TVM IR.
+#
+# Different than creating an computational expression by Tensor Expression
+# (:ref:`tutorial-tensor-expr-get-started`). TensorIR allow user to  programs through tvm script,
+# a language embedded in python AST. The new method makes it possible to write complex programs
+# and further schedule and optimize it.
+#
+# Following is an simple example for vector addition.
+#
+
+
+@tvm.script.ir_module
+class MyModule:
+    @T.prim_func
+    def main(a: T.handle, b: T.handle):
+        # We exchange data between function by handles, which are similar to pointer.
+        T.func_attr({"global_symbol": "main", "tir.noalias": True})
+        # Create buffer from handles.
+        A = T.match_buffer(a, (8,), dtype="float32")
+        B = T.match_buffer(b, (8,), dtype="float32")
+        for i in range(8):
+            # A block is an abstraction for computation.
+            with T.block("B"):
+                # Define a spatial block iterator and bind it to value i.
+                vi = T.axis.spatial(8, i)
+                B[vi] = A[vi] + 1.0
+
+
+ir_module = MyModule
+print(type(ir_module))
+print(ir_module.script())
+
+################################################################################################
+# Besides, we can also use tensor expression DSL to write simple operators, and convert them
+# to an IRModule.
+#
+
+from tvm import te
+
+A = te.placeholder((8,), dtype="float32", name="A")
+B = te.compute((8,), lambda *i: A(*i) + 1.0, name="B")
+func = te.create_prim_func([A, B])
+ir_module_from_te = IRModule({"main": func})
+print(ir_module_from_te.script())
+
+
+################################################################################################
+# Build and Run an IRModule
+# -------------------------
+# We can build the IRModule into a runnable module with specific target backends.
+#
+
+mod = tvm.build(ir_module, target="llvm")  # The module for CPU backends.
+print(type(mod))
+
+################################################################################################
+# Prepare the input array and output array, then run the module.
+#
+
+a = tvm.nd.array(np.arange(8).astype("float32"))
+b = tvm.nd.array(np.zeros((8,)).astype("float32"))
+mod(a, b)
+print(a)
+print(b)
+
+
+################################################################################################
+# Transform an IRModule
+# ---------------------
+# The IRModule is the central data structure for program optimization, which can be transformed
+# by :code:`Schedule`.
+# A schedule contains multiple primitive methods to interactively transform the program.
+# Each primitive transforms the program in certain ways to bring additional performance optimizations.
+#
+# .. image:: https://raw.githubusercontent.com/Hzfengsy/web-data/main/images/design/tvm_tensor_ir_opt_flow.png
+#    :align: center
+#    :width: 100%
+#
+# The image above is a typical workflow for optimization a tensor program. First, we need to create
+# schedule on the initial IRModule created from either TVMScript or Tensor Expression. Then, a
+# sequence of schedule primitives will help to improve the performance. And at last, we can lower
+# and build it into a runnable module.
+#
+# Here we just demostrate a very simple tranformation. First we create schedule on the input ir_module.

Review comment:
       ```suggestion
   # Here we just demostrate a very simple tranformation. First we create schedule on the input `ir_module`.
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] tqchen commented on a change in pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
tqchen commented on a change in pull request #9315:
URL: https://github.com/apache/tvm/pull/9315#discussion_r734575473



##########
File path: gallery/tutorial/tensor_ir_blitz_course.py
##########
@@ -0,0 +1,183 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+.. _tir_blitz:
+
+Blitz Course to TensorIR
+========================
+**Author**: `Siyuan Feng <https://github.com/Hzfengsy>`_
+
+TensorIR is a domain specific languages for deep learning programs serving two broad purposes:
+
+- An implementation for transforming and optimizing programs on various hardware backends.
+
+- An abstraction for automatic tensorized program optimization.
+
+"""
+
+import tvm
+from tvm.ir.module import IRModule
+from tvm.script import tir as T
+import numpy as np
+
+################################################################################################
+# IRModule
+# --------
+# An IRModule is the central data structure in TVM, which contains deep learning programs.
+# It is the basic object of interest of IR transformation and model building.
+#
+# .. image:: https://raw.githubusercontent.com/Hzfengsy/web-data/main/images/design/tvm_life_of_irmodule.png
+#    :align: center
+#    :width: 85%
+#
+# This is the life cycle of an IRModule, which can be created from TVM Script. TensorIR schedule
+# primitives and passes are two major ways to transform an IRModule. Also, a sequence of
+# transformations on an IRModule is acceptable. Note that we can print an IRModule at **ANY** stage
+# to TVMScript. After all transformations and optimizations are complete, we can build the IRModule
+# to a runnable module to deploy on target devices.
+#
+# Based on the design of TensorIR and IRModule, we are able to create a new programming method:
+#
+# 1. Write a program by TVMScript (just like write python codes)
+#
+# 2. Transform and optimize a program with python api (by schedule primitives and passes)
+#
+# 3. Interactively inspect and try the performance (print or build at any stage of IRModule)
+
+
+################################################################################################
+# Create an IRModule
+# ------------------
+# IRModule can be created by writing TVMScript, which is a round-trippable syntax for TVM IR.
+#
+# Different than creating an computational expression by Tensor Expression
+# (:ref:`tutorial-tensor-expr-get-started`). TensorIR allow user to write native programs, which
+# is similar with writing a Python program with for loops and computational body. The new method
+# makes it possible to write complex programs and further schedule and optimize it.
+#
+# Following is an simple example for vector addition.
+#
+
+
+@tvm.script.ir_module
+class MyModule:
+    @T.prim_func
+    def main(a: T.handle, b: T.handle):
+        # We exchange data between function by handles, which are similar to pointer.
+        T.func_attr({"global_symbol": "main", "tir.noalias": True})
+        # Create buffer from handles.
+        A = T.match_buffer(a, (8,), dtype="float32")
+        B = T.match_buffer(b, (8,), dtype="float32")
+        for i in range(8):
+            # A block is an abstraction for computation.
+            with T.block("B"):
+                # Define a spatial block iterator and bind it to value i.
+                vi = T.axis.spatial(8, i)
+                B[vi] = A[vi] + 1.0
+
+
+ir_module = MyModule
+print(type(ir_module))
+print(ir_module.script())
+
+################################################################################################
+# Besides, Tensor Expression (TE) is a really good abstraction for simple operators. TensorIR still

Review comment:
       We can also use tensor expression DSL to write simple operators, and convert them to an IRModule.

##########
File path: gallery/tutorial/tensor_ir_blitz_course.py
##########
@@ -0,0 +1,183 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+.. _tir_blitz:
+
+Blitz Course to TensorIR
+========================
+**Author**: `Siyuan Feng <https://github.com/Hzfengsy>`_
+
+TensorIR is a domain specific languages for deep learning programs serving two broad purposes:
+
+- An implementation for transforming and optimizing programs on various hardware backends.
+
+- An abstraction for automatic tensorized program optimization.
+
+"""
+
+import tvm
+from tvm.ir.module import IRModule
+from tvm.script import tir as T
+import numpy as np
+
+################################################################################################
+# IRModule
+# --------
+# An IRModule is the central data structure in TVM, which contains deep learning programs.
+# It is the basic object of interest of IR transformation and model building.
+#
+# .. image:: https://raw.githubusercontent.com/Hzfengsy/web-data/main/images/design/tvm_life_of_irmodule.png
+#    :align: center
+#    :width: 85%
+#
+# This is the life cycle of an IRModule, which can be created from TVM Script. TensorIR schedule
+# primitives and passes are two major ways to transform an IRModule. Also, a sequence of
+# transformations on an IRModule is acceptable. Note that we can print an IRModule at **ANY** stage
+# to TVMScript. After all transformations and optimizations are complete, we can build the IRModule
+# to a runnable module to deploy on target devices.
+#
+# Based on the design of TensorIR and IRModule, we are able to create a new programming method:
+#
+# 1. Write a program by TVMScript (just like write python codes)
+#
+# 2. Transform and optimize a program with python api (by schedule primitives and passes)
+#
+# 3. Interactively inspect and try the performance (print or build at any stage of IRModule)
+
+
+################################################################################################
+# Create an IRModule
+# ------------------
+# IRModule can be created by writing TVMScript, which is a round-trippable syntax for TVM IR.
+#
+# Different than creating an computational expression by Tensor Expression
+# (:ref:`tutorial-tensor-expr-get-started`). TensorIR allow user to write native programs, which
+# is similar with writing a Python program with for loops and computational body. The new method
+# makes it possible to write complex programs and further schedule and optimize it.
+#
+# Following is an simple example for vector addition.
+#
+
+
+@tvm.script.ir_module
+class MyModule:
+    @T.prim_func
+    def main(a: T.handle, b: T.handle):
+        # We exchange data between function by handles, which are similar to pointer.
+        T.func_attr({"global_symbol": "main", "tir.noalias": True})
+        # Create buffer from handles.
+        A = T.match_buffer(a, (8,), dtype="float32")
+        B = T.match_buffer(b, (8,), dtype="float32")
+        for i in range(8):
+            # A block is an abstraction for computation.
+            with T.block("B"):
+                # Define a spatial block iterator and bind it to value i.
+                vi = T.axis.spatial(8, i)
+                B[vi] = A[vi] + 1.0
+
+
+ir_module = MyModule
+print(type(ir_module))
+print(ir_module.script())
+
+################################################################################################
+# Besides, Tensor Expression (TE) is a really good abstraction for simple operators. TensorIR still
+# allow users to create IRModule from TE.
+#
+
+from tvm import te
+
+A = te.placeholder((8,), dtype="float32", name="A")
+B = te.compute((8,), lambda *i: A(*i) + 1.0, name="B")
+func = te.create_prim_func([A, B])
+ir_module_1 = IRModule({"main": func})

Review comment:
       ir_module_from_te




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] junrushao1994 merged pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
junrushao1994 merged pull request #9315:
URL: https://github.com/apache/tvm/pull/9315


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] tqchen commented on a change in pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
tqchen commented on a change in pull request #9315:
URL: https://github.com/apache/tvm/pull/9315#discussion_r731875826



##########
File path: gallery/tutorial/tensor_ir_blitz_course.py
##########
@@ -0,0 +1,135 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+.. _tir_blitz:
+
+Blitz Course to TensorIR
+========================
+**Author**: `Siyuan Feng <https://github.com/Hzfengsy>`_
+
+TensorIR is a domain specific languages for deep learning programs serving two broad purposes:
+
+- An implement for transforming and optimizing programs on various hardware backends.
+
+- An abstraction for automatic tensorized program optimization.
+
+"""
+
+import tvm
+from tvm.script import tir as T
+import numpy as np
+
+################################################################################################
+# IRModule
+# --------
+# An IRModule is the central data structure in TensorIR, which contains deep learning programs.
+# It is the basic object of interest of IR transformation and model building.
+#
+
+

Review comment:
       Thanks @Hzfengsy , i think it would be helpful to add a figure about "life of an IRModule" to show the static flow and runtime flow of these operations




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] MasterJH5574 commented on a change in pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
MasterJH5574 commented on a change in pull request #9315:
URL: https://github.com/apache/tvm/pull/9315#discussion_r735085668



##########
File path: gallery/tutorial/tensor_ir_blitz_course.py
##########
@@ -0,0 +1,191 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+.. _tir_blitz:
+
+Blitz Course to TensorIR
+========================
+**Author**: `Siyuan Feng <https://github.com/Hzfengsy>`_
+
+TensorIR is a domain specific languages for deep learning programs serving two broad purposes:

Review comment:
       👀
   ```suggestion
   TensorIR is a domain specific language for deep learning programs serving two broad purposes:
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] quic-sanirudh commented on pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
quic-sanirudh commented on pull request #9315:
URL: https://github.com/apache/tvm/pull/9315#issuecomment-949759035


   From my limited experience playing with TensorIR recently, I realized that almost all tests in TVM import the tir script as `from tvm.script import tir as T` and the same is used in the examples here. But, when we print out the prim_func using `print(func.script())` and try to manually modify parts of it and copy it back into our code, the printed prim_func always uses `tir.prim_func`, `tir.block()`, etc. In other words, it does not alias the `tir` module to `T`.
   
   If I understand correctly, one of the original design goals of TVM script is to support this sort of round trip, so would it make sense to try and make the syntax consistent between our examples in the documentation and the actual script being printed so that it's easy to copy paste without having to find and replace all instances of `tir` to `T`.
   
   I know the programmer can always choose to not alias `tir` module to `T`, but if it's used like that in the documentation, users are going to try and stick to that format.
   
   Just a small thing I wanted to bring up, let me know your thoughts.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] junrushao1994 commented on pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
junrushao1994 commented on pull request #9315:
URL: https://github.com/apache/tvm/pull/9315#issuecomment-952547107


   Sounds great! Let's do that


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] YuchenJin commented on a change in pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
YuchenJin commented on a change in pull request #9315:
URL: https://github.com/apache/tvm/pull/9315#discussion_r735706874



##########
File path: gallery/tutorial/tensor_ir_blitz_course.py
##########
@@ -0,0 +1,191 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+.. _tir_blitz:
+
+Blitz Course to TensorIR
+========================
+**Author**: `Siyuan Feng <https://github.com/Hzfengsy>`_
+
+TensorIR is a domain specific language for deep learning programs serving two broad purposes:
+
+- An implementation for transforming and optimizing programs on various hardware backends.
+
+- An abstraction for automatic tensorized program optimization.
+
+"""
+
+import tvm
+from tvm.ir.module import IRModule
+from tvm.script import tir as T
+import numpy as np
+
+################################################################################################
+# IRModule
+# --------
+# An IRModule is the central data structure in TVM, which contains deep learning programs.
+# It is the basic object of interest of IR transformation and model building.
+#
+# .. image:: https://raw.githubusercontent.com/Hzfengsy/web-data/main/images/design/tvm_life_of_irmodule.png
+#    :align: center
+#    :width: 85%
+#
+# This is the life cycle of an IRModule, which can be created from TVM Script. TensorIR schedule
+# primitives and passes are two major ways to transform an IRModule. Also, a sequence of
+# transformations on an IRModule is acceptable. Note that we can print an IRModule at **ANY** stage
+# to TVMScript. After all transformations and optimizations are complete, we can build the IRModule
+# to a runnable module to deploy on target devices.
+#
+# Based on the design of TensorIR and IRModule, we are able to create a new programming method:
+#
+# 1. Write a program by TVMScript in a python-AST based syntax.
+#
+# 2. Transform and optimize a program with python api.
+#
+# 3. Interactively inspect and try the performance with an imperative style transformation API.
+
+
+################################################################################################
+# Create an IRModule
+# ------------------
+# IRModule can be created by writing TVMScript, which is a round-trippable syntax for TVM IR.
+#
+# Different than creating an computational expression by Tensor Expression
+# (:ref:`tutorial-tensor-expr-get-started`). TensorIR allow user to  programs through tvm script,
+# a language embedded in python AST. The new method makes it possible to write complex programs
+# and further schedule and optimize it.

Review comment:
       small nits: "an computational expression" -> "a computational expression"
   "TensorIR allow user to programs through tvm script" -> "TensorIR allows users to program through TVMScript"
   "an simple example for vector addition" -> "a simple example of vector addition"




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] tqchen commented on a change in pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
tqchen commented on a change in pull request #9315:
URL: https://github.com/apache/tvm/pull/9315#discussion_r731862881



##########
File path: gallery/tutorial/tensor_ir_blitz_course.py
##########
@@ -0,0 +1,135 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+.. _tir_blitz:
+
+Blitz Course to TensorIR
+========================
+**Author**: `Siyuan Feng <https://github.com/Hzfengsy>`_
+
+TensorIR is a domain specific languages for deep learning programs serving two broad purposes:
+
+- An implement for transforming and optimizing programs on various hardware backends.
+
+- An abstraction for automatic tensorized program optimization.
+
+"""
+
+import tvm
+from tvm.script import tir as T
+import numpy as np
+
+################################################################################################
+# IRModule
+# --------
+# An IRModule is the central data structure in TensorIR, which contains deep learning programs.
+# It is the basic object of interest of IR transformation and model building.
+#
+
+
+################################################################################################
+# Create an IRModule
+# ------------------
+# IRModule can be created by writing TVMScript, which is a script syntax for TVM IR. (see the ref)
+# Here is a simple module for vector add.
+#
+
+
+@tvm.script.ir_module
+class MyModule:
+    @T.prim_func
+    def main(a: T.handle, b: T.handle):
+        # We exchange data between function by handles, which are similar to pointer.
+        T.func_attr({"global_symbol": "main", "tir.noalias": True})
+        # Create buffer from handles.
+        A = T.match_buffer(a, (8,), dtype="float32")
+        B = T.match_buffer(b, (8,), dtype="float32")
+        for i in range(8):
+            # A block is an abstraction for computation.
+            with T.block("B"):
+                # Define a spatial block iterator and bind it to value i.
+                vi = T.axis.spatial(8, i)
+                B[vi] = A[vi] + 1.0
+
+
+ir_module = MyModule
+print(type(ir_module))
+print(ir_module.script())
+
+################################################################################################

Review comment:
       Add an alternative section(create IRModule from tensor expression) to quickly show how to do the same thing from te




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] junrushao1994 commented on pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
junrushao1994 commented on pull request #9315:
URL: https://github.com/apache/tvm/pull/9315#issuecomment-952550201


   Thank you all for the huge effort!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] tqchen commented on pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
tqchen commented on pull request #9315:
URL: https://github.com/apache/tvm/pull/9315#issuecomment-949873841


   I agree with @quic-sanirudh that printing things as T might be better. We can do that as a separate PR


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] Hzfengsy commented on a change in pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
Hzfengsy commented on a change in pull request #9315:
URL: https://github.com/apache/tvm/pull/9315#discussion_r733646603



##########
File path: gallery/tutorial/tensor_ir_blitz_course.py
##########
@@ -0,0 +1,135 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+.. _tir_blitz:
+
+Blitz Course to TensorIR
+========================
+**Author**: `Siyuan Feng <https://github.com/Hzfengsy>`_
+
+TensorIR is a domain specific languages for deep learning programs serving two broad purposes:
+
+- An implement for transforming and optimizing programs on various hardware backends.
+
+- An abstraction for automatic tensorized program optimization.
+
+"""
+
+import tvm
+from tvm.script import tir as T
+import numpy as np
+
+################################################################################################
+# IRModule
+# --------
+# An IRModule is the central data structure in TensorIR, which contains deep learning programs.
+# It is the basic object of interest of IR transformation and model building.
+#
+
+
+################################################################################################
+# Create an IRModule
+# ------------------
+# IRModule can be created by writing TVMScript, which is a script syntax for TVM IR. (see the ref)

Review comment:
       Thanks for the reminding




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] Hzfengsy commented on pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
Hzfengsy commented on pull request #9315:
URL: https://github.com/apache/tvm/pull/9315#issuecomment-948598593


   Updated (together with the demo link). PTAL.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] YuchenJin commented on a change in pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
YuchenJin commented on a change in pull request #9315:
URL: https://github.com/apache/tvm/pull/9315#discussion_r732421803



##########
File path: gallery/tutorial/tensor_ir_blitz_course.py
##########
@@ -0,0 +1,135 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+.. _tir_blitz:
+
+Blitz Course to TensorIR
+========================
+**Author**: `Siyuan Feng <https://github.com/Hzfengsy>`_
+
+TensorIR is a domain specific languages for deep learning programs serving two broad purposes:
+
+- An implement for transforming and optimizing programs on various hardware backends.
+
+- An abstraction for automatic tensorized program optimization.
+
+"""
+
+import tvm
+from tvm.script import tir as T
+import numpy as np
+
+################################################################################################
+# IRModule
+# --------
+# An IRModule is the central data structure in TensorIR, which contains deep learning programs.
+# It is the basic object of interest of IR transformation and model building.
+#
+
+
+################################################################################################
+# Create an IRModule
+# ------------------
+# IRModule can be created by writing TVMScript, which is a script syntax for TVM IR. (see the ref)
+# Here is a simple module for vector add.
+#
+
+
+@tvm.script.ir_module
+class MyModule:
+    @T.prim_func
+    def main(a: T.handle, b: T.handle):
+        # We exchange data between function by handles, which are similar to pointer.
+        T.func_attr({"global_symbol": "main", "tir.noalias": True})
+        # Create buffer from handles.
+        A = T.match_buffer(a, (8,), dtype="float32")
+        B = T.match_buffer(b, (8,), dtype="float32")
+        for i in range(8):
+            # A block is an abstraction for computation.
+            with T.block("B"):
+                # Define a spatial block iterator and bind it to value i.
+                vi = T.axis.spatial(8, i)
+                B[vi] = A[vi] + 1.0
+
+
+ir_module = MyModule
+print(type(ir_module))
+print(ir_module.script())
+
+################################################################################################
+# Build and Run an IRModule
+# -------------------------
+# We can build the IRModule into a runnable module with specific target backends.
+#
+
+mod = tvm.build(ir_module, target="llvm")  # The module for CPU backends.
+print(type(mod))
+
+################################################################################################
+# Prepare the input array and output array, then run the module.
+#
+
+a = tvm.nd.array(np.arange(8).astype("float32"))
+b = tvm.nd.array(np.zeros((8,)).astype("float32"))
+mod(a, b)
+print(a)
+print(b)
+
+
+################################################################################################
+# Transform an IRModule
+# ---------------------
+# The IRModule is the central data structure for program optimization, which can be transformed
+# by :code:`Schedule`.
+# Schedule is consist of primitives. Each primitive does a simple job on IR transformation,
+# such as loop tiling or make computation parallel. (Please see ref)

Review comment:
       is consist of -> consists of




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] Hzfengsy commented on pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
Hzfengsy commented on pull request #9315:
URL: https://github.com/apache/tvm/pull/9315#issuecomment-947634473


   Thanks @areusch @jroesch. I totally agree that more introductory context is helpful. I'm working on it. 
   
   However, it is the first tutorial of TensorIR for the very beginning users (not for TVM experts). So I won't explain too much technical details in this tutorial (e.g. what's the difference between TE and TensorIR). More developing docs and tutorials are on the way.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] YuchenJin commented on a change in pull request #9315: [TensorIR][Tutorial] Blitz course

Posted by GitBox <gi...@apache.org>.
YuchenJin commented on a change in pull request #9315:
URL: https://github.com/apache/tvm/pull/9315#discussion_r735709947



##########
File path: gallery/tutorial/tensor_ir_blitz_course.py
##########
@@ -0,0 +1,191 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+.. _tir_blitz:
+
+Blitz Course to TensorIR
+========================
+**Author**: `Siyuan Feng <https://github.com/Hzfengsy>`_
+
+TensorIR is a domain specific language for deep learning programs serving two broad purposes:
+
+- An implementation for transforming and optimizing programs on various hardware backends.
+
+- An abstraction for automatic tensorized program optimization.
+
+"""
+
+import tvm
+from tvm.ir.module import IRModule
+from tvm.script import tir as T
+import numpy as np
+
+################################################################################################
+# IRModule
+# --------
+# An IRModule is the central data structure in TVM, which contains deep learning programs.
+# It is the basic object of interest of IR transformation and model building.
+#
+# .. image:: https://raw.githubusercontent.com/Hzfengsy/web-data/main/images/design/tvm_life_of_irmodule.png
+#    :align: center
+#    :width: 85%
+#
+# This is the life cycle of an IRModule, which can be created from TVM Script. TensorIR schedule
+# primitives and passes are two major ways to transform an IRModule. Also, a sequence of
+# transformations on an IRModule is acceptable. Note that we can print an IRModule at **ANY** stage
+# to TVMScript. After all transformations and optimizations are complete, we can build the IRModule
+# to a runnable module to deploy on target devices.
+#
+# Based on the design of TensorIR and IRModule, we are able to create a new programming method:
+#
+# 1. Write a program by TVMScript in a python-AST based syntax.
+#
+# 2. Transform and optimize a program with python api.
+#
+# 3. Interactively inspect and try the performance with an imperative style transformation API.
+
+
+################################################################################################
+# Create an IRModule
+# ------------------
+# IRModule can be created by writing TVMScript, which is a round-trippable syntax for TVM IR.
+#
+# Different than creating an computational expression by Tensor Expression
+# (:ref:`tutorial-tensor-expr-get-started`). TensorIR allow user to  programs through tvm script,
+# a language embedded in python AST. The new method makes it possible to write complex programs
+# and further schedule and optimize it.
+#
+# Following is an simple example for vector addition.
+#
+
+
+@tvm.script.ir_module
+class MyModule:
+    @T.prim_func
+    def main(a: T.handle, b: T.handle):
+        # We exchange data between function by handles, which are similar to pointer.
+        T.func_attr({"global_symbol": "main", "tir.noalias": True})
+        # Create buffer from handles.
+        A = T.match_buffer(a, (8,), dtype="float32")
+        B = T.match_buffer(b, (8,), dtype="float32")
+        for i in range(8):
+            # A block is an abstraction for computation.
+            with T.block("B"):
+                # Define a spatial block iterator and bind it to value i.
+                vi = T.axis.spatial(8, i)
+                B[vi] = A[vi] + 1.0
+
+
+ir_module = MyModule
+print(type(ir_module))
+print(ir_module.script())
+
+################################################################################################
+# Besides, we can also use tensor expression DSL to write simple operators, and convert them
+# to an IRModule.
+#
+
+from tvm import te
+
+A = te.placeholder((8,), dtype="float32", name="A")
+B = te.compute((8,), lambda *i: A(*i) + 1.0, name="B")
+func = te.create_prim_func([A, B])
+ir_module_from_te = IRModule({"main": func})
+print(ir_module_from_te.script())
+
+
+################################################################################################
+# Build and Run an IRModule
+# -------------------------
+# We can build the IRModule into a runnable module with specific target backends.
+#
+
+mod = tvm.build(ir_module, target="llvm")  # The module for CPU backends.
+print(type(mod))
+
+################################################################################################
+# Prepare the input array and output array, then run the module.
+#
+
+a = tvm.nd.array(np.arange(8).astype("float32"))
+b = tvm.nd.array(np.zeros((8,)).astype("float32"))
+mod(a, b)
+print(a)
+print(b)
+
+
+################################################################################################
+# Transform an IRModule
+# ---------------------
+# The IRModule is the central data structure for program optimization, which can be transformed
+# by :code:`Schedule`.
+# A schedule contains multiple primitive methods to interactively transform the program.
+# Each primitive transforms the program in certain ways to bring additional performance optimizations.
+#
+# .. image:: https://raw.githubusercontent.com/Hzfengsy/web-data/main/images/design/tvm_tensor_ir_opt_flow.png
+#    :align: center
+#    :width: 100%
+#
+# The image above is a typical workflow for optimization a tensor program. First, we need to create
+# schedule on the initial IRModule created from either TVMScript or Tensor Expression. Then, a

Review comment:
       "optimization" -> "optimizing"
   "create schedule" -> "create a schedule"




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org