Commit Graph

2471 Commits

Author SHA1 Message Date
Feng Liu 6de6c2c138 Add tests to verify 0.0 is quantized correctly
We should consider both signed and narrow_range cases.

PiperOrigin-RevId: 266167366
2019-08-29 10:09:22 -07:00
Uday Bondhugula 4bb6f8ecdb Extend map canonicalization to propagate constant operands
- extend canonicalizeMapAndOperands to propagate constant operands into
  the map's expressions (and thus drop those operands).
- canonicalizeMapAndOperands previously only dropped duplicate and
  unused operands; however, operands that were constants were
  retained.

This change makes IR maps/expressions generated by various
utilities/passes even simpler; also makes some of the test checks more
accurate and simpler -- for eg., 0' instead of symbol(%{{.*}}).

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

Closes tensorflow/mlir#107

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/107 from bondhugula:canonicalize-maps c889a51486d14fbf7db489f224f881e7e1ff7d72
PiperOrigin-RevId: 266085289
2019-08-29 01:13:29 -07:00
Uday Bondhugula bc2a543225 fix loop unroll and jam - operand mapping - imperfect nest case
- fix operand mapping while cloning sub-blocks to jam - was incorrect
  for imperfect nests where def/use was across sub-blocks
- strengthen/generalize the first test case to cover the previously
  missed scenario
- clean up the other cases while on this.

Previously, unroll-jamming the following nest
```
    affine.for %arg0 = 0 to 2048 {
      %0 = alloc() : memref<512x10xf32>
      affine.for %arg1 = 0 to 10 {
        %1 = affine.load %0[%arg0, %arg1] : memref<512x10xf32>
      }
      dealloc %0 : memref<512x10xf32>
    }
```

would yield

```
      %0 = alloc() : memref<512x10xf32>
      %1 = affine.apply #map0(%arg0)
      %2 = alloc() : memref<512x10xf32>
      affine.for %arg1 = 0 to 10 {
        %4 = affine.load %0[%arg0, %arg1] : memref<512x10xf32>
        %5 = affine.apply #map0(%arg0)
        %6 = affine.load %0[%5, %arg1] : memref<512x10xf32>
      }
      dealloc %0 : memref<512x10xf32>
      %3 = affine.apply #map0(%arg0)
      dealloc %0 : memref<512x10xf32>

```

instead of

```

module {
    affine.for %arg0 = 0 to 2048 step 2 {
      %0 = alloc() : memref<512x10xf32>
      %1 = affine.apply #map0(%arg0)
      %2 = alloc() : memref<512x10xf32>
      affine.for %arg1 = 0 to 10 {
        %4 = affine.load %0[%arg0, %arg1] : memref<512x10xf32>
        %5 = affine.apply #map0(%arg0)
        %6 = affine.load %2[%5, %arg1] : memref<512x10xf32>
      }
      dealloc %0 : memref<512x10xf32>
      %3 = affine.apply #map0(%arg0)
      dealloc %2 : memref<512x10xf32>
    }
```

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

Closes tensorflow/mlir#98

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/98 from bondhugula:ujam ddbc853f69b5608b3e8ff9b5ac1f6a5a0bb315a4
PiperOrigin-RevId: 266073460
2019-08-28 23:42:50 -07:00
Stephan Herhut e90542c03b Add verification for dimension attribute on GPUDialect index operations.
PiperOrigin-RevId: 266073204
2019-08-28 23:39:57 -07:00
Uday Bondhugula e8d43cafe6 Add vim scripts for indent/syntax
- some of it has been adapted from LLVM's vim utils

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

Closes tensorflow/mlir#90

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/90 from bondhugula:vim 22b1c958818c4b09de0ec8e1d7a4893171a03dbf
PiperOrigin-RevId: 266071752
2019-08-28 23:23:19 -07:00
Feng Liu 7dd5efdf2c Fix the equality check of two floating point values
PiperOrigin-RevId: 266022088
2019-08-28 16:39:48 -07:00
River Riddle 29099e03ce Generalize the analysis manager framework to work on any operation at any nesting.
The pass manager is moving towards being able to run on operations at arbitrary nesting. An operation may have both parent and child operations, and the AnalysisManager must be able to handle this generalization. The AnalysisManager class now contains generic 'getCachedParentAnalysis' and 'getChildAnalysis/getCachedChildAnalysis' functions to query analyses on parent/child operations. This removes the hard coded nesting relationship between Module/Function.

