Commit Graph

2493 Commits

Author SHA1 Message Date
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
River Riddle 85bc8655f0 Avoid assigning to an unchecked Error.
Fixes tensorflow/mlir#97

PiperOrigin-RevId: 264743395
2019-08-21 19:03:39 -07:00
Lei Zhang 1d10eb162c Point to spv.AccessChain when reporting spv.AccessChain errors
PiperOrigin-RevId: 264742130
2019-08-21 18:54:06 -07:00
Nicolas Vasilache 62ced387e0 Remove dead getLLVMLibraryCallImplDefinition in Linalg's LowerToLLVMDialect.cpp - NFC
PiperOrigin-RevId: 264740014
2019-08-21 18:36:52 -07:00
Nicolas Vasilache fe3594f745 Reduce reliance on custom grown Jit implementation - NFC
This CL makes use of the standard LLVM LLJIT and removes the need for a custom JIT implementation within MLIR.

To achieve this, one needs to clone (i.e. serde) the produced llvm::Module into a new LLVMContext. This is currently necessary because the llvm::LLVMContext is owned by the LLVMDialect, somewhat deep in the call hierarchy.

In the future we should remove the reliance of serding the llvm::Module by allowing the injection of an LLVMContext from the top-level. Unfortunately this will require deeper API changes and impact multiple places. It is therefore left for future work.

PiperOrigin-RevId: 264737459
2019-08-21 18:16:02 -07:00
Lei Zhang 748edce6b8 Remove the wrapping function in SPIR-V (de)serialization
Previously Module and Function are builtinn constructs in MLIR.
Due to the structural requirements we must wrap the SPIR-V
module inside a Function inside a Module. Now the requirement
is lifted and we can remove the wrapping function! :)

PiperOrigin-RevId: 264736051
2019-08-21 18:05:24 -07:00
MLIR Team cc0d337620 NFC: Update in-code documentation for type.
PiperOrigin-RevId: 264734014
2019-08-21 17:51:56 -07:00
Chintan Kaur 35ad095305 Fix minor typos in TestingGuide and OpDefinitions.
PiperOrigin-RevId: 264733092
2019-08-21 17:45:30 -07:00
MLIR Team 8869de5fbc NFC: Update in-code documentation for function-type.
PiperOrigin-RevId: 264723462
2019-08-21 16:51:54 -07:00
River Riddle c400c9a1ec Add a hook to the OpAsmDialectInterface to allow providing a special name for the operation result.
This generalizes the current special handling for constant operations(they get named 'cst'/'true'/'false'/etc.)

PiperOrigin-RevId: 264723379
2019-08-21 16:50:59 -07:00
MLIR Team d661eda811 [TableGen] Add a `StaticShapeMemRefOf` trait.
The trait specifies that the `MemRefOf` has to have a static shape.

PiperOrigin-RevId: 264692758
2019-08-21 14:28:41 -07:00
River Riddle b618221350 Automated rollback of commit b9dc2e4818
PiperOrigin-RevId: 264672975
2019-08-21 13:01:03 -07:00
River Riddle 2e59b86541 NFC: Make the ModuleState field in the ModulePrinter optional.
The ModuleState is only used for printing aliases, which is only done when printing the top-level module.

PiperOrigin-RevId: 264664138
2019-08-21 12:16:49 -07:00
River Riddle b9dc2e4818 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: 264637293
2019-08-21 10:23:44 -07:00
River Riddle 7e1af594d2 Move the parser extensions for aliases currently on Dialect to a new OpAsmDialectInterface.
This will allow for adding more hooks for controlling parser behavior without bloating Dialect in the common case. This cl also adds iteration support to the DialectInterfaceCollection.

PiperOrigin-RevId: 264627846
2019-08-21 09:42:02 -07:00
Lei Zhang 8d18fdf2d3 [spirv] Support i1 as bool type
PiperOrigin-RevId: 264612014
2019-08-21 08:17:50 -07:00
Lei Zhang 31cfee6077 Support variadic ops in declarative rewrite rules
This CL extends declarative rewrite rules to support matching and
generating ops with variadic operands/results. For this, the
generated `matchAndRewrite()` method for each pattern now are
changed to

* Use "range" types for the local variables used to store captured
  values (`operand_range` for operands, `ArrayRef<Value *>` for
  values, *Op for results). This allows us to have a unified way
  of handling both single values and value ranges.
* Create local variables for each operand for op creation. If the
  operand is variadic, then a `SmallVector<Value*>` will be created
  to collect all values for that operand; otherwise a `Value*` will
  be created.
* Use a collective result type builder. All result types are
  specified via a single parameter to the builder.

We can use one result pattern to replace multiple results of the
matched root op. When that happens, it will require specifying
types for multiple results. Add a new collective-type builder.

PiperOrigin-RevId: 264588559
2019-08-21 05:35:32 -07:00
Lei Zhang 69cf811d5b Materialize spv.constants at use sites
In SPIR-V binary format, constants are placed at the module level
and referenced by instructions inside functions using their result
<id>s. To model this natively (using SSA values for result <id>s),
it means we need to have implicit capturing functions. We will
lose the ability to have function passes if going down that path.

