Commit Graph

3735 Commits

Author SHA1 Message Date
Nicolas Vasilache bfaf535791 [mlir][Linalg] Refactor in preparation for automatic Linalg "named" ops.
This revision prepares the ground for declaratively defining Linalg "named" ops.
Such named ops form the backbone of operations that are ubiquitous in the ML
application domain.

This revision closely related to the definition of a "Tensor Computation
Primitives Dialect" and demonstrates that ops can be expressed as declarative
configurations of the `linalg.generic` op.

Differential Revision: https://reviews.llvm.org/D74491
2020-02-12 14:47:40 -05:00
Nicolas Vasilache 137415ad28 [mlir][EDSC][Linalg] Compose linalg_matmul and vector.contract
Summary:
This revision allows model builder to create a linalg_matmul whose body
is a vector.contract. This shows the abstractions compose nicely.

Differential Revision: https://reviews.llvm.org/D74457
2020-02-12 13:50:50 -05:00
River Riddle c832145960 [mlir] Allow constructing a ValueRange from an ArrayRef<BlockArgument>
Summary: This was a missed case when ValueRange was originally added, and allows for constructing a ValueRange from the arguments of a block.

Differential Revision: https://reviews.llvm.org/D74363
2020-02-12 09:48:44 -08:00
Alex Zinenko 5ae9c4c868 [mlir] Linalg fusion: ignore indexed_generic producers
They are currently not supported and we should not attempt fusing them.
2020-02-12 15:13:21 +01:00
Pierre Oechsel fd11cda251 [mlir] StdToLLVM: Add error when the sourceMemRef of a subview is not a llvm type.
A memref_cast casting to a memref with a non identity map can't be
lowered to llvm. Take the following case:

```

func @invalid_memref_cast(%arg0: memref<?x?xf64>) {
  %c1 = constant 1 : index
  %c0 = constant 0 : index
  %5 = memref_cast %arg0 : memref<?x?xf64> to memref<?x?xf64, #map1>
  %25 = std.subview %5[%c0, %c0][%c1, %c1][] : memref<?x?xf64, #map1> to memref<?x?xf64, #map1>
  return
}
```

When lowering the subview mlir was assuming `%5` to have an llvm type
(which is not the case as mlir failed to lower the memref_cast).

Differential Revision: https://reviews.llvm.org/D74466
2020-02-12 15:13:18 +01:00
Stephan Herhut 864110b5b4 [MLIR][CUDA] Fix build file for mlir-cuda-runner
Summary:
This was broken recently when moving from dialect registration via
static initializers to explicit intialization.

Differential Revision: https://reviews.llvm.org/D74480
2020-02-12 15:10:51 +01:00
Lei Zhang d3e7816d85 [mlir][spirv] Introduce spv.func
Thus far we have been using builtin func op to model SPIR-V functions.
It was because builtin func op used to have special treatment in
various parts of the core codebase (e.g., pass pipelines, etc.) and
it's easy to bootstrap the development of the SPIR-V dialect. But
nowadays with general op concepts and region support we don't have
such limitations and it's time to tighten the SPIR-V dialect for
completeness.

This commits introduces a spv.func op to properly model SPIR-V
functions. Compared to builtin func op, it can provide the following
benefits:

* We can control the full op so we can integrate SPIR-V information
  bits (e.g., function control) in a more integrated way and define
  our own assembly form and enforcing better verification.
* We can have a better dialect and library boundary. At the current
  moment only functions are modelled with an external op. With this
  change, all ops modelling SPIR-V concpets will be spv.* ops and
  registered to the SPIR-V dialect.
* We don't need to special-case func op anymore when creating
  ConversionTarget declaring SPIR-V dialect as legal. This is quite
  important given we'll see more and more conversions in the future.

In the process, bumps a few FuncOp methods to the FunctionLike trait.

Differential Revision: https://reviews.llvm.org/D74226
2020-02-12 07:46:43 -05:00
Mehdi Amini 7b635880ab Fix MLIR build when the NVPTX target isn't configured
Differential Revision: https://reviews.llvm.org/D74472
2020-02-12 12:38:45 +00:00
Mehdi Amini c64770506b Remove static registration for dialects, and the "alwayslink" hack for passes
In the previous state, we were relying on forcing the linker to include
all libraries in the final binary and the global initializer to self-register
every piece of the system. This change help moving away from this model, and
allow users to compose pieces more freely. The current change is only "fixing"
the dialect registration and avoiding relying on "whole link" for the passes.
The translation is still relying on the global registry, and some refactoring
is needed to make this all more convenient.

Differential Revision: https://reviews.llvm.org/D74461
2020-02-12 09:13:02 +00:00
Marius Brehler a9a305716b [mlir] Revise naming of MLIROptMain and MLIRMlirOptLib
* Rename CMake target MLIROptMain to MLIROptLib:
   The target provides the main library
* Rename CMake target MLIRMlirOptLib to MLIRMlirOptMain:
   The target provides the main() entry function

At the moment, the Bazel configuration of TenorFlow maps the target
MlirOptLib to "lib/Support/MlirOptMain.cpp" and MlirOptMain to
"tools/mlir-opt/mlir-opt.cpp". This is the other way around in the CMake
configuration. As discussed in the context of the pull request
https://github.com/tensorflow/tensorflow/pull/36301, it seems useful to
revise the naming in the MLIR repo.

