Commit graph

2652 commits

Author SHA1 Message Date
Uday Bondhugula 458ede8775 Introduce splat op + provide its LLVM lowering
- introduce splat op in standard dialect (currently for int/float/index input
  type, output type can be vector or statically shaped tensor)
- implement LLVM lowering (when result type is 1-d vector)
- add constant folding hook for it
- while on Ops.cpp, fix some stale names

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

Closes tensorflow/mlir#141

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/141 from bondhugula:splat 48976a6aa0a75be6d91187db6418de989e03eb51
PiperOrigin-RevId: 270965304
2019-09-24 12:44:58 -07:00
Nicolas Vasilache 42d8fa667b Normalize lowering of MemRef types
The RFC for unifying Linalg and Affine compilation passes into an end-to-end flow with a predictable ABI and linkage to external function calls raised the question of why we have variable sized descriptors for memrefs depending on whether they have static or dynamic dimensions  (https://groups.google.com/a/tensorflow.org/forum/#!topic/mlir/MaL8m2nXuio).

This CL standardizes the ABI on the rank of the memrefs.
The LLVM struct for a memref becomes equivalent to:
```
template <typename Elem, size_t Rank>
struct {
  Elem *ptr;
  int64_t sizes[Rank];
};
```

PiperOrigin-RevId: 270947276
2019-09-24 11:21:49 -07:00
Christian Sigg 74cdbf5909 Clone called functions into nested GPU module.
PiperOrigin-RevId: 270891190
2019-09-24 06:29:54 -07:00
Christian Sigg eba6014cdc Allow null Attribute for value when building GlobalOp.
PiperOrigin-RevId: 270853596
2019-09-24 01:19:53 -07:00
Lei Zhang 6caa4f500b [spirv] NFC: clean up (de)serialization tests
This CL uses the newly added -split-input-file CLI option to
mlir-translate to combine certain (de)serialization tests.
It also renames certain test filenames.

PiperOrigin-RevId: 270816324
2019-09-23 19:57:17 -07:00
Mahesh Ravishankar 69af468754 Make spirv::RuntimeArrayType part of spirv::CompositeType.
According to SPIR-V spec, spirv::CompositeType includes
spirv::RuntimeArrayType. This allows using objects of
spirv::RuntimeArrayType with spirv::AccessChainOp.
PiperOrigin-RevId: 270809492
2019-09-23 18:50:47 -07:00
Lei Zhang 0e7edcfe7e Let mlir-translate support -split-input-file
Similar to mlir-opt, having a -split-input-file mode is quite useful
in mlir-translate. It allows to put logically related tests in the
same test file for better organization.

PiperOrigin-RevId: 270805467
2019-09-23 18:18:23 -07:00
Mahesh Ravishankar 75906bd565 Handle OpMemberName instruction in SPIR-V deserializer.
Sdd support in deserializer for OpMemberName instruction. For now
the name is just processed and not associated with the
spirv::StructType being built. That needs an enhancement to
spirv::StructTypes itself.
Add tests to check for errors reported during deserialization with
some refactoring to common out some utility functions.
PiperOrigin-RevId: 270794524
2019-09-23 17:11:18 -07:00
Jacques Pienaar 4a862fbd63 Use constant's location for reporting errors in parsing of hex constant
Before this the line following the error would be reported in some cases.

PiperOrigin-RevId: 270778722
2019-09-23 15:51:42 -07:00
Mahesh Ravishankar 98d1d3fc43 Simplify the way spirv::StructTypes are parsed.
The existing logic to parse spirv::StructTypes is very brittle. This
change simplifies the parsing logic a lot. The simplification also
allows for memberdecorations to be separated by commas instead of
spaces (which was an artifact of the existing parsing logic). The
change also needs a modification to mlir::parseType to return the
number of chars parsed. Adding a new parseType method to do so.

Also allow specification of spirv::StructType with no members.

PiperOrigin-RevId: 270739672
2019-09-23 12:53:06 -07:00
Mehdi Amini 5583252173 Add convenience methods to set an OpBuilder insertion point after an Operation (NFC)
PiperOrigin-RevId: 270727180
2019-09-23 11:54:55 -07:00
River Riddle 8cb405a8be Add initial callgraph support.
Using the two call interfaces, CallOpInterface and CallableOpInterface, this change adds support for an initial multi-level CallGraph. This call graph builds a set of nodes for each callable region, and connects them via edges. An edge may be any of the following types:
* Abstract
  - An edge not produced by a call operation, used for connecting to internal nodes from external nodes.
* Call
  - A call edge is an edge defined via a call-like operation.
* Child
  - This is an artificial edge connecting nested callgraph nodes.

This callgraph will be used, and improved upon, to begin supporting more interesting interprocedural analyses and transformation. In a followup, this callgraph will be used to support more complex inlining support.

PiperOrigin-RevId: 270724968
2019-09-23 11:44:13 -07:00
River Riddle 8965011fad Add interfaces for call-like/callable operations.
These two operation interfaces will be used in a followup to support building a callgraph:
* CallOpInterface
  - Operations providing this interface are call-like, and have a "call" target. A call target may be a symbol reference, via SymbolRefAttr, or a SSA value.

* CallableOpInterface
  - Operations providing this interfaces define destinations to call-like operations, e.g. FuncOp. These operations may define any number of callable regions.

PiperOrigin-RevId: 270723300
2019-09-23 11:37:06 -07:00
River Riddle c61991ef01 Refactor DiagnosticEngine to support multiple registered diagnostic handlers.
This fixes a problem with current save-restore pattern of diagnostics handlers, as there may be a thread race between when the previous handler is destroyed. For example, this occurs when using multiple ParallelDiagnosticHandlers asynchronously:

Handler A
Handler B | - LifeTime - |    Restore A here.
Handler C | --- LifeTime ---| Restore B after it has been destroyed.

The new design allows for multiple handlers to be registered in a stack like fashion. Handlers can return success() to signal that they have fully processed a diagnostic, or failure to propagate otherwise.

PiperOrigin-RevId: 270720625
2019-09-23 11:25:14 -07:00
River Riddle 3eade43046 Update the Pass, Analysis, and PassManager sections of WritingAPass.md.
These have become out-of-date with the pass manager generalization.

PiperOrigin-RevId: 270719105
2019-09-23 11:18:22 -07:00
River Riddle 4b6b58ec0f NFC: Fix warning for uninitialized field.
PiperOrigin-RevId: 270704572
2019-09-23 10:20:13 -07:00
Jacques Pienaar 59e3b30af0 Add variants of interleave that take separator
Make the common case of string separator easier to specify.

PiperOrigin-RevId: 270697581
2019-09-23 09:50:10 -07:00
Christian Sigg b8676da1fc Outline GPU kernel function into a nested module.
Roll forward of commit 5684a12.

When outlining GPU kernels, put the kernel function inside a nested module. Then use a nested pipeline to generate the cubins, independently per kernel. In a final pass, move the cubins back to the parent module.

PiperOrigin-RevId: 270639748
2019-09-23 03:17:01 -07:00
Christian Sigg c900d4994e Fix a number of Clang-Tidy warnings.
PiperOrigin-RevId: 270632324
2019-09-23 02:34:27 -07:00
Jing Pu f1442f1eff [NFC] Replace std::clamp with inline implementation.
std::clamp is not in C++14, thus replace it with std::min and std::max.
PiperOrigin-RevId: 270604708
2019-09-22 23:00:58 -07:00
Jing Pu 54f4522a5c Specalize f32->i8/u8 Quanitization with C++ native arithmetic to optimize performance.
The CL adds a rounding mode flag to the class and changes the default to rmNearestTiesToAway from rmNearestTiesToEven because 1) Tensorflow QuantizeV2 ops uses rmNearestTiesToAway; 2) the specialization only implements rmNearestTiesToAway.