PiperOrigin-RevId: 266003636
2019-08-28 15:11:17 -07:00
Eric Schweitz 2225411690 Tweak to the pretty type parser to recognize that `->` is a special token.
Tweak to the pretty type parser to recognize that `->` is a special token that
shouldn't be split into two characters.  This change allows dialect
types to wrap function types as in `!my.ptr_type<(i32) -> i32>`.

Closes tensorflow/mlir#105

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/105 from schweitzpgi:parse-arrow 8b2d768053f419daae5a1a864121a44c4319acbe
PiperOrigin-RevId: 265986240
2019-08-28 13:55:42 -07:00
Stephan Herhut c60c490356 Add implementation for tensor_load and tensor_store operations.
This change adds definitions, parsing and verification for both ops.

PiperOrigin-RevId: 265954051
2019-08-28 11:25:52 -07:00
Stephan Herhut 545c3e489f Port mlir-cuda-runner to use dialect conversion framework.
Instead of lowering the program in two steps (Standard->LLVM followed
by GPU->NVVM), leading to invalid IR inbetween, the runner now uses
one pattern based rewrite step to go directly from Standard+GPU to
LLVM+NVVM.

PiperOrigin-RevId: 265861934
2019-08-28 01:50:57 -07:00
Uday Bondhugula aa2cee9cf5 Refactor / improve replaceAllMemRefUsesWith
Refactor replaceAllMemRefUsesWith to split it into two methods: the new
method does the replacement on a single op, and is used by the existing
one.

- make the methods return LogicalResult instead of bool

- Earlier, when replacement failed (due to non-deferencing uses of the
  memref), the set of ops that had already been processed would have
  been replaced leaving the IR in an inconsistent state. Now, a
  pass is made over all ops to first check for non-deferencing
  uses, and then replacement is performed. No test cases were affected
  because all clients of this method were first checking for
  non-deferencing uses before calling this method (for other reasons).
  This isn't true for a use case in another upcoming PR (scalar
  replacement); clients can now bail out with consistent IR on failure
  of replaceAllMemRefUsesWith. Add test case.

- multiple deferencing uses of the same memref in a single op is
  possible (we have no such use cases/scenarios), and this has always
  remained unsupported. Add an assertion for this.

- minor fix to another test pipeline-data-transfer case.

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

Closes tensorflow/mlir#87

PiperOrigin-RevId: 265808183
2019-08-27 17:56:56 -07:00
River Riddle 6f68def852 Update Ch.2 of the Toy tutorial.
The code and documentation for this chapter of the tutorial have been updated to follow the new flow. The toy 'array' type has been replaced by usages of the MLIR tensor type. The code has also been cleaned up and modernized.

Closes tensorflow/mlir#101

PiperOrigin-RevId: 265744086
2019-08-27 12:44:27 -07:00
MLIR Team 696fcb7520 Add 3 additional intrinsic ops to NVVM dialect, in preparation to implement block-wide reduce.
PiperOrigin-RevId: 265720077
2019-08-27 10:56:18 -07:00
Lei Zhang 3af6b53381 [spirv] Fix the entry block to start with OpLabel
Each basic block in SPIR-V must start with an OpLabel instruction.
We don't support control flow yet, so this CL just makes sure that
the entry block follows this rule and is valid.

PiperOrigin-RevId: 265718841
2019-08-27 10:51:26 -07:00
Mahesh Ravishankar 4ced99c085 Enhance GPU To SPIR-V conversion to support builtins and load/store ops.
To support a conversion of a simple load-compute-store kernel from GPU
dialect to SPIR-V dialect, the conversion of operations like
"gpu.block_dim", "gpu.thread_id" which allow threads to get the launch
conversion is needed. In SPIR-V these are specified as global
variables with builin attributes. This CL adds support to specify
builtin variables in SPIR-V conversion framework. This is used to
convert the relevant operations from GPU dialect to SPIR-V dialect.
Also add support for conversion of load/store operation in Standard
dialect to SPIR-V dialect.
To simplify the conversion add a method to build a spv.AccessChain
operation that automatically determines the return type based on the
base pointer type and the indices provided.

