Commit Graph

11765 Commits

Author SHA1 Message Date
Matthias Springer 76f7e4b7a3 [mlir][SCF][bufferize][NFC] Utilize recently added helper function
This should have been part of D128666.

Differential Revision: https://reviews.llvm.org/D128885
2022-06-30 09:54:52 +02:00
Fangrui Song 67854f9ed0 Use value_or instead of getValueOr. NFC 2022-06-29 21:55:02 -07:00
Aart Bik e057f25dee [mlir][sparse] auto-insertion of conversion to resolve cycles
When the iteration graph is cyclic (even after several attempts using less and less constraints), the current sparse compiler bails out, and no rewriting hapens. However, this revision adds some new logic where the sparse compiler tries to find a single input sparse tensor that breaks the cycle, and then adds a proper sparse conversion operation. This way, more incoming kernels can be handled!

Note, the resulting code is not optimal (although it keeps more or less proper "sparse" complexity), and more improvements should be added (especially when the kernel directly yields without computation, such as the transpose example). However, handling is better than not handling ;-)

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D128847
2022-06-29 18:28:18 -07:00
Min-Yih Hsu 9bad9248ed [mlir][LLVMIR] Apply SubElementTypeInterface on suitable types
This feature is tested by unit test since not many places in the codebase
use SubElementTypeInterface.

Differential Revision: https://reviews.llvm.org/D127539
2022-06-29 13:58:02 -07:00
Min-Yih Hsu d41028610b [mlir] Prevent SubElementInterface from going into infinite recursion
Since only mutable types and attributes can go into infinite recursion
inside SubElementInterface::walkSubElement, and there are only a few of
them (mutable types and attributes), we introduce new traits for Type
and Attribute: TypeTrait::IsMutable and AttributeTrait::IsMutable,
respectively. They indicate whether a type or attribute is mutable.
Such traits are required if the ImplType defines a `mutate` function.

Then, inside SubElementInterface, we use a set to record visited mutable
types and attributes that have been visited before.

Differential Revision: https://reviews.llvm.org/D127537
2022-06-29 13:58:02 -07:00
rdzhabarov ef2c837a73 [Fix] Fix compilation warning on unused var. 2022-06-29 19:54:49 +00:00
River Riddle 0d9e51ea42 [mlir] Update the pass crash reproducer documentation
The reproducer is now encoded using an external resource, instead
of a comment at the top of the file.
2022-06-29 12:23:11 -07:00
River Riddle 361acbb362 [mlir] Refactor pass crash reproducer generation to be an assembly resource
We currently generate reproducer configurations using a comment placed at
the top of the generated .mlir file. This is kind of hacky given that comments
have no semantic context in the source file and can easily be dropped. This
strategy also wouldn't work if/when we have a bitcode format. This commit
switches to using an external assembly resource, which is verifiable/can
work with a hypothetical bitcode naturally/and removes the awkward processing
from mlir-opt for splicing comments and re-applying command line options. With
the removal of command line munging, this opens up new possibilities for
executing reproducers in memory.

Differential Revision: https://reviews.llvm.org/D126447
2022-06-29 12:14:02 -07:00
River Riddle ea488bd6e1 [mlir] Allow for attaching external resources to .mlir files
This commit enables support for providing and processing external
resources within MLIR assembly formats. This is a mechanism with which
dialects, and external clients, may attach additional information when
printing IR without that information being encoded in the IR itself.
External resources are not uniqued within the MLIR context, are not
attached directly to any operation, and are solely intended to live and be
processed outside of the immediate IR. There are many potential uses of this
functionality, for example MLIR's pass crash reproducer could utilize this to
attach the pass resource executing when a crash occurs. Other types of
uses may be embedding large amounts of binary data, such as weights in ML
applications, that shouldn't be copied directly into the MLIR context, but
need to be kept adjacent to the IR.

External resources are encoded using a key-value pair nested within a
dictionary anchored by name either on a dialect, or an externally registered
entity. The key is an identifier used to disambiguate the data. The value
may be stored in various limited forms, but general encodings use a string
(human readable) or blob format (binary). Within the textual format, an
example may be of the form:

```mlir
{-#
  // The `dialect_resources` section within the file-level metadata
  // dictionary is used to contain any dialect resource entries.
  dialect_resources: {
    // Here is a dictionary anchored on "foo_dialect", which is a dialect
    // namespace.
    foo_dialect: {
      // `some_dialect_resource` is a key to be interpreted by the dialect,
      // and used to initialize/configure/etc.
      some_dialect_resource: "Some important resource value"
    }
  },
  // The `external_resources` section within the file-level metadata
  // dictionary is used to contain any non-dialect resource entries.
  external_resources: {
    // Here is a dictionary anchored on "mlir_reproducer", which is an
    // external entity representing MLIR's crash reproducer functionality.
    mlir_reproducer: {
      // `pipeline` is an entry that holds a crash reproducer pipeline
      // resource.
      pipeline: "func.func(canonicalize,cse)"
    }
  }
```

