tenstorrent / tt-mlir

Tenstorrent MLIR compiler
https://tenstorrent.github.io/tt-mlir/
Apache License 2.0
75 stars 11 forks source link

TTNN Op Interface: Op constraints #304

Open rjakovljevicTT opened 3 months ago

rjakovljevicTT commented 3 months ago

What Provide a TTNN API to return Op constraints to the TT-MLIR optimizer/legalizer. The goal of this issue is to do an end-to-end PoC and conclude what would be the proper solution. Based on the conclusion we will open a new issue to define the whole work.

PoC Initially, on an example of MNIST NN and all Ops that are parts of MNIST, do the following tasks:

The above tasks should be done Iteratively until it works well for both TT-MLIR Optimizer and TTNN.

ajakovljevicTT commented 2 months ago

For this (v0) sprint, we have decided that we are going to support only a subset of operations and their different implementations (colloquially called "flavors"), with the emphasis being on the MNIST model and its operations. With that in mind, we have decided on the following ops and "flavors":

With this in mind, we have made a set of factories for every op, which construct the corresponding builder objects, which can return a set of valid constraints for optimizer to use. Currently, we have (somewhat arbitrarily) decided that the parameters that define a constraint are:

Other parameters that the op needs, such as shape, sharding, orientation, currently we expect the tilizer to provide. However, this decision is not fixed, and is still susceptible to change.
Most importantly, this has an impact on how we decide "flavors" of an op. Currently, we expect the optimizer to tell the constraint framework which "flavor" it wants and fill out the necessary objects with information for that. However, this logic is better suited to stay on the tt-nn side, which requires information on datatypes. This means that the division of this information between what is provided to the constraint framework and what the framework returns is currently not fully compatible with choosing of operation "flavors" in the constraint framework.

The set of functionalities described above has been implemented in the [feature/mlir-interface] (https://github.com/tenstorrent/tt-metal/tree/feature/mlir-interface) branch, along with the corresponding test, and the overall path of process can be tracked through several PRs to this branch:

Still TBD:

As of this point, there is a WIP prototype that plugs the constraint framework into tt-mlir (more details here: https://github.com/tenstorrent/tt-metal/pull/12700).