Differential Revision: https://reviews.llvm.org/D73778
2020-02-12 09:46:09 +01:00
Alexander Belyaev 7e5d8a34e3 [MLIR] Support memrefs with complex element types.
Differential Revision: https://reviews.llvm.org/D74307
2020-02-12 09:07:15 +01:00
Mehdi Amini d6a5c31c0f Removed declared but non-existent createMaterializeVectorsPass() (NFC) 2020-02-12 02:06:03 +00:00
Jacques Pienaar 7baf2a434c [mlir] Start Shape dialect
* Add basic skeleton for Shape dialect;
* Add description of types and ops to be used;

Differential Revision: https://reviews.llvm.org/D73944
2020-02-11 14:42:59 -08:00
Andy Davis 40b2eb3530 [mlir][AffineOps] Adds affine loop fusion transformation function to LoopFusionUtils.
Summary:
Adds affine loop fusion transformation function to LoopFusionUtils.
Updates TestLoopFusion utility to run loop fusion transformation until a fixed point is reached.
Adds unit tests to test the transformation.
Includes ASAN bug fix for D73190.

Reviewers: bondhugula, dcaballe

Reviewed By: bondhugula, dcaballe

Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, Joonsoo, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D74330
2020-02-11 13:56:26 -08:00
Andy Davis 813bfffec3 [mlir][VectorOps] Adds canonicalization rewrite patterns for vector ShapeCastOp.
Summary:
Adds two rewrite patterns for the vector ShapeCastOp.
*) ShapeCastOp decomposer: decomposes ShapeCastOp on tuple-of-vectors to multiple ShapeCastOps each on vector types.
*) ShapeCastOp folder: folds canceling shape cast ops (e.g. shape_cast A -> B followed by shape_cast B -> A) away.

Reviewers: nicolasvasilache, aartbik

Reviewed By: nicolasvasilache

Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D74327
2020-02-11 13:11:45 -08:00
aartbik e83b7b99da [mlir] [VectorOps] Implement vector.reduce operation
Summary:
This new operation operates on 1-D vectors and
forms the bridge between vector.contract and
llvm intrinsics for vector reductions.

Reviewers: nicolasvasilache, andydavis1, ftynse

Reviewed By: nicolasvasilache

Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D74370
2020-02-11 11:31:59 -08:00
Diego Caballero 696f80736b [mlir] Turn flags in ConvertStandardToLLVM into pass flags
Follow-up on D72802. Turn -convert-std-to-llvm-use-alloca and
-convert-std-to-llvm-bare-ptr-memref-call-conv into pass flags
of LLVMLoweringPass.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D73912
2020-02-11 10:28:30 -08:00
Joonsoo Jeon b04885a55c [mlir][ods] Added RankedIntElementsAttr class
Defines a tablegen class RankedIntElementsAttr. This is an integer
version of RankedFloatElementsAttr.

Differential Revision: https://reviews.llvm.org/D73764
2020-02-11 10:01:57 -05:00
Stephan Herhut 890d5e2dd2 [MLIR][GPU] Disallow llvm tanh intrinsics when lowering to NVVM/ROCm.
Summary:
The lowering to NVVM and ROCm handles tanh operations differently by
mapping them to NVVM/ROCm specific intrinsics. This conflicts with
the lowering to LLVM, which uses the default llvm intrinsic. This change
declares the LLVM intrinsics to be illegal, hence disallowing the
correspondign rewrite.

Differential Revision: https://reviews.llvm.org/D74389
2020-02-11 15:09:30 +01:00
Alex Zinenko ea3a25e4f5 [mlir] StdToLLVM: add a separate test for the new memref calling convention 2020-02-11 13:56:25 +01:00
Feng Liu 8d96aed566 [mlir] Use the first location in the fused location for diagnostic handler
Differential Revision: https://reviews.llvm.org/D71851
2020-02-11 07:34:15 -05:00
Lei Zhang 50aeeed8a2 [mlir][spirv] Use spv.entry_point_abi in GPU to SPIR-V conversions
We have spv.entry_point_abi for specifying the local workgroup size.
It should be decorated onto input gpu.func ops to drive the SPIR-V
CodeGen to generate the proper SPIR-V module execution mode. Compared
to using command-line options for specifying the configuration, using
attributes also has the benefits that 1) we are now able to use
different local workgroup for different entry points and 2) the
tests contains the configuration directly.

Differential Revision: https://reviews.llvm.org/D74012
2020-02-10 16:24:48 -05:00
Hanhan Wang 4687822b9e [mlir][Linalg] Add a roundtrip test for indexed_generic op with tensors.
Summary:
After D72555 has been landed, `linalg.indexed_generic` also accepts ranked
tensor as input and output. Add a test for it.

Differential Revision: https://reviews.llvm.org/D74267
2020-02-10 15:51:59 -05:00
Nicolas Vasilache 8513ff05c8 [mlir][VectorOps][EDSC] Add EDSC for VectorOps
Summary:
This revision adds EDSC support for VectorOps to enable the creation of a `vector_matmul` declaratively. The `vector_matmul` is a simple configuration
 of the `vector.contract` op that follows the StructuredOps abstraction.

