Commit graph

2611 commits

Author SHA1 Message Date
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
Alex Zinenko a15e0ce1ba Simplify SDBM expressions more aggressively in operators and conversions
Extend SDBM simplification patterns to support more cases where the addition of
two expressions each involving one or two variables would result in a sum
expression that only contains one variable and thus remains in the SDBM domain.
This is made possible by the new canonical structure of SDBM where the constant
term appears once.  This simplification will be necessary to support
round-tripping of stripe expressions containing constant terms on the LHS
through affine expressions.

PiperOrigin-RevId: 269757732
2019-09-18 02:09:08 -07:00
River Riddle b58d9aee11 Add support to OpAsmParser for parsing unknown keywords.
This is useful in several cases, for example a user may want to sugar the syntax of a string(as we do with custom operation syntax), or avoid many nested ifs for  parsing a set of known keywords.

PiperOrigin-RevId: 269695451
2019-09-17 17:55:34 -07:00
Mahesh Ravishankar 9330c1b9a1 Add (de)serialization support for OpRuntimeArray.
Update the SPIR-V (de)serialization to handle RuntimeArrayType.

PiperOrigin-RevId: 269667196
2019-09-17 15:21:57 -07:00
Lei Zhang af45ca844f Register a -test-spirv-roundtrip hook to mlir-translate
This CL registers a new mlir-translate hook, -test-spirv-roundtrip,
for testing SPIR-V serialization and deserialization round-trip.

This CL also moves the existing -serialize-spirv and
-deserialize-spirv hooks to one source file.

PiperOrigin-RevId: 269659528
2019-09-17 14:48:24 -07:00
River Riddle 3e2ac62b7d Add a preprocess pass to remove sequences that are problematic with FileCheck
Add a preprocess phase to rewrite parts of the input line that may be problematic with filecheck. This change adds preprocessing to escape '[[' bracket sequences, as these are used by FileCheck for variables.

PiperOrigin-RevId: 269648490
2019-09-17 14:00:03 -07:00
Lei Zhang b991e8b1e4 Support file-to-file translation in mlir-translate
Existing translations are either from MLIR or to MLIR. To support
cases like round-tripping some external format via MLIR, one must
chain two mlir-translate invocations together using pipes. This
can be problematic to support -split-input-file in mlir-translate
given that it won't work across pipes.

Motivated by the above, this CL adds another translation category
that allows file to file. This gives users more freedom.

PiperOrigin-RevId: 269636438
2019-09-17 13:04:34 -07:00
Lei Zhang b00a522b80 Change MLIR translation functions signature
This CL changes translation functions to take MemoryBuffer
as input and raw_ostream as output. It is generally better to
avoid handling files directly in a library (unless the library
is specifically for file manipulation) and we can unify all
file handling to the mlir-translate binary itself.

PiperOrigin-RevId: 269625911
2019-09-17 12:16:45 -07:00
Uday Bondhugula bd7de6d4df Add rewrite pattern to compose maps into affine load/stores
- add canonicalization pattern to compose maps into affine loads/stores;
  templatize the pattern and reuse it for affine.apply as well

- rename getIndices -> getMapOperands() (getIndices is confusing since
  these are no longer the indices themselves but operands to the map
  whose results are the indices). This also makes the accessor uniform
  across affine.apply/load/store. Change arg names on the affine
  load/store builder to avoid confusion. Drop an unused confusing build
  method on AffineStoreOp.

- update incomplete doc comment for canonicalizeMapAndOperands (this was
  missed from a previous update).

Addresses issue tensorflow/mlir#121

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

Closes tensorflow/mlir#122

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/122 from bondhugula:compose-load-store e71de1771e56a85c4282c10cb43f30cef0701c4f
PiperOrigin-RevId: 269619540
2019-09-17 11:49:45 -07:00
Mehdi Amini 62e1faa6f6 Add missing CMake dependency from libAnalysis to the Vector dialect
Fixes tensorflow/mlir#138

PiperOrigin-RevId: 269509668
2019-09-17 00:39:00 -07:00
Mahesh Ravishankar 2d86ad79f0 Autogenerate (de)serialization for Extended Instruction Sets
A generic mechanism for (de)serialization of extended instruction sets
is added with this CL. To facilitate this, a new class
"SPV_ExtendedInstSetOp" is added which is a base class for all
operations corresponding to extended instruction sets. The methods to
(de)serialization such ops as well as its dispatch is generated
automatically.

