junrushao1994 commented on a change in pull request #22:
URL: https://github.com/apache/tvm-rfcs/pull/22#discussion_r698097515



##########
File path: rfcs/0022-tir-non-scalar-constants.md
##########
@@ -0,0 +1,107 @@
+
+- Feature Name: tir_non_scalar_constants
+- Start Date: 2021-06-01
+- RFC PR: https://github.com/apache/tvm-rfcs/pull/22
+- GitHub Issue: TBD
+
+# 1. Summary
+
+This RFC proposes how non-scalar constants could be represented in TIR and 
used by passes in the lowering process.
+
+# 2. Motivation 
+
+Currently, the non-scalar constants could be represented in Relay 
(relay.Constant) to be used by relay passes but not in TIR. Therefore, when 
performing lowering using TIR passes, we have to maintain a side-channel of 
tir::Var to constant non-scalar data mapping to perform transformations that 
could use the knowledge where some of the data are constants.
+
+Few example scenarios as further motivation :
+
+## Weight compression
+
+When lowering for accelerators (E.g. : [Arm(R) Ethos(TM)-U 
NPU](https://github.com/apache/tvm-rfcs/pull/11)), certain operations will need 
to get tiled to co-optimize performance and memory utilization. Such tiling 
patterns create slices of weights that need compressing that will end up with 
varying sizes. Therefore, the knowledge of some tir::Vars refer to constants 
are critical in the level of TIR to perform this.
+
+## Memory Planning
+
+The TIR program has the ability to express both inter and intra operator 
memory requirement, post-scheduling as explained further by [Unified Static 
Memory Planning RFC](https://github.com/apache/tvm-rfcs/pull/9). It would be 
better if the constants could be embedded to the TIR PrimFunc. Moreover, this 
allows various [target-dependent 
lowerings](https://github.com/apache/tvm-rfcs/pull/10), to produce TIR 
PrimFuncs with constants in it.
+
+## Winograd Constants
+
+The Winograd transformation (used for fast GEMMs) involves multiplication by a 
hard-coded constant tensor. This is currently accomplished in TE using a 
complicated TE compute expression with many nested selects. Being able to 
directly express a constant tensor here would significantly simplify this code.

Review comment:
       The constants in wingrad convolutions are a relatively small matrix, 
which are always unrolled in TIR scheduling, inlined in generated binary and 
thus won't incur any extra storage like what `relay.Constant` does. So my 
question is, how does this RFC handle inlining such constants into 
corresponding unrolled operations?
   
   As a concrete example, suppose we have the code snippet below:
   
   ```python
   tir.constant(c, [1, 2, 3])  # a temporary syntax for declaring constants
   for i in tir.unroll(3):
     a[i] = b[i] * c[i]
   ```
   
   Does this RFC consider the pass that inlines these constants into the code 
and transform into the following TIR:
   
   ```python
   a[0] = b[0] * 1
   a[1] = b[1] * 2
   a[2] = b[2] * 3
   ```




-- 
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-unsubscr...@tvm.apache.org

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


Reply via email to