Differential Revision: https://reviews.llvm.org/D74284
2020-02-10 15:01:14 -05:00
Stephen Neuendorffer 4468188db8 [MLIR] Fix lib/Dialect/Linalg/EDSC for BUILD_SHARED_LIBS=on 2020-02-10 10:23:56 -08:00
Stephen Neuendorffer 1eba3f326c [MLIR] Fix lib/ExecutionEngine for BUILD_SHARED_LIBS=on 2020-02-10 10:23:56 -08:00
Stephen Neuendorffer ed56633fb9 [MLIR][Standard] Implement constant folding for IndexCast
Differential Revision: https://reviews.llvm.org/D73672
2020-02-10 10:23:56 -08:00
Stephen Neuendorffer 12df427fb2 [MLIR][Standard] Add folding for indexCast(indexCast(x)) -> x
Allow this only if the types are the same.  e.g.:
i16 -> index -> i16  or
index -> i16 -> index

Differential Revision: https://reviews.llvm.org/D73671
2020-02-10 10:23:56 -08:00
Stephen Neuendorffer b80a9ca8cb [MLIR] Allow non-binary operations to be commutative
NFC for binary operations.

Differential Revision: https://reviews.llvm.org/D73670
2020-02-10 10:23:55 -08:00
aartbik 83003db430 [mlir] [LLVMIR] add all vector reduction intrinsics to LLVM IR dialect
Summary:
This allows for lowering of VectorOps (and others) into a LLVM IR
that maps directly to efficient implementations on the target machines.

http://llvm.org/docs/LangRef.html#experimental-vector-reduction-intrinsics

Reviewers: ftynse, andydavis1, nicolasvasilache, rriddle

Reviewed By: ftynse, rriddle

Subscribers: jfb, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D74171
2020-02-10 09:19:05 -08:00
Nicolas Vasilache 75394e1301 [mlir][EDSC] Almost NFC - Refactor and untangle EDSC dependencies
This CL refactors EDSCs to layer them better and break unnecessary
dependencies. After this refactoring, the top-level EDSC target only
depends on IR but not on Dialects anymore and each dialect has its
own EDSC directory.

This simplifies the layering and breaks cyclic dependencies.
In particular, the declarative builder + folder are made explicit and
are now confined to Linalg.

As the refactoring occurred, certain classes and abstractions that were not
paying for themselves have been removed.

Differential Revision: https://reviews.llvm.org/D74302
2020-02-10 12:10:41 -05:00
Kadir Cetinkaya 3606f792f4
[mlir] Delete unused header 2020-02-10 17:54:09 +01:00
Tobias Gysi 1555d7f729 [mlir] subview op lowering for target memrefs with const offset
The current standard to llvm conversion pass lowers subview ops only if
dynamic offsets are provided. This commit extends the lowering with a
code path that uses the constant offset of the target memref for the
subview op lowering (see Example 3 of the subview op definition for an
example) if no dynamic offsets are provided.

Differential Revision: https://reviews.llvm.org/D74280
2020-02-10 17:35:17 +01:00
Alex Zinenko 5a1778057f [mlir] use unpacked memref descriptors at function boundaries
The existing (default) calling convention for memrefs in standard-to-LLVM
conversion was motivated by interfacing with LLVM IR produced from C sources.
In particular, it passes a pointer to the memref descriptor structure when
calling the function. Therefore, the descriptor is allocated on stack before
the call. This convention leads to several problems. PR44644 indicates a
problem with stack exhaustion when calling functions with memref-typed
arguments in a loop. Allocating outside of the loop may lead to concurrent
access problems in case the loop is parallel. When targeting GPUs, the contents
of the stack-allocated memory for the descriptor (passed by pointer) needs to
be explicitly copied to the device. Using an aggregate type makes it impossible
to attach pointer-specific argument attributes pertaining to alignment and
aliasing in the LLVM dialect.

Change the default calling convention for memrefs in standard-to-LLVM
conversion to transform a memref into a list of arguments, each of primitive
type, that are comprised in the memref descriptor. This avoids stack allocation
for ranked memrefs (and thus stack exhaustion and potential concurrent access
problems) and simplifies the device function invocation on GPUs.

Provide an option in the standard-to-LLVM conversion to generate auxiliary
wrapper function with the same interface as the previous calling convention,
compatible with LLVM IR porduced from C sources. These auxiliary functions
pack the individual values into a descriptor structure or unpack it. They also
handle descriptor stack allocation if necessary, serving as an allocation
scope: the memory reserved by `alloca` will be freed on exiting the auxiliary
function.

The effect of this change on MLIR-generated only LLVM IR is minimal. When
interfacing MLIR-generated LLVM IR with C-generated LLVM IR, the integration
only needs to require auxiliary functions and change the function name to call
the wrapper function instead of the original function.

This also opens the door to forwarding aliasing and alignment information from
memrefs to LLVM IR pointers in the standrd-to-LLVM conversion.
2020-02-10 15:03:43 +01:00
Frank Laub a248fa90a7 [MLIR][Affine] NFC: Move AffineValueMap and MutableAffineMap
Summary:
The `AffineValueMap` is moved into `Dialect/AffineOps` to prevent a cyclic
dependency between `Analysis` and `Dialect/AffineOps`.

Reviewers: bondhugula, herhut, nicolasvasilache, rriddle, mehdi_amini

Reviewed By: rriddle, mehdi_amini