The behavior controlled by autogenSerialization and hasOpcode is also
slightly modified to enable this. They are now decoupled.
1) Setting hasOpcode=1 means the operation has a corresponding
   opcode in SPIR-V binary format, and its dispatch for
   (de)serialization is automatically generated.
2) Setting autogenSerialization=1 generates the function for
   (de)serialization automatically.
So now it is possible to have hasOpcode=0 and autogenSerialization=1
(for example SPV_ExtendedInstSetOp).

Since the dispatch functions is also auto-generated, the input file
needs to contain all operations. To this effect, SPIRVGLSLOps.td is
included into SPIRVOps.td. This makes the previously added
SPIRVGLSLOps.h and SPIRVGLSLOps.cpp unnecessary, and are deleted.

The SPIRVUtilsGen.cpp is also changed to make better use of
formatv,making the code more readable.

PiperOrigin-RevId: 269456263
2019-09-16 17:12:33 -07:00
Denis Khalikov 8a34d5d18c [spirv] Add support for function calls.
Add spv.FunctionCall operation and (de)serialization.

Closes tensorflow/mlir#137

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/137 from denis0x0D:sandbox/function_call_op e2e6f07d21e7f23e8b44c7df8a8ab784f3356ce4
PiperOrigin-RevId: 269437167
2019-09-16 15:39:54 -07:00
River Riddle 9619ba10d4 Add support for multi-level value mapping to DialectConversion.
When performing A->B->C conversion, an operation may still refer to an operand of A. This makes it necessary to unmap through multiple levels of replacement for a specific value.

PiperOrigin-RevId: 269367859
2019-09-16 10:38:19 -07:00
Lei Zhang 6934a337f0 [spirv] Add support for BitEnumAttr
Certain enum classes in SPIR-V, like function/loop control and memory
access, are bitmasks. This CL introduces a BitEnumAttr to properly
model this and drive auto-generation of verification code and utility
functions. We still store the attribute using an 32-bit IntegerAttr
for minimal memory footprint and easy (de)serialization. But utility
conversion functions are adjusted to inspect each bit and generate
"|"-concatenated strings for the bits; vice versa.

Each such enum class has a "None" case that means no bit is set. We
need special handling for "None". Because of this, the logic is not
general anymore. So right now the definition is placed in the SPIR-V
dialect. If later this turns out to be useful for other dialects,
then we can see how to properly adjust it and move to OpBase.td.

Added tests for SPV_MemoryAccess to check and demonstrate.

PiperOrigin-RevId: 269350620
2019-09-16 09:23:22 -07:00
Alex Zinenko cb3ecb5291 Overhaul the SDBM expression kind hierarchy
Swap the allowed nesting of sum and diff expressions: now a diff expression can
contain a sum expression, but only on the left hand side.  A difference of two
expressions sum must be canonicalized by grouping their constant terms in a
single expression.  This change of sturcture became possible thanks to the
introduction of the "direct" super-kind.  It is necessary to enable support of
sum expressions on the left hand side of the stripe expression.

SDBM expressions are now grouped into the following structure
- expression
  - varying
    - direct
      - sum <- (term, constant)
      - term
        - symbol
        - dimension
        - stripe <- (term, constant)
    - negation <- (direct)
    - difference <- (direct, term)
  - constant
The notation <- (...) denotes the types of subexpressions a compound
expression can combine.

PiperOrigin-RevId: 269337222
2019-09-16 08:16:06 -07:00
Alex Zinenko e94db619d9 Introduce SDBMDirect expression into the SDBM expression hierarchy
Direct expressions are those that do not negate any of the variables they
involve.  They include input expressions (dimensions and symbols), stripe and
sum expressions, and combinations of those.  Reifying direct expressions as a
class is a precondition for enabling additions on the LHS of a stripe
expression.

