Commit Graph

1476 Commits

Author SHA1 Message Date
Jacques Pienaar 041e961802 Add extraClassDeclaration field for ops.
Simple mechanism to allow specifying arbitrary function declarations. The modelling will not cover all cases so allow a means for users to declare a method function that they will define in their C++ files. The goal is to allow full C++ flexibility as the goal is to cover cases not modelled.

--

PiperOrigin-RevId: 245889819
2019-05-06 08:21:58 -07:00
Stella Laurenzo 9ecf6887d6 Add an "any" quantized type, which contains the underlying type correlation but does not specify any mapping.
Also fixes some comments that were stale after the last syntax upgrade.

--

PiperOrigin-RevId: 245853462
2019-05-06 08:21:42 -07:00
Jacques Pienaar 9fd1957852 Fix opt build failure.
--

PiperOrigin-RevId: 245844236
2019-05-06 08:21:25 -07:00
Jacques Pienaar 3ea13d2db0 Fixup MLIRGPU to mlir-opt in cmake.
--

PiperOrigin-RevId: 245820077
2019-05-06 08:21:09 -07:00
Nicolas Vasilache 56c7a957bf Parsing support for Range, View and Slice operations
This CL implements the previously unsupported parsing for Range, View and Slice operations.
    A pass is introduced to lower to the LLVM.
    Tests are moved out of C++ land and into mlir/test/Examples.
    This allows better fitting within standard developer workflows.

--

PiperOrigin-RevId: 245796600
2019-05-06 08:20:55 -07:00
Nicolas Vasilache c5abd6b6c9 Link MLIRSupport to IR in OSS
The missing dependency breaks linking on Linux.

--

PiperOrigin-RevId: 245773637
2019-05-06 08:20:38 -07:00
Jacques Pienaar 0ea6154b2a Add Dialect in op definition to capture prefix and documentation.
Enables specifying the documentation for dialect along with defining the ops of the dialect. The doc generator will be expanded in follow up to emit the documentation in the autogenerated files. This is precursor to allowing common base for all ops in a dialect.

    All the dialect documentation is super sparse and just added as placeholder.

    I was tempted (and started) to move ConstantOp to be generated too, but this will be easier post adding extra_methods, so deferring until then.

--

PiperOrigin-RevId: 245759984
2019-05-06 08:20:24 -07:00
Alex Zinenko aae8a7446e Start GPU Dialect
Define a new dialect related to GPU kernels.  Currently, it only contains a
    single operation for launching a kernel on a three-dimensional grid of thread
    blocks, following a model similar to that of CUDA.  In particular, the body of
    the kernel contains operations executed by each thread and uses region
    arguments to accept thread and block identifiers (similar to how the loop body
    region accepts the induction value).

--

PiperOrigin-RevId: 245713728
2019-05-06 08:20:08 -07:00
Mehdi Amini 4c74f1bf38 Rename "convert-to-llvmir" to "lower-to-llvm" (NFC)
--

PiperOrigin-RevId: 245649493
2019-05-06 08:19:52 -07:00
Smit Hinsu c9b0540b9c Make identity cast operations with the same operand and result types legal
Instead, fold such operations. This way callers don't need to conditionally create cast operations depending on if a value already has the target type.

    Also, introduce areCastCompatible to allow cast users to verify that the generated op will be valid before creating the operation.

    TESTED with unit tests

--

PiperOrigin-RevId: 245606133
2019-05-06 08:19:37 -07:00
River Riddle 1316db3baa Add support for a NoneType.
none-type ::= `none`

    The `none` type is a unit type, i.e. a type with exactly one possible value, where its value does not have a defined dynamic representation.

--

PiperOrigin-RevId: 245599248
2019-05-06 08:19:20 -07:00
River Riddle a8ef8fa182 Update the wording of a comment in the LangRef now that multi-threading is no longer an anticipated feature.
--

