Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b02c7e2

Browse files
committedAug 7, 2022
[Polly] Generalize the pattern matching to the case of tensor contractions
The pattern matching optimization of Polly detects and optimizes dense general matrix-matrix multiplication. The generated code is close to high performance implementations of matrix-matrix multiplications, which are contained in manually tuned libraries. The described pattern matching optimization is a particular case of tensor contraction optimization, which was introduced in [1]. This patch generalizes the pattern matching to the case of tensor contractions using the form of data dependencies and memory accesses produced by tensor contractions [1]. Optimization of tensor contractions will be added in the next patch. Following the ideas introduced in [2], it will logically represent tensor contraction operands as matrix multiplication operands and use an approach for optimization of matrix-matrix multiplications. [1] - Gareev R., Grosser T., Kruse M. High-Performance Generalized Tensor Op­erations: A Compiler-Oriented Approach // ACM Transactions on Architec­ture and Code Optimization (TACO). 2018. Vol. 15, no. 3. P. 34:1–34:27. DOI: 10.1145/3235029. [2] - Matthews D. High-Performance Tensor Contraction without BLAS // SIAM Journal on Scientific Computing. 2018. Vol. 40, no. 1. P. C 1—C 24. DOI: 110.1137/16m108968x. Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D114336
1 parent 6bb51bf commit b02c7e2

21 files changed

+1734
-21
lines changed
 

‎polly/include/polly/Support/ISLTools.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,11 @@ isl::set subtractParams(isl::set Set, isl::set Params);
523523
/// value. Otherwise, return NaN.
524524
isl::val getConstant(isl::pw_aff PwAff, bool Max, bool Min);
525525

526+
/// If the relation @p PwAff lies on a hyperplane where the given
527+
/// dimension @p Pos with the type @p Dim has a fixed value, then
528+
/// return that value. Otherwise return NaN.
529+
isl::val getConstant(isl::map Map, isl::dim Dim, int Pos);
530+
526531
/// Check that @p End is valid and return an iterator from @p Begin to @p End
527532
///
528533
/// Use case example:

‎polly/lib/Support/ISLTools.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,18 @@ isl::map polly::shiftDim(isl::map Map, isl::dim Dim, int Pos, int Amount) {
263263
}
264264
}
265265

266+
isl::val polly::getConstant(isl::map Map, isl::dim Dim, int Pos) {
267+
unsigned NumDims = unsignedFromIslSize(Map.dim(Dim));
268+
if (Pos < 0)
269+
Pos = NumDims + Pos;
270+
assert(unsigned(Pos) < NumDims && "Dimension index must be in range");
271+
// TODO: The isl_map_plain_get_val_if_fixed function is not robust, since its
272+
// result is different depending on the internal representation.
273+
// Replace it with a different implementation.
274+
return isl::manage(isl_map_plain_get_val_if_fixed(
275+
Map.get(), static_cast<enum isl_dim_type>(Dim), Pos));
276+
}
277+
266278
isl::union_map polly::shiftDim(isl::union_map UMap, isl::dim Dim, int Pos,
267279
int Amount) {
268280
isl::union_map Result = isl::union_map::empty(UMap.ctx());

0 commit comments

Comments
 (0)
Please sign in to comment.