PiperOrigin-RevId: 269336031
2019-09-16 08:09:01 -07:00
MLIR Team 0ce64b0bf3 Unify how errors are emitted in LaunchFuncOp verification.
PiperOrigin-RevId: 269331869
2019-09-16 07:45:59 -07:00
MLIR Team 1da0290c4b Error out when kernel function is not found while translating GPU calls.
PiperOrigin-RevId: 269327909
2019-09-16 07:19:36 -07:00
Alex Zinenko 6755dfdec9 Drop makePositionAttr and the like in favor of Builder::getI64ArrayAttr
The helper functions makePositionAttr() and positionAttr() were originally
introduced in the lowering-to-LLVM-dialect pass to construct integer array
attributes that are used for static positions in extract/insertelement.
Constructing an integer array attribute being fairly common, a utility function
Builder::getI64ArrayAttr was later introduced into the Builder API.  Drop
makePositionAttr and similar homegrown functions and use that API instead.
PiperOrigin-RevId: 269295836
2019-09-16 03:31:09 -07:00
Mahesh Ravishankar 9814b3fa0d Add mechanism to specify extended instruction sets in SPIR-V.
Add support for specifying extended instructions sets. The operations
in SPIR-V dialect are named as 'spv.<extension-name>.<op-name>'. Use
this mechanism to define a 'Exp' operation from GLSL(450)
instructions.
Later CLs will add support for (de)serialization of these operations,
and update the dialect generation scripts to auto-generate the
specification using the spec directly.

Additional changes:
Add a Type Constraint to OpBase.td to check for vector of specified
lengths. This is used to check that the vector type used in SPIR-V
dialect are of lengths 2, 3 or 4.
Update SPIRVBase.td to use this Type constraints for vectors.

PiperOrigin-RevId: 269234377
2019-09-15 19:40:07 -07:00
River Riddle faaa1ced10 Update the pass registration section and add a sub-section on the textual pipeline specification.
Now that the pass manager is generalized, and nested/arbritrary pipelines are possible, it is important to document how to specify these types of pipelines from the command line.

PiperOrigin-RevId: 269207681
2019-09-15 14:01:06 -07:00
Uday Bondhugula 16eac96560 Fix typo in test/AffineOps/ops.mlir
Closes tensorflow/mlir#135

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/135 from bondhugula:patch-1 539a7f1b43d09ef539b2fd15875f8ac765600263
PiperOrigin-RevId: 269187507
2019-09-15 09:06:39 -07:00
River Riddle f22011ccba NFC: Update the PassInstrumentation section.
This section has grown stale as the pass infrastructure has been generalized.

PiperOrigin-RevId: 269140863
2019-09-14 22:10:28 -07:00
River Riddle bbc6d48d1c NFC: Update the expected outputs of pass-timing.
The output of the pass timing instrumentation has been changed now that the pass hierarchy has been generalized.

PiperOrigin-RevId: 269140277
2019-09-14 22:03:08 -07:00
River Riddle d37777c440 Update the IRPrinter instrumentation to work on non function/module operations.
This is necessary now that the pass manager may work on different types of operations.

PiperOrigin-RevId: 269139669
2019-09-14 21:56:38 -07:00
River Riddle bbe65b46f5 NFC: Pass PassInstrumentations by unique_ptr instead of raw pointer.
This makes the ownership model explicit, and removes potential user errors.

PiperOrigin-RevId: 269122834
2019-09-14 17:44:50 -07:00
River Riddle cb1bcba69b NFC: Merge OpPass with OperationPass into just OperationPass.
OperationPass' are defined exactly the same way as they are now:
   class DerivedPass :  public OperationPass<DerivedPass>;

OpPass' are now defined as OperationPass, but with an additional template parameter for the operation type:
   class DerivedPass :  public OperationPass<DerivedPass, FuncOp>;

PiperOrigin-RevId: 269122410
2019-09-14 17:37:43 -07:00
Jing Pu 38e7226606 Add convenience methods to create i8 and i16 attributes in Builder.
PiperOrigin-RevId: 269120226
2019-09-14 17:02:54 -07:00
Uday Bondhugula 4f32ae61b4 NFC - Move explicit copy/dma generation utility out of pass and into LoopUtils
- turn copy/dma generation method into a utility in LoopUtils, allowing
  it to be reused elsewhere.

- no functional/logic change to the pass/utility

- trim down header includes in files affected

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

Closes tensorflow/mlir#124

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/124 from bondhugula:datacopy 9f346e62e5bd9dd1986720a30a35f302eb4d3252
PiperOrigin-RevId: 269106088
2019-09-14 13:23:48 -07:00
Uday Bondhugula 1366467a3b update normalizeMemRef utility; handle missing failure check + add more tests
- take care of symbolic operands with alloc
- add missing check for compose map failure and a test case
- add test cases on strides
- drop incorrect check for one-to-one'ness

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

Closes tensorflow/mlir#132

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/132 from bondhugula:normalize-memrefs 8aebf285fb0d7c19269d85255aed644657e327b7
PiperOrigin-RevId: 269105947
2019-09-14 13:21:35 -07:00
Uday Bondhugula 018cfa94d9 Clean up build trip count analysis method - avoid mutating IR
- NFC - on any pass/utility logic/output.

