Commit Graph

2294 Commits

Author SHA1 Message Date
Lei Zhang 7bf65a0086 Migrate NativeCodeCall and AllAttrConstraintsOf tests to use TestDialect
PiperOrigin-RevId: 256685260
2019-07-05 10:05:43 -07:00
Lei Zhang 80381abfd0 Migrate pattern attribute matching tests to use TestDialect
This CL also reorders op definitions and tests a bit to make them
group more logically.

PiperOrigin-RevId: 256682105
2019-07-05 09:24:15 -07:00
Nicolas Vasilache afadfebe9c Move StdForOp to ODS ForOp
PiperOrigin-RevId: 256657155
2019-07-05 05:05:19 -07:00
Nicolas Vasilache 991040478b Add a standard if op
This CL adds an "std.if" op to represent an if-then-else construct whose condition is an arbitrary value of type i1.
This is necessary to lower all the existing examples from affine and linalg to std.for + std.if.

This CL introduces the op and adds the relevant positive and negative unit test. Lowering will be done in a separate followup CL.

PiperOrigin-RevId: 256649138
2019-07-05 03:35:18 -07:00
Alex Zinenko 471da08e4e Simplify launch_func rewrite pattern in mlir-cuda-runner
Use the bulk setOperands on the cloned operation, no need to cast or iterate
over the operand list.

PiperOrigin-RevId: 256643496
2019-07-05 02:51:53 -07:00
Alex Zinenko ead1acaef2 ODS: provide a flag to skip generation of default build methods
Some operations need to override the default behavior of builders, in
particular region-holding operations such as affine.for or tf.graph want to
inject default terminators into the region upon construction, which default
builders won't do.  Provide a flag that disables the generation of default
builders so that the custom builders could use the same function signatures.
This is an intentionally low-level and heavy-weight feature that requires the
entire builder to be implemented, and it should be used sparingly.  Injecting
code into the end of a default builder would depend on the naming scheme of the
default builder arguments that is not visible in the ODS.  Checking that the
signature of a custom builder conflicts with that of a default builder to
prevent emission would require teaching ODG to differentiate between types and
(optional) argument names in the generated C++ code.  If this flag ends up
being used a lot, we should consider adding traits that inject specific code
into the default builder.

PiperOrigin-RevId: 256640069
2019-07-05 02:28:05 -07:00
Nicolas Vasilache 8c6a3ace16 Add ODS accessors for named regions.
PiperOrigin-RevId: 256639471
2019-07-05 02:21:06 -07:00
Chris Lattner 75ae06acf3 Trivial typo in comment fix.
PiperOrigin-RevId: 256616187
2019-07-04 22:18:12 -07:00
River Riddle 474e354179 NFC: Remove Region::getContainingFunction as Functions are now Operations.
PiperOrigin-RevId: 256579717
2019-07-04 13:23:10 -07:00
Alex Zinenko fa6b49b095 Fix another incorrect forward declaration of LogicalResult
LogicalResult is a struct and the Windows build is unhappy about it being
forward-declared as class.

PiperOrigin-RevId: 256578230
2019-07-04 13:05:54 -07:00
Alex Zinenko abc722a582 Forward-declare LogicalResult as struct
LogicalResult is a struct but some headers forward-declare it as a class, which
breaks Windows builds.  Forward-delcare as a struct instead.

PiperOrigin-RevId: 256565699
2019-07-04 10:17:11 -07:00
Alex Zinenko 6f7f2bced8 Make TranslateFromMLIRFunction type return LogicalResult instead of bool
This interface was created before MLIR introduced LogicalResult.

PiperOrigin-RevId: 256554557
2019-07-04 08:19:14 -07:00
Stephan Herhut e8b21a75f8 Add an mlir-cuda-runner tool.
This tool allows to execute MLIR IR snippets written in the GPU dialect
on a CUDA capable GPU. For this to work, a working CUDA install is required
and the build has to be configured with MLIR_CUDA_RUNNER_ENABLED set to 1.