Subscribers: mgorny, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, Joonsoo, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D74277
2020-02-10 02:26:27 -08:00
MaheshRavishankar aaddca1efd [mlir][GPUToSPIRV] Modify the lowering of gpu.block_dim to be consistent with Vulkan SPEC
The existing lowering of gpu.block_dim added a global variable with
the WorkGroupSize decoration. This raises an error within
Vulkan/SPIR-V validation since Vulkan requires this to have a constant
initializer. This is not yet supported in SPIR-V dialect. Changing the
lowering to return the workgroup size as a constant value instead,
obtained from spv.entry_point_abi attribute gets around the issue for
now. The validation goes through since the workgroup size is specified
using spv.execution_mode operation.
2020-02-08 22:30:03 -08:00
River Riddle 2f94ce0dcf [mlir][DeclarativeParser] Move several missed parsers over to the declarative form.
Differential Revision: https://reviews.llvm.org/D74283
2020-02-08 15:47:55 -08:00
River Riddle 1b2c16f2ae [mlir][DeclarativeParser] Add support for attributes with buildable types.
This revision adds support in the declarative assembly form for printing attributes with buildable types without the type, and moves several more parsers over to the declarative form.

Differential Revision: https://reviews.llvm.org/D74276
2020-02-08 15:46:46 -08:00
Dmitry Murygin 327e062a02 [mlir][quantizer] Add gathering of per-axis statistics in quantizer.
Reviewers: stellaraccident, nicolasvasilache

Reviewed By: stellaraccident

Subscribers: Joonsoo, merge_guards_bot, denis13

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D73556
2020-02-08 15:17:37 -08:00
River Riddle abe3e5babd [mlir] Add support for generating debug locations from intermediate levels of the IR.
Summary:
This revision adds a utility to generate debug locations from the IR during compilation, by snapshotting to a output stream and using the locations that operations were dumped in that stream. The new locations may either;
* Replace the original location of the operation.

old:
   loc("original_source.cpp":1:1)
new:
   loc("snapshot_source.mlir":10:10)

* Fuse with the original locations as NamedLocs with a specific tag.

old:
    loc("original_source.cpp":1:1)
new:
    loc(fused["original_source.cpp":1:1, "snapshot"("snapshot_source.mlir":10:10)])

This feature may be used by a debugger to display the code at various different levels of the IR. It would also be able to show the different levels of IR attached to a specific source line in the original source file.

This feature may also be used to generate locations for operations generated during compilation, that don't necessarily have a user source location to attach to.

This requires changes in the printer to track the locations of operations emitted in the stream. Moving forward we need to properly(and efficiently) track the number of newlines emitted to the stream during printing.

Differential Revision: https://reviews.llvm.org/D74019
2020-02-08 15:11:29 -08:00
River Riddle 5c159b91a2 [mlir] Add a utility method on CallOpInterface for resolving the callable.
Summary: This is the most common operation performed on a CallOpInterface. This just moves the existing functionality from the CallGraph so that other users can access it.

Differential Revision: https://reviews.llvm.org/D74250
2020-02-08 10:44:29 -08:00
Nicolas Vasilache d4fbf8312b [mlir][EDSC] NFC - Move StructuredIndexed and IteratorType out of Linalg
Summary:
This NFC revision will allow those classes to be reused to allow
building structured vector operations.

Reviewers: aartbik, ftynse

Subscribers: arphaman, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D74279
2020-02-08 13:42:28 -05:00
River Riddle 20344d3704 [mlir] Add a document detailing the design of the SymbolTable.
Summary: This document provides insight on the rationale and the design of Symbols in MLIR, and why they are necessary.

Differential Revision: https://reviews.llvm.org/D73590
2020-02-08 10:40:07 -08:00
Benjamin Kramer 7355364f63 Put back makeArrayRef to make GCC 5 happy 2020-02-08 16:15:09 +01:00
Benjamin Kramer ec93c758ce Drop some uses of StringLiteral in favor of StringRef
StringRef can be used in constexpr contexts, so StringLiteral isn't
necessary anymore.
2020-02-08 15:51:33 +01:00
River Riddle 7476e569b5 [mlir][Pass] Enable printing pass options as part of `-help`.
Summary:
This revision adds support for printing pass options as part of the normal help description. This also moves registered passes and pipelines into different sections of the help.

Example:
```
  Compiler passes to run
    --pass-pipeline                                     -   ...
    Passes:
      --affine-data-copy-generate                       -   ...
      --convert-gpu-to-spirv                            -   ...
        --workgroup-size=<long>                         - ...
      --test-options-pass                               -   ...
        --list=<int>                                    - ...
        --string=<string>                               - ...
        --string-list=<string>                          - ...
    Pass Pipelines:
      --test-options-pass-pipeline                      -   ...
        --list=<int>                                    - ...
        --string=<string>                               - ...
        --string-list=<string>                          - ...
```

Differential Revision: https://reviews.llvm.org/D74246
2020-02-07 14:11:50 -08:00
natashaknk 9c1c825b72 [mlir][spirv] Adding sin op in the GLSL extension
Differential Revision: https://reviews.llvm.org/D74151
2020-02-07 16:36:12 -05:00
Nicolas Vasilache 681f929f59 [mlir][VectorOps] Introduce a `vector.fma` op that works on n-D vectors and lowers to `llvm.intrin.fmuladd`
Summary:
The `vector.fma` operation is portable enough across targets that we do not want
to keep it wrapped under `vector.outerproduct` and `llvm.intrin.fmuladd`.
This revision lifts the op into the vector dialect and implements the lowering to LLVM by using two patterns:
1. a pattern that lowers from n-D to (n-1)-D by unrolling when n > 2
2. a pattern that converts from 1-D to the proper LLVM representation

