Commit graph

2691 commits

Author SHA1 Message Date
Mahesh Ravishankar 2f7bb1e25f Add support for Logical Ops in SPIR-V dialect
Add operations corresponding to OpLogicalAnd, OpLogicalNot,
OpLogicalEqual, OpLogicalNotEqual and OpLogicalOr instructions in
SPIR-V dialect. This needs changes to class hierarchy in SPIR-V
TableGen files to split SPIRVLogicalOp into SPIRVLogicalUnaryOp and
SPIRVLogicalBinaryOp. All derived classes of SPIRVLogicalOp are
updated accordingly.

Update the spirv dialect generation script to
1) Allow specifying base class to use for instruction spec generation
and file name to generate the specification in separately.
2) Use the existing descriptions for operations.
3) Update define_inst.sh to also invoke define_opcode.sh to also
define the corresponding SPIR-V instruction opcode enum.

PiperOrigin-RevId: 272014876
2019-09-30 10:40:36 -07:00
Jacques Pienaar a932f0786c Use MaybeAlign when setting alignment
PiperOrigin-RevId: 272000548
2019-09-30 09:37:23 -07:00
Nicolas Vasilache 1ce524623c Fix MemRefType::getStrides corner case
MemRefType::getStrides uses AffineExpr::walk which operates in post-order from the leaves. In order to compute strides properly, it needs to escape on terminal nodes and analyze binary ops only. This did not work for AffineExpr that consist of a single term (i.e. without a binary op).

This CL fixes the corner case and adds relevant tests.

PiperOrigin-RevId: 271975746
2019-09-30 07:27:39 -07:00
Christian Sigg 3d9679bde4 Switch comments from GPU dialect terms to CUDA terms (NFC).
local workgroup -> block, subgroup -> warp, invocation -> thread.

PiperOrigin-RevId: 271946342
2019-09-30 03:19:45 -07:00
Jacques Pienaar e5a43186d3 Add InferTypeOpTrait & enable generating its member function definition
Use OpInterfaces to add an interface for ops defining a return type function.

This change does not use this trait in any meaningful way, I'll use it in a
follow up to generalize and unify some of the op type traits/constraints. Also,
currently the infer type function can only be manually specified in C++, that should rather be the fallback in future.

PiperOrigin-RevId: 271883746
2019-09-29 17:29:00 -07:00
Uday Bondhugula f45a392566 update Rationale.md - remove outdated info
- removing outdated/confusing info
- the affine dialect is missing documentation on
  affine.load/affine.store; the references herein have to be updated
  once that's updated.

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

Closes tensorflow/mlir#159

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/159 from bondhugula:doc 86dd794f2d0d7fd097dde5764c62eb406ed4f910
PiperOrigin-RevId: 271876525
2019-09-29 16:28:24 -07:00
Roberto Rosmaninho 0db0fe3c03 Fix a typo in Toy Chapter 2 tutorial documentation
Closes tensorflow/mlir#155

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/155 from Robertorosmaninho:patch-1 232ac4e1253948c7f3150515e93abe50fcec2f96
PiperOrigin-RevId: 271876515
2019-09-29 16:16:29 -07:00
Uday Bondhugula b6cec098f9 Fix syntax of 'call' and 'splat' ops
- fix missing return value syntax on call / splat ops
- reflow cond_br / store op syntax

Closes tensorflow/mlir#161

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/161 from bondhugula:patch-1 2beb5bdcb387a5e7c52438985f79e2987d3b3ebe
PiperOrigin-RevId: 271876453
2019-09-29 15:53:31 -07:00
Jacques Pienaar c57f202c8c Switch explicit create methods to match generated build's order
The generated build methods have result type before the arguments (operands and attributes, which are also now adjacent in the explicit create method). This also results in changing the create method's ordering to match most build method's ordering.

PiperOrigin-RevId: 271755054
2019-09-28 09:35:58 -07:00
Geoffrey Martin-Noble e7c3ca92f8 Tablegen helpers for accessing properties of shaped types
Tablegen's lack of functions continues to be annoying

PiperOrigin-RevId: 271680947
2019-09-27 17:35:34 -07:00
Yanan Cao 5f8dff936b Append a newline when dumping a Value.
This is more consistent with other dump methods. Otherwise successive Value dumps are concatenated in same line, hurting readability.

PiperOrigin-RevId: 271669846
2019-09-27 16:20:46 -07:00
Nicolas Vasilache b569c969f0 Remove spurious debug spew in tests
PiperOrigin-RevId: 271624731
2019-09-27 12:31:43 -07:00
Nicolas Vasilache bc4984e4f7 Add TODO to revisit coupling of CallOp to MemRefType lowering
PiperOrigin-RevId: 271619132
2019-09-27 12:03:00 -07:00
Uday Bondhugula 74eabdd14e NFC - clean up op accessor usage, std.load/store op verify, other stale info
- also remove stale terminology/references in docs

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