PiperOrigin-RevId: 256551415
2019-07-04 07:53:54 -07:00
Alex Zinenko bd17bd299f AllocOp: drop redundant verifier check
The equality check between the rank of a memref and the input size of the
layout affine map in AllocOp::verify is subsumed by the well-formedness check
of the memref type itself.  Drop the redundant check from the verifier since it
is never exercised (the type builder does not allow one to construct a type
that would not pass the verifier check).

PiperOrigin-RevId: 256551247
2019-07-04 07:53:42 -07:00
Stephan Herhut 1bcaa3185d Add missing mlir:: namespace in definition of createConvertToLLVMIRPass.
PiperOrigin-RevId: 256546769
2019-07-04 07:53:31 -07:00
Alex Zinenko 9a1b6fec79 Make ConvertStandardToLLVMPass extendable with other patterns
Extend the LLVM lowering pass to accept callbacks that construct an instance of
(a subclass of) LLVMTypeConverter and populate a list of conversion patterns.
These callbacks will be called when the pass processes a module and their
results will be used to set up the dialect conversion infrastructure.  Clients
can now provide additional conversion patterns to avoid the need of
materializing type conversions between LLVM and other types.

PiperOrigin-RevId: 256532415
2019-07-04 07:53:19 -07:00
Mahesh Ravishankar 82679d4718 NFC: Refactoring to remove code bloat in SPIRV due to handling of Enum
Class Attribute parsing

PiperOrigin-RevId: 256471248
2019-07-03 18:18:01 -07:00
Lei Zhang 9cde4be7a5 [TableGen] Support creating multi-result ops in result patterns
This CL introduces a new syntax for creating multi-result ops and access their
results in result patterns. Specifically, if a multi-result op is unbound or
bound to a name without a trailing `__N` suffix, it will act as a value pack
and expand to all its values. If a multi-result op is bound to a symbol with
`__N` suffix, only the N-th result will be extracted and used.

PiperOrigin-RevId: 256465208
2019-07-03 18:17:49 -07:00
River Riddle e7d594bb1c Replace the implementation of Function and Module with FuncOp and ModuleOp.
This is an important step in allowing for the top-level of the IR to be extensible. FuncOp and ModuleOp contain all of the necessary functionality, while using the existing operation infrastructure. As an interim step, many of the usages of Function and Module, including the name, will remain the same. In the future, many of these will be relaxed to allow for many different types of top-level operations to co-exist.

PiperOrigin-RevId: 256427100
2019-07-03 14:37:18 -07:00
Andy Davis 2e1187dd25 Globally change load/store/dma_start/dma_wait operations over to affine.load/store/dma_start/dma_wait.
In most places, this is just a name change (with the exception of affine.dma_start swapping the operand positions of its tag memref and num_elements operands).
Significant code changes occur here:
*) Vectorization: LoopAnalysis.cpp, Vectorize.cpp
*) Affine Transforms: Transforms/Utils/Utils.cpp

PiperOrigin-RevId: 256395088
2019-07-03 14:37:06 -07:00
Nicolas Vasilache 28fb743798 More general subview calculation in tiling
This CL refactors tiling to enable tiling of views that are not just specified by a simple permutation. This allows the tiling of convolutions for which a new example is added.

PiperOrigin-RevId: 256346028
2019-07-03 14:36:42 -07:00
Nicolas Vasilache 0024ddc4ae Add a generic loop abstraction to the std dialect
This CL is the first step of a refactoring unification of the control flow abstraction used in different dialects. The `std.for` loop accepts unrestricted indices to encode min, max and step and will be used as a common abstraction on the way to lower level dialects.

PiperOrigin-RevId: 256331795
2019-07-03 14:36:30 -07:00
River Riddle 95279afbf7 NFC: Allow clearing the functions of a Module and splicing the functions from other modules.
PiperOrigin-RevId: 256280543
2019-07-03 14:36:18 -07:00
River Riddle ff9779e5b4 Add support for getting and setting the dialect attributes of an operation.
This allows for handling dialect attributes, those with names starting with a dialect prefix, to be handled explicitly.

PiperOrigin-RevId: 256279728
2019-07-03 14:36:06 -07:00
River Riddle 611ae950ed Add a 'getOps<>' method to Block to only iterate operations of a certain kind.
PiperOrigin-RevId: 256277436
2019-07-03 14:35:54 -07:00
Lei Zhang 0782b37936 NFC: Move Standard to SPIR-V conversion to lib/Conversion
PiperOrigin-RevId: 256271759
2019-07-03 14:35:42 -07:00
River Riddle d3f743252d NFC: Move the Function/Module/Operation::verify methods out-of-line.
As Functions/Modules becomes operations, these methods will conflict with the 'verify' hook already on derived operation types.

PiperOrigin-RevId: 256246112
2019-07-02 16:43:36 -07:00
Nicolas Vasilache 516188bf1c Add support for promoting Linalg views into new buffers.
This CL uses the generic CopyOp to promote a subview (constructed during tiling) into a new buffer + copy by:
  1. Creating a new buffer for the subview.
  2. Taking a view into the buffer and copying into it.
  3. Adapting the linalg op to operating on the view from point 2.
Tiling is extended with a boolean flag to enable promoting views (all or nothing for now).

More specifically, the current implementation creates a buffer that is always of the full size of the ranges of the subview. This produces a buffer whose size may be bigger
than the actual size of the `subView` at the boundaries and is related to the full/partial tile problem.

In practice, we introduce a `buffer`, a `fullLocalView` and a `partialLocalView` such that:
  * `buffer` is always the size of the subview in the full tile case.
  * `fullLocalView` is a dense contiguous view into that buffer.
  * `partialLocalView` is a dense non-contiguous slice of `fullLocalView`
     that corresponds to the size of `subView` and accounting for boundary
     effects.
The point of the full tile buffer is that constant static tile sizes are
folded and result in a buffer type with statically known size and alignment
properties.

Padding is introduced on the boundary tiles with a `fill` op followed by a partial `copy` op.

These behaviors will be refined later, on a per-need basis.

PiperOrigin-RevId: 256237319
2019-07-02 16:43:36 -07:00
Mahesh Ravishankar c73edeec13 Add support for SPIR-V Struct Types. Current support is limited to
supporting only Offset decorations

PiperOrigin-RevId: 256216704
2019-07-02 16:43:36 -07:00
Lei Zhang 08927308b7 [spirv] Various small improvements
* Added comments
* Improved op creation
* Used LogicalResult where suitable

PiperOrigin-RevId: 256203068
2019-07-02 16:43:36 -07:00
River Riddle 206e55cc16 NFC: Refactor Module to be value typed.
As with Functions, Module will soon become an operation, which are value-typed. This eases the transition from Module to ModuleOp. A new class, OwningModuleRef is provided to allow for owning a reference to a Module, and will auto-delete the held module on destruction.

PiperOrigin-RevId: 256196193
2019-07-02 16:43:36 -07:00
Brett Koonce b4a2dbc8b6 docs: minor spelling tweaks
Close tensorflow/mlir#23
2019-07-02 16:43:02 -07:00
Mahesh Ravishankar 25094e90bd Resolving buffer operand of linalg.view doesnt have the information
about the buffer size. This is needed to resolve the operand
correctly. Add that information to view op
serialization/deserialization

Also modify the parsing of buffer type by splitting at 'x' to
side-step issues with StringRef number parsing.

PiperOrigin-RevId: 256188319
2019-07-02 10:28:59 -07:00
Jacques Pienaar 5c4ae813ee Update readme to reflect accepting contributions.
PiperOrigin-RevId: 256171145
2019-07-02 10:28:48 -07:00
Lei Zhang 509411c229 [ODS] NFC: Rename EnumAttr to StrEnumAttr to be consistent with IntEnumAttr
PiperOrigin-RevId: 256169019
2019-07-02 10:28:36 -07:00
Lei Zhang 32f3c6c74e [spirv] Use I32EnumAttr for enum attributes
This saves us the excessive string conversions and comparisons in
verification and transformation and scopes them only to parsing
and printing, which are meant for I/O so string conversions should
be fine.

In order to do this, changed the custom assembly format of
spv.module regarding addressing model and memory model.

PiperOrigin-RevId: 256149856
2019-07-02 10:28:24 -07:00
River Riddle 25f29e1b15 NFC: Update the Operation 'walk' methods to use llvm::function_ref instead of std::function.
PiperOrigin-RevId: 256099638
2019-07-02 10:28:12 -07:00
River Riddle 479a3e0613 NFC: Add several utilities to OpState.
* 'walk' functionality.
* Method to set the location.
* 'dump'/'print' methods.
* Method to set the attributes.

PiperOrigin-RevId: 256097960
2019-07-02 10:28:00 -07:00
Lei Zhang 22883036cd EnumsGen: remove dangling assertion
StringAttr-backed enum attribute cases changed to allow explicit values,
But this assertion was not deleted.

Fixes https://github.com/tensorflow/mlir/issues/39

PiperOrigin-RevId: 256090793
2019-07-02 10:27:49 -07:00
Jacques Pienaar d71b8bae02 Update variable naming to match LLVM coding style.
Update to follow enumerators naming style
https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly
this also avoids the mach/boolean.h macros.

PiperOrigin-RevId: 256069831
2019-07-01 18:00:58 -07:00
Alex Zinenko 0b468b0101 gpu::LaunchOp: canonicalize away constant kernel arguments
The GPU Launch operation may take constants as arguments, in particular
affine-to-GPU mapping pass automatically forwards potentially constant lower
bounds of loops into the kernel.  Define a canonicalization pattern for
LaunchOp that recreates the constants inside the kernel region instead of
accepting them as kernel arguments.  This is currently restricted to standard
constants but may be extended to other constant operations.

Also fix an off-by-one indexing bug in OperandStorage::eraseOperand.

PiperOrigin-RevId: 256035437
2019-07-01 17:03:03 -07:00
River Riddle 705b80918d Generalize the CFG graph printing for Functions to work on Regions instead.
PiperOrigin-RevId: 256029944
2019-07-01 17:02:51 -07:00
River Riddle 694975ddbc Standardize the definition and usage of getAllArgAttrs between FuncOp and Function.
PiperOrigin-RevId: 255988352
2019-07-01 11:39:12 -07:00
River Riddle 54cd6a7e97 NFC: Refactor Function to be value typed.
Move the data members out of Function and into a new impl storage class 'FunctionStorage'. This allows for Function to become value typed, which will greatly simplify the transition of Function to FuncOp(given that FuncOp is also value typed).

PiperOrigin-RevId: 255983022
2019-07-01 11:39:00 -07:00
River Riddle 84bd67fc4f Update the 1->N legalizer test to use "test.return" so that the conversion cast is elided properly.
PiperOrigin-RevId: 255979732
2019-07-01 11:38:47 -07:00
Alex Zinenko 5eef726bc8 TypeConversion: do not materialize conversion of the type to itself
Type conversion does not necessarily affect all types, some of them may remain
untouched.  The type conversion tool from the dialect conversion framework will
unconditionally insert a temporary cast operation from the type to itself
anyway, and will try to materialize it to a real conversion operation if there
are remaining uses.  Simply use the original value instead.

PiperOrigin-RevId: 255975450
2019-07-01 09:56:56 -07:00
Alex Zinenko a83fd0d2c7 Run FileCheck on test-legalizer.mlir
The RUN line was missing a call to FileCheck making the test always pass.  Add
the call to FileCheck and temporarily disable one of the tests that does not
produce the expected result.

PiperOrigin-RevId: 255974805
2019-07-01 09:56:44 -07:00
Andy Davis f487d20bf0 Add affine-to-standard lowerings for affine.load/store/dma_start/dma_wait.
PiperOrigin-RevId: 255960171
2019-07-01 09:56:22 -07:00
Lei Zhang 2dc5e19426 Also disable generating underlying value to symbol conversion declaration when there is an enumerant without explicit value
PiperOrigin-RevId: 255950779
2019-07-01 09:56:11 -07:00
Lei Zhang 2652be7934 Avoid generating underlying value to symbol conversion function if there is an enumerant without explicit value.
PiperOrigin-RevId: 255945801
2019-07-01 09:55:59 -07:00