PiperOrigin-RevId: 245586656
2019-05-06 08:19:03 -07:00
Alex Zinenko 54ee709e88 Add LLVM Conversion Tutorial
Add a tutorial document explaining how to define a conversion from the Linalg
    dialect to the LLVM IR dialect, bypassing the Affine dialect.  It defines a
    dynamic representation for a range and a view for the sake of type conversion.
    Operation conversion becomes straightforward given the dynamic representation.
    The code in the tutorial is better structured and better document that what we
    currently have in the example, which will be updated separately.

--

PiperOrigin-RevId: 245498394
2019-05-06 08:18:47 -07:00
Alex Zinenko 9de199676f Implement the conversion between SDBMExpr and AffineExpr
Since SDBM expressions are a subset of affine expressions, they can be
    converted to affine expressions in a straightforward way.  The inverse
    conversion may fail when the affine expression is not an SDBM.  Implement the
    inverse convresion assuming affine expressions are simplified and
    canonicalizied, detect subtractive and multiplicative forms of the stripe
    operation.

--

PiperOrigin-RevId: 245494735
2019-05-06 08:18:31 -07:00
Alex Zinenko 8a5f88191b Decouple region argument parsing from their type assignment
The parser currently expects region arguments to have a fixed, known type when
    the %-name of the region argument is parsed.  This may not necessarily be the
    case, for example, if the region argument types are the same as the operand
    types, located at the end of the operation.  Furthermore, the parser currently
    stores the values for region arguments internally and attaches them to the next
    parsed region implicitly.  This makes it impossible to attach some of the
    arguments to one region and some other arguments to another region if the
    regions are not textually interleaved with operation arguments.

    Provide `OpAsmParser::parseRegionArgument` that parses an SSA identifier and
    delays its type assignment until the region is parsed, similarly to operands.
    Update `OpAsmParser::parseRegion` to accept a list of pre-parsed SSA
    identifiers and a list of types instead of using SSA identifiers stored in the
    parser.

--

PiperOrigin-RevId: 245491133
2019-05-06 08:18:14 -07:00
River Riddle 40ab8e0fb3 Enable multi-threading in the pass manager by default.
--

PiperOrigin-RevId: 245458081
2019-05-06 08:17:58 -07:00
Alex Zinenko 24d0f60d31 Start building SDBM infrastructure
Striped difference-bound matrix expressions are a subset of affine expressions
    supporting low-complexity algorithms that can be useful for loop
    transformations.  This introduces the basic data data structures for building
    such expressions and unique'ing them in a MLIRContext.

--

PiperOrigin-RevId: 245380206
2019-05-06 08:17:42 -07:00
Stephan Herhut 65ccb8cfd5 Add a new NVVM dialect that extends the LLVM dialect with some NVVM specific operations.
Currently, this is limited to operations that give access to the special registers of
    NVIDIA gpus that represent block and thread indices.

--

PiperOrigin-RevId: 245378632
2019-05-06 08:17:24 -07:00
River Riddle 880df8f6ad Refactor the generic storage object uniquing functionality from TypeUniquer into its own class 'StorageUniquer'. This is the first step in supporting dialect extensible attributes.
--

PiperOrigin-RevId: 245358744
2019-05-06 08:17:08 -07:00
Lei Zhang 6749c21d6e [TableGen] Support multiple variadic operands/results
Certain ops can have multiple variadic operands/results, e.g., `tf.DynamicStitch`.
    Even if an op has only one variadic operand/result, it is not necessarily the
    very last one, e.g., `tf.RaggedGather`. This CL enhances TableGen subsystem to be
    able to represent such cases.

    In order to deduce the operand/result value range for each variadic operand,
    currently we only support variadic operands/results all of the same size.
    So two new traits, `SameVariadicOperandSize` and `SameVariadicResultSize` are
    introduced.

--