PiperOrigin-RevId: 265718525
2019-08-27 10:50:23 -07:00
Denis Khalikov 8f2dfb51d4 [spirv] Add Block decoration for spv.struct.
Add Block decoration for top-level spv.struct.

Closes tensorflow/mlir#102

PiperOrigin-RevId: 265716241
2019-08-27 10:41:42 -07:00
River Riddle 2f59f76876 NFC: Remove the explicit context from Operation::create and OperationState.
The context can easily be recovered from the Location in these situations.

PiperOrigin-RevId: 265578574
2019-08-26 17:34:48 -07:00
Eric Schweitz 761d57d187 Add FPToSI/FPExt/FPTrunc cast ops to the LLVM dialect.
Closes tensorflow/mlir#99

PiperOrigin-RevId: 265538731
2019-08-26 14:19:19 -07:00
River Riddle 23251f9f3a NFC: Remove unnecessary context parameters from several Location getters.
The context can be recovered by other means in these methods and doesn't need to be passed explicitly.

PiperOrigin-RevId: 265532956
2019-08-26 13:54:01 -07:00
MLIR Team cb8c451541 Update documentation for custom rewrite specs.
PiperOrigin-RevId: 265485862
2019-08-26 10:28:09 -07:00
Andy Ly 6a501e3d1b Support folding of ops with inner ops in GreedyPatternRewriteDriver.
This fixes a bug when folding ops with inner ops and inner ops are still being visited.

PiperOrigin-RevId: 265475780
2019-08-26 09:44:39 -07:00
Alina Sbirlea 96e96e0243 NFC: Add doc for id-punct
PiperOrigin-RevId: 265190168
2019-08-23 21:01:12 -07:00
River Riddle 4da37417ad NFC: Update Ch.1 of the Toy tutorial.
Change the use of 'array' to 'tensor' to reflect the new flow that the tutorial will follow. Also tidy up some of the documentation, code comments, and fix a few out-dated links.

PiperOrigin-RevId: 265174676
2019-08-23 18:11:56 -07:00
Nicolas Vasilache 46084c03f4 Lower linalg.copy to LLVM dialect in the presence of transposes.
Add an extra RewritePattern that does not convert types to rewrite a CopyOp that has non-identity permutations into a sequence of TransposeOp followed by a CopyOp without such permutations.

This RewitePattern is made to fail in the non-permutation case so that the conversion pattern can kick in to lower to LLVM.

This is an instance of A->A->B lowering where A->A is done by a RewritePattern in case_1 and A->B is done by a ConversionPatternRewriter when not(case_1).

PiperOrigin-RevId: 265171380
2019-08-23 17:45:19 -07:00
Nicolas Vasilache 28e28e5d65 Lower linalg.transpose to LLVM dialect
Add a conversion pattern that transforms a linalg.transpose op into:
   1. A function entry `alloca` operation to allocate a ViewDescriptor.
   2. A load of the ViewDescriptor from the pointer allocated in 1.
   3. Updates to the ViewDescriptor to introduce the data ptr, offset, size
      and stride. Size and stride are permutations of the original values.
   4. A store of the resulting ViewDescriptor to the alloca'ed pointer.
The linalg.transpose op is replaced by the alloca'ed pointer.

PiperOrigin-RevId: 265169112
2019-08-23 17:29:26 -07:00
Nicolas Vasilache 2c2c9ffd80 Add a linalg.transpose op
A linalg.transpose op is a pure metadata operation that takes a view + permutation map and produces
another view of the same underlying data, with a different reindexing. This is a
pure metadata operation that does not touch the underlying data.

Example:

```
  %t = linalg.transpose %v (i, j) -> (j, i) : !linalg.view<?x?xf32>
```

