Commit Graph

2294 Commits

Author SHA1 Message Date
Alex Zinenko 60965b4612 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
2019-07-25 00:41:17 -07:00
River Riddle 36bb03b94d 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
2019-07-24 16:41:48 -07:00
Alex Zinenko 055d7dedcb 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
2019-07-24 13:13:39 -07:00
Lei Zhang 046a3f563a 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
2019-07-24 12:35:56 -07:00
Nicolas Vasilache 8ebb4281aa Cleanup slicing test.
Remove hardcoded SSA names and make use of CHECK-LABEL directives.

PiperOrigin-RevId: 259767803
2019-07-24 10:28:33 -07:00
Nicolas Vasilache 1ff95e5120 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
2019-07-24 05:10:54 -07:00
Mahesh Ravishankar 2ad92b6e50 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
2019-07-23 22:38:51 -07:00
Jacques Pienaar e8bd81ba1a 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
2019-07-23 20:09:36 -07:00
MLIR Team 8cb82c9478 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
2019-07-23 11:23:40 -07:00
Alex Zinenko 480d68f8de 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
2019-07-23 10:18:46 -07:00
Alex Zinenko 0aed5222d8 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
2019-07-23 10:17:29 -07:00
Alex Zinenko 8543f8aaba 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
2019-07-23 09:26:39 -07:00
River Riddle 42a767b23d 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
2019-07-22 21:43:37 -07:00
Uday Bondhugula b5f8a4be27 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
2019-07-22 17:42:08 -07:00
River Riddle 40493a07a3 Emit an error for missing '[' when parsing an AffineMapOfSSAIds.
Fixes tensorflow/mlir#51