Reviewers: ftynse, stellaraccident, aartbik, dcaballe, jsetoain, tetuante

Reviewed By: aartbik

Subscribers: fhahn, dcaballe, merge_guards_bot, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, Joonsoo, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D74075
2020-02-07 15:44:53 -05:00
Nicolas Vasilache 499ad45877 [mlir][VectorOps] Expose and use llvm.intrin.fma*
Summary:
This revision exposes the portable `llvm.fma` intrinsic in LLVMOps and uses it
in lieu of `llvm.fmuladd` when lowering the `vector.outerproduct` op to LLVM.
This guarantees proper `fma` instructions will be emitted if the target ISA
supports it.

`llvm.fmuladd` does not have this guarantee in its semantics, despite evidence
that the proper x86 instructions are emitted.

For more details, see https://llvm.org/docs/LangRef.html#llvm-fmuladd-intrinsic.

Reviewers: ftynse, aartbik, dcaballe, fhahn

Reviewed By: aartbik

Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D74219
2020-02-07 15:38:40 -05:00
MaheshRavishankar d06dd29e09 [mlir][Linalg] Implement fusion of linalg.generic operation on tensors.
The initial implementation of the fusion operation exposes a method to
fuse a consumer with its producer, when
- both the producer and consumer operate on tensors
- the producer has only a single result value
- the producer has only "parallel" iterator types
A new interface method hasTensorSemantics is added to verify that an
operation has all operands and results of type RankedTensorType.

Differential Revision: https://reviews.llvm.org/D74172
2020-02-07 10:36:53 -08:00
aartbik e52414b1ae [mlir][VectorOps] Generalized vector.print to i32/i64
Summary:
Lowering to LLVM IR was restricted to float/double.
This CL also adds the integral values.

Reviewers: andydavis1, nicolasvasilache, ftynse

Reviewed By: nicolasvasilache, ftynse

Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D74179
2020-02-07 09:25:30 -08:00
OuHangKresnik 7edf27f7a7 [mlir] Add NoSideEffect to Affine min max
Add NoSideEffect to Affine min and max operations.

Differential Revision: https://reviews.llvm.org/D74203
2020-02-07 15:19:48 +01:00
River Riddle 58c18ca135 [mlir][AsmPrinter] Fix edge case when printing floating point values.
Summary: In some edge cases the default APFloat printer will generate something that we can't parse back in. In these cases, fallback to using hex instead.

Differential Revision: https://reviews.llvm.org/D74181
2020-02-06 18:05:53 -08:00
River Riddle 1eaa31ce0e [mlir][DialectConversion] Change erroneous return to a continue
This fixes a nasty bug where the loop would return prematurely when
notifying the argument converter that an operation was removed.
2020-02-06 17:55:14 -08:00
Benjamin Kramer b68b8be8e2 [mlir-tblgen] Stop leaking PredNodes
Technically a leak in tblgen is harmless, but this makes asan builds of
mlir very noisy. Just use a SpecificBumpPtrAllocator that knows how to
clean up after itself.
2020-02-06 18:03:15 +01:00
Mehdi Amini 2724ada8d2 Revert "[mlir] Adds affine loop fusion transformation function to LoopFusionUtils."
This reverts commit 64871f778d.

ASAN indicates a use-after-free in in mlir::canFuseLoops(mlir::AffineForOp, mlir::AffineForOp, unsigned int, mlir::ComputationSliceState*) lib/Transforms/Utils/LoopFusionUtils.cpp:202:41
2020-02-06 16:46:28 +00:00
OuHangKresnik 5c3b34930c [mlir] Add AffineMaxOp
Differential Revision: https://reviews.llvm.org/D73848
2020-02-06 10:26:50 +01:00
Kern Handa 8dc3da7d58 [mlir] Build fix for mlir-opt
mlir-opt needs to link against MLIRLoopAnalysis
This shouldn't be needed but MLIR "hack" for
"whole-archive" linking is not compatible with
CMake transitive dependencies management.

Differential Revision: https://reviews.llvm.org/D74097
2020-02-06 05:16:01 +00:00
River Riddle 93dc8bd267 [mlir] Add explicit friendship to LLVM::ModuleTranslation to derived
classes.

This allows for the `LLVM::ModuleTranslation::translateModule` to properly access the constructors of the derived classes.
2020-02-05 18:34:44 -08:00
River Riddle c33d6970e0 [mlir] Add support for basic location translation to LLVM.
Summary:
This revision adds basic support for emitting line table information when exporting to LLVMIR. We don't yet have a story for supporting all of the LLVM debug metadata, so this revision stubs some features(like subprograms) to enable emitting line tables.

Differential Revision: https://reviews.llvm.org/D73934
2020-02-05 17:41:51 -08:00
River Riddle c3f0ed7bcc [mlir] Register the GDB listener with ExecutionEngine to enable debugging JIT'd code
Differential Revision: https://reviews.llvm.org/D73932
2020-02-05 17:41:51 -08:00
aartbik 6e2309d7fa [mlir] [VectorOps] generalized vector.contract semantics
Summary:
Previously, vector.contract did not allow an empty set of
free or batch dimensions (K = 0) which defines a basic
reduction into a scalar (like a dot product). This CL
relaxes that restriction. Also adds constraints on
element type of operands and results. With tests.