PiperOrigin-RevId: 245310628
2019-05-06 08:16:54 -07:00
River Riddle 22ad45a7aa Add support for Unit Attributes.
A unit attribute is an attribute that represents a value of `unit` type. The
    `unit` type allows only one value forming a singleton set. This attribute value
    is used to represent attributes that only have meaning from their existence.

    One example of such an attribute could be the `swift.self` attribute. This attribute indicates that a function parameter is the self/context
    parameter. It could be represented as a boolean attribute(true or false), but a
    value of false doesn't really bring any value. The parameter either is the
    self/context or it isn't.

    ```mlir {.mlir}
    // A unit attribute defined with the `unit` value specifier.
    func @verbose_form(i1 {unitAttr : unit})

    // A unit attribute can also be defined without the `unit` value specifier.
    func @simple_form(i1 {unitAttr})
    ```

--

PiperOrigin-RevId: 245254045
2019-05-06 08:16:39 -07:00
Rob Suderman 69cdceae73 GetMemRefType failed on 0-D tensors. Loosened check to allow tensors with shape
{}.

--

PiperOrigin-RevId: 245104548
2019-05-06 08:16:23 -07:00
Lei Zhang ce12875333 [TableGen] Refine OpTrait classes and defs to be consistent
--

PiperOrigin-RevId: 245075421
2019-05-06 08:16:11 -07:00
Alex Zinenko 4beef47b35 Introduce functionality for defining region ancestor relation
Add member functions for Regions to query if another Region is a ancestor.  The
    implementation is naive and traverses all parent regions performing one-to-one
    comparisons.  As a side effect, this introduces `getContainingRegion` function
    for Operations and Values to return the Region in which they are defined, and
    for Regions to return the "parent" region if any.

--

PiperOrigin-RevId: 245057980
2019-05-06 08:16:00 -07:00
Lei Zhang 9f934f2a59 Add MultiResultTraitBase
Similar to MultiOperandTraitBase, this can simply the implementation of
    NResults, AtLeastNResults, and VariadicResults.

--

PiperOrigin-RevId: 245052333
2019-05-06 08:15:50 -07:00
River Riddle 5f801366d1 Fix flaky Linalg roundtrip test. This removes an invalid "%s" from the second mlir-opt command.
--

PiperOrigin-RevId: 244953230
2019-04-23 22:03:31 -07:00
Mehdi Amini 8034407f54 Use -force_load instead of -all_load on MacOS
The -all_load flag will apply to all future libraries added on the command line,
    while the -force_load flag only applies to the next library. Using the latter
    allows to selectively force load the specific libraries we want.

--

PiperOrigin-RevId: 244949770
2019-04-23 22:03:23 -07:00
River Riddle 1423acc03c Rename isa_nonnull to isa_and_nonnull to match the upstream llvm name.
--

PiperOrigin-RevId: 244928036
2019-04-23 22:03:14 -07:00
Nicolas Vasilache a2e7775441 [Linalg] Add basic linalg ops
This CL adds linalg.dot, linalg.matvec and linalg.matmul ops with the proper roundtripping test. These are the first LinalgOp that operate on views and that will lower to library calls.
    Linalg ops exhibit some common properties and behavior that are modeled with Traits.

    A LinalgOp is defined as a generic Op that operates on input and output views (passed as operands) and has the following properties:
    1. a number of input and outputs captured by the `NInputsAndOutputs` trait.
    2. a list of ranks for each operand captured by the `ViewRanks` trait.
    3. a set of parallel, reduction and windowing loops captured by `NLoopTypes` trait.

    These represent are a first set of generic properties that will enable the definition of generic linear algebra operations and the properties necessary for upcoming transformations.

--

PiperOrigin-RevId: 244912754
2019-04-23 22:03:06 -07:00
MLIR Team ff6804c045 Minor typo in integer type definition.
--

PiperOrigin-RevId: 244854008
2019-04-23 22:02:58 -07:00
Alex Zinenko 06ca99530d Factor out thread-safe uniqu'ing backed by vector in MLIRcontext
Extract common code from getAffineSymbolExpr and getAffineConstantExpr into a
    utility function safeGetOrCreate, similarly to the existing overloads for sets
    and maps.  The position in the vector is used as indexing key.  NFC.

--