PiperOrigin-RevId: 270600739
2019-09-22 22:07:51 -07:00
MLIR Team 541f1945d1 Update TruncateIOp builder to pass OperationState by reference.
PiperOrigin-RevId: 270560295
2019-09-22 13:15:23 -07:00
Uday Bondhugula 08ae1bb830 update layout map examples in doc, drop stale ones
- add more examples for affine layout maps showing various use
  cases

- affine map range sizes were removed from code, but examples in
  LangRef weren't updated

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

Closes tensorflow/mlir#142

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/142 from bondhugula:doc 3291a8784bc69883f7a7cead21445fc8118aaad2
PiperOrigin-RevId: 270548991
2019-09-22 10:14:39 -07:00
Denis Khalikov 6414c08556 Fix undefined reference to mlir::getElementTypeOrSelf(mlir::Type)
Fix undefined reference:
mlir/lib/Dialect/StandardOps/Ops.cpp:2029:
undefined reference to `mlir::getElementTypeOrSelf(mlir::Type)'

Closes tensorflow/mlir#144

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/144 from denis0x0D:sandbox/fix_undef 494d4f7fa2e98ba21954d2b2f7ec1776b9397e08
PiperOrigin-RevId: 270545190
2019-09-22 09:08:56 -07:00
Manuel Freiberger 2c11997d48 Add integer sign- and zero-extension and truncation to standard.
This adds sign- and zero-extension and truncation of integer types to the
standard dialects. This allows to perform integer type conversions without
having to go to the LLVM dialect and introduce custom type casts (between
standard and LLVM integer types).

Closes tensorflow/mlir#134

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/134 from ombre5733:sext-zext-trunc-in-std c7657bc84c0ca66b304e53ec03797e09152e4d31
PiperOrigin-RevId: 270479722
2019-09-21 16:14:56 -07:00
brett koonce a26bb0346e minor spelling tweaks
Closes tensorflow/mlir#143

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/143 from brettkoonce:minor_sp_demo 76bdf7c121a824417969627fc15e50259356a2fa
PiperOrigin-RevId: 270462293
2019-09-21 11:39:10 -07:00
Denis Khalikov 2ec8e2be1f [spirv] Add OpControlBarrier and OpMemoryBarrier.
Add OpControlBarrier and OpMemoryBarrier (de)serialization.

Closes tensorflow/mlir#130

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/130 from denis0x0D:sandbox/memory_barrier 2e3fff16bca44904dc1039592cb9a65d526faea8
PiperOrigin-RevId: 270457478
2019-09-21 10:18:34 -07:00
Uday Bondhugula f559c38c28 Upgrade/fix/simplify store to load forwarding
- fix store to load forwarding for a certain set of cases (where
  forwarding shouldn't have happened); use AffineValueMap difference
  based MemRefAccess equality checking; utility logic is also greatly
  simplified

- add missing equality/inequality operators for AffineExpr ==/!= ints

- add == != operators on MemRefAccess

Closes tensorflow/mlir#136

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/136 from bondhugula:store-load-forwarding d79fd1add8bcfbd9fa71d841a6a9905340dcd792
PiperOrigin-RevId: 270457011
2019-09-21 10:08:56 -07:00
Mehdi Amini 4d880d09e0 Add a note about the use of recursion in the developer guide
PiperOrigin-RevId: 270455509
2019-09-21 09:46:02 -07:00
Lei Zhang 8e4906362e [ODS] Add support for FloatElementsAttr
This CL adds a new FloatElementsAttr definition to ODS for float
elements attributes of a certain type.

Tests are added to show both verification and how to use it in patterns.

PiperOrigin-RevId: 270455487
2019-09-21 09:45:15 -07:00
Christian Sigg 33a3a91ba2 Make GlobalOp's value attribute optional.
Make GlobalOp's value attribute an OptionalAttr. Change code that uses the value to handle 'nullopt'. Translate an unitialized value attribute to llvm::UndefValue.

PiperOrigin-RevId: 270423646
2019-09-21 01:20:28 -07:00
River Riddle 3a643de92b NFC: Pass OpAsmPrinter by reference instead of by pointer.
MLIR follows the LLVM style of pass-by-reference.

PiperOrigin-RevId: 270401378
2019-09-20 20:43:35 -07:00
River Riddle 729727ebc7 NFC: Pass OperationState by reference instead of by pointer.
MLIR follows the LLVM convention of passing by reference instead of by pointer.

PiperOrigin-RevId: 270396945
2019-09-20 19:47:32 -07:00
River Riddle 91125d33ed Avoid iterator invalidation when recursively computing pattern depth.
computeDepth calls itself recursively, which may insert into minPatternDepth. minPatternDepth is a DenseMap, which invalidates iterators on insertion, so this may lead to asan failures.

PiperOrigin-RevId: 270374203
2019-09-20 16:30:29 -07:00
River Riddle 2797517ecf NFC: Pass OpAsmParser by reference instead of by pointer.
MLIR follows the LLVM style of pass-by-reference.

PiperOrigin-RevId: 270315612
2019-09-20 11:37:21 -07:00
Nicolas Vasilache d8fda38cea Use SmallVectorImpl in getStrides
No need to force a particular size on the user of the API.

PiperOrigin-RevId: 270310570
2019-09-20 11:13:58 -07:00
Nicolas Vasilache daf3b85510 Fix public build
TestMemRefStrideCalculation.cpp was missing

PiperOrigin-RevId: 270304543
2019-09-20 10:50:04 -07:00
Nicolas Vasilache a00b568277 Add utility to extract strides from layout map in MemRefType.
The RFC for unifying Linalg and Affine compilation passes into an end-to-end flow discusses the notion of a strided MemRef (https://groups.google.com/a/tensorflow.org/forum/#!topic/mlir/MaL8m2nXuio).

This CL adds helper functions to extract strides from the layout map which in turn will allow converting between a strided form of the type and a layout map.

For now strides are only computed on a single affine map with a single result (i.e. the closed subset of linearization maps that are compatible with striding semantics). This restriction will be reevaluated / lifted in the future based on concrete use cases.

PiperOrigin-RevId: 270284686
2019-09-20 09:26:21 -07:00
Jacques Pienaar 5002e98b92 Remove unused import and two import forms
argparse was imported with both 'import' and 'import from' and string import was unused,

PiperOrigin-RevId: 270164488
2019-09-19 17:45:31 -07:00
Mahesh Ravishankar 9a4f5d2ee3 Allow specification of decorators on SPIR-V StructType members.
Allow specification of decorators on SPIR-V StructType members. If the
struct has layout information, these decorations are to be specified
after the offset specification of the member. These decorations are
emitted as OpMemberDecorate instructions on the struct <id>. Update
(de)serialization to handle these decorations.

PiperOrigin-RevId: 270130136
2019-09-19 14:50:05 -07:00
George Karpenkov 2df646bef6 Automated rollback of commit 5684a12434
PiperOrigin-RevId: 270126672
2019-09-19 14:34:30 -07:00
Feng Liu c8961d408e Quantize attribute values by per axis quantization parameters
A new converter with per axis quantization parameters is added to quantize a
dense elements attribute. For each slice along the quantization axis, it
creates an uniform quantized value converter, with different scale and zero
point, and quantizes the values in the slice.

The current implementation doesn't handle sparse elements attributes.

PiperOrigin-RevId: 270121986
2019-09-19 14:12:08 -07:00
Prakalp Srivastava 5f86dc5fc9 NFC: Fix return indentation in generated op definitions.
PiperOrigin-RevId: 270070670
2019-09-19 10:24:06 -07:00
MLIR Team e79bfefb89 Add address space attribute to LLVMIR's GlobalOp.
PiperOrigin-RevId: 270012505
2019-09-19 04:50:46 -07:00
MLIR Team 5684a12434 Outline GPU kernel function into a nested module.
When outlining GPU kernels, put the kernel function inside a nested module. Then use a nested pipeline to generate the cubins, independently per kernel. In a final pass, move the cubins back to the parent module.

PiperOrigin-RevId: 269987720
2019-09-19 01:51:28 -07:00
River Riddle 25f0f769aa NFC: Remove stray logging from ~Block().
PiperOrigin-RevId: 269941815
2019-09-18 19:21:05 -07:00
River Riddle 35df51086a Fix nested dominance relationship between parent results and child operations.
This modifies DominanceInfo::properlyDominates(Value *value, Operation *op) to return false if the value is defined by a parent operation of 'op'. This prevents using values defined by the parent operation from within any child regions.

PiperOrigin-RevId: 269934920
2019-09-18 18:23:41 -07:00
Uday Bondhugula 727a50ae2d Support symbolic operands for memref replacement; fix memrefNormalize
- allow symbols in index remapping provided for memref replacement
- fix memref normalize crash on cases with layout maps with symbols

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

Closes tensorflow/mlir#139

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/139 from bondhugula:memref-rep-symbols 2f48c1fdb5d4c58915bbddbd9f07b18541819233
PiperOrigin-RevId: 269851182
2019-09-18 11:26:11 -07:00
MLIR Team 1c73be76d8 Unify error messages to start with lower-case.
PiperOrigin-RevId: 269803466
2019-09-18 07:45:17 -07:00
Alex Zinenko 5709aeb993 SDBM: support sum expressions on the LHS of stripe expressions
Introduce support for applying the stripe operator to sum expressions, as in
  (x + A) # B = x + A - (x + A) mod B.
This is required to represent a combination of tiling and padding in the SDBM
framework, and is a valid SDBM construct that was not originally supported.

PiperOrigin-RevId: 269758807
2019-09-18 02:17:34 -07:00