Reviewers: nicolasvasilache, andydavis1, rriddle

Reviewed By: andydavis1

Subscribers: merge_guards_bot, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D74014
2020-02-05 17:20:32 -08:00
Andy Davis f9efce1dd5 [mlir][VectorOps] Support vector transfer_read/write unrolling for memrefs with vector element type.
Summary:
[mlir][VectorOps] Support vector transfer_read/write unrolling for memrefs with vector element type.  When unrolling vector transfer read/write on memrefs with vector element type, the indices used to index the memref argument must be updated to reflect the unrolled operation.   However, in the case of memrefs with vector element type, we need to be careful to only update the relevant memref indices.

For example, a vector transfer read with the following source/result types, memref<6x2x1xvector<2x4xf32>>, vector<2x1x2x4xf32>, should only update memref indices 1 and 2 during unrolling.

Reviewers: nicolasvasilache, aartbik

Reviewed By: nicolasvasilache, aartbik

Subscribers: lebedev.ri, Joonsoo, merge_guards_bot, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, liufengdb, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D72965
2020-02-05 16:21:58 -08:00
Andy Davis 64871f778d [mlir] Adds affine loop fusion transformation function to LoopFusionUtils.
Summary:
Adds affine loop fusion transformation function to LoopFusionUtils.
Updates TestLoopFusion utility to run loop fusion transformation until a fixed point is reached.
Adds unit tests to test the transformation.

Reviewers: bondhugula, dcaballe, nicolasvasilache

Reviewed By: bondhugula, dcaballe

Subscribers: Joonsoo, merge_guards_bot, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D73190
2020-02-05 16:01:06 -08:00
Andy Davis 3ce8095c29 [mlir][VectorOps] Add ShapeCastOp to the vector ops dialect.
Summary:
Add ShapeCastOp to the vector ops dialect.

The shape_cast operation casts between an n-D source vector shape and a k-D result vector shape (the element type remains the same).

Reviewers: nicolasvasilache, aartbik

Reviewed By: nicolasvasilache

Subscribers: Joonsoo, merge_guards_bot, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, liufengdb, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D73635
2020-02-05 15:45:12 -08:00
Jacques Pienaar 2697e8bc1e [mlir] Update generic op ebnf to include region
Summary: Optional regions are supported in the generic op print/parse form, update the docs to match.

Differential Revision: https://reviews.llvm.org/D74061
2020-02-05 13:16:28 -08:00
Stephen Neuendorffer 7b7e505813 [MLIR] Break cyclic dependencies with MLIRAnalysis
Summary:

MLIRAnalysis depended on MLIRVectorOps
MLIRVectorOps depended on MLIRAnalysis for Loop information.

Both of these can be solved by factoring out libraries related to loop
analysis into their own library. The new MLIRLoopAnalysis might be
better off with the Loop Dialect in the future.

Reviewers: nicolasvasilache, rriddle!, mehdi_amini

Reviewed By: mehdi_amini

Subscribers: Joonsoo, vchuravy, merge_guards_bot, mgorny, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D73655
2020-02-05 11:27:28 -08:00
Stephen Neuendorffer b692f43e42 [MLIR] Rename MemRefBoundCheck.cpp -> TestMemRefBoundCheck.cpp
Summary:

This makes it consistent with other test passes.

Reviewers: rriddle

Reviewed By: rriddle

Subscribers: merge_guards_bot, mgorny, mehdi_amini, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, Joonsoo, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D74068
2020-02-05 11:27:09 -08:00
Stephen Neuendorffer b3dd31711a [MLIR] Move test passes out of lib/Analysis
Summary:

This breaks a cyclic library dependency where MLIRPass used the verifier
in MLIRAnalysis, but MLIRAnalysis also contained passes used for testing.
The presence of the test passes here is archaeology, predating
test/lib/Transform.

Reviewers: rriddle

Reviewed By: rriddle

Subscribers: merge_guards_bot, mgorny, mehdi_amini, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D74067
2020-02-05 11:26:49 -08:00
River Riddle c1bcdb935a [mlir][ODS] Add documentation for the declarative assembly format.
Summary: This details the structure of the format, it's requirements, and gives a few examples.

Differential Revision: https://reviews.llvm.org/D73983
2020-02-05 10:29:46 -08:00
Stephan Herhut 921d4e7c8d [MLIR][GPU] Fix build files for mlir-opt.
The recent refactoring of build files broke building with the MIR CUDA
integration enabled. This fixes it by adding some additional
dependencies to mlir-opt.

Differential Revision: https://reviews.llvm.org/D74041
2020-02-05 17:13:48 +00:00
Stephan Herhut e1e09f0ce6 [MLIR] Add mapping based on ValueRange to BlockAndValueMapper.
Summary:
It is often needed to map entire ranges rather than single values. To avoid
writing the same for loop every time, I have added an overload to the map
method.

Differential Revision: https://reviews.llvm.org/D73894
2020-02-05 15:48:13 +01:00
Kern Handa b8004b7308 [mlir] Mark the MLIR tools for installation in CMake
This binplaces `mlir-translate`, `mlir-cuda-runner`, and `mlir-cpu-runner` when building the CMake install target.

