[REFACTOR][TE][TIR] Call::Halide => ProducerLoad, DSL/TIR decouple. (#5743)
authorTianqi Chen <tqchen@users.noreply.github.com>
Sun, 7 Jun 2020 21:11:05 +0000 (14:11 -0700)
committerGitHub <noreply@github.com>
Sun, 7 Jun 2020 21:11:05 +0000 (14:11 -0700)
commit6ae439c8c58dd0118d2f2c5d1c4bcb650df47104
tree46dff550f2a4500fb59bb2920514cc06b0b692f7
parent7053546a9a89c05657431dca07250e949c3e7866
[REFACTOR][TE][TIR] Call::Halide => ProducerLoad, DSL/TIR decouple. (#5743)

In the HalideIR's design, DSL components and IR are mixed together.
For example, Call::Halide can containa reference to a function which is
constructed in the tensor expression language.

While this coupled design simplifies certain aspect of the DSL construction,
it prevents the TIR to evolve as a clean standalone IR:

- The additional tensor expression provided in the function is opaque to the IR
  and may become obsolete as we transform them.
- The duplication of the information in the DSL tensor and IR makes it hard to
  design a stand-alone text format (when there are elements shared in the tensor
  expression and normal statements).

This PR aims to clearly de-couple the TIR from high-level DSL structures(tensor expression),
while still provide clear extensions to build DSLs on top of the TIR.

We introduce a DataProducer as a base class for high level tensor expressions objects
that produce data. We then introduce ProducerLoad to replace the Call::Halide usage,
so that the Call node can always be self contained and used for low-level calls.

The high-level tensor expression DSL can still generate a PrimExpr that contains a ProducerLoad.
These PrimExprs contains fragments of information that can be combined together to
generate a low-level TIR PrimFunc.

We also state clearly that DataProducer **should not** appear in any TIR PrimFunc.
Instead, the high-level DSL layer should lowered DataProducers to Buffers and TIR statements
that produces these buffers. We can further provide verifications to validate such invariance.

Changes:
- Introduce DataProducer to serve as a base class for Tensor in tensor expressions.
- Migrate use of Call::Halide to ProducerLoad
- Migrate the other usages of Calls.

We will also create follow-up PRs to migrate the remaining two DSL related IR nodes(Realize/Provide)
to use the DataProducer.
44 files changed:
include/tvm/te/tensor.h
include/tvm/tir/buffer.h
include/tvm/tir/expr.h
include/tvm/tir/expr_functor.h
python/tvm/autotvm/task/task.py
python/tvm/target/datatype.py
python/tvm/te/hybrid/parser.py
python/tvm/te/hybrid/util.py
python/tvm/te/tensor.py
python/tvm/tir/__init__.py
python/tvm/tir/buffer.py
python/tvm/tir/expr.py
python/tvm/tir/ir_builder.py
python/tvm/tir/op.py
src/contrib/hybrid/codegen_hybrid.cc
src/contrib/hybrid/codegen_hybrid.h
src/printer/text_printer.h
src/printer/tir_text_printer.cc
src/te/autodiff/jacobian.cc
src/te/operation/compute_op.cc
src/te/operation/hybrid_op.cc
src/te/operation/op_util.cc
src/te/operation/tensorize.cc
src/te/schedule/graph.cc
src/te/schedule/operation_inline.cc
src/te/schedule/schedule_ops.cc
src/te/schedule/schedule_postproc_rewrite_for_tensor_core.cc
src/te/schedule/schedule_postproc_to_primfunc.cc
src/te/tensor.cc
src/tir/ir/expr.cc
src/tir/ir/expr_functor.cc
src/tir/transforms/storage_flatten.cc
src/tir/transforms/vectorize_loop.cc
tests/lint/git-clang-format.sh
tests/python/unittest/test_arith_canonical_simplify.py
tests/python/unittest/test_target_codegen_llvm.py
tests/python/unittest/test_te_hybrid_script.py
tests/python/unittest/test_tir_constructor.py
tests/python/unittest/test_tir_nodes.py
tests/python/unittest/test_tir_transform_combine_context_call.py
topi/python/topi/cuda/rcnn/proposal.py
topi/python/topi/cuda/sort.py
vta/python/vta/environment.py
vta/python/vta/transform.py