PiperOrigin-RevId: 259415034
2019-07-22 15:06:44 -07:00
Lei Zhang 8b8caa888d (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
2019-07-22 13:31:00 -07:00
River Riddle 3edbd8bf80 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
2019-07-22 13:22:49 -07:00
River Riddle e5fbcec465 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
2019-07-22 11:29:47 -07:00
Jacques Pienaar 772930f8c6 Update style/clang-format (NFC).
Update to be consistent & so that future save + clang-format workflows don't introduce extra changes.

PiperOrigin-RevId: 259361174
2019-07-22 11:29:21 -07:00
Lei Zhang 83c97a6784 (De)serialize float scalar spv.constant
This CL adds support for float scalar spv.constant in (de)serialization.

PiperOrigin-RevId: 259311776
2019-07-22 06:02:32 -07:00
Lei Zhang c1844220cd (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
2019-07-22 06:02:08 -07:00
Lei Zhang 9d52ceaf16 [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
2019-07-22 06:01:19 -07:00
Alex Zinenko 52cf6b8044 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
2019-07-22 05:38:30 -07:00
Lei Zhang 17c18840da [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
2019-07-22 05:37:39 -07:00
Nicolas Vasilache 48a1baeb8a Refactor LoopParametricTiling as a test pass - NFC
This CL moves LoopParametricTiling into test/lib as a pass for purely testing purposes.

PiperOrigin-RevId: 259300264
2019-07-22 04:31:17 -07:00
Alex Zinenko fa86c89917 SingleBlockImplicitTerminator: report the wrong terminator op found
In the trait verifier of SingleBlockImplicitTerminator, report the name of the
unexpected terminator op found in the end of the block in addition to the name
of the expected terminator op.  This may simplify debugging, especially in
cases where the terminator is omitted for brevity and/or after a long series of
conversions.

PiperOrigin-RevId: 259287452
2019-07-22 02:42:06 -07:00
River Riddle 00bdc8e070 Refactor region type signature conversion to be explicit via patterns.
This cl enforces that the conversion of the type signatures for regions, and thus their entry blocks, is handled via ConversionPatterns. A new hook 'applySignatureConversion' is added to the ConversionPatternRewriter to perform the desired conversion on a region. This also means that the handling of rewriting the signature of a FuncOp is moved to a pattern. A default implementation is provided via 'mlir::populateFuncOpTypeConversionPattern'. This removes the hacky implicit 'dynamically legal' status of FuncOp that was present previously, and leaves it up to the user to decide when/how to convert the signature of a function.

PiperOrigin-RevId: 259161999
2019-07-20 19:06:07 -07:00
Mahesh Ravishankar 2fb53e65ab Add (de)serialization of EntryPointOp and ExecutionModeOp
Since the serialization of EntryPointOp contains the name of the
function as well, the function serialization emits the function name
using OpName instruction, which is used during deserialization to get
the correct function name.

PiperOrigin-RevId: 259158784
2019-07-20 18:12:05 -07:00
River Riddle a47704e1e1 Ensure that DenseElementAttr data is 64-bit aligned.
This allows for the raw data to be reinterpreted as the derived c++ type, e.g. ArrayRef<uint64_t>. This fixes a ubsan error for misaligned-pointer-use.

PiperOrigin-RevId: 259128031
2019-07-20 09:23:03 -07:00
Alex Zinenko 6b436eacbc Merge TypeUtilities library into the IR library
The TypeUtilities.{cpp,h}, currently living in {lib,include/mlir}/Support, do
not belong to the Support library.  Instead, they form a separate utility
library that depends on the IR library.  The operations it provides relate to
standard types (tensors, memrefs) as well as to operation manipulation, making
them a better fit for the main IR library.

PiperOrigin-RevId: 259108314
2019-07-20 03:04:22 -07:00
MLIR Team 63b4b547b6 Fix a comment about ShapedType::getNumElements()
PiperOrigin-RevId: 259057303
2019-07-19 17:25:09 -07:00
Lei Zhang 05ab648740 [spirv] Avoid printing duplicate trailing type
When printing the value attribute in spv.constant, OpAsmPrinter
already attaches a trailing type. So we don't need to duplicate
it again unless it's an array attribute, which does not have
type by default but we use it for spirv::ArrayType.

PiperOrigin-RevId: 258994197
2019-07-19 11:41:49 -07:00
Lei Zhang 9da6e90e1c Replace bitwiseCast with llvm::bit_cast
PiperOrigin-RevId: 258986485
2019-07-19 11:41:41 -07:00
Lei Zhang e239f9647e Suppress compiler warnings regarding unused variables
Not all ops have operands or results, so it ends up there may be no
use of wordIndex or the generated op's results.

PiperOrigin-RevId: 258984485
2019-07-19 11:41:34 -07:00
Lei Zhang 1331c84fe3 Wrap op (de)serialization methods in anonymous namespace
It's a known bug that older GCC is not happy with method specialization in
the enclosing (global) namespace:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480

This CL wraps the generated specialization methods in the anonymous namespace
to make sure the specialization is in the same namespace as the class.

PiperOrigin-RevId: 258983181
2019-07-19 11:41:27 -07:00
Jacques Pienaar c253c6eb2f Switch C++14 std::equal usage to for-loop.
Version of std::equal used required C++14, switching to for-loop for now. Just a direct change from std::equal to the equivalent using for loop.

PiperOrigin-RevId: 258970366
2019-07-19 11:41:20 -07:00
Alex Zinenko 6fe99662aa Move loop dialect tests into separate files - NFC
This was overlooked when moving out loop operations from Standard to a separate
dialect.

PiperOrigin-RevId: 258970115
2019-07-19 11:41:12 -07:00
Lei Zhang 89a10b73fb Add missing MLIRDialect dependency for MLIRDialect
Tests for the Broadcastable trait was added in a previous CL, which
makes MLIRDialect depend on MLIRDialect now.

PiperOrigin-RevId: 258967332
2019-07-19 11:41:06 -07:00
Mahesh Ravishankar 03c8303a12 Make SPIR-V spv.EntryPoint and spv.ExecutionMode consistent with SPIR-V spec
This CL changes the Op definition of spirv::EntryPointOp and
spirv::ExecutionModeOp to be consistent with the SPIR-V spec.
1) The EntryPointOp doesn't return a value
2) The ExecutionModeOp takes as argument, the SymbolRefAttr to refer
to the function, instead of the result of the EntryPointOp.

Following this, the spirv::EntryPointType is no longer necessary, and
is removed.

PiperOrigin-RevId: 258964027
2019-07-19 11:40:58 -07:00
Alex Zinenko 287d111023 Generalize implicit terminator into an OpTrait
Several groups of operations in different dialects (e.g. AffineForOp,
AffineIfOp; loop::ForOp, loop::IfOp) share the requirement for their regions to
contain 0 or 1 block, and for blocks to always have a specific terminator type.
Furthermore, this terminator may be omitted from the custom syntax.  Generalize
this behavior into OpTrait::SingleBlockImplicitTerminator, parameterized by the
terminator operation type.  This trait provides the verifier that checks the
presence of the terminator, and utility functions adding the terminator in case
of absence.

PiperOrigin-RevId: 258957180
2019-07-19 11:40:51 -07:00
Nicolas Vasilache 6204acacc7 Uniformize test name - NFC
PiperOrigin-RevId: 258956693
2019-07-19 11:40:43 -07:00
Nicolas Vasilache d2a872922f Refactor stripmineSink for AffineForOp - NFC
More moving less cloning.

PiperOrigin-RevId: 258947575
2019-07-19 11:40:37 -07:00
Nicolas Vasilache db4cd1c8dc Utility function to map a loop on a parametric grid of virtual processors
This CL introduces a simple loop utility function which rewrites the bounds and step of a loop so as to become mappable on a regular grid of processors whose identifiers are given by SSA values.

A corresponding unit test is added.

For example, using CUDA terminology, and assuming a 2-d grid with processorIds = [blockIdx.x, threadIdx.x] and numProcessors = [gridDim.x, blockDim.x], the loop:
```
   loop.for %i = %lb to %ub step %step {
     ...
   }
```
is rewritten into a version resembling the following pseudo-IR:
```
   loop.for %i = %lb + threadIdx.x + blockIdx.x * blockDim.x to %ub
      step %gridDim.x * blockDim.x {
     ...
   }
```

PiperOrigin-RevId: 258945942
2019-07-19 11:40:31 -07:00
Nicolas Vasilache 5bc344743c Uniformize the API for the mlir::tile functions on AffineForOp and loop::ForOp
This CL adapts the recently introduced parametric tiling to have an API matching the tiling
of AffineForOp. The transformation using stripmineSink is more general and produces  imperfectly nested loops.

Perfect nesting invariants of the tiled version are obtained by selectively applying hoisting of ops to isolate perfectly nested bands. Such hoisting may fail to produce a perfect loop nest in cases where ForOp transitively depend on enclosing induction variables. In such cases, the API provides a LogicalResult return but the SimpleParametricLoopTilingPass does not currently use this result.

A new unit test is added with a triangular loop for which the perfect nesting property does not hold. For this example, the old behavior was to produce IR that did not verify (some use was not dominated by its def).

PiperOrigin-RevId: 258928309
2019-07-19 11:40:25 -07:00
River Riddle 28057ff3da Add support for providing a legality callback for dynamic legality in DialectConversion.
This allows for providing specific handling for dynamically legal operations/dialects without overriding the general 'isDynamicallyLegal' hook. This also means that a derived ConversionTarget class need not always be defined when some operations are dynamically legal.

Example usage:

ConversionTarget target(...);
target.addDynamicallyLegalOp<ReturnOp>([](ReturnOp op) {
  return ...
};
target.addDynamicallyLegalDialect<StandardOpsDialect>([](Operation *op) {
  return ...
};

PiperOrigin-RevId: 258884753
2019-07-19 11:40:19 -07:00
Lei Zhang 36a26e0033 [spirv] group methods better and improve comments
This CL groups (de)serialization methods logically and improves comments
at various places. It also sorted method implementations to follow the
order of their declarations. There is NFC.

PiperOrigin-RevId: 258843490
2019-07-19 11:40:12 -07:00
Lei Zhang 9291868960 Place generated StandardOps to SPIR-V patterns in anonymous namespace
This avoids polluting the mlir namespace.

PiperOrigin-RevId: 258826497
2019-07-19 11:40:06 -07:00
River Riddle 8b447b6cad NFC: Expose a ConversionPatternRewriter for use with ConversionPatterns.
This specific PatternRewriter will allow for exposing hooks in the future that are only useful for the conversion framework, e.g. type conversions.

PiperOrigin-RevId: 258818122
2019-07-19 11:40:00 -07:00
Feng Liu 701266c47a Add an "is_signed" attribute to the quant_ConstFakeQuant op
Some TensorFlow simulated quantize ops such as QuantizeAndDequantizeV2Op have
attribute for the sign of the quantization, so quant_ConstFakeQuant should be
able to represent it with the new attribute is added.

The method for converting these attributes to an QuantizedType is updated to
handle this new argument.

PiperOrigin-RevId: 258810290
2019-07-19 11:39:54 -07:00
Mehdi Amini 90b5a381ce Minor cleanup to LangRef, MLIR stands for "Multi-Level IR"
PiperOrigin-RevId: 258798577
2019-07-19 11:39:47 -07:00