Differential Revision: https://reviews.llvm.org/D126446
2022-06-29 12:14:01 -07:00
Benoit Jacob 694ad3eaef Fix CombineContractBroadcast folding reduction iterators.
Fix CombineContractBroadcast folding reduction iterators.

Differential Revision: https://reviews.llvm.org/D128739
2022-06-29 18:01:56 +00:00
Nicolas Vasilache 0fb24a85cb [mlir][Tensor] Improve documentation of verification behavior of InsertSliceOp. 2022-06-29 07:52:54 -07:00
Nicolas Vasilache 741f8f2bed [mlir][Tensor][NFC] Better document rank-reducing behavior of ExtractSliceOp and cleanup 2022-06-29 07:37:58 -07:00
Mehdi Amini 84124ff891 Apply clang-tidy fixes for readability-simplify-boolean-expr in ViewLikeInterface.cpp (NFC) 2022-06-29 12:15:39 +00:00
Mehdi Amini be7997221d Apply clang-tidy fixes for readability-identifier-naming in Float16bits.cpp (NFC) 2022-06-29 12:13:57 +00:00
Arjun P d08522f5bc [MLIR][Preburger] fix typo covertVarKind -> convertVarKind
Also update parameter names in the implementation file to match the header.
2022-06-29 13:08:20 +01:00
Arjun P 7236e5de54 Revert clang-tidy fixes for readability-simplify-boolean-expr and add NOLINT
The original code is more readable because the goal is to check if the given
value does *not* lie in the range. It is harder to understand this by
reading the rewritten code.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D128753
2022-06-29 12:23:35 +01:00
Benjamin Kramer 206a6037a0 [Presburger] Cheat around old versions of clang not doing NRVO when there's a derived-to-base cast in the way
Should be NFC. We can just do the base conversion manually and avoid
warnings about it. Clang before Clang 13 didn't implement P1825 and
complains:

mlir/lib/Analysis/Presburger/IntegerRelation.cpp:226:10: warning: local variable 'result' will be copied
      despite being returned by name [-Wreturn-std-move]
  return result;
         ^~~~~~
mlir/lib/Analysis/Presburger/IntegerRelation.cpp:226:10: note: call 'std::move' explicitly to avoid copying
  return result;
         ^~~~~~
         std::move(result)
2022-06-29 12:40:59 +02:00
Christian Sigg f6d00bac77 Revert "Add default copy and move c'tor/assignment to PresburgerRelation."
This reverts commit 2cd468ef15.
2022-06-29 12:24:28 +02:00
Christian Sigg 2cd468ef15 Add default copy and move c'tor/assignment to PresburgerRelation.
Differential Revision: https://reviews.llvm.org/D128789
2022-06-29 12:07:55 +02:00
lewuathe 0180709590 [mlir][complex] Canonicalization for consecutive complex.neg
Consecutive complex.neg are redundant so that we can canonicalize them to the original operands.

Reviewed By: pifon2a

Differential Revision: https://reviews.llvm.org/D128781
2022-06-29 11:11:40 +02:00
Adrian Kuegel 0a6e29f455 Revert "[mlir][Presburger] Fix warning Wreturn-std-move (NFC)"
This reverts commit a4070a5e77.
It introduced another warning instead.
2022-06-29 09:22:36 +02:00
Adrian Kuegel a4070a5e77 [mlir][Presburger] Fix warning Wreturn-std-move (NFC) 2022-06-29 09:10:20 +02:00
lorenzo chelini 58a55107c2 [MLIR][Math] Improve docs for round op (NFC)
Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D128662
2022-06-29 08:35:07 +02:00
Peixin-Qiao 1795f8cd2e [NFC][OpenMP] Fix worksharing-loop
1. Remove the redundant collapse clause in MLIR OpenMP worksharing-loop
   operation.
2. Fix several typos.
3. Refactor the chunk size type conversion since CreateSExtOrTrunc has
   both type check and type conversion.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D128338
2022-06-29 12:20:03 +08:00
River Riddle 9560f02141 [mlir] Add `enableSplitting` and `insertMarkerInOutput` options to `splitAndProcessBuffer`
`enableSplitting` simply enables/disables whether we should split
or use the full buffer. `insertMarkerInOutput` toggles if split markers
should be inserted in between prcessed output chunks.

These options allow for merging the duplicate code paths we have
when splitting is optional.

Differential Revision: https://reviews.llvm.org/D128764
2022-06-28 15:42:35 -07:00
Jacques Pienaar 04235d07ad [mlir] Update flipped accessors (NFC)
Follow up with memref flipped and flipping any intermediate changes
made.
2022-06-28 13:11:26 -07:00
Mehdi Amini 08d651d7ba Apply clang-tidy fixes for performance-unnecessary-value-param in VectorDistribute.cpp (NFC) 2022-06-28 19:52:46 +00:00
Mehdi Amini b254d55711 Apply clang-tidy fixes for readability-simplify-boolean-expr in SPIRVOps.cpp (NFC) 2022-06-28 19:51:28 +00:00
Arjun P dda8b1ceda [MLIR][Presburger] subtract: support non-div locals
Also added test cases. Also extend support for `computeReprWithOnlyDivLocals` from `IntegerPolyhedron` to `IntegerRelation` and `PresburgerRelation`.

Depends on D128736.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D128737
2022-06-28 20:37:22 +01:00
Arjun P fd26d86f5f [MLIR][Presburger] subtract: fix support for divs defined by equalities
Also added test cases to test this. Both IntegerRelation::addLocalFloorDiv and the fixed implementation of subtraction need to compute division inequalities from dividend and divisor, so this also adds helper util functions to avoid duplicating this logic.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D128736
2022-06-28 20:24:51 +01:00
Groverkss da0f151401 [MLIR][Affine][NFC] Fix affine utlities docs using "identifiers" instead of "variables" 2022-06-28 19:35:17 +01:00
Mehdi Amini 35d7ebb1b7 Apply clang-tidy fixes for readability-simplify-boolean-expr in Shape.cpp (NFC) 2022-06-28 18:08:58 +00:00
Mehdi Amini cd417c6a46 Apply clang-tidy fixes for modernize-use-emplace in SCFTransformOps.cpp (NFC) 2022-06-28 18:08:58 +00:00
Groverkss d95140a5a9 [MLIR][Presburger] Rename variable/identifier -> variable
Currently, in the Presburger library, we use the words "variables" and
"identifiers" interchangeably. This patch changes this to only use "variables" to
refer to the variables of PresburgerSpace.

The reasoning behind this change is that the current usage of the word "identifier"
is misleading. variables do not "identify" anything. The information attached to them is the
actual "identifier" for the variable. The word "identifier", will later be used
to refer to the information attached to each variable in space.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D128585
2022-06-28 19:08:08 +01:00
Stella Stamenova ac521d9ecd [mlir] Leverage CMake interface libraries for mlir python
This is already partially the case, but we can rely more heavily on interface libraries and how they are imported/exported in other to simplify the implementation of the mlir python functions in Cmake.

This change also makes a couple of other changes:
1) Add a new CMake function which handles "pure" sources. This was done inline previously
2) Moves the headers associated with CAPI libraries to the libraries themselves. These were previously managed in a separate source target. They can now be added directly to the CAPI libraries using DECLARED_HEADERS.
3) Cleanup some dependencies that showed up as an issue during the refactor

This is a big CMake change that should produce no impact on the build of mlir and on the produced *build tree*. However, this change fixes an issue with the *install tree* of mlir which was previously unusable for projects like torch-mlir because both the "pure" and "extension" targets were pointing to either the build or source trees.

Reviewed By: stellaraccident

Differential Revision: https://reviews.llvm.org/D128230
2022-06-28 10:42:58 -07:00
Mehdi Amini f68454ee8f Fix printing for ArrayRef attributes/types in declarative assembly format
These were abbreviated when parsing, but not when printing.

Reviewed By: Mogball, rriddle

Differential Revision: https://reviews.llvm.org/D128720
2022-06-28 17:39:38 +00:00
Mehdi Amini eafb18eb87 Apply clang-tidy fixes for performance-unnecessary-value-param in LinalgStrategyPasses.cpp (NFC) 2022-06-28 17:30:46 +00:00
Mehdi Amini c2828b6363 Apply clang-tidy fixes for readability-identifier-naming in ArithmeticOps.cpp (NFC) 2022-06-28 17:30:46 +00:00
Nicolas Vasilache a48bdee686 q[mlir][Vector] Add a ShapeCastOp(BroadcastOp) canonicalization pattern
This pattern can kick in when the source of the broadcast has a shape
that is a prefix/suffix of the result of the shape_cast.

Differential Revision: https://reviews.llvm.org/D128734
2022-06-28 09:49:37 -07:00
Mehdi Amini 6901607822 Fix build with some GCC version: `global qualification of class name is invalid before '{' token` 2022-06-28 16:48:08 +00:00
Aart Bik eca6f9160f [mlir][sparse][bufferization] refine bufferization assumption enforcement
Enforce the assumption made on tensor buffers explicitly. When in-place,
reuse the buffer, but fill with all zeroes for the non-update case, since
the kernel assumes all elements are written to. When not in-place, zero
out the new buffer when materializing or when no-updates occur. Copy the
original tensor value when updates occur. This prepares migrating to the
new bufferization strategy, where these assumptions must be made explicit.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D128691
2022-06-28 09:43:30 -07:00
Lei Zhang e1e0ecb96e [mlir][spirv] Support more comparisons on boolean values
Reviewed By: hanchung

Differential Revision: https://reviews.llvm.org/D128692
2022-06-28 11:58:42 -04:00
Arjun P e9fa18637d [MLIR][Presburger] getDivRepr: fix bug where dividend was negated
Also updated the tests, which were asserting the wrong behaviour.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D128735
2022-06-28 16:43:32 +01:00
Mehdi Amini 7faf75bb3e Introduce a new Dense Array attribute
This attribute is similar to DenseElementsAttr but does not support
splat. As such it has a much simpler API and does not need any smart
iterator: it exposes direct ArrayRef access.

A new syntax is introduced so that the generic printing/parsing looks
like:

  [:i64 1, -2, 3]

This attribute beings like an ArrayAttr but has a `:` token after the
opening square brace to introduce the element type (supported are I8,
I16, I32, I64, F32, F64) and the comma separated list for the data.

This is particularly convenient for attributes intended to be small,
like those referring to shapes.
For example a `transpose` operation with a `dims` attribute could be
defined as such:

  let arguments = (ins AnyTensor:$input, DenseI64ArrayAttr:$dims);
  let assemblyFormat = "$input `dims` `=` $dims attr-dict : type($input)";

And printed this way (the element type is elided in this case):

  transpose %input dims = [0, 2, 1] : tensor<2x3x4xf32>

The C++ API for dims would just directly return an ArrayRef<int64>

RFC: https://discourse.llvm.org/t/rfc-introduce-a-new-dense-array-attribute/63279

Recommit with a custom DenseArrayBaseAttrStorage class to ensure
over-alignment of the storage to the largest type.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D123774
2022-06-28 13:28:06 +00:00
Mehdi Amini 744d06e4f2 Revert "Introduce a new Dense Array attribute"
This reverts commit 508eb41d82.

UBSAN indicates some pointer mis-alignment I need to investigate
2022-06-28 12:47:15 +00:00
Mehdi Amini 508eb41d82 Introduce a new Dense Array attribute
This attribute is similar to DenseElementsAttr but does not support
splat. As such it has a much simpler API and does not need any smart
iterator: it exposes direct ArrayRef access.

A new syntax is introduced so that the generic printing/parsing looks
like:

  [:i64 1, -2, 3]

This attribute beings like an ArrayAttr but has a `:` token after the
opening square brace to introduce the element type (supported are I8,
I16, I32, I64, F32, F64) and the comma separated list for the data.

This is particularly convenient for attributes intended to be small,
like those referring to shapes.
For example a `transpose` operation with a `dims` attribute could be
defined as such:

  let arguments = (ins AnyTensor:$input, DenseI64ArrayAttr:$dims);
  let assemblyFormat = "$input `dims` `=` $dims attr-dict : type($input)";

And printed this way (the element type is elided in this case):

  transpose %input dims = [0, 2, 1] : tensor<2x3x4xf32>

The C++ API for dims would just directly return an ArrayRef<int64>

RFC: https://discourse.llvm.org/t/rfc-introduce-a-new-dense-array-attribute/63279

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D123774
2022-06-28 12:08:25 +00:00
Mehdi Amini 2d70faa299 Apply clang-tidy fixes for readability-simplify-boolean-expr in TosaToLinalg.cpp (NFC) 2022-06-28 11:21:43 +00:00
Mehdi Amini cf3f477d30 Apply clang-tidy fixes for readability-simplify-boolean-expr in Utils.cpp (NFC) 2022-06-28 11:21:37 +00:00
Matthias Springer 04dac2ca7c [mlir][SCF][bufferize][NFC] Implement resolveConflicts for ParallelInsertSliceOp
This was previous implemented as part of the BufferizableOpInterface of ForEachThreadOp. Moving the implementation to ParallelInsertSliceOp to be consistent with the remaining ops and to have a nice example op that can serve as a blueprint for other ops.

Differential Revision: https://reviews.llvm.org/D128666
2022-06-28 12:18:22 +02:00
lewuathe 036a699675 [mlir][complex] Canonicalization for consecutive complex.add and sub
Add basic canonicalization for consecutive complex.add and sub operations.

Reviewed By: pifon2a

Differential Revision: https://reviews.llvm.org/D128702
2022-06-28 11:41:16 +02:00