This is an archive of the discontinued LLVM Phabricator instance.

[mlir][vector] Allow transposing multi_reduction when the parallel dim is in the middle
ClosedPublic

Authored by bkramer on Jan 24 2023, 9:03 AM.

Details

Summary

The check here was stricter than necessary, we just want all the
parallel dims to go to one side and all reduction dims to go to the
other.

Diff Detail

Event Timeline

bkramer created this revision.Jan 24 2023, 9:03 AM
Herald added a project: Restricted Project. · View Herald Transcript
bkramer requested review of this revision.Jan 24 2023, 9:03 AM
vmurali added a comment.EditedJan 25 2023, 12:38 PM

The original code is wrong when the case is outer-reductions. Instead, it should check that

!useInnerDimsForReduction &&
(parallelDims ==
 llvm::to_vector<4>(llvm::seq<int64_t>(reductionDims.size(), parallelDims.size() + reductionDims.size()))))

The code that you submitted wouldn't work if you switch the RUN command to use inner-reductions strategy for your test example. (There are other cases also where it wouldn't work.)

// RUN: mlir-opt %s -test-vector-multi-reduction-lowering-patterns | FileCheck %s

whereas the change I wrote should work.

Basically, you want to ensure that the transpose happens whenever the reduction dimensions are either not contiguous or not in the innermost/outermost dimensions depending on the strategy.

vmurali requested changes to this revision.Jan 25 2023, 12:45 PM
This revision now requires changes to proceed.Jan 25 2023, 12:45 PM
bkramer updated this revision to Diff 492393.Jan 26 2023, 4:46 AM
  • Address review comments
  • Add a test to make sure the inner reduction strategy still works
vmurali accepted this revision.Jan 26 2023, 8:36 AM
This revision is now accepted and ready to land.Jan 26 2023, 8:36 AM