apache / tvm

Open deep learning compiler stack for cpu, gpu and specialized accelerators
https://tvm.apache.org/
Apache License 2.0
11.6k stars 3.44k forks source link

[RFC][Tracking Issue] TensorIR Scheduling #7527

Closed tqchen closed 2 years ago

tqchen commented 3 years ago

This is a global tracking issue for landing the initial PRs of TensorIR scheduling. The original RFC can be found here. Please feel free to bring in more questions to the corresponding thread.

To make the improvement manageable, we will be breaking the code into several steps. The main architecture scaffolding and data structure changes will come first, then we will upstream individual scheduling primitives in a incremental way, where each component are self-contained.

Key Data Structures

The following key data structures will be introduced to handle the support of TensorIR. Logically the data structures belongs to the following layers:

These data structures will form the initial scafolds. The transformation primitives will then become like passes, that only depends on D0 and D1. The each primitive will be exposed to an user facing API via D2.

Steps

tqchen commented 3 years ago

key data structures are updated as per @jcf94 's comment

manupak commented 3 years ago

Hi @junrushao1994 @Hzfengsy ,

Thanks for the effort that goes in here. Some of this scheduling primitives are really useful that are not there in TE.

Will there be a task to integrate these scheduling primitives to be used by main compilation flow? (i.e. relay.build) ?

Hzfengsy commented 3 years ago

Thanks, @manupa-arm.

Of course, we will! The ultimate goal of TensorIR is to replace the current TE schedule.

Before integrating it to relay, we need to finish all of our M2 items (there are only two left). Here are the following steps:

manupak commented 3 years ago

Ack. Thanks.

Out of curiosity for the planned relay integration,

junrushao commented 3 years ago

Hey @manupa-arm thanks for your interest!

Will the integration be using #7987 ?

Most of the operators are defined with the TE DSL in TOPI, so in these cases we will definitely use #7987, which converts TE compute dag to TensorIR.

If you guys have decided, please let us know what other the APIs (at least initially) be used to create the high-level non scheduled Primfunc?

Yep, we introduced a python-based text format (so it's the frontend for TensorIR DSL) as a convenient way to write scehduleable TensorIR. Our unittests contain a lot of examples of these: https://github.com/apache/tvm/blob/main/tests/python/unittest/test_tir_schedule_split_fuse.py#L29-L34.

Will it include rewriting schedules in TOPI? i.e. decoupling te.compute and scheduling applied to TE graph as passes?

Great question! While #7987 converts TE compute dag to TensorIR, we cannot reuse TOPI's schedule and AutoTVM schedule templates. However, as meta schedule is coming to the rescue, in most of the cases, schedule can be generated automatically with meta schedule. We are designing some APIs to allow customized schedule as well.

Happy to discuss more if you are interested :-)

manupak commented 3 years ago

Hey @junrushao1994 ,

Thanks for the clarifications.

Since the relay integration is supposed to be happening prior to meta schedule is being concluded, will there be a default 'schedule' (or maybe in the context of TensorIR: default set of scheduling passes) used in a relay.build flow ?

Hzfengsy commented 3 years ago

Hey @manupa-arm,

Don't worry. We will make TensorIR be an optional but not the default backend of relay as our first step. There must be many works (including meta schedule and some corner cases that meta schedule can not generate automatically) to do before totally switching TE to TensorIR.

On the other hand, if you really want to use TensorIR in compilation flow before meta-schedule, you may have to rewrite TOPI schedules you need. Theoretically, we can use both TE and TensorIR in one relay network (i.e., use TensorIR for one special Op but use TE for the rest). Unfortunately, our current implementation does not support it. And we haven't decided if we will support it.

manupak commented 3 years ago

Ack, Many thanks for the info 🙂!

junrushao commented 3 years ago

Hey @manupa-arm, to clarify, Relay integration is probably not happening prior to meta schedule, but along with meta schedule (see M4a of meta schedule timeline). Right now we can use either #7987 or just handwrite TensorIR to play with the scheduling/codegen code path

manupak commented 3 years ago

Thanks @junrushao1994.

tqchen commented 2 years ago

All the items are merged as of today. As a result, this issue is closed. Thanks everyone for pushing and landing this major effort.