Commit graph

2598 commits

Author SHA1 Message Date
Lei Zhang
af45ca844f Register a -test-spirv-roundtrip hook to mlir-translate
This CL registers a new mlir-translate hook, -test-spirv-roundtrip,
for testing SPIR-V serialization and deserialization round-trip.

This CL also moves the existing -serialize-spirv and
-deserialize-spirv hooks to one source file.

PiperOrigin-RevId: 269659528
2019-09-17 14:48:24 -07:00
River Riddle
3e2ac62b7d Add a preprocess pass to remove sequences that are problematic with FileCheck
Add a preprocess phase to rewrite parts of the input line that may be problematic with filecheck. This change adds preprocessing to escape '[[' bracket sequences, as these are used by FileCheck for variables.

PiperOrigin-RevId: 269648490
2019-09-17 14:00:03 -07:00
Lei Zhang
b991e8b1e4 Support file-to-file translation in mlir-translate
Existing translations are either from MLIR or to MLIR. To support
cases like round-tripping some external format via MLIR, one must
chain two mlir-translate invocations together using pipes. This
can be problematic to support -split-input-file in mlir-translate
given that it won't work across pipes.

Motivated by the above, this CL adds another translation category
that allows file to file. This gives users more freedom.

PiperOrigin-RevId: 269636438
2019-09-17 13:04:34 -07:00
Lei Zhang
b00a522b80 Change MLIR translation functions signature
This CL changes translation functions to take MemoryBuffer
as input and raw_ostream as output. It is generally better to
avoid handling files directly in a library (unless the library
is specifically for file manipulation) and we can unify all
file handling to the mlir-translate binary itself.

PiperOrigin-RevId: 269625911
2019-09-17 12:16:45 -07:00
Uday Bondhugula
bd7de6d4df Add rewrite pattern to compose maps into affine load/stores
- add canonicalization pattern to compose maps into affine loads/stores;
  templatize the pattern and reuse it for affine.apply as well

- rename getIndices -> getMapOperands() (getIndices is confusing since
  these are no longer the indices themselves but operands to the map
  whose results are the indices). This also makes the accessor uniform
  across affine.apply/load/store. Change arg names on the affine
  load/store builder to avoid confusion. Drop an unused confusing build
  method on AffineStoreOp.

- update incomplete doc comment for canonicalizeMapAndOperands (this was
  missed from a previous update).

Addresses issue tensorflow/mlir#121

Signed-off-by: Uday Bondhugula <uday@polymagelabs.com>

Closes tensorflow/mlir#122

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/122 from bondhugula:compose-load-store e71de1771e56a85c4282c10cb43f30cef0701c4f
PiperOrigin-RevId: 269619540
2019-09-17 11:49:45 -07:00
Mehdi Amini
62e1faa6f6 Add missing CMake dependency from libAnalysis to the Vector dialect
Fixes tensorflow/mlir#138

PiperOrigin-RevId: 269509668
2019-09-17 00:39:00 -07:00
Mahesh Ravishankar
2d86ad79f0 Autogenerate (de)serialization for Extended Instruction Sets
A generic mechanism for (de)serialization of extended instruction sets
is added with this CL. To facilitate this, a new class
"SPV_ExtendedInstSetOp" is added which is a base class for all
operations corresponding to extended instruction sets. The methods to
(de)serialization such ops as well as its dispatch is generated
automatically.

The behavior controlled by autogenSerialization and hasOpcode is also
slightly modified to enable this. They are now decoupled.
1) Setting hasOpcode=1 means the operation has a corresponding
   opcode in SPIR-V binary format, and its dispatch for
   (de)serialization is automatically generated.
2) Setting autogenSerialization=1 generates the function for
   (de)serialization automatically.
So now it is possible to have hasOpcode=0 and autogenSerialization=1
(for example SPV_ExtendedInstSetOp).

Since the dispatch functions is also auto-generated, the input file
needs to contain all operations. To this effect, SPIRVGLSLOps.td is
included into SPIRVOps.td. This makes the previously added
SPIRVGLSLOps.h and SPIRVGLSLOps.cpp unnecessary, and are deleted.

The SPIRVUtilsGen.cpp is also changed to make better use of
formatv,making the code more readable.

PiperOrigin-RevId: 269456263
2019-09-16 17:12:33 -07:00
Denis Khalikov
8a34d5d18c [spirv] Add support for function calls.
Add spv.FunctionCall operation and (de)serialization.

Closes tensorflow/mlir#137

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/137 from denis0x0D:sandbox/function_call_op e2e6f07d21e7f23e8b44c7df8a8ab784f3356ce4
PiperOrigin-RevId: 269437167
2019-09-16 15:39:54 -07:00
River Riddle
9619ba10d4 Add support for multi-level value mapping to DialectConversion.
When performing A->B->C conversion, an operation may still refer to an operand of A. This makes it necessary to unmap through multiple levels of replacement for a specific value.

PiperOrigin-RevId: 269367859
2019-09-16 10:38:19 -07:00
Lei Zhang
6934a337f0 [spirv] Add support for BitEnumAttr
Certain enum classes in SPIR-V, like function/loop control and memory
access, are bitmasks. This CL introduces a BitEnumAttr to properly
model this and drive auto-generation of verification code and utility
functions. We still store the attribute using an 32-bit IntegerAttr
for minimal memory footprint and easy (de)serialization. But utility
conversion functions are adjusted to inspect each bit and generate
"|"-concatenated strings for the bits; vice versa.

Each such enum class has a "None" case that means no bit is set. We
need special handling for "None". Because of this, the logic is not
general anymore. So right now the definition is placed in the SPIR-V
dialect. If later this turns out to be useful for other dialects,
then we can see how to properly adjust it and move to OpBase.td.

Added tests for SPV_MemoryAccess to check and demonstrate.

PiperOrigin-RevId: 269350620
2019-09-16 09:23:22 -07:00
Alex Zinenko
cb3ecb5291 Overhaul the SDBM expression kind hierarchy
Swap the allowed nesting of sum and diff expressions: now a diff expression can
contain a sum expression, but only on the left hand side.  A difference of two
expressions sum must be canonicalized by grouping their constant terms in a
single expression.  This change of sturcture became possible thanks to the
introduction of the "direct" super-kind.  It is necessary to enable support of
sum expressions on the left hand side of the stripe expression.

SDBM expressions are now grouped into the following structure
- expression
  - varying
    - direct
      - sum <- (term, constant)
      - term
        - symbol
        - dimension
        - stripe <- (term, constant)
    - negation <- (direct)
    - difference <- (direct, term)
  - constant
The notation <- (...) denotes the types of subexpressions a compound
expression can combine.

PiperOrigin-RevId: 269337222
2019-09-16 08:16:06 -07:00
Alex Zinenko
e94db619d9 Introduce SDBMDirect expression into the SDBM expression hierarchy
Direct expressions are those that do not negate any of the variables they
involve.  They include input expressions (dimensions and symbols), stripe and
sum expressions, and combinations of those.  Reifying direct expressions as a
class is a precondition for enabling additions on the LHS of a stripe
expression.

PiperOrigin-RevId: 269336031
2019-09-16 08:09:01 -07:00
MLIR Team
0ce64b0bf3 Unify how errors are emitted in LaunchFuncOp verification.
PiperOrigin-RevId: 269331869
2019-09-16 07:45:59 -07:00
MLIR Team
1da0290c4b Error out when kernel function is not found while translating GPU calls.
PiperOrigin-RevId: 269327909
2019-09-16 07:19:36 -07:00
Alex Zinenko
6755dfdec9 Drop makePositionAttr and the like in favor of Builder::getI64ArrayAttr
The helper functions makePositionAttr() and positionAttr() were originally
introduced in the lowering-to-LLVM-dialect pass to construct integer array
attributes that are used for static positions in extract/insertelement.
Constructing an integer array attribute being fairly common, a utility function
Builder::getI64ArrayAttr was later introduced into the Builder API.  Drop
makePositionAttr and similar homegrown functions and use that API instead.
PiperOrigin-RevId: 269295836
2019-09-16 03:31:09 -07:00
Mahesh Ravishankar
9814b3fa0d Add mechanism to specify extended instruction sets in SPIR-V.
Add support for specifying extended instructions sets. The operations
in SPIR-V dialect are named as 'spv.<extension-name>.<op-name>'. Use
this mechanism to define a 'Exp' operation from GLSL(450)
instructions.
Later CLs will add support for (de)serialization of these operations,
and update the dialect generation scripts to auto-generate the
specification using the spec directly.

