Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Canonicalizers for doubly strided ops such as npu.dma_cpy_nd #680

Merged
merged 1 commit into from
Aug 19, 2024

Conversation

newling
Copy link
Contributor

@newling newling commented Aug 15, 2024

Doubly strided ops have, for both source and target, and for all of offsets/sizes/strides, 2 fields:

  1. a vector of dynamic Values
  2. a vector of static integers

For example it might be

  1. dynamic = {v0}
  2. static = {16, kDynamic, 32, 64}

The size of dynamic is always exactly equal to the number of appearances of kDynamic in the static vector. This pass does the following: it checks if any of the Values in dynamic are actually MLIR constants, and if they are then it removes the Value from the dynamic vector and updates the corresponding index in static. So for example if v0 above is actually

%v0 = arith.constant 6 : index

then this canonicalization updates dynamic/static to

  1. dynamic = {}
  2. static = {16, 6, 32, 64}

@newling newling changed the title Canonicalize npu.dma_cpy_nd Canonicalizer for npu.dma_cpy_nd Aug 15, 2024
Copy link
Collaborator

@MaheshRavishankar MaheshRavishankar left a comment

Choose a reason for hiding this comment

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

There is a canonicalizer upstream here that does this, but it is a bit hard-coded for tensor.extract_slice like op that have a single offset , size and stride. It should be split up to handle each of the offset , size and stride separately. Then you could reuse that here. Maybe just use the same style here to be consistent

Copy link
Contributor

@jtuyls jtuyls left a comment

Choose a reason for hiding this comment

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

Nice, should help make IR more compact and readable! Would be great to do for all doubly strided ops in one go I think.

@MaheshRavishankar
Copy link
Collaborator

Actually, if your wait for this PR (llvm/llvm-project#104488) it might get even easier

@newling newling force-pushed the npu_dma_cpy_nd_canonicalizer branch from 3f0ca36 to 1de7f26 Compare August 16, 2024 18:23
@newling
Copy link
Contributor Author

newling commented Aug 16, 2024

@MaheshRavishankar thanks for the pointer, I've changed to use the same style for now.
@jtuyls ok, will get this working for all the doubly strided ops

@newling newling changed the title Canonicalizer for npu.dma_cpy_nd Canonicalizers for doubly strided ops such as npu.dma_cpy_nd Aug 16, 2024
@newling newling force-pushed the npu_dma_cpy_nd_canonicalizer branch from 8e99191 to a0a4bad Compare August 16, 2024 20:29
@newling newling requested a review from jtuyls August 16, 2024 21:34
Copy link
Contributor

@jtuyls jtuyls left a comment

Choose a reason for hiding this comment

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

LGTM, just a few small nits

@@ -93,6 +90,70 @@ TileOp CoreOp::getTileOp() {
// AMDAIE_DmaCpyNdBaseOp
//===----------------------------------------------------------------------===//

namespace {
// Simplified from upstream MLIR's foldDynamicIndexList:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Simplified from upstream MLIR's foldDynamicIndexList:
/// Simplified from upstream MLIR's foldDynamicIndexList:

Nit, but IREE uses /// for function/class comments.

Comment on lines +109 to +110
// Based on upstream MLIR's
// OpWithOffsetSizesAndStridesConstantArgumentFolder
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Based on upstream MLIR's
// OpWithOffsetSizesAndStridesConstantArgumentFolder
/// Based on upstream MLIR's
/// OpWithOffsetSizesAndStridesConstantArgumentFolder

Nit, but IREE uses /// for function/class comments.

Comment on lines +525 to +526
// Build a NpuDmaCpyNdOp with mixed static and dynamic entries and target
// and source BD IDs.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Build a NpuDmaCpyNdOp with mixed static and dynamic entries and target
// and source BD IDs.
/// Build a NpuDmaCpyNdOp with mixed static and dynamic entries and target
/// and source BD IDs.

@newling
Copy link
Contributor Author

newling commented Aug 19, 2024

LGTM, just a few small nits

Ok I'll use /// by default in future. As this particular file uses both /// and // quite a lot I'm not going to update this PR.

@newling newling merged commit aa112f7 into nod-ai:main Aug 19, 2024
2 checks passed
@newling newling deleted the npu_dma_cpy_nd_canonicalizer branch August 29, 2024 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants