Commit Graph

647 Commits

Author SHA1 Message Date
Groverkss 8c867f7827 [MLIR][Presburger] Improve unittest parsing
This patch adds better functions for parsing MultiAffineFunctions and
PWMAFunctions in Presburger unittests.

A PWMAFunction can now be parsed as:

```
PWMAFunction result = parsePWMAF({
    {"(x, y) : (x >= 10, x <= 20, y >= 1)", "(x, y) -> (x + y)"},
    {"(x, y) : (x >= 21)", "(x, y) -> (x + y)"},
    {"(x, y) : (x <= 9)", "(x, y) -> (x - y)"},
    {"(x, y) : (x >= 10, x <= 20, y <= 0)", "(x, y) -> (x - y)"},
});
```

which is much more readable than the old format since the output can be
described as an AffineMap, instead of coefficients.

This patch also adds support for parsing divisions in MultiAffineFunctions
and PWMAFunctions which was previously not possible.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D133654
2022-09-15 19:28:49 +01:00
Haojian Wu 6c9d2ee490 Revert "Fix bazel build after 84d07d021333f7b5716f0444d5c09105557272e0."
This reverts commit 10250c5a2a as the
related patch is being reverted.
2022-09-15 20:02:27 +02:00
Haojian Wu 10250c5a2a Fix bazel build after 84d07d0213. 2022-09-15 13:52:46 +02:00
Christian Sigg 70ac466676 [Bazel] Add lit tests to bazel builds.
Add BUILD.bazel files for most of the MLIR tests and lit tests itself.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D133455
2022-09-15 07:49:37 +02:00
Christian Sigg d308113354 [Bazel] Bump bazel version to 5.0.
See https://discourse.llvm.org/t/use-bazelisk-for-bazel-buildbots/65188.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D133750
2022-09-13 20:09:13 +02:00
Haojian Wu 6a49c801a7 Fix Bazel build for llvm-lipo (61e5438498) 2022-09-13 10:26:43 +02:00
Fangrui Song 0845969a28 [Bazel] Port eb65327fe9 2022-09-09 15:35:52 -07:00
Benjamin Kramer f055d9c549 [bazel] Port 7fa1d743d0 2022-09-09 09:31:13 +02:00
Christopher Bate f4a478cd01 [mlir][Tensor] Add rewrites to extract slices through `tensor.collape_shape`
This change adds a set of utilities to replace the result of a
`tensor.collapse_shape -> tensor.extract_slice` chain with the
equivalent result formed by aggregating slices of the
`tensor.collapse_shape` source. In general, it is not possible to
commute `extract_slice` and `collapse_shape` if linearized dimensions
are sliced. The i-th dimension of the `tensor.collapse_shape`
result is a "linearized sliced dimension" if:

1) Reassociation indices of tensor.collapse_shape in the i'th position
   is greater than size 1 (multiple dimensions of the input are collapsed)
2) The i-th dimension is sliced by `tensor.extract_slice`.

We can work around this by stitching together the result of
`tensor.extract_slice` by iterating over any linearized sliced dimensions.
This is equivalent to "tiling" the linearized-and-sliced dimensions of
the `tensor.collapse_shape` operation in order to manifest the result
tile (the result of the `tensor.extract_slice`). The user of the
utilities must provide the mechanism to create the tiling (e.g. a loop).
In the tests, it is demonstrated how to apply the utilities using either
`scf.for` or `scf.foreach_thread`.

The below example illustrates the pattern using `scf.for`:

```
%0 = linalg.generic ... -> tensor<3x7x11x10xf32>
%1 = tensor.collapse_shape %0 [[0, 1, 2], [3]] : ... to tensor<341x10xf32>
%2 = tensor.extract_slice %1 [13, 0] [10, 10] [2, 1] : .... tensor<10x10xf32>
```

We can construct %2 by generating the following IR:

```
%dest = linalg.init_tensor() : tensor<10x10xf32>
%2 = scf.for %iv = %c0 to %c10 step %c1 iter_args(%arg0) -> tensor<10x10xf32> {
   // Step 1: Map this output idx (%iv) to a multi-index for the input (%3):
   %linear_index = affine.apply affine_map<(d0)[]->(d0*2 + 11)>(%iv)
   %3:3 = arith.delinearize_index %iv into (3, 7, 11)
   // Step 2: Extract the slice from the input
   %4 = tensor.extract_slice %0 [%3#0, %3#1, %3#2, 0] [1, 1, 1, 10] [1, 1, 1, 1] :
         tensor<3x7x11x10xf32> to tensor<1x1x1x10xf32>
   %5 = tensor.collapse_shape %4 [[0, 1, 2], [3]] :
         tensor<1x1x1x10xf32> into tensor<1x10xf32>
   // Step 3: Insert the slice into the destination
   %6 = tensor.insert_slice %5 into %arg0 [%iv, 0] [1, 10] [1, 1] :
         tensor<1x10xf32> into tensor<10x10xf32>
   scf.yield %6 : tensor<10x10xf32>
}
```

The pattern was discussed in the RFC here: https://discourse.llvm.org/t/rfc-tensor-extracting-slices-from-tensor-collapse-shape/64034

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D129699
2022-09-08 21:58:21 -06:00
rdzhabarov fba411aa47 Revert "Fix bazel deps.". Original change has been reverted.
This reverts commit b3999fd261.
2022-09-08 22:11:44 +00:00
rdzhabarov b3999fd261 Fix bazel deps. 2022-09-08 21:21:20 +00:00
Quentin Colombet e833fdcd05 [mlir] Add missing dependency in bazel build
The MemRefTransform library now depends on ArithmeticUtils because
of the newly added SimplifyExtractStridedMetadata pass.
2022-09-08 18:51:14 +00:00
Christian Sigg 250cde6ea9 [MLIR] NFC: add back exports_files(["run_lit.sh"]). 2022-09-08 07:46:10 +02:00
Christian Sigg 482aff4576 [MLIR] NFC: add back `exports_files(["LICENSE.txt"])`. 2022-09-07 22:14:12 +02:00
Christian Sigg c69c780aef [MLIR] NFC: expand comment in bazel BUILD file
... and remove unnecessry `exports_files()`.
2022-09-07 22:00:18 +02:00
Fangrui Song 98fe49c463 [Bazel] Make clang/unittests:lex_tests depend on //llvm:TestingSupport 2022-09-07 12:51:31 -07:00
Oleg Shyshkov fcab0a04c5 [mlir] Change CombiningKind in Vector dialect to EnumAttr.
CombiningKind was implemented before EnumAttr, so it reimplements the same behaviour with the custom code. Except for a few places, EnumAttr is a drop-in replacement.

Reviewed By: nicolasvasilache, pifon2a

Differential Revision: https://reviews.llvm.org/D133343
2022-09-07 13:40:45 +02:00
Benjamin Kramer a7c6cdc5cf [bazel] port 5dbc7cf7ca 2022-09-06 17:43:04 +02:00
Christian Sigg 0f2ec35691 [MLIR] Switch lit tests to %mlir_lib_dir and %mlir_src_dir replacements.
The old replacements will be removed soon:
- `%linalg_test_lib_dir`
- `%cuda_wrapper_library_dir`
- `%spirv_wrapper_library_dir`
- `%vulkan_wrapper_library_dir`
- `%mlir_runner_utils_dir`
- `%mlir_integration_test_dir`

Reviewed By: herhut

Differential Revision: https://reviews.llvm.org/D133270
2022-09-06 12:34:14 +02:00
Mehdi Amini 89418ddcb5 Plumb write_bytecode to the Python API
This adds a `write_bytecode` method to the Operation class.
The method takes a file handle and writes the binary blob to it.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D133210
2022-09-05 12:02:06 +00:00
Christian Sigg 69778121e4 [bazel] NFC: Move licenses declaration from package to function.
The `licences` attribute is deprecated, see https://docs.bazel.build/versions/4.0.0/be/common-definitions.html#common-attributes.
2022-09-05 10:47:06 +02:00
Christian Sigg 725cdc451a [mlir:vscode] Fix bazel build after commit f7b8a70 2022-09-04 11:37:06 +02:00
Benjamin Kramer 278de327d9 [bazel] Port f7b8a70e7a 2022-09-03 09:55:37 +02:00
Mikhail Goncharov 5856576202 [bazel] fix libc build
For a4d48e3b0b
2022-09-02 18:33:28 +02:00
Matthias Springer f7f0c7f7e3 [mlir][bufferize] Add isRepetitiveRegion to BufferizableOpInterface
This method allows to declare regions as "repetitive" even if the parent op does not implement the RegionBranchOpInterface.

This is needed to support loop-like ops that have parallel semantics but do not branch between regions.

Differential Revision: https://reviews.llvm.org/D133113
2022-09-02 14:47:20 +02:00
Mikhail Goncharov 8a4d6133de [bazel] additional build fixes for libc
after fe41529755
2022-09-02 13:04:51 +02:00
Wei Yi Tee 14757d5b84 [clang][dataflow] Refactor `TypeErasedDataflowAnalysisTest` - replace usage of the deprecated overload of `checkDataflow`.
Reviewed By: gribozavr2, sgatev

Differential Revision: https://reviews.llvm.org/D132756
2022-09-01 19:17:37 +00:00
Michael Jones cb84721c3c [libc] add division, modulo, and power to UInt
This adds division and power implementations to UInt. Modulo and
division are handled by the same function. These are necessary for some
higher order mathematics, often involving large floating point numbers.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D132184
2022-09-01 11:22:26 -07:00
Michael Jones fe41529755 [libc] move builtin_wrappers out of fputil
builtin_wrappers contains the wrappers for the clz builtins, which do
not depend on anything in fputil. This patch moves the file out of
FPUtil. The location is updated as appropriate.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D133035
2022-09-01 11:17:00 -07:00
Michael Jones c5f08544e8 [libc][bazel] split fputil into individual targets
This matches the change made to cmake, mostly. I've left the process of
splitting the inclusions for all the math functions for a later time.

Reviewed By: lntue, sivachandra

Differential Revision: https://reviews.llvm.org/D133073
2022-09-01 10:58:56 -07:00
Wei Yi Tee f6b66cbc7d [llvm][Testing/ADT] Implement `IsStringMapEntry` testing matcher for verifying the entries in a `StringMap`.
Reviewed By: gribozavr2, ymandel, sgatev

Differential Revision: https://reviews.llvm.org/D132753
2022-09-01 17:30:41 +00:00
Tres Popp 7c0cf32838 bazel fixes for c55b41d519 2022-09-01 08:19:52 +02:00
Wei Yi Tee d45c04da7c [llvm][ADT] Overload output stream operator `<<` for `StringMapEntry` and `StringMap`.
Printing support enables the production of more useful error messages in unit testing e.g. when using matchers such as `UnorderedElementsAre()` to inspect the contents of a `StringMap`.

Reviewed By: gribozavr2, sgatev, ymandel

Differential Revision: https://reviews.llvm.org/D132747
2022-08-31 17:37:58 +00:00
Siva Chandra Reddy ada51eed7e [bazel overlay][libc] Add unistd targets.
Reviewed By: gchatelet

Differential Revision: https://reviews.llvm.org/D133004
2022-08-31 14:29:50 +00:00
Benjamin Kramer 4b63507811 [bazel] Drop ConversionPassDetail, it shouldn't be needed after 67d0d7ac0a 2022-08-31 13:31:52 +02:00
Johannes Reifferscheid 23dec4a352 Move BufferViewFlowAnalysis to the Bufferization dialect.
It's only used from there, and this lets us remove the dependency from Analysis
to the Arith dialect.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D132928
2022-08-30 14:25:49 +02:00
Benjamin Kramer bb3d14ec8b [bazel] Stop building PassGenTest.cpp.inc, it was removed in 13ed6958df 2022-08-30 11:01:33 +02:00
Benjamin Kramer 9a9d027086 [bazel] Add missing dependency after 1b002d2768 2022-08-28 09:56:17 +02:00
Benjamin Kramer adb3a09b90 [bazel] Drop clang-offload-wrapper. It was deleted in 47166968db 2022-08-26 21:02:39 +02:00
Benjamin Kramer 766f5d8c3c [bazel] Port a235562c0a 2022-08-26 19:17:19 +02:00
Adrian Kuegel d0546fbea2 [mlir][Bazel] Fix wrong dependency to //llvm:Support 2022-08-26 09:06:40 +02:00
Adrian Kuegel 26b84eb143 [mlir][Bazel] Fix bazel build. 2022-08-26 09:04:50 +02:00
Guillaume Chatelet 9d239b37f7 [NFC][libc] Move Uint implementation to parent directory
Differential Revision: https://reviews.llvm.org/D132638
2022-08-25 12:42:06 +00:00
Mircea Trofin 5ce4c9aa04 [mlgo] Use TFLite for 'development' mode.
TLite is a lightweight, statically linkable[1], model evaluator, supporting a
subset of what the full tensorflow library does, sufficient for the
types of scenarios we envision having. It is also faster.

We still use saved models as "source of truth" - 'release' mode's AOT
starts from a saved model; and the ML training side operates in terms of
saved models.

Using TFLite solves the following problems compared to using the full TF
C API:

- a compiler-friendly implementation for runtime-loadable (as opposed
  to AOT-embedded) models: it's statically linked; it can be built via
  cmake;
- solves an issue we had when building the compiler with both AOT and
  full TF C API support, whereby, due to a packaging issue on the TF
  side, we needed to have the pip package and the TF C API library at
  the same version. We have no such constraints now.

The main liability is it supporting a subset of what the full TF
framework does. We do not expect that to cause an issue, but should that
be the case, we can always revert back to using the full framework
(after also figuring out a way to address the problems that motivated
the move to TFLite).

Details:

This change switches the development mode to TFLite. Models are still
expected to be placed in a directory - i.e. the parameters to clang
don't change; what changes is the directory content: we still need
an `output_spec.json` file; but instead of the saved_model protobuf and
the `variables` directory, we now just have one file, `model.tflite`.

The change includes a utility showing how to take a saved model and
convert it to TFLite, which it uses for testing.

The full TF implementation can still be built (not side-by-side). We
intend to remove it shortly, after patching downstream dependencies. The
build behavior, however, prioritizes TFLite - i.e. trying to enable both
full TF C API and TFLite will just pick TFLite.

[1] thanks to @petrhosek's changes to TFLite's cmake support and its deps!
2022-08-24 16:07:24 -07:00
Adrian Kuegel 9ef41ecb2a [mlir][Bazel] Fix bazel build. 2022-08-24 10:13:53 +02:00
Adrian Kuegel 23b3bcc7a6 [mlir][Bazel] Fix bazel build.
To avoid a dependency cycle, add BytecodeImplementation.h header to the
"IR" target.
2022-08-24 08:51:44 +02:00
Johannes Reifferscheid 27a1a85662 buffer-deallocation: consider aliases introduced by arith.select.
Currently, buffer deallocation considers arith.select to be
non-aliasing, which results in deallocs being inserted incorrectly. Since
arith.select doesn't implement any useful interfaces, this change just handles
it explicitly. Eventually this should probably be fixed properly, if this pass
is going to be used long term.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D132460
2022-08-23 14:37:02 +02:00
Matthias Springer c37ed7762e [tensor][bufferize] Use affine.apply instead of arith.addi in PadOp lowering
Affine exprs compose better than arith ops.

Differential Revision: https://reviews.llvm.org/D132456
2022-08-23 11:46:11 +02:00
Arthur Eubanks b04d01c009 [bazel][docs] Mention how to provide path to compiler
And some other cleanups/clarifications.

Reviewed By: saugustine

Differential Revision: https://reviews.llvm.org/D132396
2022-08-22 10:13:47 -07:00
Arthur Eubanks d5a57ab742 [bazel] Move some CI flags into .bazelrc 2022-08-22 10:12:29 -07:00