Differential Revision: https://reviews.llvm.org/D73986
2020-02-05 03:42:57 +00:00
Lei Zhang 13b197c7d1 [mlir][spirv] Add dialect-specific attribute for target environment
We were using normal dictionary attribute for target environment
specification. It becomes cumbersome with more and more fields.
This commit changes the modelling to a dialect-specific attribute,
where we can have control over its storage and assembly form.

Differential Revision: https://reviews.llvm.org/D73959
2020-02-04 21:33:13 -05:00
Dimitry Andric 31fd112eb4 Fix x86 32bits MLIR build (NFC)
This is fixing a build error:

error: non-constant-expression cannot be narrowed from type 'unsigned int' to 'Region::iterator::difference_type' (aka 'int') in initializer list

Fix pr44767
2020-02-04 23:58:58 +00:00
River Riddle f0fb09c33e [mlir] Print types to the OpAsmPrinter instead of the raw_ostream.
This allows for reusing the internal state of the printer, which is more
efficient and also allows for using type aliases
2020-02-04 12:17:14 -08:00
aartbik 3c7e9c34b3 [mlir] [VectorOps] refined description of vector.contract
Summary:
A few details were missing in the description. These
changes makes the documented code "compile".

Reviewers: nicolasvasilache, andydavis1

Reviewed By: nicolasvasilache, andydavis1

Subscribers: merge_guards_bot, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D73923
2020-02-04 11:18:30 -08:00
Jacques Pienaar 28cd54cdbb [mlir] Fix clang 5 warning for missing braces 2020-02-04 10:35:47 -08:00
Stephen Neuendorffer d7cbef2714 [MLIR] Fixes for shared library dependencies.
Summary:

This patch is a step towards enabling BUILD_SHARED_LIBS=on, which
builds most libraries as DLLs instead of statically linked libraries.
The main effect of this is that incremental build times are greatly
reduced, since usually only one library need be relinked in response
to isolated code changes.

The bulk of this patch is fixing incorrect usage of cmake, where library
dependencies are listed under add_dependencies rather than under
target_link_libraries or under the LINK_LIBS tag.  Correct usage should be
like this:

add_dependencies(MLIRfoo MLIRfooIncGen)
target_link_libraries(MLIRfoo MLIRlib1 MLIRlib2)

A separate issue is that in cmake, dependencies between static libraries
are automatically included in dependencies.  In the above example, if MLIBlib1
depends on MLIRlib2, then it is sufficient to have only MLIRlib1 in the
target_link_libraries.  When compiling with shared libraries, it is necessary
to have both MLIRlib1 and MLIRlib2 specified if MLIRfoo uses symbols from both.

Reviewers: mravishankar, antiagainst, nicolasvasilache, vchuravy, inouehrs, mehdi_amini, jdoerfert

Reviewed By: nicolasvasilache, mehdi_amini

Subscribers: Joonsoo, merge_guards_bot, jholewinski, mgorny, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, csigg, arpith-jacob, mgester, lucyrfox, herhut, aartbik, liufengdb, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D73653
2020-02-04 08:56:37 -08:00
Lei Zhang aad352f77c [mlir][spirv] Wrap debug-only method in #ifndef NDEBUG 2020-02-04 08:57:29 -05:00
Alexander Belyaev baecae838d [Linalg] Add tiling of Linalg to parallel loops.
Differential Revision: https://reviews.llvm.org/D73955
2020-02-04 14:51:19 +01:00
Lei Zhang 399887c9e4 [mlir][spirv] Add resource limits into target environment
This commit adds two resource limits, max_compute_workgroup_size
and max_compute_workgroup_invocations as resource limits to
the target environment. They are not used at the current moment,
but they will affect the SPIR-V CodeGen. Adding for now to have
a proper target environment modelling.

Differential Revision: https://reviews.llvm.org/D73905
2020-02-04 08:35:19 -05:00
River Riddle abe6d1174d [mlir] Emit a fatal error when the assembly format is invalid
This revision makes sure that errors emitted outside of testing are treated as fatal errors. This avoids the current silent failures that occur when the format is invalid.
2020-02-03 22:14:33 -08:00
River Riddle fbba639517 [mlir][ODS] Refactor BuildableType to use $_builder as part of the format
Summary:
Currently BuildableType is assumed to be preceded by a builder. This prevents constructing types that don't have a callable 'get' method with the builder. This revision reworks the format to be like attribute builders, i.e. by accepting $_builder within the format itself.

Differential Revision: https://reviews.llvm.org/D73736
2020-02-03 21:55:34 -08:00
River Riddle 7ef37a5f99 [mlir] Initial support for type constraints in the declarative assembly format
Summary: This revision add support for accepting a few type constraints, e.g. AllTypesMatch, when inferring types for operands and results. This is used to remove the c++ parsers for several additional operations.

Differential Revision: https://reviews.llvm.org/D73735
2020-02-03 21:55:09 -08:00
Mehdi Amini ea4652ebeb Fix unused variable warning (NFC)
Use isa<> instead of dyn_cast<> when the result isn't used.
2020-02-04 03:38:13 +00:00
Alex Zinenko 3b4d24d770 [mlir] Accept an LLVM::LLVMFuncOp in the builder of LLVM::CallOp
Summary:
Replace the generic zero- and one-result builders in LLVM::CallOp with a custom
builder that takes an LLVMFuncOp, which can be used to extract the result type
and create the symbol reference attribute. This is merely a convenience for
upcoming changes. The ODS-generated builders remain present.