- Resolve TODO; the method building loop trip count maps was
  creating and deleting affine.apply ops (transforming IR from under
  analysis!, strictly speaking). Introduce AffineValueMap::difference to
  do this correctly (without the need to create any IR).

- Move AffineApplyNormalizer out so that its methods are reusable from
  AffineStructures.cpp; add a helper method 'normalize' to it. Fix
  AffineApplyNormalize::renumberOneDim (Issue tensorflow/mlir#89).

- Trim includes on files touched.

- add test case on a scenario previously not covered

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

Closes tensorflow/mlir#133

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/133 from bondhugula:trip-count-build 7fc34d857f7788f98b641792cafad6f5bd50e47b
PiperOrigin-RevId: 269101118
2019-09-14 12:10:55 -07:00
River Riddle 2de18fb84d NFC: Fix stray character in error message: 1 -> '
PiperOrigin-RevId: 269091468
2019-09-14 09:44:23 -07:00
Lei Zhang aac8fa8c47 Update QuickstartRewrites.md regarding op definition and rewrites
This CL updates the doc with recent changes. It also adds a section
on registering and using the auto-generated patterns.

PiperOrigin-RevId: 269086830
2019-09-14 08:37:38 -07:00
Uday Bondhugula f2eb0f02fa Add pattern to canonicalize for loop bounds
- add pattern to canonicalize affine.for loop bounds (using
  canonicalizeMapAndOperands)
- rename AffineForLoopBoundFolder -> AffineForLoopBoundFolder for
  consistency

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

Closes tensorflow/mlir#111

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/111 from bondhugula:bound-canonicalize ee8fb7f43a7ffd45f6df3f53c95098d8b7e494c7
PiperOrigin-RevId: 269041220
2019-09-13 22:11:56 -07:00
River Riddle 4e48beadbb Verify that ModuleOps only contain dialect specific attributes.
ModuleOp has no expected operations, so only dialect-specific attributes are valid.

PiperOrigin-RevId: 269020062
2019-09-13 18:19:33 -07:00
Uday Bondhugula 1e6a93b7ca add missing memref cast fold pattern for dim op
- add missing canonicalization pattern to fold memref_cast + dim to
  dim (needed to propagate constant when folding a dynamic shape to
  a static one)

- also fix an outdated/inconsistent comment in StandardOps/Ops.td

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

Closes tensorflow/mlir#126

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/126 from bondhugula:quickfix 4566e75e49685c532faffff91d64c5d83d4da524
PiperOrigin-RevId: 269020058
2019-09-13 18:18:48 -07:00
River Riddle d780bdef20 Publicly expose the functionality to parse a textual pass pipeline.
This allows for users other than those on the command line to apply a textual description of a pipeline to a given pass manager.

PiperOrigin-RevId: 269017028
2019-09-13 17:54:00 -07:00
Geoffrey Martin-Noble efbd3e4610 Add type constraints for shaped types with same rank and element count
PiperOrigin-RevId: 269000237
2019-09-13 16:05:38 -07:00
Lei Zhang 113aadddf9 Update SPIR-V symbols and use GLSL450 instead of VulkanKHR
SPIR-V recently publishes v1.5, which brings a bunch of symbols
into core. So the suffix "KHR"/"EXT"/etc. is removed from the
symbols. We use a script to pull information from the spec
directly.

Also changed conversion and tests to use GLSL450 instead of
VulkanKHR memory model. GLSL450 is still the main memory model
supported by Vulkan shaders and it does not require extra
capability to enable.

PiperOrigin-RevId: 268992661
2019-09-13 15:26:32 -07:00
River Riddle f1b100c77b NFC: Finish replacing FunctionPassBase/ModulePassBase with OpPassBase.
These directives were temporary during the generalization of FunctionPass/ModulePass to OpPass.

PiperOrigin-RevId: 268970259
2019-09-13 13:34:27 -07:00
Geoffrey Martin-Noble a260436714 Add tablegen class for memrefs with rank constraints
PiperOrigin-RevId: 268968004
2019-09-13 13:22:21 -07:00
River Riddle 8a1cdeb31b Forward diagnostics from untracked threads in ParallelDiagnosticHandler.
This allows for the use of multiple ParallelDiagnosticHandlers without having them conflict with each other.

PiperOrigin-RevId: 268967407
2019-09-13 13:19:19 -07:00