Skip to content
This repository has been archived by the owner on Apr 23, 2021. It is now read-only.

LICM pass zero trip count loop handling; zero trip count loop removal in #203

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bondhugula
Copy link
Contributor

-simplify-affine-structures

Signed-off-by: Uday Bondhugula [email protected]

lib/Dialect/LoopOps/LoopOps.cpp Outdated Show resolved Hide resolved
lib/Transforms/SimplifyAffineStructures.cpp Outdated Show resolved Hide resolved
tools/mlir-tblgen/OpInterfacesGen.cpp Outdated Show resolved Hide resolved
include/mlir/Transforms/LoopLikeInterface.td Outdated Show resolved Hide resolved
lib/Dialect/LoopOps/LoopOps.cpp Show resolved Hide resolved
lib/Transforms/SimplifyAffineStructures.cpp Outdated Show resolved Hide resolved
lib/Dialect/LoopOps/LoopOps.cpp Outdated Show resolved Hide resolved
include/mlir/Transforms/LoopLikeInterface.td Outdated Show resolved Hide resolved
lib/Transforms/SimplifyAffineStructures.cpp Outdated Show resolved Hide resolved
-simplify-affine-structures

- addresses tensorflow#194

- change name of tablegen auto-generated internal helper for op
  interfaces to avoid potential conflicts with methods of same
  name in dialect namespaces. (addresses tensorflow#197)

Signed-off-by: Uday Bondhugula <[email protected]>
@@ -22,6 +22,7 @@
#ifndef MLIR_TRANSFORMS_LOOPLIKEINTERFACE_H_
#define MLIR_TRANSFORMS_LOOPLIKEINTERFACE_H_

#include "mlir/Analysis/LoopAnalysis.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a problem in terms of dependencies (Bazel is catching some cycles for us here).

The problem is that while the LoopOps.h which defines the LoopOps dialect is correctly providing a self-contained version of getConstantTripCount, the Affine dialect is not: instead it relies on the getConstantTripCount provided by the Analysis library.
Having the affine dialect itself be dependent on the Analysis library, while the Analysis library is also depending on Affine does not seem right.

I suspect all the Affine specific Analysis should be moved into the affine dialect to avoid the cycle.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This issue was discussed on this thread: https://groups.google.com/a/tensorflow.org/forum/?utm_medium=email&utm_source=footer#!msg/mlir/6DV_IbyfnQ8/0Ub44e0eDgAJ

While moving the Analysis into the dialect is one solution, the plan from the start has been to keep ops separate from analysis and transforms, and not have a dependence from the dialect ops to analysis/transforms. The issue here is that LoopInterface.h is needed both for "op support" and "analysis support". In this scenario which is a first I think, there is a free function being generated via the operation interface. If we had a separate header for it, we wouldn't have that being included from the affine dialect. Note that the affine dialect is not using getConstantTripCount anywhere inside (only those that already depend on Analysis use it). It's actually odd / out of line that something from "mlir/Transforms/" is being included into include/mlir/Dialect/AffineOps/AffineOps.h! (see here:

#include "mlir/Transforms/LoopLikeInterface.h"
)

So, the larger issue is that: since operation interfaces could be used to generate reusable op get/set methods as well as analysis/transform methods, shouldn't we be segregating their headers? If we want to go with merging affine analysis and ops, at some point, the issue of merging standardops and analysis/transforms is also likely to come up.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in general we'll have something like:

  • lib/Transforms & lib/Analysis : should contain core logic, using only interfaces. These should not depend on dialects like Affine.
  • lib/Dialect/XYZ/Transforms & lib/Dialect/XYZ/Analysis : dialect specific passes. For instance we have already lib/Dialect/Linalg/Analysis/ and lib/Dialect/Linalg/Transforms/
  • include/mlir/Interfaces/... : self-contained interface headers intended to implemented/overridden in dialects and used everywhere.

(I haven't thought much further, there might be another reasonable and scalable option)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but this doesn't solve the dependence cycle issue we have here unless you have:

include/mlir/Interfaces/Ops/...
include/mlir/Interfaces/Analysis/
include/mlir/Interfaces/Transforms/

(Because the cycle in context is created due to dialect ops depending on Interfaces and Interfaces depending on Analysis. Having the above separation would mean a Dialect/XYZ/Ops would only depend on InterfaceOps and InterfaceAnalysis can depend on Analysis/ or any Dialect/XYZ/Analysis. )

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the cycle in context is created due to dialect ops depending on Interfaces and Interfaces depending on Analysis

Can you clarify how is this interface depending on Analysis?

I don't see a direct dependency other than the Affine situation. For instance the use of this interface in the loop dialect does not pull anything from Analysis as far as I can tell.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the cycle in context is created due to dialect ops depending on Interfaces and Interfaces depending on Analysis

Can you clarify how is this interface depending on Analysis?

The interface method getConstantTripCount depends on the analysis method mlir::getConstantTripCount for AffineForOp, but for loop::ForOp depends on ForOp::getConstantTripCount, which is simpler (doesn't need analysis) and is thus an op method.

I don't see a direct dependency other than the Affine situation. For instance the use of this interface in the loop dialect does not pull anything from Analysis as far as I can tell.

That's because: for loop::forOp, mlir::loop::getConstantTripCount doesn't rely on Analysis and lives on loop::ForOp itself. It's a method of loop::ForOp defined in Dialect/LoopOps/LoopOps.cpp unlike the free function mlir::getConstantTripCount(AffineForOp) in mlir/Analysis/LoopAnalysis.cpp.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with what you wrote, but my conclusion is that the interface itself does not depends on Analysis. Only the affine dialect does.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants