Commit Graph

2172 Commits

Author SHA1 Message Date
MLIR Team 7b5f49af76 Parenthesize match expression to avoid operator precedence issues
PiperOrigin-RevId: 255435454
2019-06-27 11:07:07 -07:00
River Riddle bda669beea Allow attaching a type to StringAttr.
Some dialects allow for string types, and this allows for reusing StringAttr for constants of these types.

PiperOrigin-RevId: 255413948
2019-06-27 09:13:44 -07:00
Jacques Pienaar c48675fd87 Fix incorrect type used in forward declaration.
Addresses compiler warning.

PiperOrigin-RevId: 255407691
2019-06-27 08:39:17 -07:00
MLIR Team 1533e53159 Support parsing MLIR source from stdin.
PiperOrigin-RevId: 255316118
2019-06-26 19:57:04 -07:00
River Riddle 6ebd6df69f Add a new AttributeElementIterator to DenseElementsAttr.
This allows for iterating over the internal elements via an iterator_range of Attribute, and also allows for removing the final SmallVectorImpl based 'getValues' method.

PiperOrigin-RevId: 255309555
2019-06-26 18:50:18 -07:00
River Riddle 260d3e39ad Standardize and refactor Attribute type printing.
Remove the ability to print an attribute without a type, but allow for attributes to elide the type under certain circumstances. This fixes a bug where attributes within ArrayAttr, and other collection attributes, would never print the type.

PiperOrigin-RevId: 255306974
2019-06-26 18:29:54 -07:00
Jacques Pienaar d4cf54f2c1 Split out TranslateClParser and add new parse method that reuses SourceMgr.
Split out class to command line parser for translate methods into standalone
class. Similar to splitting up mlir-opt to reuse functionality with different
initialization.

PiperOrigin-RevId: 255225790
2019-06-26 11:14:45 -07:00
Stephan Herhut 630119f84f Add a pass that inserts getters for all cubins found via nvvm.cubin
annotations.

Getters are required as there are currently no global constants in MLIR and this
is an easy way to unblock CUDA execution while waiting for those.

PiperOrigin-RevId: 255169002
2019-06-26 05:33:11 -07:00
Stephan Herhut c72c6c3907 Make GPU to CUDA transformations independent of CUDA runtime.
The actual transformation from PTX source to a CUDA binary is now factored out,
enabling compiling and testing the transformations independently of a CUDA
runtime.

MLIR has still to be built with NVPTX target support for the conversions to be
built and tested.

PiperOrigin-RevId: 255167139
2019-06-26 05:16:37 -07:00
River Riddle a4c3a6455c Move the emitError/Warning/Remark utility methods out of MLIRContext and into the mlir namespace.
Now that Locations are attributes, they have direct access to the MLIR context. This allows for simplifying error emission by removing unnecessary context lookups.

PiperOrigin-RevId: 255112791
2019-06-25 21:32:23 -07:00
River Riddle 679a3b4191 Change the attribute dictionary syntax to separate name and value with '='.
The current syntax separates the name and value with ':', but ':' is already overloaded by several other things(e.g. trailing types). This makes the syntax difficult to parse in some situtations:

Old:
  "foo: 10 : i32"

New:
  "foo = 10 : i32"
PiperOrigin-RevId: 255097928
2019-06-25 19:06:34 -07:00
River Riddle 49162524d8 NFC: Uniformize the return of the LocationAttr 'get' methods to 'Location'.
PiperOrigin-RevId: 255078768
2019-06-25 16:57:56 -07:00
River Riddle 4842b2d42e Modify the syntax of the the ElementsAttrs to print the type as a colon type.
This is the standard syntax for types on operations, and is also already used by IntegerAttr and FloatAttr.

Example:
  dense<5> : tensor<i32>
  dense<[3]> : tensor<1xi32>
PiperOrigin-RevId: 255069157
2019-06-25 16:06:58 -07:00
Rasmus Munk Larsen 1df5f3159e Fix typo in Toy tutorial documentation
PiperOrigin-RevId: 255054639
2019-06-25 15:00:08 -07:00
Rasmus Munk Larsen 9966ba2b3c Fix unclear sentence.
PiperOrigin-RevId: 255022564
2019-06-25 12:24:00 -07:00
River Riddle 3ca33a5c62 Move the IndexedAccessorIterator to STLExtras to allow for reuse.
This iterator is useful for implementing random access iterators based upon an index and an object pointer. Moving it to STLExtras allows for reuse elsewhere throughout the codebase, e.g. simplifying the DenseElementsAttr iterators.

PiperOrigin-RevId: 255020377
2019-06-25 12:11:14 -07:00
Nicolas Vasilache f08dcfaf89 Internal change
PiperOrigin-RevId: 255018853
2019-06-25 12:03:29 -07:00
Andy Davis 91f27d025b Support printing SSA ids in affine.load/store which do not have special names.
PiperOrigin-RevId: 254997746
2019-06-25 10:30:26 -07:00
River Riddle 66ed7d6d83 Update the OperationFolder to find a valid insertion point when materializing constants.
The OperationFolder currently just inserts into the entry block of a Function, but regions may be isolated above, i.e. explicit capture only, and blindly inserting constants may break the invariants of these regions.

PiperOrigin-RevId: 254987796
2019-06-25 09:43:21 -07:00
Alex Zinenko 2628641b23 GPUtoNVVM: adjust integer bitwidth when lowering special register ops
GPU dialect operations (launch and launch_func) use `index` type for thread and
block index values inside the kernel, for compatibility with affine loops.
NVVM dialect operations, following the NVVM intrinsics, use `!llvm.i32` type,
which does not necessarily have the same bit width as the lowered `index` type.
Optionally sign-extend (indices are signed) or truncate the result of the NVVM
dialect operation to the bit width of the lowered `index` type before passing
it to other operations.  This behavior is consistent with `std.index_cast`.  We
cannot use the latter since we are targeting LLVM dialect types directly,
rather than standard integer types.

PiperOrigin-RevId: 254980868
2019-06-25 09:21:26 -07:00
Stephan Herhut 10f320f7c0 Add gpu::GPUDialect::isKernel helper.
Also some mild cleanup of the kernel to cubin conversion pass.

PiperOrigin-RevId: 254959303
2019-06-25 09:20:40 -07:00
Nicolas Vasilache 594c826578 Add missing dependence to MLIRLLVMIR
PiperOrigin-RevId: 254957980
2019-06-25 09:19:59 -07:00
Alex Zinenko f35d0c8570 NVVM target: emit nvvm.annotations for kernel functions
PTX backend in LLVM expects additional module-level metadata
`!nvvm.annotations` that lists functions that can be used as GPU kernels.
Generate this metadata based on the `gpu.kernel` attribute attached to
functions.  This attribute is added automatically by the kernel outlining pass
in the GPU dialect lowering flow.

PiperOrigin-RevId: 254957345
2019-06-25 09:19:27 -07:00
Alex Zinenko 43c0cf109f gpu.launch_func: add accessors to grid configuration operands
Add accessor functions that return `gpu::KernelDim3` containing the respective
operands for grid and block size accepted by `gpu.launch_func`.  Use the same
signature as for `gpu.launch`.

PiperOrigin-RevId: 254942674
2019-06-25 09:18:47 -07:00
Mehdi Amini 14a10a818b Print both type in diagnostic emitted on mismatch between def/use of SSA Values (NFC)
The error would look like:

  path/filename.mlir:32:23: error: use of value '%28' expects different type than prior uses: ''i32'' vs ''!_tf.control''

PiperOrigin-RevId: 254874859
2019-06-25 09:05:02 -07:00
River Riddle c32080a1b0 NFC: Move the ArgConverter methods out-of-line to improve readability.
PiperOrigin-RevId: 254872695
2019-06-24 17:47:51 -07:00
Nicolas Vasilache 95cfd99616 Fix OSS build
PiperOrigin-RevId: 254847773
2019-06-24 17:47:27 -07:00
Nicolas Vasilache dac75ae5ff Split test-specific passes out of mlir-opt
Instead put their impl in test/lib and link them into mlir-test-opt

PiperOrigin-RevId: 254837439
2019-06-24 17:47:12 -07:00
River Riddle 6192978bc0 Cache several common LLVMTypes in the LLVMDialect.
LLVM is not thread-safe which means that several of the 'get' methods for LLVMType must be double locked to ensure thread-safety. This cl adds static caching, i.e. no lookups or locking, for several simple LLVM types(i1, half, void, etc.). It also cleans up the implementation of the double locking that is required for some types. In the future we could add a form of dynamic caching to only need to lock one mutex in the best case, but that requires analysis on the memory overhead/vs time lost to taking two locks.

PiperOrigin-RevId: 254806747
2019-06-24 13:50:10 -07:00
Mahesh Ravishankar 74127bc062 Add SPIR-V Load/Store operations. Currently this only support memory
operands being None, Volatile, Aligned and Nontemporal

PiperOrigin-RevId: 254792353
2019-06-24 13:49:55 -07:00
River Riddle 52ba785758 NFC: Simplify Operation::getContext to use the context within the location.
PiperOrigin-RevId: 254771979
2019-06-24 13:49:38 -07:00
Nicolas Vasilache 7e7ed9104a Cleanup test following bad merge
PiperOrigin-RevId: 254770395
2019-06-24 13:46:22 -07:00
Nicolas Vasilache 46b755d405 Use linalg.view_slice in tiling and fusion
This CL makes use of view_slice in tiling and fusion.
Using a higher level IR element greatly simplifies the IR produced during tiling and fusion.
Lowering to LLVM is updated to first translate view_slice into a sequence of dim, range and cmpi.
This level will also be useful when lowering to affine.