Closes tensorflow/mlir#148

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/148 from bondhugula:cleanup e846b641a3c2936e874138aff480a23cdbf66591
PiperOrigin-RevId: 271618279
2019-09-27 11:58:24 -07:00
Nicolas Vasilache ddf737c5da Promote MemRefDescriptor to a pointer to struct when passing function boundaries in LLVMLowering.
The strided MemRef RFC discusses a normalized descriptor and interaction with library calls (https://groups.google.com/a/tensorflow.org/forum/#!topic/mlir/MaL8m2nXuio).
Lowering of nested LLVM structs as value types does not play nicely with externally compiled C/C++ functions due to ABI issues.
Solving the ABI problem generally is a very complex problem and most likely involves taking
a dependence on clang that we do not want atm.

A simple workaround is to pass pointers to memref descriptors at function boundaries, which this CL implement.

PiperOrigin-RevId: 271591708
2019-09-27 09:57:36 -07:00
Nicolas Vasilache 6543e99fe5 Fix JitRunner.cpp Error creation pattern and reactivate tests.
linalg_integration_test.mlir and simple.mlir were temporarily disabled due to an OSS-only failure.

The issue is that, once created, an llvm::Error must be explicitly checked before it can be discarded or overwritten.

This CL fixes the issue and reenable the test.

PiperOrigin-RevId: 271589651
2019-09-27 09:56:40 -07:00
Denis Khalikov e39b5a19ba Fix Documentation OpDefinitions.md
Add missing semicolon for the builders example.

Closes tensorflow/mlir#150

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/150 from denis0x0D:sandbox/doc_fix 07e3680e678bf141a70af7747136e9fde7b4cc0a
PiperOrigin-RevId: 271568527
2019-09-27 08:08:25 -07:00
Kazuaki Ishizaki 18f4a37836 Fix missing links in the documentation
Closes tensorflow/mlir#149

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/149 from kiszk:missing_links_g3doc 5f98bc279649d54ea3dcf9fe0e17be6ad6d6cb8f
PiperOrigin-RevId: 271568274
2019-09-27 08:07:31 -07:00
Deven Desai fee40fef5c [ROCm] Adding ROCDL Dialect.
This commit introduces the ROCDL Dialect (i.e. the ROCDL ops + the code to lower those ROCDL ops to LLWM intrinsics/functions). Think of ROCDL Dialect as analogous to the NVVM Dialect, but for AMD GPUs. This patch contains just the essentials needed to get a simple example up and running. We expect to make further additions to the ROCDL Dialect.

This is the first of 3 commits, the follow-up will be:
 * add a pass that lowers GPU Dialect to ROCDL Dialect
 * add a "mlir-rocm-runner" utility

Closes tensorflow/mlir#146

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/146 from deven-amd:deven-rocdl-dialect e78e8005c75a78912631116c78dc844fcc4b0de9
PiperOrigin-RevId: 271511259
2019-09-27 00:22:32 -07:00
Jacques Pienaar 7385d87895 Disable failing tests
PiperOrigin-RevId: 271460509
2019-09-26 16:42:35 -07:00
Jacques Pienaar 19841775d4 Make result ops generated output deterministic
Sort the result ops reported in lexographical order.

PiperOrigin-RevId: 271426258
2019-09-26 14:00:59 -07:00
Nicolas Vasilache 445232df0b Decouple tiling from fusion in Linalg.
This CL modifies the linalg-fusion pass such that it does not tile anymore as part of the pass. Tiling is a separate concern that enables linalg fusion but should happen before.
This makes fusion more composable with other decisions.
In particular the fusion pass now becomes greedy and only applies the transformation on a best-effort basis.

This should also let fusion work in a multi-hop fashion with chains of producer/consumers.

Since the fusion pass does not perform tiling anymore, tests are rewritten to be in pretiled form and make the intent of the test clearer (albeit more verbose).

PiperOrigin-RevId: 271357741
2019-09-26 08:44:31 -07:00
Alex Zinenko 99be3351b8 Drop support for memrefs from JitRunner
The support for functions taking and returning memrefs of floats was introduced
in the first version of the runner, created before MLIR had reliable lowering
of allocation/deallocation to library calls.  It forcibly runs MLIR
transformation convering affine, loop and standard dialects into the LLVM
dialect, unlike the other runner flows that accept the LLVM dialect directly.
Memref support leads to more complex layering and is generally fragile.  Drop
it in favor of functions returning a scalar, or library-based function calls to
print memrefs and other data structures.

PiperOrigin-RevId: 271330839
2019-09-26 05:42:01 -07:00
Christian Sigg 116dac00ba Add AllReduceOp to GPU dialect with lowering to NVVM.
The reduction operation is currently fixed to "add", and the scope is fixed to "workgroup".

The implementation is currently limited to sizes that are multiple 32 (warp size) and no larger than 1024.

PiperOrigin-RevId: 271290265
2019-09-26 00:17:50 -07:00
Lei Zhang 94298cea93 Remove unused variables and methods to address compiler warnings
PiperOrigin-RevId: 271256784
2019-09-25 19:05:30 -07:00
Mahesh Ravishankar 6f0e65441c Add spv.Bitcast operation to SPIR-V dialect
Support the OpBitcast instruction of SPIR-V using the spv.Bitcast
operation. The semantics implemented in the dialect differ from the
SPIR-V spec in that the dialect does not allow conversion to/from
pointer types from/to non-pointer types.

PiperOrigin-RevId: 271255957
2019-09-25 19:01:53 -07:00
Jing Pu 47a7021cc3 Change the return type of createPrintCFGGraphPass to match other passes.
PiperOrigin-RevId: 271252404
2019-09-25 18:33:47 -07:00
Lei Zhang ae13c28f3f [spirv] Add SPV_UnaryOp and spv.FNegate
This CL also moves common parsers and printers to the
same section in SPIRVOps.cpp.

PiperOrigin-RevId: 271233546
2019-09-25 16:35:08 -07:00
Kazuaki Ishizaki a2bce652af Minor spelling tweaks
Closes tensorflow/mlir#145

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/145 from kiszk:spelling_tweaks_g3doc ae9140aab5b797441e880d43e557903585815e40
PiperOrigin-RevId: 271173907
2019-09-25 11:57:44 -07:00
Jacques Pienaar 3848baec69 Emit function name being tested in TestMemRefStrideCalculation
Bring back CHECK-LABEL post

PiperOrigin-RevId: 271166428
2019-09-25 11:23:50 -07:00
Geoffrey Martin-Noble 9b7435fb50 Add tablegen verification traits for comparing different properties
This allows things like comparing the rank of one operand to the size of another that specifies indices into it.

PiperOrigin-RevId: 271150439
2019-09-25 10:17:12 -07:00
Lei Zhang b76c4f8780 Fix memref-stride-calculation on Windows
Call llvm::outs().flush() to make sure we don't mix streams.
Remove CHECK-LABEL to avoid assuming the relative order
between the additional info and the output IR.

PiperOrigin-RevId: 271131100
2019-09-25 08:41:44 -07:00
Lei Zhang 4e32dc9b8a Forward declare LogicalResult as a struct to be consistent
This addresses a MSVC linker error saying splitAndProcessBuffer
was unresolved.

PiperOrigin-RevId: 271126570
2019-09-25 08:15:24 -07:00
Mahesh Ravishankar 3a4bee0fe1 Miscellaneous fixes to SPIR-V Deserializer (details below).
1) Process and ignore the following debug instructions: OpSource,
OpSourceContinued, OpSourceExtension, OpString, OpModuleProcessed.
2) While processing OpTypeInt instruction, ignore the signedness
specification. Currently MLIR doesnt make a distinction between signed
and unsigned integer types.
3) Process and ignore BufferBlock decoration (similar to Buffer
decoration). StructType needs to be enhanced to track this attribute
since its needed for proper validation checks.
4) Report better error for unhandled instruction during
deserialization.

