Commit Graph

2052 Commits

Author SHA1 Message Date
Lei Zhang a3e6f102ca [ODG] Fix value indices in verification error messages
we should use the dynamic index for the specific value instead
of the static one for ODS-declared values.

PiperOrigin-RevId: 252873052
2019-06-19 23:00:04 -07:00
Nicolas Vasilache de32c03ebe Add Linalg FillOp
This CL adds a generic FillOp to Linalg and its lowering to loops.
This is achieved by avoiding to specify the static NLoopTypes and ViewRanks type traits but instead defines the relevant methods as `extraClassDeclaration`.
The relevant AffineMap and scalar emission code are added, with relevant tests.

This gives us a first rank-agnostic Linalg op with its generic lowering to loops that should compose with view-based tiling and fusion.

PiperOrigin-RevId: 252869205
2019-06-19 22:59:54 -07:00
Alex Zinenko 867867a44d Fix static assertion in AttributeDetail.h
llvm::maskTrailingOnes<char> runs into a static assertion on the type not being
unsigned.  Use `unsigned char` instead of `char`.
PiperOrigin-RevId: 252827214
2019-06-19 22:59:45 -07:00
Nicolas Vasilache d43b8923e0 Update 2 instances of isa<BlockArgument>
PiperOrigin-RevId: 252739405
2019-06-19 22:59:35 -07:00
Nicolas Vasilache 705b2b5ea4 Fix OSS build
Missing a spot with std::make_pair causes a compiler error in OSS.
Also fixes the warning:
```
warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]
            it->getSecond()->getType().isa<BufferType>() &&
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
                "Buffer or block argument expected");
```
PiperOrigin-RevId: 252738323
2019-06-19 22:59:25 -07:00
River Riddle d8cd96bc8b Refactor DenseElementsAttr to support auto-splatting the dense data on construction. This essentially means that we always auto-detect splat data and only store the minimum amount of data necessary. Support for parsing dense splats, and removing SplatElementsAttr(now that it is redundant) will come in followup cls
PiperOrigin-RevId: 252720561
2019-06-19 22:59:15 -07:00
River Riddle 5da741f671 Add basic cost modeling to the dialect conversion infrastructure. This initial cost model favors specific patterns based upon two criteria:
1) Lowest minimum pattern stack depth when legalizing.
  - This leads the system to favor patterns that have lower legalization stacks, i.e. represent a more direct mapping to the target.

2)  Pattern benefit.
  - When considering multiple patterns with the same legalization depth, this favors patterns with a larger specified benefit.

PiperOrigin-RevId: 252713470
2019-06-19 22:59:06 -07:00
Nicolas Vasilache bab53a9484 Add a Linalg fusion pass.
This CL adds a fusion pass for the Linalg dialect.
Fusion is backed by a simple analysis on SSA values and proceeds as follows:
1. A dependence and alias analyses are performed on views.
2. A Linalg op is tiled by a particular tile size. This creates a new Linalg op operating on tiled loops and tiled views.
3. The dependence analysis is used to obtain ops that produce views that are consumed by the original Linalg op.
4. Dependence analysis is used to determine whether op-level fusion would violate any dependence.
5. If fusion is safe, matching tiled views are sliced for the producing op.
6. A tiled clone of the producer op is written before the tiled consumer op.

If a producer is fused, its entire output view has been computed in tiled form.
The original producer op is then erased.

PiperOrigin-RevId: 252695194
2019-06-19 22:58:56 -07:00
Nicolas Vasilache a8a4d35d3f Add a lowering for Linalg matmul to LLVM
This CL adds a lowering to LLVM for MamulOp and a corresponding integration test.

View descriptor manipulation is moved from MLIR's LLVM dialect to C++ code compiled on the side. To this end a separation is introduced between `cblas.cpp` and `cblas_interface.cpp`, the latter operating on view types whose ABI correspond to the LLVM signature generated by MLIR.

An intermediary step is introduced that allocates a new descriptor on the MLIR side for the purpose of passing it to LLVM. The reason for this extra step is that the ABI for by-value ViewType objects wants aligned descriptors, e.g.:
```
extern "C" void linalg_dot_impl(ViewType<float, 1> X, ViewType<float, 1> Y,
                                BaseViewType<float> Z) {
   ...
}
```
produces LLVM IR with the signature:
```
%struct.ViewType = type { %struct.BaseViewType, [1 x i64], [1 x i64] }
%struct.BaseViewType = type { float*, i64 }

define void @linalg_dot_impl(%struct.ViewType* byval align 8, %struct.ViewType* byval align 8, float*, i64) tensorflow/mlir#0 {
...
}
```

We don't seem to be able to make such aligned  allocations in the MLIR -> LLVM converter atm.
Going through a level of indirection allows the test to pass.
The temporary tradeoff is that the MLIR shims have to be written by hand.
They will disappear in the future.

PiperOrigin-RevId: 252670672
2019-06-19 22:58:46 -07:00
Jacques Pienaar f3ececd6b3 Simplify trait naming for verifying argument/result constraints.
Improve the naming to something more intuitive.

PiperOrigin-RevId: 252662347
2019-06-19 22:58:36 -07:00
Mahesh Ravishankar d3a601ce33 [spirv] Add a skeleton to translate standard ops into SPIR-V dialect
PiperOrigin-RevId: 252651994
2019-06-19 22:58:26 -07:00
River Riddle 420c1f383a Add a utility to OpAsmPrinter for printing an optional trailing arrow type list. This is useful for any operation that wants to print a set of types in the same format as a FunctionType/Operation signature.
PiperOrigin-RevId: 252647152
2019-06-19 22:58:16 -07:00
River Riddle eb28b30940 NFC: Cleanup the naming scheme for registering legalization actions to be consistent, and move a file functions to the source file.
PiperOrigin-RevId: 252639629
2019-06-11 10:14:35 -07:00
Alex Zinenko 8ad35b90ec Use DialectConversion to lower the Affine dialect to the Standard dialect
This introduces the support for region-containing operations to the dialect
conversion framework in order to support the conversion of affine control-flow
operations into the standard control flow with branches.  Regions that belong
to an operation are converted before the operation itself.  The
DialectConversionPattern can therefore access the converted regions of the
original operation and process them further if necessary.  In particular, the
conversion is allowed to move the blocks from the original region to other
regions and to split blocks into multiple blocks.  All block manipulations must
be performed through the PatternRewriter to ensure they will be undone if the
conversion fails.

Port the pass converting from the affine dialect (loops and ifs with bodies as
regions) to the standard dialect (branch-based cfg) to use DialectConversion in
order to exercise this new functionality.  The modification to the lowering
functions are minor and are focused on using the PatterRewriter instead of
directly modifying the IR.

PiperOrigin-RevId: 252625169
2019-06-11 10:14:27 -07:00
Lei Zhang c680d7d063 [spirv] Include SPIRVStructureOps.td in SPIRVOps.td
This allows us to have SPIRVOps.td as the single entry point for
all SPIR-V ops, which simplifies downstream users and build rules.

PiperOrigin-RevId: 252609258
2019-06-11 10:14:19 -07:00
Lei Zhang 6553b90c82 [ODG] Add support for private methods in class writers
PiperOrigin-RevId: 252602093
2019-06-11 10:14:11 -07:00
Lei Zhang fd6542c12b [spirv] Add missing CMake rules for enum utility generation
PiperOrigin-RevId: 252601308
2019-06-11 10:14:02 -07:00
Jacques Pienaar 765734c6ab Add bool constant attributes.
PiperOrigin-RevId: 252551030
2019-06-11 10:13:54 -07:00
Mehdi Amini dfd6b349ea Fix MSVC 2019 missing <string> include (NFC)
Fix tensorflow/mlir#31.

PiperOrigin-RevId: 252547010
2019-06-11 10:13:46 -07:00
River Riddle d4491084ae Change a call to FloatAttr::getChecked to FloatAttr::get inside of 'parseFloatAttr'. The invariants of FloatAttr are already checked before construction. This also removes an unnecessary materialization of a mlir::Location which becomes expensive when parsing dense element literals.
PiperOrigin-RevId: 252545776
2019-06-11 10:13:37 -07:00
River Riddle 65c94470ed Add a general Operation::verify that verifies an operation instance and the dominance of operations in any nested regions.
PiperOrigin-RevId: 252529850
2019-06-11 10:13:28 -07:00
Lei Zhang eb3ed07cd1 [spirv] Add values for enum cases and generate the enum utilities
PiperOrigin-RevId: 252494957
2019-06-11 10:13:20 -07:00
Lei Zhang 5392d3badf [spirv] NFC: use two spaces for indentation in gen_spirv_dialect.py
PiperOrigin-RevId: 252469663
2019-06-11 10:13:11 -07:00
Nicolas Vasilache 3148d60e60 Expose a minimal type parser to dialects.
This CL exposes a parseType method which allows standalone reuse of the MLIR type parsing mechanism. This is a free function for now because the underlying MLIR parser is not guaranteed to receive a StringRef which lives in the proper MemBuffer. This requires building a new MemBuffer/SourceMgr and modifying the Parser constructor to not require an mlir::Module.

The error diagnostic emitted by parseType has context limited to the local string.
For now the dialect has the additional option to emit its own extra error that has the FileLineColLoc context.

In the future, both error messages should be combined into a single error.

PiperOrigin-RevId: 252468911
2019-06-11 10:13:02 -07:00
Lei Zhang e5c8bed43a [spirv] Add array and run-time array types
PiperOrigin-RevId: 252458108
2019-06-11 10:12:53 -07:00
Lei Zhang 9e95e07987 [ODG] Address compiler warnings of comparing signed and unsigned integer expressions
PiperOrigin-RevId: 252442613
2019-06-11 10:12:44 -07:00
Andy Davis e33e36f178 Return dependence result enum to distiguish between dependence result and error cases (NFC).
PiperOrigin-RevId: 252437616
2019-06-11 10:12:36 -07:00
Lei Zhang 3812d956ea [ODS] Support variadic operand/result verification
This CL enables verification code generation for variadic operands and results.
In verify(), we use fallback getter methods to access all the dynamic values
belonging to one static variadic operand/result to reuse the value range
calculation there.

PiperOrigin-RevId: 252288219
2019-06-09 16:24:29 -07:00
Lei Zhang 7f108e60cc [ODG] Use getODSOperands() and getODSResults() to back accessors
This CL added getODSOperands() and getODSResults() as fallback getter methods for
getting all the dynamic values corresponding to a static operand/result (which
can be variadic). It should provide a uniform way of calculating the value ranges.
All named getter methods are layered on top of these methods now.

PiperOrigin-RevId: 252284270
2019-06-09 16:24:18 -07:00
Lei Zhang 1be9fc6611 [TableGen] Generating enum definitions and utility functions
Enum attributes can be defined using `EnumAttr`, which requires all its cases
to be defined with `EnumAttrCase`. To facilitate the interaction between
`EnumAttr`s and their C++ consumers, add a new EnumsGen TableGen backend
to generate a few common utilities, including an enum class, `llvm::DenseMapInfo`
for the enum class, conversion functions from/to strings.

This is controlled via the `-gen-enum-decls` and `-gen-enum-defs` command-line
options of `mlir-tblgen`.

PiperOrigin-RevId: 252209623
2019-06-09 16:24:08 -07:00
MLIR Team b0ee20f924 Update function comment, since we added FP16 support for getZeroAttr.
PiperOrigin-RevId: 252110998
2019-06-09 16:23:56 -07:00
River Riddle 61c3b5df38 NFC: Cleanup the grouping of DenseElementsAttr 'get' methods, and move the bit write/read functions to static functions in Attributes.cpp.
PiperOrigin-RevId: 252094145
2019-06-09 16:23:45 -07:00
River Riddle 0cadec8ae6 Remove the ability to directly construct a DenseElementsAttr with a raw character buffer. This made assumptions about how DenseElementsAttr structured its internal storage, which may change in the future. To replace the existing use cases, a few utility methods have been added:
* 'get' methods that allow constructing from an ArrayRef of integer or floating point values.
* A 'reshape' method to allow for changing the shape without changing the underlying data.

