Skip to content

Tosa Changes Integration #524

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

Merged
merged 47 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
d59e6b9
Fix problem where the shape of the insert shape was calculated incorr…
josel-amd Feb 14, 2025
b39a27c
Revert "Revert "Merge pull request #407 from Xilinx/matthias.fix_non_…
josel-amd Feb 17, 2025
9406825
Revert change on the TileUsingInterface.cpp
josel-amd Feb 17, 2025
0c37ff2
Check for monotonic functions
josel-amd Feb 17, 2025
e273ea6
Update tests
josel-amd Feb 17, 2025
aeda3ee
[mlir][linalg] Remove `computeStaticLoopSizes` (#124778) (#475)
josel-amd Feb 18, 2025
b31574a
Merge pull request #465 from Xilinx/bump_to_3494ee95
jorickert Feb 18, 2025
fe9d73c
Remove ununsed function
josel-amd Feb 19, 2025
e69f389
Merge pull request #470 from Xilinx/jose.fix_insert_tile_problem
mgehre-amd Feb 19, 2025
3c94045
When writing PDLL patterns it is often assumed that some basic checks…
jorickert Feb 18, 2025
91ca2e1
Merge pull request #474 from Xilinx/jrickert.constraints_prio
jorickert Feb 21, 2025
b3be25a
Do not print unnecessary newlines if attributes are elided
jorickert Feb 22, 2025
2b2e860
Merge pull request #481 from Xilinx/jrickert.print_newline_skipped_attrs
jorickert Feb 24, 2025
8f479a4
Update comment and message about folding cast where the input has mul…
jorickert Mar 4, 2025
b40461d
Compute affine expression bounds
cferry-AMD Mar 4, 2025
a8c0978
Add width for int64_t interface, remove one warning
cferry-AMD Mar 4, 2025
cce9117
Merge pull request #482 from Xilinx/corentin.affine_expr_bounds
cferry-AMD Mar 5, 2025
3e3f092
Ensure 0 <= x mod N < N semantics
cferry-AMD Mar 6, 2025
350e0bd
Merge pull request #484 from Xilinx/corentin.mod_bounds
mgehre-amd Mar 6, 2025
212603a
Add tosa.cast folding for unsigned integers
jorickert Mar 5, 2025
1656bbb
Merge pull request #483 from Xilinx/jrickert.cast_folding
jorickert Mar 7, 2025
88bd7cf
Merge pull request #469 from Xilinx/bump_to_ceeb08b9
mgehre-amd Mar 12, 2025
f0a4187
Merge pull request #473 from Xilinx/bump_to_258a5d49
mgehre-amd Mar 12, 2025
55654e9
Canonicalize 'self-concats' to tile
jorickert Mar 11, 2025
358df15
Fold consecutive tosa.tiles
jorickert Mar 11, 2025
eb3aed5
Extend concat -> slice canonicalization to remove concat inputs if po…
jorickert Mar 11, 2025
0aad4d9
Add canonicalization pattern for tile -> slice to minimize the tile m…
jorickert Mar 11, 2025
b87be4f
Add check for canonicalization of slice(concat %a, %a)) = %a
jorickert Mar 12, 2025
c733a76
Merge pull request #471 from Xilinx/bump_to_68a39081
jorickert Mar 13, 2025
2afdeee
Add test for complete folding of tile + slice
jorickert Mar 13, 2025
6bdce9c
Merge pull request #478 from Xilinx/bump_to_beff2bac
jorickert Mar 13, 2025
8859aa8
Merge pull request #486 from Xilinx/jrickert.fold_concat
jorickert Mar 14, 2025
d1b83b6
Merge pull request #476 from Xilinx/bump_to_cbc78022
jorickert Mar 14, 2025
33ab764
Merge pull request #479 from Xilinx/bump_to_56eb559b
jorickert Mar 14, 2025
bb0d9a5
Merge pull request #477 from Xilinx/bump_to_776476c2
jorickert Mar 17, 2025
e896a3e
Merge remote-tracking branch 'origin/feature/fused-ops' into jrickert…
jorickert Mar 20, 2025
bb99503
Pick getTosaConstShape helper from 571a987
jorickert Mar 21, 2025
51065a3
Do not link internal mlir-libs shared, even if MLIR_LINK_MLIR_DYLIB …
jorickert Mar 24, 2025
de23f58
Move getConvOpsAccType from torch-mlir 12250739bfe85b702f9503cad45c2e…
jorickert Mar 24, 2025
dd65947
feat: allow arrayAttr parsing in constraint
mathmer-amd Mar 18, 2025
4c14f66
test: check some edge cases
mathmer-amd Mar 18, 2025
cba66f4
chore: add assertion
mathmer-amd Mar 18, 2025
a474457
chore: use llvm::SmallVector
mathmer-amd Mar 19, 2025
a008a59
test: array with contraints results
mathmer-amd Mar 20, 2025
4cfc438
Check valid emitc float/opaque types, not float (#525)
TinaAMD Mar 27, 2025
61a20b8
cmake: Use old CMP0175 policy
mgehre-amd Apr 1, 2025
11193c5
Add support for folding tosa.slice with tosa.slice
jorickert Apr 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion mlir/cmake/modules/AddMLIR.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,8 @@ function(mlir_target_link_libraries target type)
endif()

if (MLIR_LINK_MLIR_DYLIB)
target_link_libraries(${target} ${type} MLIR)
# AMD: Do not link shared, as this casues linking errors
target_link_libraries(${target} ${type} ${ARGN})
else()
target_link_libraries(${target} ${type} ${ARGN})
endif()
Expand Down
5 changes: 5 additions & 0 deletions mlir/cmake/modules/AddMLIRPython.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
# grouping. Source groupings form a DAG.
# SOURCES: List of specific source files relative to ROOT_DIR to include.
# SOURCES_GLOB: List of glob patterns relative to ROOT_DIR to include.

if (POLICY CMP0175)
cmake_policy(SET CMP0175 OLD)
endif()

function(declare_mlir_python_sources name)
cmake_parse_arguments(ARG
""
Expand Down
91 changes: 91 additions & 0 deletions mlir/include/mlir/Analysis/AffineExprBounds.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//===- AffineExprBounds.h - Compute bounds of affine expressions *- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This header file defines an analysis of affine expressions to compute their
// ranges (lower/upper bounds) in a given context.
//
//===----------------------------------------------------------------------===//
#ifndef MLIR_ANALYSIS_AFFINEEXPRBOUNDS_H
#define MLIR_ANALYSIS_AFFINEEXPRBOUNDS_H

#include "mlir/IR/AffineExprVisitor.h"
#include "mlir/IR/Attributes.h"
#include "mlir/IR/BuiltinAttributes.h"
#include "mlir/Interfaces/InferIntRangeInterface.h"

#include "mlir/IR/AffineExpr.h"
#include "mlir/IR/AffineMap.h"
#include "mlir/Support/LogicalResult.h"

using namespace mlir;

/// This visitor computes the bounds of affine expressions, using as context the
/// bounds of the dimensions of the expression.
///
/// Example:
/// Given bounds 0 <= d0 <= 99 and 0 <= d1 <= 199, we can compute the bounds
/// of the following expression:
/// lb(2 * d0 + 3 * d1) = 0
/// ub(2 * d0 + 3 * d1) = 795
///
/// * The bounds given in the context are inclusive, and the bounds returned
/// are also inclusive.
/// * If bounds are not available for a dimension, std::nullopt can be used
/// instead. The bounds of an expression that involves it will be std::nullopt.
/// * Limitations:
/// - Parametric expressions (using symbols) are not supported.
/// - Unsigned FloorDiv is currently not supported.
class AffineExprBoundsVisitor
: public AffineExprVisitor<AffineExprBoundsVisitor, LogicalResult> {
public:
/// Initialize the context (bounds) with APInt. All bounds must have the same
/// signedness and bit width.
AffineExprBoundsVisitor(ArrayRef<std::optional<APInt>> constLowerBounds,
ArrayRef<std::optional<APInt>> constUpperBounds,
bool boundsSigned, uint64_t bitWidth,
MLIRContext *context);

/// Initialize the context (bounds) with 64-bit signed integers. This allows
/// to directly map index-type values such as Linalg op bounds, which are
/// represented as int64_t.
AffineExprBoundsVisitor(ArrayRef<std::optional<int64_t>> constLowerBounds,
ArrayRef<std::optional<int64_t>> constUpperBounds,
MLIRContext *context);

/// Get the upper bound of \p expr using the context bounds.
std::optional<APInt> getUpperBound(AffineExpr expr);
std::optional<int64_t> getIndexUpperBound(AffineExpr expr);

/// Get the lower bound of \p expr using the context bounds.
std::optional<APInt> getLowerBound(AffineExpr expr);
std::optional<int64_t> getIndexLowerBound(AffineExpr expr);

// These methods are directly called by the AffineExprVisitor base class.
LogicalResult visitMulExpr(AffineBinaryOpExpr expr);
LogicalResult visitAddExpr(AffineBinaryOpExpr expr);
LogicalResult visitDimExpr(AffineDimExpr expr);
LogicalResult visitSymbolExpr(AffineSymbolExpr expr);
LogicalResult visitConstantExpr(AffineConstantExpr expr);
LogicalResult visitCeilDivExpr(AffineBinaryOpExpr expr);
LogicalResult visitFloorDivExpr(AffineBinaryOpExpr expr);
LogicalResult visitModExpr(AffineBinaryOpExpr expr);

private:
bool boundsSigned;
uint64_t bitWidth;
void inferBinOpRange(
AffineBinaryOpExpr expr,
const std::function<ConstantIntRanges(ArrayRef<ConstantIntRanges>)>
&opInference);

/// Bounds that have been computed for subexpressions are memoized and reused.
llvm::DenseMap<AffineExpr, APInt> lb;
llvm::DenseMap<AffineExpr, APInt> ub;
};

#endif // MLIR_ANALYSIS_AFFINEEXPRBOUNDS_H
5 changes: 0 additions & 5 deletions mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td
Original file line number Diff line number Diff line change
Expand Up @@ -860,11 +860,6 @@ def LinalgStructuredInterface
/// `createFlatListOfOperandDims`.
SmallVector<Range, 4> createLoopRanges(OpBuilder &b, Location loc);

/// Compute the static loop sizes necessary to vectorize the computation.
/// This is done by applying `getShapesToLoopsMap` to
/// `createFlatListOfOperandStaticDims`.
SmallVector<int64_t, 4> computeStaticLoopSizes();

/// Returns the value that expresses the shape of the output in terms of
/// shape of the input operands where possible
LogicalResult reifyResultShapes(OpBuilder &b,
Expand Down
5 changes: 3 additions & 2 deletions mlir/include/mlir/Dialect/PDL/IR/Builtins.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ enum class UnaryOpKind {
LogicalResult addEntryToDictionaryAttr(PatternRewriter &rewriter,
PDLResultList &results,
ArrayRef<PDLValue> args);
Attribute addElemToArrayAttr(PatternRewriter &rewriter, Attribute attr,
Attribute element);
LogicalResult addElemToArrayAttr(PatternRewriter &rewriter,
PDLResultList &results,
ArrayRef<PDLValue> args);
LogicalResult mul(PatternRewriter &rewriter, PDLResultList &results,
llvm::ArrayRef<PDLValue> args);
LogicalResult div(PatternRewriter &rewriter, PDLResultList &results,
Expand Down
10 changes: 10 additions & 0 deletions mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,7 @@ def Tosa_TileOp : Tosa_InferShapedTypeOp<"tile"> {
}];

let hasFolder = 1;
let hasCanonicalizer = 1;
let hasVerifier = 1;
}

Expand Down Expand Up @@ -1877,6 +1878,15 @@ def Tosa_CastOp: Tosa_Op<"cast", [Pure,
| signed 16 to float | int16 | float |
| float 32 to float 64 | float32 | float64 |
| float 64 to float 32 | float64 | float32 |

AMD extensions:
| signed to unsigned | signed | unsigned|
| unsigned to signed | unsigned| signed |
| unsigned to float | unsigned| float |
- unsigned to signed integer and signed to unsigned integer:
wrap on overflow
- unsigned to float:
uses llvm's float to int conversion with TOSA rounding mode
}];

let arguments = (ins
Expand Down
15 changes: 14 additions & 1 deletion mlir/include/mlir/Dialect/Tosa/Utils/ConversionUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ LogicalResult EqualizeRanks(PatternRewriter &rewriter, Location loc,
LogicalResult EqualizeRanks(ImplicitLocOpBuilder &builder, Value &input1,
Value &input2);

Value getTosaConstShape(ImplicitLocOpBuilder &builder,
llvm::ArrayRef<int64_t> shape);

Value getTosaConstShape(PatternRewriter &rewriter, Location loc,
llvm::ArrayRef<int64_t> shape);

// Get accumulator type for TOSA convolution ops
LogicalResult getConvOpsAccType(PatternRewriter &rewriter,
RankedTensorType inputTy,
RankedTensorType weightTy,
RankedTensorType outputTy, TypeAttr &accType);

namespace {

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

// Apply an int32_t permutation to some input, that should be of the same
// size as perms. Perms should contain some permutation of 0 - perms.size() - 1.
// size as perms. Perms should contain some permutation of 0 - perms.size()
// - 1.
template <typename T>
SmallVector<T> applyTOSAPermutation(ArrayRef<T> input,
ArrayRef<int32_t> perms) {
Expand Down
5 changes: 5 additions & 0 deletions mlir/include/mlir/IR/AffineExpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ class AffineExpr {
/// floordiv, ceildiv, and mod is only allowed w.r.t constants.
bool isPureAffine() const;

/// Returns true if this expression is monotonicically increasing with respect
/// to the AffineDimExprs, i.e. increasing the value of any AffineDimExpr will
/// never decrease the value of the result.
bool isMonotonicallyIncreasing() const;

/// Returns the greatest known integral divisor of this affine expression. The
/// result is always positive.
int64_t getLargestKnownDivisor() const;
Expand Down
Loading