PiperOrigin-RevId: 271057060
2019-09-24 22:51:02 -07:00
River Riddle 03db422359 NFC: Add 'const' dereference method to OperandTypeIterator.
The deference provided by mapped_iterator is non-const.

PiperOrigin-RevId: 271051375
2019-09-24 21:54:56 -07:00
Mahesh Ravishankar c5284fe85e Add support for GLSL Binary ops, and use it to implement GLSL FMax.
A base class is added to implement all GLSL Binary operations and is
used to implement the FMax operation. The existing framework already
generates all the necessary (de)serialization code.

PiperOrigin-RevId: 271037166
2019-09-24 19:42:11 -07:00
Lei Zhang cf00feed03 [spirv] Replace bitwiseCast with llvm::bit_cast
PiperOrigin-RevId: 271035618
2019-09-24 19:25:02 -07:00
River Riddle f7ad5b411c NFC: Add a description to the ODS interface example.
PiperOrigin-RevId: 270978748
2019-09-24 14:07:54 -07:00
River Riddle 635544fc12 Allow attaching descriptions to OpInterfaces and InterfaceMethods.
This change adds support for documenting interfaces and their methods. A tablegen generator for the interface documentation is also added(gen-op-interface-doc).

Documentation is added to an OpInterface via the `description` field:
def MyOpInterface : OpInterface<"MyOpInterface"> {
  let description = [{
    My interface is very interesting.
  }];
}

Documentation is added to an InterfaceMethod via a new `description` field that comes right before the optional body:

InterfaceMethod<"void", "foo", (ins), [{
  This is the foo method.
}]>,

PiperOrigin-RevId: 270965485
2019-09-24 12:46:17 -07:00
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