Additional changes:
Add a Type Constraint to OpBase.td to check for vector of specified
lengths. This is used to check that the vector type used in SPIR-V
dialect are of lengths 2, 3 or 4.
Update SPIRVBase.td to use this Type constraints for vectors.

PiperOrigin-RevId: 269234377
2019-09-15 19:40:07 -07:00
River Riddle
faaa1ced10 Update the pass registration section and add a sub-section on the textual pipeline specification.
Now that the pass manager is generalized, and nested/arbritrary pipelines are possible, it is important to document how to specify these types of pipelines from the command line.

PiperOrigin-RevId: 269207681
2019-09-15 14:01:06 -07:00
Uday Bondhugula
16eac96560 Fix typo in test/AffineOps/ops.mlir
Closes tensorflow/mlir#135

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/135 from bondhugula:patch-1 539a7f1b43d09ef539b2fd15875f8ac765600263
PiperOrigin-RevId: 269187507
2019-09-15 09:06:39 -07:00
River Riddle
f22011ccba NFC: Update the PassInstrumentation section.
This section has grown stale as the pass infrastructure has been generalized.

PiperOrigin-RevId: 269140863
2019-09-14 22:10:28 -07:00
River Riddle
bbc6d48d1c NFC: Update the expected outputs of pass-timing.
The output of the pass timing instrumentation has been changed now that the pass hierarchy has been generalized.

PiperOrigin-RevId: 269140277
2019-09-14 22:03:08 -07:00
River Riddle
d37777c440 Update the IRPrinter instrumentation to work on non function/module operations.
This is necessary now that the pass manager may work on different types of operations.

PiperOrigin-RevId: 269139669
2019-09-14 21:56:38 -07:00
River Riddle
bbe65b46f5 NFC: Pass PassInstrumentations by unique_ptr instead of raw pointer.
This makes the ownership model explicit, and removes potential user errors.

PiperOrigin-RevId: 269122834
2019-09-14 17:44:50 -07:00
River Riddle
cb1bcba69b NFC: Merge OpPass with OperationPass into just OperationPass.
OperationPass' are defined exactly the same way as they are now:
   class DerivedPass :  public OperationPass<DerivedPass>;

OpPass' are now defined as OperationPass, but with an additional template parameter for the operation type:
   class DerivedPass :  public OperationPass<DerivedPass, FuncOp>;

PiperOrigin-RevId: 269122410
2019-09-14 17:37:43 -07:00
Jing Pu
38e7226606 Add convenience methods to create i8 and i16 attributes in Builder.
PiperOrigin-RevId: 269120226
2019-09-14 17:02:54 -07:00
Uday Bondhugula
4f32ae61b4 NFC - Move explicit copy/dma generation utility out of pass and into LoopUtils
- turn copy/dma generation method into a utility in LoopUtils, allowing
  it to be reused elsewhere.

- no functional/logic change to the pass/utility

- trim down header includes in files affected

Signed-off-by: Uday Bondhugula <uday@polymagelabs.com>

Closes tensorflow/mlir#124

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/124 from bondhugula:datacopy 9f346e62e5bd9dd1986720a30a35f302eb4d3252
PiperOrigin-RevId: 269106088
2019-09-14 13:23:48 -07:00
Uday Bondhugula
1366467a3b update normalizeMemRef utility; handle missing failure check + add more tests
- take care of symbolic operands with alloc
- add missing check for compose map failure and a test case
- add test cases on strides
- drop incorrect check for one-to-one'ness

Signed-off-by: Uday Bondhugula <uday@polymagelabs.com>

Closes tensorflow/mlir#132

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/132 from bondhugula:normalize-memrefs 8aebf285fb0d7c19269d85255aed644657e327b7
PiperOrigin-RevId: 269105947
2019-09-14 13:21:35 -07:00
Uday Bondhugula
018cfa94d9 Clean up build trip count analysis method - avoid mutating IR
- NFC - on any pass/utility logic/output.