PiperOrigin-RevId: 244820859
2019-04-23 22:02:50 -07:00
Alex Zinenko ea86e7652e ExecutionEngine: update to reflect LLVM API changes
LLVM Orc JIT changed the API for DynamicLibrarySearchGenerator::
    GetForCurrentProcess to only take one value of the DataLayout that it actually
    uses instead of the whole data layout.  Update MLIR ExecutionEngine call to
    this function accordingly.

--

PiperOrigin-RevId: 244820235
2019-04-23 22:02:41 -07:00
Smit Hinsu 017cf6c7b8 Fix unused variable warning in opt build
TESTED with existing tests

--

PiperOrigin-RevId: 244808731
2019-04-23 22:02:33 -07:00
Stella Laurenzo 8189e6ef90 Implement lowering of quant.dcast to the fxpmathops and standard dialect.
Note that I broke this out as a separate pass because intermediate transformations often produce qcast/dcast ops that are integral to the transformation, and it is typical to want to lower any remaining, unmatched casts at the end of quantization. If this flexibility ends up not being needed, they can be collapsed into the same pass. This is included in the same cpp file because all of the math ops will need to defer to emitting quantize/dequantize logic for cases that they cannot be fully lowered to fixed-point math.

    Also, the new convertistof op needs to be evaluated for inclusion in StandardOps.

--

PiperOrigin-RevId: 244768679
2019-04-23 22:02:25 -07:00
Feng Liu 5c757087c7 Apply patterns repeatly if the function is modified
During the pattern rewrite, if the function is changed, i.e. ops created,
    deleted or swapped, the pattern rewriter needs to re-scan the function entirely
    and apply the patterns again, so the patterns whose root ops have been popped
    out from the working list nor an immediate users of the changed ops can be
    reconsidered.

    A command line flag is added to set the max number of iterations rescanning the
    function for pattern match. If the rewrite doesn' converge after this number,
    this compiling will continue and the result can be sub-optimal.

    One unit test is updated because this change fixed the missing optimization opportunities.

--

PiperOrigin-RevId: 244754190
2019-04-23 22:02:16 -07:00
Lei Zhang 10bcc34a68 [TableGen] Clean up comments regarding op and result
An op can have multiple results. Being explicit that we are binding to the
    whole op instead of one of the results. A way to bind to a specific result
    is yet to come.

--

PiperOrigin-RevId: 244741137
2019-04-23 22:02:08 -07:00
Lei Zhang d0e2019d39 [TableGen] Unify cOp and tAttr into NativeCodeCall
Both cOp and tAttr were used to perform some native C++ code expression.
    Unifying them simplifies the concepts and reduces cognitive burden.

--

PiperOrigin-RevId: 244731946
2019-04-23 22:02:00 -07:00
Lei Zhang 09b623aa93 [TableGen] Capture bound source ops in PatternState
This allows accessing those bound source ops in result patterns, which can be
    useful for invoking native C++ op creation.

    We bind the op entirely here because ops can have multiple results. Design a
    approach to bind to a specific result is not the concern of this commit.

--

PiperOrigin-RevId: 244724750
2019-04-23 22:01:52 -07:00
Jacques Pienaar f7f2760c30 Update lib path in whole_archive_link.
The added library path is now specified explicitly wrt top-level build directory.

--

PiperOrigin-RevId: 244507187
2019-04-23 22:01:44 -07:00
Lei Zhang 82a586e658 Use StringRef::drop_while() to simplify a while loop
--

PiperOrigin-RevId: 244488612
2019-04-23 22:01:35 -07:00
Mehdi Amini 159d07254e Add references to the EuroLLVM talks in the README
--