PiperOrigin-RevId: 265139429
2019-08-23 14:48:13 -07:00
River Riddle 32052c8417 NFC: Add a note to 'applyPatternsGreedily' that it also performs folding/dce.
Fixes tensorflow/mlir#72

PiperOrigin-RevId: 265097597
2019-08-23 11:28:45 -07:00
Nicolas Vasilache 7f42b3d721 Add lowering of linalg.copy to an external C++ library and a test.
This CL extends support for lowering of linalg to external C++ libraries with CopyOp. Currently this can only work when the permutation maps in the copies are identity. Future support for permutations will be added later.

PiperOrigin-RevId: 265093025
2019-08-23 11:09:53 -07:00
Nicolas Vasilache 3d409386a0 Update Linalg slice and subview documentation - NFC
PiperOrigin-RevId: 265092922
2019-08-23 11:09:02 -07:00
Lei Zhang 0e131d83fe [spirv] NFC: move SPIR-V control flow ops to a separate file
This CL is also purely moving code around for better file organization.

PiperOrigin-RevId: 265092566
2019-08-23 11:07:52 -07:00
Chris Lattner 31a003dc3c Introduce the ability for "isolated from above" ops to introduce shadowing
names for the basic block arguments in their body.

PiperOrigin-RevId: 265084627
2019-08-23 10:35:49 -07:00
MLIR Team 00177962ed NFC: Update in-code documentation. Make the two grammar definitions of static-dimension-list consistent.
PiperOrigin-RevId: 265084348
2019-08-23 10:34:35 -07:00
Lei Zhang 21b77fc11f [spirv] NFC: move arithmetic and logical ops to separate files
This is purely moving code around for better file organization.

PiperOrigin-RevId: 265082517
2019-08-23 10:26:45 -07:00
Nicolas Vasilache 988dab0abc Fix BufferAllocOp builder.
One of the BufferAllocOp builders was improperly specified which triggered infinite recursion. This CL fixes it.

PiperOrigin-RevId: 265080371
2019-08-23 10:15:59 -07:00
River Riddle f772d2c90c NFC: Move the operation, region, and block sections to after the dialect section.
Operations/Regions/Blocks represent the core IR building blocks and should be introduced before types and attributes.

PiperOrigin-RevId: 265079103
2019-08-23 10:09:14 -07:00
MLIR Team a329d33b4f Add I32ElementsAttr to OpBase
PiperOrigin-RevId: 264969142
2019-08-22 19:05:40 -07:00
River Riddle d906f84b52 Add iterator support to ElementsAttr and SparseElementsAttr.
This will allow iterating the values of a non-opaque ElementsAttr, with all of the types currently supported by DenseElementsAttr. This should help reduce the amount of specialization on DenseElementsAttr.

PiperOrigin-RevId: 264968151
2019-08-22 18:59:24 -07:00
River Riddle fc86c57bd0 NFC: Cleanup the Attribute section in the LangRef.
* Add a section on dialect attribute values and attribute aliases
* Move FloatAttr into its alphabetically correct place
* Add a "Standard Attribute Values" section

PiperOrigin-RevId: 264959306
2019-08-22 17:51:31 -07:00
River Riddle 9fc1657af0 NFC: Cleanup the type system section of the LangRef.
* Alphabetize the type definitions
* Make 'Dialect specific types' a type-system subsection
* Merge Builtin types and Standard types

PiperOrigin-RevId: 264947721
2019-08-22 16:43:29 -07:00
Lei Zhang 51cbf97b53 [spirv] Add support for extension (de)serialization
Only a few important KHR extensions are registered to the
SPIR-V dialect for now.

PiperOrigin-RevId: 264939428
2019-08-22 16:01:35 -07:00
River Riddle 986f93001a NFC: Rework and cleanup the High-Level structure and Dialect sections.
Both sections are out-of-date and need to be updated. The dialect section is particularly bad in that it never actually mentions what a 'Dialect' is.

PiperOrigin-RevId: 264937905
2019-08-22 15:54:09 -07:00
River Riddle 02c8b06891 NFC: Remove mentions of the TensorFlow dialect from the langref.
PiperOrigin-RevId: 264904489
2019-08-22 13:21:00 -07:00
Nicolas Vasilache 6f1d4bb8df Avoid overflow when lowering linalg.slice
linalg.subview used to lower to a slice with a bounded range resulting in correct bounded accesses. However linalg.slice could still index out of bounds. This CL moves the bounding to linalg.slice.

LLVM select and cmp ops gain a more idiomatic builder.

PiperOrigin-RevId: 264897125
2019-08-22 12:47:01 -07:00
River Riddle 140b28ec12 NFC: Avoid reconstructing the OpInterface methods.
PiperOrigin-RevId: 264881293
2019-08-22 11:31:27 -07:00
Lei Zhang 27ed82f99c [spirv] Add support for capability (de)serialization
This CL pulls in capabilities defined in the spec and adds
support for (de)serialize capabilities of a spv.module.

PiperOrigin-RevId: 264877413
2019-08-22 11:15:41 -07:00
Logan Chien b1ce4df505 Add Positive{I32,I64}Attr and HasAnyRankOfPred
This commit adds `PositiveI32Attr` and `PositiveI64Attr` to match positive
integers but not zero nor negative integers.  This commit also adds
`HasAnyRankOfPred` to match tensors with the specified ranks.

PiperOrigin-RevId: 264867046
2019-08-22 10:36:32 -07:00
Jacques Pienaar 0c7f3f7108 Split out parsing location into separate functions per instance
Split out method into specialized instances + add an early exit. Should be NFC, but simplifies reading the logic slightly IMHO.

PiperOrigin-RevId: 264855529
2019-08-22 09:45:33 -07:00
Nicolas Vasilache fa592908af Let LLVMOpLowering specify a PatternBenefit - NFC
Currently the benefit is always set to 1 which limits the ability to do A->B->C lowering

PiperOrigin-RevId: 264854146
2019-08-22 09:38:42 -07:00
River Riddle 38d4e0b6a1 NFC: Fix path of LinalgLibraryOpInterfaces inc files.
PiperOrigin-RevId: 264827908
2019-08-22 07:15:36 -07:00
River Riddle b9377d7ec6 Add support for generating operation interfaces from the ODS framework.
Operation interfaces generally require a bit of boilerplate code to connect all of the pieces together. This cl introduces mechanisms in the ODS to allow for generating operation interfaces via the 'OpInterface' class.

Providing a definition of the `OpInterface` class will auto-generate the c++
classes for the interface. An `OpInterface` includes a name, for the c++ class,
along with a list of interface methods. There are two types of methods that can be used with an interface, `InterfaceMethod` and `StaticInterfaceMethod`. They are both comprised of the same core components, with the distinction that `StaticInterfaceMethod` models a static method on the derived operation.

An `InterfaceMethod` is comprised of the following components:
    * ReturnType
      - A string corresponding to the c++ return type of the method.
    * MethodName
      - A string corresponding to the desired name of the method.
    * Arguments
      - A dag of strings that correspond to a c++ type and variable name
        respectively.
    * MethodBody (Optional)
      - An optional explicit implementation of the interface method.

def MyInterface : OpInterface<"MyInterface"> {
  let methods = [
    // A simple non-static method with no inputs.
    InterfaceMethod<"unsigned", "foo">,

    // A new non-static method accepting an input argument.
    InterfaceMethod<"Value *", "bar", (ins "unsigned":$i)>,

    // Query a static property of the derived operation.
    StaticInterfaceMethod<"unsigned", "fooStatic">,

    // Provide the definition of a static interface method.
    // Note: `ConcreteOp` corresponds to the derived operation typename.
    StaticInterfaceMethod<"Operation *", "create",
      (ins "OpBuilder &":$builder, "Location":$loc), [{
        return builder.create<ConcreteOp>(loc);
    }]>,

    // Provide a definition of the non-static method.
    // Note: `op` corresponds to the derived operation variable.
    InterfaceMethod<"unsigned", "getNumInputsAndOutputs", (ins), [{
      return op.getNumInputs() + op.getNumOutputs();
    }]>,
  ];

PiperOrigin-RevId: 264754898
2019-08-21 20:57:51 -07:00