- Resolve TODO; the method building loop trip count maps was
  creating and deleting affine.apply ops (transforming IR from under
  analysis!, strictly speaking). Introduce AffineValueMap::difference to
  do this correctly (without the need to create any IR).

- Move AffineApplyNormalizer out so that its methods are reusable from
  AffineStructures.cpp; add a helper method 'normalize' to it. Fix
  AffineApplyNormalize::renumberOneDim (Issue tensorflow/mlir#89).

- Trim includes on files touched.

- add test case on a scenario previously not covered

Signed-off-by: Uday Bondhugula <uday@polymagelabs.com>

Closes tensorflow/mlir#133

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/133 from bondhugula:trip-count-build 7fc34d857f7788f98b641792cafad6f5bd50e47b
PiperOrigin-RevId: 269101118
2019-09-14 12:10:55 -07:00
River Riddle
2de18fb84d NFC: Fix stray character in error message: 1 -> '
PiperOrigin-RevId: 269091468
2019-09-14 09:44:23 -07:00
Lei Zhang
aac8fa8c47 Update QuickstartRewrites.md regarding op definition and rewrites
This CL updates the doc with recent changes. It also adds a section
on registering and using the auto-generated patterns.

PiperOrigin-RevId: 269086830
2019-09-14 08:37:38 -07:00
Uday Bondhugula
f2eb0f02fa Add pattern to canonicalize for loop bounds
- add pattern to canonicalize affine.for loop bounds (using
  canonicalizeMapAndOperands)
- rename AffineForLoopBoundFolder -> AffineForLoopBoundFolder for
  consistency

Signed-off-by: Uday Bondhugula <uday@polymagelabs.com>

Closes tensorflow/mlir#111

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/111 from bondhugula:bound-canonicalize ee8fb7f43a7ffd45f6df3f53c95098d8b7e494c7
PiperOrigin-RevId: 269041220
2019-09-13 22:11:56 -07:00
River Riddle
4e48beadbb Verify that ModuleOps only contain dialect specific attributes.
ModuleOp has no expected operations, so only dialect-specific attributes are valid.

PiperOrigin-RevId: 269020062
2019-09-13 18:19:33 -07:00
Uday Bondhugula
1e6a93b7ca add missing memref cast fold pattern for dim op
- add missing canonicalization pattern to fold memref_cast + dim to
  dim (needed to propagate constant when folding a dynamic shape to
  a static one)

- also fix an outdated/inconsistent comment in StandardOps/Ops.td

Signed-off-by: Uday Bondhugula <uday@polymagelabs.com>

Closes tensorflow/mlir#126

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/126 from bondhugula:quickfix 4566e75e49685c532faffff91d64c5d83d4da524
PiperOrigin-RevId: 269020058
2019-09-13 18:18:48 -07:00
River Riddle
d780bdef20 Publicly expose the functionality to parse a textual pass pipeline.
This allows for users other than those on the command line to apply a textual description of a pipeline to a given pass manager.

PiperOrigin-RevId: 269017028
2019-09-13 17:54:00 -07:00
Geoffrey Martin-Noble
efbd3e4610 Add type constraints for shaped types with same rank and element count
PiperOrigin-RevId: 269000237
2019-09-13 16:05:38 -07:00
Lei Zhang
113aadddf9 Update SPIR-V symbols and use GLSL450 instead of VulkanKHR
SPIR-V recently publishes v1.5, which brings a bunch of symbols
into core. So the suffix "KHR"/"EXT"/etc. is removed from the
symbols. We use a script to pull information from the spec
directly.

Also changed conversion and tests to use GLSL450 instead of
VulkanKHR memory model. GLSL450 is still the main memory model
supported by Vulkan shaders and it does not require extra
capability to enable.

PiperOrigin-RevId: 268992661
2019-09-13 15:26:32 -07:00
River Riddle
f1b100c77b NFC: Finish replacing FunctionPassBase/ModulePassBase with OpPassBase.
These directives were temporary during the generalization of FunctionPass/ModulePass to OpPass.

PiperOrigin-RevId: 268970259
2019-09-13 13:34:27 -07:00
Geoffrey Martin-Noble
a260436714 Add tablegen class for memrefs with rank constraints
PiperOrigin-RevId: 268968004
2019-09-13 13:22:21 -07:00
River Riddle
8a1cdeb31b Forward diagnostics from untracked threads in ParallelDiagnosticHandler.
This allows for the use of multiple ParallelDiagnosticHandlers without having them conflict with each other.

PiperOrigin-RevId: 268967407
2019-09-13 13:19:19 -07:00
MLIR Team
d3787e5865 Improve verifier error reporting on type mismatch (NFC)
Before this change, it only reports expected type but not exact type, so
it's hard to troubleshoot.

PiperOrigin-RevId: 268961078
2019-09-13 12:46:34 -07:00
River Riddle
9274ed66ef Refactor pass pipeline command line parsing to support explicit pipeline strings.
This allows for explicitly specifying the pipeline to add to the pass manager. This includes the nesting structure, as well as the passes/pipelines to run. A textual pipeline string is defined as a series of names, each of which may in itself recursively contain a nested pipeline description. A name is either the name of a registered pass, or pass pipeline, (e.g. "cse") or the name of an operation type (e.g. "func").

For example, the following pipeline:
$ mlir-opt foo.mlir -cse -canonicalize -lower-to-llvm

Could now be specified as:
$ mlir-opt foo.mlir -pass-pipeline='func(cse, canonicalize), lower-to-llvm'

This will allow for running pipelines on nested operations, like say spirv modules. This does not remove any of the current functionality, and in fact can be used in unison. The new option is available via 'pass-pipeline'.

PiperOrigin-RevId: 268954279
2019-09-13 12:10:31 -07:00
Geoffrey Martin-Noble
70653ed600 NFC: Update comments about rank constraints
These refer to ranked tensors, but are actually applicable to any shaped type

PiperOrigin-RevId: 268931789
2019-09-13 10:29:18 -07:00
MLIR Team
6cce275301 Fixing typo in documentation.
PiperOrigin-RevId: 268877189
2019-09-13 04:08:12 -07:00
Smit Hinsu
1854c64c7c Log name of the generated illegal operation name in DialectConversion debug mode
PiperOrigin-RevId: 268859399
2019-09-13 01:37:38 -07:00
Geoffrey Martin-Noble
2ccbb3f1ce Cmpf constant folding for nan and inf
PiperOrigin-RevId: 268783645
2019-09-12 15:43:59 -07:00
Geoffrey Martin-Noble
f39a599e46 NFC: Clean up constant fold tests
Use variable captures to make constant folding tests less sensitive to printer/parser implementation details.

See guidelines at https://github.com/tensorflow/mlir/blob/master/g3doc/TestingGuide.md

PiperOrigin-RevId: 268780812
2019-09-12 15:30:58 -07:00
Lei Zhang
a84bc68acc [spirv] Add support for spv.loop (de)serialization
This CL adds support for serializing and deserializing spv.loop ops.
This adds support for spv.Branch and spv.BranchConditional op
(de)serialization, too, because they are needed for spv.loop.

PiperOrigin-RevId: 268536962
2019-09-11 14:02:59 -07:00
Alex Zinenko
e15356f8ed Rename SDBMPositiveExpr to SDBMTermExpr
This better reflects how this kind of expressions is used and avoids the
potential confusion since the expression can take negative values.  Term
expressions comprise dimensions, symbols and stripe expressions.  In an SDBM
domain, a stripe expression always corresponds to a variable, input or
temporary.  This expression can appear anywhere an input variable can,
including on the LHS of other stripe expressions.

PiperOrigin-RevId: 268486066
2019-09-11 10:18:29 -07:00
Alex Zinenko
9037f28cb4 Fix typos in SDBMTest.cpp
PiperOrigin-RevId: 268443146
2019-09-11 06:11:36 -07:00
MLIR Team
bc9b52f2ed Add logical groups to NVVM op definitions.
PiperOrigin-RevId: 268436116
2019-09-11 05:10:29 -07:00
MLIR Team
6f8321f06f Fix a typo in comments. The Inequality and Equality explanations were apparently reversed.
PiperOrigin-RevId: 268395163
2019-09-10 23:54:36 -07:00