PiperOrigin-RevId: 244433092
2019-04-23 22:01:26 -07:00
Stella Laurenzo 4292294a65 Simplify and enable pretty-parsing/printing of the uniform quantized types.
The per-layer format is now like:
      !quant.uniform<i8<-8:7>:f32, 9.987200e-01:127>
    and per-axis is:
      !quant.uniform<i8:f32:1, {2.0e+2,0.99872:120}>

    I used the following sed script to update the unit tests (invoked with commands like `sed -i -r -f fix_quant.sed $(find . -name '*.mlir')`).
    ---
    # Per-layer
    s|\!quant<"uniform\[([iu][0-9]+):([fb]+[0-9]+)\]\{([^\}]+)\}\s*">|!quant.uniform<\1:\2, \3>|g
    s|\!quant<"uniform\[([iu][0-9]+)\(([^\)]+)\):([fb]+[0-9]+)\]\{([^\}]+)\}\s*">|!quant.uniform<\1<\2>:\3, \4>|g

    # Per-axis
    s|\!quant<"uniform\[([iu][0-9]+):([fb]+[0-9]+)(:[0-9]+)?\]\{([^\}]+)\}\s*">|!quant.uniform<\1:\2\3, {\4}>|g
    s|\!quant<"uniform\[([iu][0-9]+)\(([^\)]+)\):([fb]+[0-9]+)(:[0-9]+)?\]\{([^\}]+)\}\s*">|!quant.uniform<\1<\2>:\3\4, {\5}>|g
    ---
    I fixed up the one file of error cases manually.
    Since this is a one time syntax fix, I am not persisting the script anywhere.

--

PiperOrigin-RevId: 244425331
2019-04-23 22:01:18 -07:00
Nicolas Vasilache 0b47f74037 [Linalg] Add a slice op
This CL adds a linalg.slice op with the proper roundtripping test.
    A slice op allows taking subviews that may be rank-reducing (if some indexing is of index type) or not (if all indexings are of linalg.range type).

    A slice must be constructed directly from a base view (no chains of slices may exist in the IR). Helper functions that fold will be provided for construction if/when necessary.

    This also renames base_view to view.

--

PiperOrigin-RevId: 244406827
2019-04-23 22:01:10 -07:00
Nicolas Vasilache 1d5dc840e7 [Linalg] Add a view type with base_view op
This CL adds a linalg.view<?x?xf32> type and base_view op with the proper roundtripping test. The parser will be improved in a subsequent CL once portions of the mlir::Parser are exposed.

    For now this only supports dynamic views, static views will be introduced at a later time when they are needed.

--

PiperOrigin-RevId: 244374180
2019-04-23 22:01:02 -07:00
Stella Laurenzo e8d551e2bd Implement lowering of element-wise fixed point add and mul to the standard dialect.
This also does the following:
      - Removes the poc POT add implementation in favor of a version that does not rescale.
      - Adds a handful of FxpMathOps which are needed (these are for comment and we may want to move them to the StandardOps dialect).
      - Adds a canonicalizer to the StorageCastOp, which removes some cruft once conversions have been done.
      - Adds a couple of predicates to OpBase.

--

PiperOrigin-RevId: 244287706
2019-04-23 22:00:53 -07:00
Guangda Lai 7977e62b96 Fix typo (transpose -> reshape).
--

PiperOrigin-RevId: 244270801
2019-04-23 22:00:45 -07:00
Nicolas Vasilache 75be1fe82b [Linalg] Add a simple buffer type with alloc/dealloc ops
This CL adds a linalg.buffer<f32> type and buffer_alloc / buffer_dealloc ops with the proper roundtripping test.

--

PiperOrigin-RevId: 244252306
2019-04-23 22:00:36 -07:00
Nicolas Vasilache 8370cc7492 Start a Linalg dialect
This CL starts implementing a Linalg dialect with the objective of supporting
    optimizing compilation of loops and library calls for a subset of common linear
    algebra operations.

    This CL starts by simply adding a linalg.range type and an operation with the
    proper roundtripping test.

--

PiperOrigin-RevId: 244189468
2019-04-18 11:50:27 -07:00
Lei Zhang 05dfb1c7e0 Fix MLIRTableGenTests target_link_libraries typo
--

PiperOrigin-RevId: 244168112
2019-04-18 11:50:19 -07:00
Lei Zhang 13285ee907 [TableGen] Simplify NOperands trait generation
--

PiperOrigin-RevId: 244162515
2019-04-18 11:50:11 -07:00