PiperOrigin-RevId: 252067898
2019-06-09 16:23:34 -07:00
River Riddle 62facfaf42 NFC: Cleanup FuncVerifier and refactor it into a general OperationVerifier. The function specific verification has been moved into Function::verify. This is in preparation for adding a general Operation::verify method.
PiperOrigin-RevId: 252065646
2019-06-09 16:23:23 -07:00
Geoffrey Martin-Noble 24723de5c2 Remove unnecessary StandardOps dependency
PiperOrigin-RevId: 252032386
2019-06-09 16:23:11 -07:00
Mehdi Amini 37f54b3552 Add a convenient getDialect() accessor on Op<> class
PiperOrigin-RevId: 251988464
2019-06-09 16:23:01 -07:00
River Riddle 7c50d6afbe NFC: Replace typelist_contains with llvm::is_one_of. This should also fix weird build failures on MSVC related to typelist_contains for missing template arguments.
PiperOrigin-RevId: 251987621
2019-06-09 16:22:49 -07:00
Jacques Pienaar 0b88d44943 Add free standing getElementTypeOrSelf member.
This function returns the element type of the underlying type or the input type itself. This removes some of the casting and code from ODS and into C++ code.

I've not converted all the call sites (as this requires a new include and target) and wanted to run it past folks first.

PiperOrigin-RevId: 251978156
2019-06-09 16:22:38 -07:00
Mehdi Amini 36ebf56a19 Internal change
PiperOrigin-RevId: 251972430
2019-06-09 16:22:27 -07:00
MLIR Team b8227c9ac3 Add the getDialectNamespace static utility method to the Linalg dialect.
PiperOrigin-RevId: 251953766
2019-06-09 16:22:16 -07:00
River Riddle b790a2f396 Remove the explicit attribute kinds for DenseIntElementsAttr and DenseFPElementsAttr in favor of just one DenseElementsAttr. Now that attribute has the ability to define 'classof(Attribute attr)' methods, these derived classes can just be specializations of the main attribute class.
PiperOrigin-RevId: 251948820
2019-06-09 16:22:05 -07:00
Ben Vanik cc8a8fa76a Adding utility to parse optional colon-type-lists.
PiperOrigin-RevId: 251945512
2019-06-09 16:21:54 -07:00
River Riddle e6872ce7b7 Simplify DenseElementsAttr by rounding up the storage of odd bit widths to 8-bits. This removes the requirement that the underlying buffer be aligned to 64 bits which opens the door for several optimizations in the future, e.g. detecting splat.
PiperOrigin-RevId: 251944922
2019-06-09 16:21:43 -07:00
River Riddle e7ccfb2ae8 Add support to ConversionTarget for storing legalization actions for entire dialects as opposed to individual operations. This allows for better support of unregistered operations, as well as removing the need to collect all of the operations for a given dialect(which may be very expensive).
PiperOrigin-RevId: 251943590
2019-06-09 16:21:32 -07:00
River Riddle e25796ef6e Add support for matchAndRewrite to the DialectConversion patterns. This also drops the default "always succeed" match override to better align with RewritePattern.
PiperOrigin-RevId: 251941625
2019-06-09 16:21:20 -07:00
River Riddle 3ab5c0bfaf Add a general operation property 'IsolatedFromAbove' that guarantees that all regions of a given operation are explicit capture only and will not reference values defined above the enclosing operation. This trait will be useful for applying some of the properties currently attached to Functions to operations, e.g. verifying dominance within a specific operation, enabling multi-threading of certain transformations between different instances, etc.
PiperOrigin-RevId: 251927466
2019-06-09 16:21:08 -07:00
River Riddle fa187e0f3b Support constructing DominanceInfo with an Operation. This computes the dominance information for any nested regions within the operation.
PiperOrigin-RevId: 251896520
2019-06-09 16:20:57 -07:00
MLIR Team f55f7dc769 Support FP16 in getZeroAttr.
PiperOrigin-RevId: 251783931
2019-06-09 16:20:47 -07:00
River Riddle 82f9be83a3 Add a verify method to FuncOp and check that the type signature matches the signature of the entry block.
PiperOrigin-RevId: 251759848
2019-06-09 16:20:35 -07:00
River Riddle 0840ecfd46 NFC: Rename FunctionParser to OperationParser. There is nothing specific to functions about this parser and provides general parser support for operations, and regions of operations.
PiperOrigin-RevId: 251749622
2019-06-09 16:20:24 -07:00