Introduce LLVM::LLVMType::isVoidTy by analogy with the underlying LLVM type.

Differential Revision: https://reviews.llvm.org/D73895
2020-02-03 22:28:17 +01:00
Alexander Belyaev 0da755df85 [MLIR][Linalg] Use GenericLoopNestRangeBuilder in tiling code.
Preparation for adding support for tiling to parallel loops.

Differential Revision: https://reviews.llvm.org/D73872
2020-02-03 21:10:39 +01:00
Alexander Belyaev eda6b2e2b3 [MLIR][Linalg] Allow fusion of more than 2 linalg ops.
LinalgDependenceGraph was not updated after successful producer-consumer
fusion for linalg ops. In this patch it is fixed by reconstructing
LinalgDependenceGraph on every iteration. This is very ineffective and
should be improved by updating LDGraph only when it is necessary.
2020-02-03 21:00:23 +01:00
Alex Zinenko e0ea706a59 [mlir] ConvertStandardToLLVM: do not rely on command line options internally
The patterns for converting `std.alloc` and `std.dealoc` can be configured to
use `llvm.alloca` instead of calling `malloc` and `free`. This configuration
has been only possible through a command-line flag, despite the presence of a
(misleading) parameter in the pass constructor. Use the parameter instead and
only initalize it from the command line flags if the pass is constructed from
the mlir-opt registration.
2020-02-03 13:50:41 +01:00
Alex Zinenko f3fa4a34b6 [mlir] Drop customization hooks from StandardToLLVM conversion
Summary:
These hooks were originally introduced to support passes deriving the
StandardToLLVM conversion, in particular converting types from different
dialects to LLVM types in a single-step conversion. They are no longer in use
since the pass and conversion infrastructure has evolved sufficiently to make
defining new passes with exactly the same functionality simple through the use
of populate* functions, conversion targets and type converters. Remove the
hooks. Any users of this hooks can call the dialect conversion infrastructure
directly instead, which is likely to require less LoC than these hooks.

Differential Revision: https://reviews.llvm.org/D73795
2020-02-03 13:26:17 +01:00
Marius Brehler 9adbb6c468 [mlir] Fix link to 'Getting started with MLIR'
The link in the toy example pointed to the 'tensorflow/mlir' repo and is
replaced with https://mlir.llvm.org.

Differential Revision: https://reviews.llvm.org/D73770
2020-02-03 13:01:22 +01:00
Alexander Belyaev 3dcc1fc61b [MLIR][Linalg] Lower linalg.generic to ploops.
Differential Revision: https://reviews.llvm.org/D73684
2020-02-03 11:52:23 +01:00
Stephan Herhut 283b5e733d [MLIR] Make gpu.launch implicitly capture uses of values defined above.
Summary:
In the original design, gpu.launch required explicit capture of uses
and passing them as operands to the gpu.launch operation. This was
motivated by infrastructure restrictions rather than design. This
change lifts the requirement and removes the concept of kernel
arguments from gpu.launch. Instead, the kernel outlining
transformation now does the explicit capturing.

This is a breaking change for users of gpu.launch.

Differential Revision: https://reviews.llvm.org/D73769
2020-02-03 10:08:48 +01:00
Kazuaki Ishizaki 549588698f [mlir] NFC: Fix trivial typo in comment
Summary: Also, an exercise to merge this into the master myself after a reviewer gives LGTM.

Reviewers: nicolasvasilache, mehdi_amini

Reviewed By: mehdi_amini

Subscribers: Joonsoo, merge_guards_bot, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, liufengdb, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D73432
2020-02-03 17:39:56 +09:00
Nicolas Vasilache 34cd354ea9 [mlir][Linalg][doc] Add Design Document for the Linalg Dialect
Summary: This revision adds a Rationale for the Linalg Dialect

Reviewers: rriddle, mehdi_amini, ftynse, albertcohen

Reviewed By: albertcohen

Subscribers: merge_guards_bot, jfb, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D73595
2020-02-02 14:55:35 -05:00
Nicolas Vasilache ff50c8dcef Revert "[mlir][Linalg][doc] Add Design Document for the Linalg Dialect"
This reverts commit 1d58a7c82f.
2020-02-02 14:55:35 -05:00
Jacques Pienaar c4b4c0c47c [mlir] Expand shape functions in ShapeInference doc
Summary:
Start filling in some requirements for the shape function descriptions
that will be used to derive shape computations. This requiement part may
later be reworked to be part of the "context" section of shape dialect. Without
examples this may be a bit too abstract but I hope not (given mappings to
existing shape functions).

Differential Revision: https://reviews.llvm.org/D73572
2020-02-01 14:44:38 -08:00
Jacques Pienaar 1544cf2d7c [mlir] Fix errors in release & no-assert
Seen on gcc 8, in release mode & assertions off warnings about logger,
made all statements referencing logger inside LLVM_DEBUG blocks and
ifdef a few variables only used in debug.

This is mechanical fix to get CI green.
2020-02-01 08:57:01 -08:00
Nicolas Vasilache dc1d43cfa0 [mlir][Linalg] NFC - Cleanup and split input file for roundtrip.mlir 2020-01-31 22:01:56 -05:00