PiperOrigin-RevId: 254767814
2019-06-24 13:46:08 -07:00
Jacques Pienaar 05c110adf3 Remove leftover change from splitting mlir-opt change.
PiperOrigin-RevId: 254767366
2019-06-24 13:45:53 -07:00
Jacques Pienaar 257a654b72 Split out mlir-opt main into separate file.
Enable reusing the real mlir-opt main from unit tests and in case where
additional initialization needs to happen before main is invoked (e.g., when
using different command line flag libraries).

PiperOrigin-RevId: 254764575
2019-06-24 13:45:39 -07:00
Nicolas Vasilache 2ff1c01063 Add higher-level linalg.view_slice operation.
This will be useful to simplify the IR emitted during transformations as well as lowering to affine.

PiperOrigin-RevId: 254757641
2019-06-24 13:45:24 -07:00
Andy Davis 3df510bf42 Add parsing/printing for new affine.load and affine.store operations.
The new operations affine.load and affine.store will take composed affine maps by construction.
These operations will eventually replace load and store operations currently used in affine regions and operated on by affine transformation and analysis passes.

PiperOrigin-RevId: 254754048
2019-06-24 13:45:09 -07:00
River Riddle b67cab4c44 Update CSE to respect nested regions that are isolated from above. This cl also removes the unused 'NthRegionIsIsolatedFromAbove' trait as it was replaced with a more general 'IsIsolatedFromAbove'.
PiperOrigin-RevId: 254709704
2019-06-24 13:44:53 -07:00
Jacques Pienaar 4dc629fc67 Change string to std::string.
PiperOrigin-RevId: 254580672
2019-06-24 13:44:38 -07:00
River Riddle 650dc4bb65 Allow converting Diagnostic to LogicalResult::Failure. This matches the behavior of InFlightDiagnostic and enables notes to be converted to failure.
PiperOrigin-RevId: 254579098
2019-06-24 13:44:22 -07:00
Jacques Pienaar af9bc7e50d Linalg1LLVMConversion should depend on MLIRLLVMIR to ensure ops generated.
PiperOrigin-RevId: 254578530
2019-06-24 13:44:06 -07:00
River Riddle bcacef1a70 Add a new dialect hook 'materializeConstant' to create a constant operation that materializes an attribute value with the given type. This effectively adds support for dialect specific constant values that have different invariants than std.constant. 'OperationFolder' is updated to use this new hook, or attempt to default to std.constant when legal.
PiperOrigin-RevId: 254570153
2019-06-22 13:05:27 -07:00
River Riddle 48d6cf1ced NFC: Remove the 'context' parameter from OperationState.
Now that Locations are Attributes they contain a direct reference to the MLIRContext, i.e. the context can be directly accessed from the given location instead of being explicitly passed in.

PiperOrigin-RevId: 254568329
2019-06-22 13:05:10 -07:00
Jacques Pienaar dbc96d6775 Add missing build dep.
PiperOrigin-RevId: 254557652
2019-06-22 09:19:06 -07:00
Feng Liu bf1afdd276 Add int8 predicates to the tf lite ops
PiperOrigin-RevId: 254519710
2019-06-22 09:18:51 -07:00
River Riddle 25734596e4 Define a ModuleOp that represents a Module as an Operation.
The ModuleOp contains a single region that must contain a single block. This block must be terminated by a new pseudo operation 'module_terminator'. The syntax for this operations is as follows:

  `module` (`attributes` attr-dict)? region

Example:

  module {
    ...
  }

  module attributes { ... } {
    ...
  }

PiperOrigin-RevId: 254513752
2019-06-22 09:18:36 -07:00
Nicolas Vasilache 9bcf8e6422 Remove dead function
PiperOrigin-RevId: 254507641
2019-06-22 09:18:21 -07:00
Nicolas Vasilache 4a1df48f44 Add a Linalg convolution op.
This CL adds a conv op that corresponds to the TF description along with its lowering to loops (https://www.tensorflow.org/api_docs/python/tf/nn/convolution).

The dimension of the convolution is inferred from the rank of the views. The other logical
dimensions correspond to the TF description.

The computation of tiled views need to be updated to work for the input tensor. This is left for a future CL.

PiperOrigin-RevId: 254505644
2019-06-22 09:18:06 -07:00
River Riddle 36b7c2da1d Refactor the location classes to be attributes instead of separate IR classes.
This will allow for locations to be used in the same contexts as attributes. Given that attributes are nullable types, the 'Location' class now represents a non-nullable wrapper around a 'LocationAttr'. This preserves the desired semantics we have for non-optional locations.

PiperOrigin-RevId: 254505278
2019-06-22 09:17:51 -07:00
River Riddle e4f8f3bc35 Simplify PredecessorIterator by using mapped_iterator.
PiperOrigin-RevId: 254495164
2019-06-22 09:17:36 -07:00