Nicolas Vasilache [Thu, 8 Aug 2019 16:09:29 +0000 (09:09 -0700)]
Add canonicalization pattern for linalg.dim
This CL introduces canonicalization patterns for linalg.dim.
This allows the dimenions of chains of view, slice and subview operations to simplify.
Down the line, when mixed with cse, this also allows better composition of linalg tiling and fusion by tracking operations that give the same result (not in this CL).
PiperOrigin-RevId:
262365865
Eric Schweitz [Thu, 8 Aug 2019 08:05:26 +0000 (01:05 -0700)]
Add the LLVM IR unreachable instruction to the LLVMIR dialect.
http://llvm.org/docs/LangRef.html#unreachable-instruction
Closes tensorflow/mlir#64
PiperOrigin-RevId:
262301557
River Riddle [Thu, 8 Aug 2019 02:23:35 +0000 (19:23 -0700)]
NFC: Update FuncOp::addEntryBlock to return the newly inserted block.
The entry block is often used recently after insertion. This removes the need to perform an additional lookup in such cases.
PiperOrigin-RevId:
262265671
Lei Zhang [Wed, 7 Aug 2019 22:19:02 +0000 (15:19 -0700)]
Initialize local variables for opcode to fix MSAN failures
PiperOrigin-RevId:
262225919
River Riddle [Wed, 7 Aug 2019 20:48:19 +0000 (13:48 -0700)]
Add utility 'replaceAllUsesWith' methods to Operation.
These methods will allow replacing the uses of results with an existing operation, with the same number of results, or a range of values. This removes a number of hand-rolled result replacement loops and simplifies replacement for operations with multiple results.
PiperOrigin-RevId:
262206600
Chris Lattner [Wed, 7 Aug 2019 18:49:56 +0000 (11:49 -0700)]
Improve support for opaque types in MLIR, allowing dialects to opt into
supporting opaque types, and providing ODS support for matching them.
PiperOrigin-RevId:
262183028
Diego Caballero [Wed, 7 Aug 2019 17:31:14 +0000 (10:31 -0700)]
Fix verification of zero-dim memref in affine.load/affine.store/std.load/std.store
Verification complained when using zero-dimensional memrefs in
affine.load, affine.store, std.load and std.store. This PR extends
verification so that those memrefs can be used.
Closes tensorflow/mlir#58
COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/58 from dcaballe:dcaballe/zero-dim
49bcdcd45c52c48beca776431328e5ce551dfa9e
PiperOrigin-RevId:
262164916
Andy Ly [Wed, 7 Aug 2019 03:48:29 +0000 (20:48 -0700)]
Have ValueUseIterator template use OperandType instead of IROperand.
This was causing some issues using helper methods like llvm::make_early_inc_range on Value::getUses(), resulting in IROperand instead of OpOperand.
PiperOrigin-RevId:
262056425
River Riddle [Tue, 6 Aug 2019 18:46:01 +0000 (11:46 -0700)]
NFC: Simplify ModuleTerminatorOp by using the HasParent trait.
PiperOrigin-RevId:
261962104
Andy Ly [Tue, 6 Aug 2019 18:08:22 +0000 (11:08 -0700)]
Remove ops in regions/blocks from worklist when parent op is being removed via GreedyPatternRewriteDriver::replaceOp.
This fixes a bug where ops inside the parent op are visited even though the parent op has been removed.
PiperOrigin-RevId:
261953580
River Riddle [Tue, 6 Aug 2019 17:33:11 +0000 (10:33 -0700)]
NFC: Simplify ModuleOp by using the SingleBlockImplicitTerminator trait.
PiperOrigin-RevId:
261944712
Lei Zhang [Tue, 6 Aug 2019 14:09:55 +0000 (07:09 -0700)]
Emit matchAndRewrite() for declarative rewrite rules
Previously we are emitting separate match() and rewrite()
methods, which requires conveying a match state struct
in a unique_ptr across these two methods. Changing to
emit matchAndRewrite() simplifies the picture.
PiperOrigin-RevId:
261906804
Lei Zhang [Tue, 6 Aug 2019 14:02:35 +0000 (07:02 -0700)]
[spirv] Provide decorations in batch for op construction
Instead of setting the attributes for decorations one by one
after constructing the op, this CL changes to attach all
the attributes for decorations to the attribute vector for
constructing the op. This should be simpler and more
efficient.
PiperOrigin-RevId:
261905578
Nicolas Vasilache [Tue, 6 Aug 2019 12:50:10 +0000 (05:50 -0700)]
Add a region to linalg.generic
This CL extends the Linalg GenericOp with an alternative way of specifying the body of the computation based on a single block region. The "fun" attribute becomes optional.
Either a SymbolRef "fun" attribute or a single block region must be specified to describe the side-effect-free computation. Upon lowering to loops, the new region body is inlined in the innermost loop.
The parser, verifier and pretty printer are extended.
Appropriate roundtrip, negative and lowering to loop tests are added.
PiperOrigin-RevId:
261895568
Nicolas Vasilache [Tue, 6 Aug 2019 12:37:47 +0000 (05:37 -0700)]
Refactor Linalg ops to loop lowering (NFC)
This CL modifies the LowerLinalgToLoopsPass to use RewritePattern.
This will make it easier to inline Linalg generic functions and regions when emitting to loops in a subsequent CL.
PiperOrigin-RevId:
261894120
Diego Caballero [Tue, 6 Aug 2019 05:13:56 +0000 (22:13 -0700)]
Add TTI pass initialization to pass managers.
Many LLVM transformations benefits from knowing the targets. This enables optimizations,
especially in a JIT context when the target is (generally) well-known.
Closes tensorflow/mlir#49
PiperOrigin-RevId:
261840617
River Riddle [Tue, 6 Aug 2019 01:37:56 +0000 (18:37 -0700)]
NFC: Implement OwningRewritePatternList as a class instead of a using directive.
This allows for proper forward declaration, as opposed to leaking the internal implementation via a using directive. This also allows for all pattern building to go through 'insert' methods on the OwningRewritePatternList, replacing uses of 'push_back' and 'RewriteListBuilder'.
PiperOrigin-RevId:
261816316
Suharsh Sivakumar [Mon, 5 Aug 2019 21:49:32 +0000 (14:49 -0700)]
Fix header guard.
PiperOrigin-RevId:
261774919
Nicolas Vasilache [Mon, 5 Aug 2019 12:25:50 +0000 (05:25 -0700)]
Drop linalg.range_intersect op
This op is not useful.
PiperOrigin-RevId:
261665736
Lei Zhang [Mon, 5 Aug 2019 12:09:34 +0000 (05:09 -0700)]
Use SingleBlockImplicitTerminator trait for spv.module
This trait provides the ensureTerminator() utility function and
the checks to make sure a spv.module is indeed terminated with
spv._module_end.
PiperOrigin-RevId:
261664153
Alex Zinenko [Mon, 5 Aug 2019 08:57:27 +0000 (01:57 -0700)]
Introduce custom syntax for llvm.func
Similar to all LLVM dialect operations, llvm.func needs to have the custom
syntax. Use the generic FunctionLike printer and parser to implement it.
PiperOrigin-RevId:
261641755
Denis Khalikov [Mon, 5 Aug 2019 08:39:26 +0000 (01:39 -0700)]
[mlir-translate] Fix test suite.
llvm ir printer was changed at LLVM r367755.
Prints value numbers for unnamed functions argument.
Closes tensorflow/mlir#67
COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/67 from denis0x0D:sandbox/fix_mlir_translate
ae46844e66f34a02e0cf86782ddadc5bce58b30d
PiperOrigin-RevId:
261640048
Mehdi Amini [Sun, 4 Aug 2019 17:58:48 +0000 (10:58 -0700)]
Remove non-needed includes from ConvertControlFlowToCFG.cpp (NFC)
The includes related to the LLVM dialect are not used in this file and
introduce an implicit dependencies between the two libraries which isn't
reflected in the CMakeLists.txt, causing non-deterministic build failures.
PiperOrigin-RevId:
261576935
Alex Zinenko [Sun, 4 Aug 2019 14:47:36 +0000 (07:47 -0700)]
Fix ExecutionEngine post-update in upstream LLVM
LLVM r367686 changed the locking scheme to avoid potential deadlocks and the
related llvm::orc::ThreadSafeModule APIs ExecutionEngine was relying upon,
breaking the MLIR build. Update our use of ThreadSafeModule to unbreak the
build.
PiperOrigin-RevId:
261566571
Lei Zhang [Sat, 3 Aug 2019 23:58:26 +0000 (16:58 -0700)]
[ODS] Add new definitions for non-negative integer attributes
This CL added a new NonNegativeIntAttrBase class and two instantiations,
one for I32 and the other for I64.
PiperOrigin-RevId:
261513292
Mehdi Amini [Sat, 3 Aug 2019 18:35:22 +0000 (11:35 -0700)]
Fix clang 5.0 by using type aliases for LLVM DenseSet/Map
When inlining the declaration for llvm::DenseSet/DenseMap in the mlir
namespace from a forward declaration, clang does not take the default
for the template parameters if their are declared later.
namespace llvm {
template<typename Foo>
class DenseMap;
}
namespace mlir {
using llvm::DenseMap;
}
namespace llvm {
template<typename Foo = int>
class DenseMap {};
}
namespace mlir {
DenseMap<> map;
}
PiperOrigin-RevId:
261495612
Nicolas Vasilache [Fri, 2 Aug 2019 16:53:08 +0000 (09:53 -0700)]
Add a generic Linalg op
This CL introduces a linalg.generic op to represent generic tensor contraction operations on views.
A linalg.generic operation requires a numbers of attributes that are sufficient to emit the computation in scalar form as well as compute the appropriate subviews to enable tiling and fusion.
These attributes are very similar to the attributes for existing operations such as linalg.matmul etc and existing operations can be implemented with the generic form.
In the future, most existing operations can be implemented using the generic form.
This CL starts by splitting out most of the functionality of the linalg::NInputsAndOutputs trait into a ViewTrait that queries the per-instance properties of the op. This allows using the attribute informations.
This exposes an ordering of verifiers issue where ViewTrait::verify uses attributes but the verifiers for those attributes have not been run. The desired behavior would be for the verifiers of the attributes specified in the builder to execute first but it is not the case atm. As a consequence, to emit proper error messages and avoid crashing, some of the
linalg.generic methods are defensive as such:
```
unsigned getNumInputs() {
// This is redundant with the `n_views` attribute verifier but ordering of verifiers
// may exhibit cases where we crash instead of emitting an error message.
if (!getAttr("n_views") || n_views().getValue().size() != 2)
return 0;
```
In pretty-printed form, the specific attributes required for linalg.generic are factored out in an independent dictionary named "_". When parsing its content is flattened and the "_name" is dropped. This allows using aliasing for reducing boilerplate at each linalg.generic invocation while benefiting from the Tablegen'd verifier form for each named attribute in the dictionary.
For instance, implementing linalg.matmul in terms of linalg.generic resembles:
```
func @mac(%a: f32, %b: f32, %c: f32) -> f32 {
%d = mulf %a, %b: f32
%e = addf %c, %d: f32
return %e: f32
}
#matmul_accesses = [
(m, n, k) -> (m, k),
(m, n, k) -> (k, n),
(m, n, k) -> (m, n)
]
#matmul_trait = {
doc = "C(m, n) += A(m, k) * B(k, n)",
fun = @mac,
indexing_maps = #matmul_accesses,
library_call = "linalg_matmul",
n_views = [2, 1],
n_loop_types = [2, 1, 0]
}
```
And can be used in multiple places as:
```
linalg.generic #matmul_trait %A, %B, %C [other-attributes] :
!linalg.view<?x?xf32>, !linalg.view<?x?xf32>, !linalg.view<?x?xf32>
```
In the future it would be great to have a mechanism to alias / register a new
linalg.op as a pair of linalg.generic, #trait.
Also, note that with one could theoretically only specify the `doc` string and parse all the attributes from it.
PiperOrigin-RevId:
261338740
Jacques Pienaar [Fri, 2 Aug 2019 15:27:31 +0000 (08:27 -0700)]
Fully qualify DenseMap.
PiperOrigin-RevId:
261325481
Diego Caballero [Fri, 2 Aug 2019 15:23:48 +0000 (08:23 -0700)]
Add StdIndexedValue to EDSC helpers
Add StdIndexedValue to EDSC helper so that we can use it
to generated std.load and std.store in EDSC.
Closes tensorflow/mlir#59
PiperOrigin-RevId:
261324965
Alex Zinenko [Fri, 2 Aug 2019 15:04:00 +0000 (08:04 -0700)]
AffineDataCopyGeneration: don't use CL flag values inside the pass
AffineDataCopyGeneration pass relied on command line flags for internal logic
in several places, which makes it unusable in a library context (i.e. outside a
standalone mlir-opt binary that does the command line parsing). Define
configuration flags in the constructor instead, and set them up to command
line-based defaults to maintain the original behavior.
PiperOrigin-RevId:
261322364
Alex Zinenko [Fri, 2 Aug 2019 14:54:30 +0000 (07:54 -0700)]
WritingAPass doc: demonstrate registration of a non-default-constructible pass
This functionality was added recently and is intended to ensure that parametric
passes can be configured programmatically and not only from command-line flags,
which are mostly useless outside of standalone mlir-opt biary.
PiperOrigin-RevId:
261320932
Mehdi Amini [Thu, 1 Aug 2019 23:38:26 +0000 (16:38 -0700)]
Add missing include to DenseMap in MLIRContext.cpp
This is fixing the build of MLIR on MacOS when built within TensorFlow
PiperOrigin-RevId:
261223250
Uday Bondhugula [Thu, 1 Aug 2019 23:31:15 +0000 (16:31 -0700)]
Introduce explicit copying optimization by generalizing the DMA generation pass
Explicit copying to contiguous buffers is a standard technique to avoid
conflict misses and TLB misses, and improve hardware prefetching
performance. When done in conjunction with cache tiling, it nearly
eliminates all cache conflict and TLB misses, and a single hardware
prefetch stream is needed per data tile.
- generalize/extend DMA generation pass (renamed data copying pass) to
perform either point-wise explicit copies to fast memory buffers or
DMAs (depending on a cmd line option). All logic is the same as
erstwhile -dma-generate.
- -affine-dma-generate is now renamed -affine-data-copy; when -dma flag is
provided, DMAs are generated, or else explicit copy loops are generated
(point-wise) by default.
- point-wise copying could be used for CPUs (or GPUs); some indicative
performance numbers with a "C" version of the MLIR when compiled with
and without this optimization (about 2x improvement here).
With a matmul on 4096^2 matrices on a single core of an Intel Core i7
Skylake i7-8700K with clang 8.0.0:
clang -O3: 518s
clang -O3 with MLIR tiling (128x128): 24.5s
clang -O3 with MLIR tiling + data copying 12.4s
(code equivalent to test/Transforms/data-copy.mlir func @matmul)
- fix some misleading comments.
- change default fast-mem space to 0 (more intuitive now with the
default copy generation using point-wise copies instead of DMAs)
On a simple 3-d matmul loop nest, code generated with -affine-data-copy:
```
affine.for %arg3 = 0 to 4096 step 128 {
affine.for %arg4 = 0 to 4096 step 128 {
%0 = affine.apply #map0(%arg3, %arg4)
%1 = affine.apply #map1(%arg3, %arg4)
%2 = alloc() : memref<128x128xf32, 2>
// Copy-in Out matrix.
affine.for %arg5 = 0 to 128 {
%5 = affine.apply #map2(%arg3, %arg5)
affine.for %arg6 = 0 to 128 {
%6 = affine.apply #map2(%arg4, %arg6)
%7 = load %arg2[%5, %6] : memref<4096x4096xf32>
affine.store %7, %2[%arg5, %arg6] : memref<128x128xf32, 2>
}
}
affine.for %arg5 = 0 to 4096 step 128 {
%5 = affine.apply #map0(%arg3, %arg5)
%6 = affine.apply #map1(%arg3, %arg5)
%7 = alloc() : memref<128x128xf32, 2>
// Copy-in LHS.
affine.for %arg6 = 0 to 128 {
%11 = affine.apply #map2(%arg3, %arg6)
affine.for %arg7 = 0 to 128 {
%12 = affine.apply #map2(%arg5, %arg7)
%13 = load %arg0[%11, %12] : memref<4096x4096xf32>
affine.store %13, %7[%arg6, %arg7] : memref<128x128xf32, 2>
}
}
%8 = affine.apply #map0(%arg5, %arg4)
%9 = affine.apply #map1(%arg5, %arg4)
%10 = alloc() : memref<128x128xf32, 2>
// Copy-in RHS.
affine.for %arg6 = 0 to 128 {
%11 = affine.apply #map2(%arg5, %arg6)
affine.for %arg7 = 0 to 128 {
%12 = affine.apply #map2(%arg4, %arg7)
%13 = load %arg1[%11, %12] : memref<4096x4096xf32>
affine.store %13, %10[%arg6, %arg7] : memref<128x128xf32, 2>
}
}
// Compute.
affine.for %arg6 = #map7(%arg3) to #map8(%arg3) {
affine.for %arg7 = #map7(%arg4) to #map8(%arg4) {
affine.for %arg8 = #map7(%arg5) to #map8(%arg5) {
%11 = affine.load %7[-%arg3 + %arg6, -%arg5 + %arg8] : memref<128x128xf32, 2>
%12 = affine.load %10[-%arg5 + %arg8, -%arg4 + %arg7] : memref<128x128xf32, 2>
%13 = affine.load %2[-%arg3 + %arg6, -%arg4 + %arg7] : memref<128x128xf32, 2>
%14 = mulf %11, %12 : f32
%15 = addf %13, %14 : f32
affine.store %15, %2[-%arg3 + %arg6, -%arg4 + %arg7] : memref<128x128xf32, 2>
}
}
}
dealloc %10 : memref<128x128xf32, 2>
dealloc %7 : memref<128x128xf32, 2>
}
%3 = affine.apply #map0(%arg3, %arg4)
%4 = affine.apply #map1(%arg3, %arg4)
// Copy out result matrix.
affine.for %arg5 = 0 to 128 {
%5 = affine.apply #map2(%arg3, %arg5)
affine.for %arg6 = 0 to 128 {
%6 = affine.apply #map2(%arg4, %arg6)
%7 = affine.load %2[%arg5, %arg6] : memref<128x128xf32, 2>
store %7, %arg2[%5, %6] : memref<4096x4096xf32>
}
}
dealloc %2 : memref<128x128xf32, 2>
}
}
```
With -affine-data-copy -dma:
```
affine.for %arg3 = 0 to 4096 step 128 {
%0 = affine.apply #map3(%arg3)
%1 = alloc() : memref<128xf32, 2>
%2 = alloc() : memref<1xi32>
affine.dma_start %arg2[%arg3], %1[%c0], %2[%c0], %c128_0 : memref<4096xf32>, memref<128xf32, 2>, memref<1xi32>
affine.dma_wait %2[%c0], %c128_0 : memref<1xi32>
%3 = alloc() : memref<1xi32>
affine.for %arg4 = 0 to 4096 step 128 {
%5 = affine.apply #map0(%arg3, %arg4)
%6 = affine.apply #map1(%arg3, %arg4)
%7 = alloc() : memref<128x128xf32, 2>
%8 = alloc() : memref<1xi32>
affine.dma_start %arg0[%arg3, %arg4], %7[%c0, %c0], %8[%c0], %c16384, %c4096, %c128_2 : memref<4096x4096xf32>, memref<128x128xf32, 2>, memref<1xi32>
affine.dma_wait %8[%c0], %c16384 : memref<1xi32>
%9 = affine.apply #map3(%arg4)
%10 = alloc() : memref<128xf32, 2>
%11 = alloc() : memref<1xi32>
affine.dma_start %arg1[%arg4], %10[%c0], %11[%c0], %c128_1 : memref<4096xf32>, memref<128xf32, 2>, memref<1xi32>
affine.dma_wait %11[%c0], %c128_1 : memref<1xi32>
affine.for %arg5 = #map3(%arg3) to #map5(%arg3) {
affine.for %arg6 = #map3(%arg4) to #map5(%arg4) {
%12 = affine.load %7[-%arg3 + %arg5, -%arg4 + %arg6] : memref<128x128xf32, 2>
%13 = affine.load %10[-%arg4 + %arg6] : memref<128xf32, 2>
%14 = affine.load %1[-%arg3 + %arg5] : memref<128xf32, 2>
%15 = mulf %12, %13 : f32
%16 = addf %14, %15 : f32
affine.store %16, %1[-%arg3 + %arg5] : memref<128xf32, 2>
}
}
dealloc %11 : memref<1xi32>
dealloc %10 : memref<128xf32, 2>
dealloc %8 : memref<1xi32>
dealloc %7 : memref<128x128xf32, 2>
}
%4 = affine.apply #map3(%arg3)
affine.dma_start %1[%c0], %arg2[%arg3], %3[%c0], %c128 : memref<128xf32, 2>, memref<4096xf32>, memref<1xi32>
affine.dma_wait %3[%c0], %c128 : memref<1xi32>
dealloc %3 : memref<1xi32>
dealloc %2 : memref<1xi32>
dealloc %1 : memref<128xf32, 2>
}
```
Signed-off-by: Uday Bondhugula <uday@polymagelabs.com>
Closes tensorflow/mlir#50
PiperOrigin-RevId:
261221903
Lei Zhang [Thu, 1 Aug 2019 21:13:55 +0000 (14:13 -0700)]
Qualify StringRef to fix Windows build failure
PiperOrigin-RevId:
261195069
Lei Zhang [Thu, 1 Aug 2019 21:12:58 +0000 (14:12 -0700)]
[spirv] Add support for specialization constant
This CL extends the existing spv.constant op to also support
specialization constant by adding an extra unit attribute
on it.
PiperOrigin-RevId:
261194869
Eric Schweitz [Thu, 1 Aug 2019 20:39:21 +0000 (13:39 -0700)]
Add FIR, the Flang project's IR, to the dialect registry.
Closes tensorflow/mlir#62
PiperOrigin-RevId:
261187850
Denis Khalikov [Thu, 1 Aug 2019 20:05:28 +0000 (13:05 -0700)]
[spirv] Add binary logical operations.
Add binary logical operations regarding to the spec section 3.32.15:
OpIEqual, OpINotEqual, OpUGreaterThan, OpSGreaterThan,
OpUGreaterThanEqual, OpSGreaterThanEqual, OpULessThan, OpSLessThan,
OpULessThanEqual, OpSLessThanEqual.
Closes tensorflow/mlir#61
PiperOrigin-RevId:
261181281
Lei Zhang [Thu, 1 Aug 2019 18:50:47 +0000 (11:50 -0700)]
Replace the verifyUnusedValue directive with HasNoUseOf constraint
verifyUnusedValue is a bit strange given that it is specified in a
result pattern but used to generate match statements. Now we are
able to support multi-result ops better, we can retire it and replace
it with a HasNoUseOf constraint. This reduces the number of mechanisms.
PiperOrigin-RevId:
261166863
Lei Zhang [Thu, 1 Aug 2019 02:28:39 +0000 (19:28 -0700)]
Migrate pattern symbol binding tests to use TestDialect
PiperOrigin-RevId:
261045611
Lei Zhang [Wed, 31 Jul 2019 23:03:13 +0000 (16:03 -0700)]
Fix support for auxiliary ops in declarative rewrite rules
We allow to generate more ops than what are needed for replacing
the matched root op. Only the last N static values generated are
used as replacement; the others serve as auxiliary ops/values for
building the replacement.
With the introduction of multi-result op support, an op, if used
as a whole, may be used to replace multiple static values of
the matched root op. We need to consider this when calculating
the result range an generated op is to replace.
For example, we can have the following pattern:
```tblgen
def : Pattern<(ThreeResultOp ...),
[(OneResultOp ...), (OneResultOp ...), (OneResultOp ...)]>;
// Two op to replace all three results
def : Pattern<(ThreeResultOp ...),
[(TwoResultOp ...), (OneResultOp ...)]>;
// One op to replace all three results
def : Pat<(ThreeResultOp ...), (ThreeResultOp ...)>;
def : Pattern<(ThreeResultOp ...),
[(AuxiliaryOp ...), (ThreeResultOp ...)]>;
```
PiperOrigin-RevId:
261017235
Lei Zhang [Wed, 31 Jul 2019 22:30:46 +0000 (15:30 -0700)]
NFC: refactor ODS builder generation
Previously we use one single method with lots of branches to
generate multiple builders. This makes the method difficult
to follow and modify. This CL splits the method into multiple
dedicated ones, by extracting common logic into helper methods
while leaving logic specific to each builder in their own
methods.
PiperOrigin-RevId:
261011082
Mahesh Ravishankar [Wed, 31 Jul 2019 19:34:17 +0000 (12:34 -0700)]
Use operand number during serialization to get the <id>s of the operands
During serialization, the operand number must be used to get the
values assocaited with an operand. Using the argument number in Op
specification was wrong since some of the elements in the arguments
list might be attributes on the operation. This resulted in a segfault
during serialization.
Add a test that exercise that path.
PiperOrigin-RevId:
260977758
Denis Khalikov [Wed, 31 Jul 2019 18:10:17 +0000 (11:10 -0700)]
[spirv] Add binary arithmetic operations tensorflow/mlir#2.
Add binary operations such as: OpUdiv, OpSDiv, OpUMod, OpSRem, OpSMod.
Closes tensorflow/mlir#56
COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/56 from denis0x0D:sandbox/bin_ops_int
4959325a693b4658b978a8b97f79b8237eb39764
PiperOrigin-RevId:
260961681
Mahesh Ravishankar [Tue, 30 Jul 2019 23:11:14 +0000 (16:11 -0700)]
Add missing include file to StringExtrasTest.cpp
Use of std::isupper and std::islower need <cctype> header file. Fix
that and also fix the header of a file to match the file name.
PiperOrigin-RevId:
260816852
Alex Zinenko [Tue, 30 Jul 2019 21:24:30 +0000 (14:24 -0700)]
Support hexadecimal floats in tensor literals
Extend the recently introduced support for hexadecimal float literals to tensor
literals, which may also contain special floating point values such as
infinities and NaNs.
Modify TensorLiteralParser to store the list of tokens representing values
until the type is parsed instead of trying to guess the tensor element type
from the token kinds (hexadecimal values can be either integers or floats, and
can be mixed with both). Maintain the error reports as close as possible to
the existing implementation to avoid disturbing the tests. They can be
improved in a separate clean-up if deemed necessary.
PiperOrigin-RevId:
260794716
Mahesh Ravishankar [Tue, 30 Jul 2019 21:14:28 +0000 (14:14 -0700)]
Add support for (de)serialization of SPIR-V Op Decorations
All non-argument attributes specified for an operation are treated as
decorations on the result value and (de)serialized using OpDecorate
instruction. An error is generated if an attribute is not an argument,
and the name doesn't correspond to a Decoration enum. Name of the
attributes that represent decoerations are to be the snake-case-ified
version of the Decoration name.
Add utility methods to convert to snake-case and camel-case.
PiperOrigin-RevId:
260792638
Alex Zinenko [Tue, 30 Jul 2019 21:05:49 +0000 (14:05 -0700)]
Add support for hexadecimal float literals
MLIR does not have support for parsing special floating point values such as
infinities and NaNs. If programmatically constructed, these values are printed
as NaN and (+-)Inf and cannot be parsed back. Add parser support for
hexadecimal literals in float attributes, following LLVM IR. The literal
corresponds to the in-memory representation of the floating point value.
IEEE 754 defines a range of possible values for NaNs, storing the bitwise
representation allows MLIR to properly roundtrip NaNs with different bit values
of significands.
The initial version of this commit was missing support for float literals that
used to be printed in decimal notation as a fallback, but ended up being
printed in hexadecimal format which became the fallback for special values.
The decimal fallback behavior was not exercised by tests. It is currently
reinstated and tested by the newly added test @f32_potential_precision_loss in
parser.mlir.
PiperOrigin-RevId:
260790900
Mahesh Ravishankar [Tue, 30 Jul 2019 19:39:09 +0000 (12:39 -0700)]
Link in MLIRGPUtoSPIRVTransforms with mlir-opt
Add a missed library that needs to be linked with mlir-opt. This
results in a test failure in the MLIR due to the pass
`-convert-gpu-to-spirv` not being found.
PiperOrigin-RevId:
260773067
Jacques Pienaar [Tue, 30 Jul 2019 18:54:29 +0000 (11:54 -0700)]
Add std::move in UniformSupport.
Fixes build warnings on clang-8, no warnings on redundant moves on
gcc-(6.5,7.4,8.3).
Closes tensorflow/mlir#41
PiperOrigin-RevId:
260764269
Mahesh Ravishankar [Tue, 30 Jul 2019 18:29:48 +0000 (11:29 -0700)]
Initial implementation to translate kernel fn in GPU Dialect to SPIR-V Dialect
This CL adds an initial implementation for translation of kernel
function in GPU Dialect (used with a gpu.launch_kernel) op to a
spv.Module. The original function is translated into an entry
function.
Most of the heavy lifting is done by adding TypeConversion and other
utility functions/classes that provide most of the functionality to
translate from Standard Dialect to SPIR-V Dialect. These are intended
to be reusable in implementation of different dialect conversion
pipelines.
Note : Some of the files for have been renamed to be consistent with
the norm used by the other Conversion frameworks.
PiperOrigin-RevId:
260759165
Lei Zhang [Tue, 30 Jul 2019 17:21:25 +0000 (10:21 -0700)]
[spirv] Add basic infrastructure for negative deserializer tests
We are relying on serializer to construct positive cases to drive
the test for deserializer. This leaves negative cases untested.
This CL adds a basic test fixture for covering the negative
corner cases to enforce a more robust deserializer.
Refactored common SPIR-V building methods out of serializer to
share it with the deserialization test.
PiperOrigin-RevId:
260742733
Denis Khalikov [Tue, 30 Jul 2019 16:42:33 +0000 (09:42 -0700)]
[spirv] Add binary arithmetic operations.
Add binary operations such as: OpIAdd, OpFAdd, OpISub, OpFSub, OpIMul,
OpFDiv, OpFRem, OpFMod.
Closes tensorflow/mlir#54
PiperOrigin-RevId:
260734166
Jacques Pienaar [Mon, 29 Jul 2019 21:52:51 +0000 (14:52 -0700)]
Remove dead code.
PiperOrigin-RevId:
260585594
Alex Zinenko [Mon, 29 Jul 2019 21:12:15 +0000 (14:12 -0700)]
RewriterGen: properly handle zero-result ops
RewriterGen was emitting invalid C++ code if the pattern required to create a
zero-result operation due to the absence of a special case that would avoid
generating a spurious comma. Handle this case. Also add rewriter tests for
zero-argument operations.
PiperOrigin-RevId:
260576998
Mehdi Amini [Mon, 29 Jul 2019 18:21:55 +0000 (11:21 -0700)]
Fix SingleBlockImplicitTerminator traits to catch empty blocks
The code was written with the assumption that on failure an error would be
issued by another verifier. However verification is stopping on the first
failure which lead to an empty output. Instead we make sure an error is
displayed.
Also add tests in the test dialect for this trait.
PiperOrigin-RevId:
260541290
Mehdi Amini [Mon, 29 Jul 2019 18:14:25 +0000 (11:14 -0700)]
Simplify ODS for loop.if and loop.for traits (NFC)
There is a wrapper for SingleBlockImplicitTerminator in ODS, this is nicer to
read than using `NativeOpTrait`.
PiperOrigin-RevId:
260539473
Mahesh Ravishankar [Mon, 29 Jul 2019 17:45:17 +0000 (10:45 -0700)]
Enable (de)serialization support for spirv::AccessChainOp
Automatic generation of spirv::AccessChainOp (de)serialization needs
the (de)serialization emitters to handle argument specified as
Variadic<...>. To handle this correctly, this argument can only be
the last entry in the arguments list.
Add a test to (de)serialize spirv::AccessChainOp
PiperOrigin-RevId:
260532598
Mehdi Amini [Mon, 29 Jul 2019 17:45:17 +0000 (10:45 -0700)]
Add a `HasParent` operation trait to enforce a specific parent on an operation (NFC)
PiperOrigin-RevId:
260532592
Mehdi Amini [Mon, 29 Jul 2019 17:44:33 +0000 (10:44 -0700)]
[mlir-tblgen] Emit forward declarations for all the classes before the definitions
This allows classes to refer to each other in the ODS file, for instance for traits.
PiperOrigin-RevId:
260532419
Jacques Pienaar [Sat, 27 Jul 2019 18:46:22 +0000 (11:46 -0700)]
Initialize union to avoid -Wmissing-field-initializers warning.
Reported by clang-6.
PiperOrigin-RevId:
260311814
Andy Davis [Fri, 26 Jul 2019 20:00:01 +0000 (13:00 -0700)]
Verify that affine.load/store/dma_start/dma_wait operands are valid dimension or symbol identifiers.
PiperOrigin-RevId:
260197567
Nicolas Vasilache [Fri, 26 Jul 2019 13:49:41 +0000 (06:49 -0700)]
Automated rollback of commit
3708f53219aa2b201e82e7172c5064c1eb9d483b
PiperOrigin-RevId:
260136255
Nicolas Vasilache [Fri, 26 Jul 2019 12:40:58 +0000 (05:40 -0700)]
Add sgemm specializations - NFC
This CL adds a few specializations for sgemm.
A minor change to alpha is made in cblas_interface.cpp to be compatible with actual BLAS calls.
For now this is for internal testing purposes only.
PiperOrigin-RevId:
260129027
Lei Zhang [Fri, 26 Jul 2019 11:31:15 +0000 (04:31 -0700)]
Support referencing a single value generated by a matched multi-result op
It's quite common that we want to put further constraints on the matched
multi-result op's specific results. This CL enables referencing symbols
bound to source op with the `__N` syntax.
PiperOrigin-RevId:
260122401
Nicolas Vasilache [Fri, 26 Jul 2019 10:48:51 +0000 (03:48 -0700)]
Fix backward slice corner case
In the backward slice computation, BlockArgument coming from function arguments represent a natural boundary for the traversal and should not trigger llvm_unreachable.
This CL also improves the error message and adds a relevant test.
PiperOrigin-RevId:
260118630
Nicolas Vasilache [Fri, 26 Jul 2019 10:33:53 +0000 (03:33 -0700)]
Fix linalg_matmul_impl interfacing with sgemm
This CL provides a fix that makes linal_matmul_impl compliant with the BLAS interface. Before this CL it would compute either C += A * B when called with cblas.cpp:cblas_sgemm implementation and C = A * B with other implementations.
PiperOrigin-RevId:
260117367
Nicolas Vasilache [Fri, 26 Jul 2019 09:33:58 +0000 (02:33 -0700)]
Use "standard" load and stores in LowerVectorTransfers
Clipping creates non-affine memory accesses, use std_load and std_store instead of affine_load and affine_store.
In the future we may also want a fill with the neutral element rather than clip, this would make the accesses affine if we wanted more analyses and transformations to happen post lowering to pointwise copies.
PiperOrigin-RevId:
260110503
Krzysztof Drewniak [Thu, 25 Jul 2019 23:13:18 +0000 (16:13 -0700)]
Add API for bulk-setting attributes in an OperationState
This API is needed for the TFLite flatbuffer importer as the importer constructs
arrays of NamedAttributes based on the flatbuffer that need to be added to an
operation.
PiperOrigin-RevId:
260041403
Mehdi Amini [Thu, 25 Jul 2019 22:50:54 +0000 (15:50 -0700)]
Automated rollback of commit
fc194a4f22fe53f46729821d9c4a993fe200facf
PiperOrigin-RevId:
260037115
Denis Khalikov [Thu, 25 Jul 2019 22:42:41 +0000 (15:42 -0700)]
[spirv] Add AccessChainOp operation.
AccessChainOp creates a pointer into a composite object that can be used with
OpLoad and OpStore.
Closes tensorflow/mlir#52
PiperOrigin-RevId:
260035676
Mehdi Amini [Thu, 25 Jul 2019 22:27:31 +0000 (15:27 -0700)]
Use perfect forwarding for OpBuilder::create args (NFC)
This looks like an oversight, and it can be useful for building using
non-copyable types.
PiperOrigin-RevId:
260032944
Alex Zinenko [Thu, 25 Jul 2019 21:26:41 +0000 (14:26 -0700)]
Genericize function-like printer and parser. NFC
Function-like operations are likely to have similar custom syntax, in
particular they all need to print function signature with argument attributes.
Transform function printer and parser so that they can be applied to any
operation with the FunctionLike trait. Move them to the trait itself. To
avoid large member functions in the class template, define a concrete base
class for the trait and implement common functionality in it. This allows
printer and parser to be implemented in a source file without templating.
PiperOrigin-RevId:
260020893
Alex Zinenko [Thu, 25 Jul 2019 21:15:33 +0000 (14:15 -0700)]
Add support for hexadecimal float literals
MLIR does not have support for parsing special floating point values such as
infinities and NaNs. If programmatically constructed, these values are printed
as NaN and (+-)Inf and cannot be parsed back. Add parser support for
hexadecimal literals in float attributes, following LLVM IR. The literal
corresponds to the in-memory representation of the floating point value.
IEEE 754 defines a range of possible values for NaNs, storing the bitwise
representation allows MLIR to properly roundtrip NaNs with different bit values
of significands.
PiperOrigin-RevId:
260018802
River Riddle [Thu, 25 Jul 2019 18:30:41 +0000 (11:30 -0700)]
Add support for an analysis mode to DialectConversion.
This mode analyzes which operations are legalizable to the given target if a conversion were to be applied, i.e. no rewrites are ever performed even on success. This mode is useful for device partitioning or other utilities that may want to analyze the effect of conversion to different targets before performing it.
The analysis method currently just fills a provided set with the operations that were found to be legalizable. This can be extended in the future to capture more information as necessary.
PiperOrigin-RevId:
259987105
Nicolas Vasilache [Thu, 25 Jul 2019 08:33:02 +0000 (01:33 -0700)]
Fix backward slice computation to iterate through known control flow
This CL fixes an oversight with dealing with loops in slicing analysis.
The forward slice computation properly propagates through loops but not the backward slice.
Add relevant unit tests.
PiperOrigin-RevId:
259903396
Alex Zinenko [Thu, 25 Jul 2019 07:40:48 +0000 (00:40 -0700)]
Move GPU dialect to {lib,include/mlir}/Dialect
Per tacit agreement, individual dialects should now live in lib/Dialect/Name
with headers in include/mlir/Dialect/Name and tests in test/Dialect/Name.
PiperOrigin-RevId:
259896851
River Riddle [Wed, 24 Jul 2019 23:41:11 +0000 (16:41 -0700)]
NFC: Use ValueOfRange instead of T in Diagnostic::appendRange.
For iterator_range, T is often the name of another iterator type and not the the value of the range.
PiperOrigin-RevId:
259843446
Alex Zinenko [Wed, 24 Jul 2019 20:13:14 +0000 (13:13 -0700)]
Move SPIRV dialect tests under test/Dialect
This was overlooked when the dialect code was moved under
{lib,include/mlir}/Dialect. NFC.
PiperOrigin-RevId:
259801927
Lei Zhang [Wed, 24 Jul 2019 19:35:24 +0000 (12:35 -0700)]
Disable auto-generated builders for spv.module
We need to ensure the block inside the region is properly terminated;
the auto-generated builders do not guarantee that.
PiperOrigin-RevId:
259793777
Nicolas Vasilache [Wed, 24 Jul 2019 17:28:04 +0000 (10:28 -0700)]
Cleanup slicing test.
Remove hardcoded SSA names and make use of CHECK-LABEL directives.
PiperOrigin-RevId:
259767803
Nicolas Vasilache [Wed, 24 Jul 2019 12:10:26 +0000 (05:10 -0700)]
Enable multi-level Linalg fusion
This CL adds support for SubViewOp in the alias analysis to permit multiple Linalg fusion passes to compose. The debugging messages are also improved for better readability. The readability benefits came in handy when tracking this issue.
A 2-level fusion test is added to capture the new behavior.
PiperOrigin-RevId:
259720246
Mahesh Ravishankar [Wed, 24 Jul 2019 05:38:23 +0000 (22:38 -0700)]
Add a utility function to populate StdOp to SPIRV Conversion Patterns
The function populateStdOpsToSPIRVPatterns appends the conversion
patterns automatically generated from StdOpsToSPIRVConversion.td to a
list of patterns
PiperOrigin-RevId:
259677890
Jacques Pienaar [Wed, 24 Jul 2019 03:09:11 +0000 (20:09 -0700)]
Update cmake files.
Use MLIR_MAIN_SRC_DIR that also works if MLIR is not checked out in projects
directory & simplify dir for EDSC test.
PiperOrigin-RevId:
259664306
MLIR Team [Tue, 23 Jul 2019 18:23:14 +0000 (11:23 -0700)]
Add sitofp to the standard dialect
Conversion from integers (window or input size, padding etc) to floating point is required to express many ML kernels, for example average pooling.
PiperOrigin-RevId:
259575284
Alex Zinenko [Tue, 23 Jul 2019 17:18:18 +0000 (10:18 -0700)]
Affine loop parallelism detection: conservatively handle unknown ops
The loop parallelism detection utility only collects the affine.load and
affine.store operations appearing inside the loop to analyze the access
patterns for the absence of dependences. However, any operation, including
unregistered operations, can appear in a body of an affine loop. If such
operation has side effects, the result of parallelism analysis is incorrect.
Conservatively assume affine loops are not parallel in presence of operations
other than affine.load, affine.store, affine.for, affine.terminator that may
have side effects.
This required to update the loop-fusion unit test that relies on parallelism
analysis and was exercising loop fusion in presence of an unregistered
operation.
PiperOrigin-RevId:
259560935
Alex Zinenko [Tue, 23 Jul 2019 17:16:52 +0000 (10:16 -0700)]
ODS: support UnitAttr in Operation definitions
A recent commit introduced UnitAttr into the ODS but did not include the
support for using UnitAttrs in operation definitions (only patterns were
supported). Extend the ODS definition of UnitAttr to be usable in operation
definition by providing a trivial builder and an accessor that returns "true"
if the unit attribute is present since the attribute presence itself has
meaning.
Additionally, test that unit attributes are effectively rewritten in patterns
in addition to the already available FileCheck tests of the generated rewriter
code.
PiperOrigin-RevId:
259560653
Alex Zinenko [Tue, 23 Jul 2019 16:26:15 +0000 (09:26 -0700)]
Introduce LLVMFuncOp
Originally, MLIR only supported functions of the built-in FunctionType. On the
conversion path to LLVM IR, we were creating MLIR functions that contained LLVM
dialect operations and used LLVM IR types for everything expect top-level
functions (e.g., a second-order function would have a FunctionType that consume
or produces a wrapped LLVM function pointer type). With MLIR functions
becoming operations, it is now possible to introduce non-built-in function
operations. This will let us use conversion patterns for function conversion,
simplify the MLIR-to-LLVM translation by removing the knowledge of the MLIR
built-in function types, and provide stronger correctness verifications (e.g.
LLVM functions only accept LLVM types).
Furthermore, we can currently construct a situation where the same function is
used with two different types: () -> () when its specified and called directly,
and !llvm<"void ()"> when it's passed somewhere on called indirectly. Having a
special function-op that is always of !llvm<"void ()"> type makes the function
model and the llvm dialect type system more consistent.
Introduce LLVMFuncOp to represent a function in the LLVM dialect. Unlike
standard FuncOp, this function has an LLVMType wrapping an LLVM IR function
type. Generalize the common behavior of function-defining operations
(functions live in a symbol table of a module, contain a single region, are
iterable as a list of blocks, and support argument attributes).
This only defines the operation. Custom syntax, conversion and translation
rules will be added in follow-ups.
The operation name mentions LLVM explicitly to avoid confusion with standard
FuncOp, especially in multiple files that use both `mlir` and `mlir::LLVM`
namespaces.
PiperOrigin-RevId:
259550940
River Riddle [Tue, 23 Jul 2019 04:43:14 +0000 (21:43 -0700)]
Allow std.constant to hold a boolean value.
This was an oversight in the original implementation, std.constant already supports IntegerAttr just not BoolAttr.
PiperOrigin-RevId:
259467710
Uday Bondhugula [Tue, 23 Jul 2019 00:41:38 +0000 (17:41 -0700)]
Introduce parser library method to parse list of region arguments
- introduce parseRegionArgumentList (similar to parseOperandList) to parse a
list of region arguments with a delimiter
- allows defining custom parse for op's with multiple/variadic number of
region arguments
- use this on the gpu.launch op (although the latter has a fixed number
of region arguments)
- add a test dialect op to test region argument list parsing (with the
no delimiter case)
Signed-off-by: Uday Bondhugula <uday@polymagelabs.com>
Closes tensorflow/mlir#40
PiperOrigin-RevId:
259442536
River Riddle [Mon, 22 Jul 2019 22:06:15 +0000 (15:06 -0700)]
Emit an error for missing '[' when parsing an AffineMapOfSSAIds.
Fixes tensorflow/mlir#51
PiperOrigin-RevId:
259415034
Lei Zhang [Mon, 22 Jul 2019 20:30:25 +0000 (13:30 -0700)]
(De)serialize composite spv.constant
This CL covers the case of composite spv.constant. We encode/decode
them into/from OpConstantComposite/OpConstantNull.
PiperOrigin-RevId:
259394700
River Riddle [Mon, 22 Jul 2019 20:22:24 +0000 (13:22 -0700)]
NFC: Update the LoopToStd conversion patterns to use RewritePattern instead of ConversionPattern.
These patterns don't require type changes so they don't need to be using ConversionPattern.
PiperOrigin-RevId:
259393151
River Riddle [Mon, 22 Jul 2019 18:28:04 +0000 (11:28 -0700)]
NFC: Update usage of multi-threading flags.
The multi-threading flags have changed as the feature is on by default and not experimental.
PiperOrigin-RevId:
259369313
Jacques Pienaar [Mon, 22 Jul 2019 17:51:40 +0000 (10:51 -0700)]
Update style/clang-format (NFC).
Update to be consistent & so that future save + clang-format workflows don't introduce extra changes.
PiperOrigin-RevId:
259361174
Lei Zhang [Mon, 22 Jul 2019 13:01:34 +0000 (06:01 -0700)]
(De)serialize float scalar spv.constant
This CL adds support for float scalar spv.constant in (de)serialization.
PiperOrigin-RevId:
259311776
Lei Zhang [Mon, 22 Jul 2019 13:01:11 +0000 (06:01 -0700)]
(De)serialize bool and integer scalar spv.constant
SPIR-V has multiple constant instructions covering different
constant types:
* `OpConstantTrue` and `OpConstantFalse` for boolean constants
* `OpConstant` for scalar constants
* `OpConstantComposite` for composite constants
* `OpConstantNull` for null constants
* ...
We model them all with a single spv.constant op for uniformity
and friendliness to transformations. This does mean that when
doing (de)serialization, we need to poke spv.constant's type
to determine which SPIR-V binary instruction to use.
This CL only covers the case of bool and integer spv.constant.
The rest will follow.
PiperOrigin-RevId:
259311698
Lei Zhang [Mon, 22 Jul 2019 13:00:47 +0000 (06:00 -0700)]
[spirv] NFC: adjust `encode*` function signatures in Serializer
* Let them return `LogicalResult` so we can chain them together
with other functions returning `LogicalResult`.
* Added "Into" as the suffix to the function name and made the
`binary` as the first parameter so that it reads more naturally.
PiperOrigin-RevId:
259311636
Alex Zinenko [Mon, 22 Jul 2019 12:37:57 +0000 (05:37 -0700)]
ODS: introduce ParamNativeOpTrait
In MLIR C++ implementation, certain OpTraits are parameterized by values or
types using nested class templates. These traits correspond to trait
identifiers of the form "OpTrait::TraitName<Parameters>::Impl". Such long
names are arguably too verbose to be spelled out entirely as NativeOpTrait in
ODS and obscure the fact of parameterization. Introduce ParamNativeOpTrait to
generate such trait identifiers from the base name and the parameters directly
in ODS. Exercise the functionality on the SingleBlockImplicitTerminator trait.
PiperOrigin-RevId:
259308796
Lei Zhang [Mon, 22 Jul 2019 12:37:12 +0000 (05:37 -0700)]
[spirv] Remove one level of indirection: processOp to processOpImpl
We already have two levels of controls in SPIRVBase.td: hasOpcode and
autogenSerialization. The former controls whether to add an entry to
the dispatch table, while the latter controls whether to autogenerate
the op's (de)serialization method specialization. This is enough for
our cases. Remove the indirection from processOp to processOpImpl
to simplify the picture.
PiperOrigin-RevId:
259308711
Nicolas Vasilache [Mon, 22 Jul 2019 11:30:50 +0000 (04:30 -0700)]
Refactor LoopParametricTiling as a test pass - NFC
This CL moves LoopParametricTiling into test/lib as a pass for purely testing purposes.
PiperOrigin-RevId:
259300264