This is an archive of the discontinued LLVM Phabricator instance.

[mlir][gpu] Add `uniform` flag to gpu reduction ops
ClosedPublic

Authored by Hardcode84 on Nov 27 2022, 6:20 AM.

Diff Detail

Event Timeline

Hardcode84 created this revision.Nov 27 2022, 6:20 AM
Hardcode84 requested review of this revision.Nov 27 2022, 6:20 AM

Sorry for the slow review. Why are we adding it without any lowering? The goal is to lower to SPIRV that has those semantics?

mlir/include/mlir/Dialect/GPU/IR/GPUOps.td
692

I wonder if the flag should be reverted and be uniform instead. non_uniform should be the default as it is the most conservative case. This way unless specified the op is created without the uniform assumption.
What do you think?

mlir/lib/Dialect/GPU/Transforms/AllReduceLowering.cpp
398

Should this be an error?

Sorry for the slow review. Why are we adding it without any lowering? The goal is to lower to SPIRV that has those semantics?

I was planning to add spirv lowering in separate review.

mlir/include/mlir/Dialect/GPU/IR/GPUOps.td
692

The idea itself is ok to me, but:

  • We are changing default semantics and it can broke user code without any warning
  • Historically, at least in spirv, uniform ops appeared much earlier than non-uniform (i.e. GroupFAdd is 1.0 but GroupNonUniformFAdd is 1.3)
mlir/lib/Dialect/GPU/Transforms/AllReduceLowering.cpp
398

There is no good way to return error from rewrite, I think. Even if we use emitError it will only change error message, but won't propagate it.

ThomasRaoux added inline comments.Dec 12 2022, 11:54 AM
mlir/include/mlir/Dialect/GPU/IR/GPUOps.td
692

using non-uniform version should be conservative and correct at the GPU level. The part that does break is the lowering and there should be an explicit lowering failure there.

Historically, at least in spirv, uniform ops appeared much earlier than non-uniform (i.e. GroupFAdd is 1.0 but GroupNonUniformFAdd is 1.3)

I wonder if this is due to the order in which those got added. If there were added at the same time and/or we didn't have to keep compatibility I would guess that's not how they would have been done.

mlir/lib/Dialect/GPU/Transforms/AllReduceLowering.cpp
398

Yes, in general we should just fail the pattern, here because this pattern tries to convert the whole function this is a bit awkward.
I think the best would be to fail the pattern and return notifyMatchFailure.

rebase, invert flag, fix pattern

Hardcode84 marked 4 inline comments as done.Dec 13 2022, 10:07 AM
ThomasRaoux accepted this revision.Dec 13 2022, 10:10 AM
This revision is now accepted and ready to land.Dec 13 2022, 10:10 AM
Hardcode84 retitled this revision from [mlir][gpu] Add `non_uniform` flag to gpu reduction ops to [mlir][gpu] Add `uniform` flag to gpu reduction ops.Dec 13 2022, 10:11 AM
This revision was automatically updated to reflect the committed changes.