Skip to content

Commit 365c2d6

Browse files
authored
Merge pull request #524 from Xilinx/jrickert.bump_integration
Tosa Changes Integration
2 parents f93946e + 11193c5 commit 365c2d6

37 files changed

+1792
-178
lines changed

mlir/cmake/modules/AddMLIR.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,8 @@ function(mlir_target_link_libraries target type)
732732
endif()
733733

734734
if (MLIR_LINK_MLIR_DYLIB)
735-
target_link_libraries(${target} ${type} MLIR)
735+
# AMD: Do not link shared, as this casues linking errors
736+
target_link_libraries(${target} ${type} ${ARGN})
736737
else()
737738
target_link_libraries(${target} ${type} ${ARGN})
738739
endif()

mlir/cmake/modules/AddMLIRPython.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
# grouping. Source groupings form a DAG.
2424
# SOURCES: List of specific source files relative to ROOT_DIR to include.
2525
# SOURCES_GLOB: List of glob patterns relative to ROOT_DIR to include.
26+
27+
if (POLICY CMP0175)
28+
cmake_policy(SET CMP0175 OLD)
29+
endif()
30+
2631
function(declare_mlir_python_sources name)
2732
cmake_parse_arguments(ARG
2833
""
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
//===- AffineExprBounds.h - Compute bounds of affine expressions *- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This header file defines an analysis of affine expressions to compute their
10+
// ranges (lower/upper bounds) in a given context.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
#ifndef MLIR_ANALYSIS_AFFINEEXPRBOUNDS_H
14+
#define MLIR_ANALYSIS_AFFINEEXPRBOUNDS_H
15+
16+
#include "mlir/IR/AffineExprVisitor.h"
17+
#include "mlir/IR/Attributes.h"
18+
#include "mlir/IR/BuiltinAttributes.h"
19+
#include "mlir/Interfaces/InferIntRangeInterface.h"
20+
21+
#include "mlir/IR/AffineExpr.h"
22+
#include "mlir/IR/AffineMap.h"
23+
#include "mlir/Support/LogicalResult.h"
24+
25+
using namespace mlir;
26+
27+
/// This visitor computes the bounds of affine expressions, using as context the
28+
/// bounds of the dimensions of the expression.
29+
///
30+
/// Example:
31+
/// Given bounds 0 <= d0 <= 99 and 0 <= d1 <= 199, we can compute the bounds
32+
/// of the following expression:
33+
/// lb(2 * d0 + 3 * d1) = 0
34+
/// ub(2 * d0 + 3 * d1) = 795
35+
///
36+
/// * The bounds given in the context are inclusive, and the bounds returned
37+
/// are also inclusive.
38+
/// * If bounds are not available for a dimension, std::nullopt can be used
39+
/// instead. The bounds of an expression that involves it will be std::nullopt.
40+
/// * Limitations:
41+
/// - Parametric expressions (using symbols) are not supported.
42+
/// - Unsigned FloorDiv is currently not supported.
43+
class AffineExprBoundsVisitor
44+
: public AffineExprVisitor<AffineExprBoundsVisitor, LogicalResult> {
45+
public:
46+
/// Initialize the context (bounds) with APInt. All bounds must have the same
47+
/// signedness and bit width.
48+
AffineExprBoundsVisitor(ArrayRef<std::optional<APInt>> constLowerBounds,
49+
ArrayRef<std::optional<APInt>> constUpperBounds,
50+
bool boundsSigned, uint64_t bitWidth,
51+
MLIRContext *context);
52+
53+
/// Initialize the context (bounds) with 64-bit signed integers. This allows
54+
/// to directly map index-type values such as Linalg op bounds, which are
55+
/// represented as int64_t.
56+
AffineExprBoundsVisitor(ArrayRef<std::optional<int64_t>> constLowerBounds,
57+
ArrayRef<std::optional<int64_t>> constUpperBounds,
58+
MLIRContext *context);
59+
60+
/// Get the upper bound of \p expr using the context bounds.
61+
std::optional<APInt> getUpperBound(AffineExpr expr);
62+
std::optional<int64_t> getIndexUpperBound(AffineExpr expr);
63+
64+
/// Get the lower bound of \p expr using the context bounds.
65+
std::optional<APInt> getLowerBound(AffineExpr expr);
66+
std::optional<int64_t> getIndexLowerBound(AffineExpr expr);
67+
68+
// These methods are directly called by the AffineExprVisitor base class.
69+
LogicalResult visitMulExpr(AffineBinaryOpExpr expr);
70+
LogicalResult visitAddExpr(AffineBinaryOpExpr expr);
71+
LogicalResult visitDimExpr(AffineDimExpr expr);
72+
LogicalResult visitSymbolExpr(AffineSymbolExpr expr);
73+
LogicalResult visitConstantExpr(AffineConstantExpr expr);
74+
LogicalResult visitCeilDivExpr(AffineBinaryOpExpr expr);
75+
LogicalResult visitFloorDivExpr(AffineBinaryOpExpr expr);
76+
LogicalResult visitModExpr(AffineBinaryOpExpr expr);
77+
78+
private:
79+
bool boundsSigned;
80+
uint64_t bitWidth;
81+
void inferBinOpRange(
82+
AffineBinaryOpExpr expr,
83+
const std::function<ConstantIntRanges(ArrayRef<ConstantIntRanges>)>
84+
&opInference);
85+
86+
/// Bounds that have been computed for subexpressions are memoized and reused.
87+
llvm::DenseMap<AffineExpr, APInt> lb;
88+
llvm::DenseMap<AffineExpr, APInt> ub;
89+
};
90+
91+
#endif // MLIR_ANALYSIS_AFFINEEXPRBOUNDS_H

mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -860,11 +860,6 @@ def LinalgStructuredInterface
860860
/// `createFlatListOfOperandDims`.
861861
SmallVector<Range, 4> createLoopRanges(OpBuilder &b, Location loc);
862862

863-
/// Compute the static loop sizes necessary to vectorize the computation.
864-
/// This is done by applying `getShapesToLoopsMap` to
865-
/// `createFlatListOfOperandStaticDims`.
866-
SmallVector<int64_t, 4> computeStaticLoopSizes();
867-
868863
/// Returns the value that expresses the shape of the output in terms of
869864
/// shape of the input operands where possible
870865
LogicalResult reifyResultShapes(OpBuilder &b,

mlir/include/mlir/Dialect/PDL/IR/Builtins.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ enum class UnaryOpKind {
4343
LogicalResult addEntryToDictionaryAttr(PatternRewriter &rewriter,
4444
PDLResultList &results,
4545
ArrayRef<PDLValue> args);
46-
Attribute addElemToArrayAttr(PatternRewriter &rewriter, Attribute attr,
47-
Attribute element);
46+
LogicalResult addElemToArrayAttr(PatternRewriter &rewriter,
47+
PDLResultList &results,
48+
ArrayRef<PDLValue> args);
4849
LogicalResult mul(PatternRewriter &rewriter, PDLResultList &results,
4950
llvm::ArrayRef<PDLValue> args);
5051
LogicalResult div(PatternRewriter &rewriter, PDLResultList &results,

mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,6 +1724,7 @@ def Tosa_TileOp : Tosa_InferShapedTypeOp<"tile"> {
17241724
}];
17251725

17261726
let hasFolder = 1;
1727+
let hasCanonicalizer = 1;
17271728
let hasVerifier = 1;
17281729
}
17291730

@@ -1877,6 +1878,15 @@ def Tosa_CastOp: Tosa_Op<"cast", [Pure,
18771878
| signed 16 to float | int16 | float |
18781879
| float 32 to float 64 | float32 | float64 |
18791880
| float 64 to float 32 | float64 | float32 |
1881+
1882+
AMD extensions:
1883+
| signed to unsigned | signed | unsigned|
1884+
| unsigned to signed | unsigned| signed |
1885+
| unsigned to float | unsigned| float |
1886+
- unsigned to signed integer and signed to unsigned integer:
1887+
wrap on overflow
1888+
- unsigned to float:
1889+
uses llvm's float to int conversion with TOSA rounding mode
18801890
}];
18811891

18821892
let arguments = (ins

mlir/include/mlir/Dialect/Tosa/Utils/ConversionUtils.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ LogicalResult EqualizeRanks(PatternRewriter &rewriter, Location loc,
8484
LogicalResult EqualizeRanks(ImplicitLocOpBuilder &builder, Value &input1,
8585
Value &input2);
8686

87+
Value getTosaConstShape(ImplicitLocOpBuilder &builder,
88+
llvm::ArrayRef<int64_t> shape);
89+
90+
Value getTosaConstShape(PatternRewriter &rewriter, Location loc,
91+
llvm::ArrayRef<int64_t> shape);
92+
93+
// Get accumulator type for TOSA convolution ops
94+
LogicalResult getConvOpsAccType(PatternRewriter &rewriter,
95+
RankedTensorType inputTy,
96+
RankedTensorType weightTy,
97+
RankedTensorType outputTy, TypeAttr &accType);
98+
8799
namespace {
88100

89101
// Creates a TOSA operation and performs shape inference on the individual
@@ -217,7 +229,8 @@ TosaOp CreateOpAndInferShape(PatternRewriter &rewriter, Location loc,
217229
}
218230

219231
// Apply an int32_t permutation to some input, that should be of the same
220-
// size as perms. Perms should contain some permutation of 0 - perms.size() - 1.
232+
// size as perms. Perms should contain some permutation of 0 - perms.size()
233+
// - 1.
221234
template <typename T>
222235
SmallVector<T> applyTOSAPermutation(ArrayRef<T> input,
223236
ArrayRef<int32_t> perms) {

mlir/include/mlir/IR/AffineExpr.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ class AffineExpr {
110110
/// floordiv, ceildiv, and mod is only allowed w.r.t constants.
111111
bool isPureAffine() const;
112112

113+
/// Returns true if this expression is monotonicically increasing with respect
114+
/// to the AffineDimExprs, i.e. increasing the value of any AffineDimExpr will
115+
/// never decrease the value of the result.
116+
bool isMonotonicallyIncreasing() const;
117+
113118
/// Returns the greatest known integral divisor of this affine expression. The
114119
/// result is always positive.
115120
int64_t getLargestKnownDivisor() const;

0 commit comments

Comments
 (0)