Instead, this CL changes to materialize constants at their use
sites in deserialization. It's cheap to copy constants in MLIR
given that attributes is uniqued to MLIRContext. By localizing
constants into functions, we can preserve isolated functions.

PiperOrigin-RevId: 264582532
2019-08-21 04:45:49 -07:00
River Riddle ad8b410f16 NFC: Keep the dialect list in the context sorted by namespace.
Most dialects are initialized statically, which does not have a guaranteed initialization order. By keeping the dialect list sorted, we can guarantee a deterministic iteration order of dialects.

PiperOrigin-RevId: 264522875
2019-08-20 19:59:01 -07:00
River Riddle 5e17730cde NFC: Use a DenseSet instead of a DenseMap for DialectInterfaceCollection.
The interfaces are looked up by dialect, which can always be retrieved from an interface instance.

PiperOrigin-RevId: 264516023
2019-08-20 18:49:37 -07:00
River Riddle 35102ea2c3 NFC: Move the LangRef documentation on StandardOps to a new document.
The LangRef should contain documentation about the core system, and standard ops is a dialect just like any other. This will also simplify the transition when StandardOps is eventually split apart.

PiperOrigin-RevId: 264514988
2019-08-20 18:42:05 -07:00
River Riddle ffde975e21 NFC: Move AffineOps dialect to the Dialect sub-directory.
PiperOrigin-RevId: 264482571
2019-08-20 15:36:39 -07:00
Lei Zhang f4934bcc3e Add spv.specConstant and spv._reference_of
Similar to global variables, specialization constants also live
in the module scope and can be referenced by instructions in
functions in native SPIR-V. A direct modelling would be to allow
functions in the SPIR-V dialect to implicit capture, but it means
we are losing the ability to write passes for Functions. While
in SPIR-V normally we want to process the module as a whole,
it's not common to see multiple functions get used so we'd like
to leave the door open for those cases. Therefore, similar to
global variables, we introduce spv.specConstant to model three
SPIR-V instructions: OpSpecConstantTrue, OpSpecConstantFalse,
and OpSpecConstant. They do not return SSA value results;
instead they have symbols and can only be referenced by the
symbols. To use it in a function, we need to have another op
spv._reference_of to turn the symbol into an SSA value. This
breaks the tie and makes functions still explicit capture.
Previously specialization constants were handled similarly as
normal constants. That is incorrect given that specialization
constant actually acts more like variable (without need to
load and store). E.g., they cannot be de-duplicated like normal
constants.

This CL also refines various documents and comments.

PiperOrigin-RevId: 264455172
2019-08-20 13:34:13 -07:00
Denis Khalikov 82cf6051ee [spirv] Support (de)serialization of spv.struct
Support (de)serialization of spv.struct with offset decorations.

Closes tensorflow/mlir#94

PiperOrigin-RevId: 264421427
2019-08-20 11:03:42 -07:00
Diego Caballero 9e6cf0d025 Fix build of affine load/store with empty map
tensorflow/mlir#58 fixed and exercised
verification of load/store ops using empty affine maps. Unfortunately,
it didn't exercise the creation of them. This PR addresses that aspect.
It removes the assumption of AffineMap having at least one result and
stores a pointer to MLIRContext as member of AffineMap.

* Add empty map support to affine.store + test
* Move MLIRContext to AffineMapStorage

Closes tensorflow/mlir#74

PiperOrigin-RevId: 264416260
2019-08-20 10:44:18 -07:00
Andy Davis 3d32ca9776 Update MLIR code examples in Passes.md doc to use new affine.load/store dma_start/wait operations.
PiperOrigin-RevId: 264415037
2019-08-20 10:38:55 -07:00
Zhang 5c7fd5ff32 Update Ch-2.md
--
406f1e8211f8f5017f44f46af750dec061e707a2 by Zhang <5205699+Naville@users.noreply.github.com>:

Update Ch-2.md

Closes tensorflow/mlir#93

PiperOrigin-RevId: 264392995
2019-08-20 08:53:27 -07:00
Alex Zinenko 006fcce44a ConvertLaunchFuncToCudaCalls: use LLVM dialect globals
This conversion has been using a stack-allocated array of i8 to store the
null-terminated kernel name in order to pass it to the CUDA wrappers expecting
a C string because the LLVM dialect was missing support for globals.  Now that
the suport is introduced, use a global instead.

Refactor global string construction from GenerateCubinAccessors into a common
utility function living in the LLVM namespace.

PiperOrigin-RevId: 264382489
2019-08-20 07:52:01 -07:00
Alex Zinenko 0d82a292b0 JitRunner: support entry functions returning void
JitRunner can use as entry points functions that produce either a single
'!llvm.f32' value or a list of memrefs.  Memref support is legacy and was
introduced before MLIR could lower memref allocation and deallocation to
malloc/free calls so as to allocate the memory externally, and is likely to be
dropped in the future since it unconditionally runs affine+standard-to-llvm
lowering on the module instead of accepting the LLVM dialect.  CUDA runner
relies on memref-based flow in the runner without actually returning anything.
Introduce a runner flow to use functions that return void as entry points.

PiperOrigin-RevId: 264381686
2019-08-20 07:46:17 -07:00