Commit Graph

1334 Commits

Author SHA1 Message Date
Mehdi Amini 092f3facad Fix Toy Ch3 testing with CMake
Mainly a missing dependency caused the tests to pass if one already built
    the repo, but not from a clean (or incremental) build.

--

PiperOrigin-RevId: 241852313
2019-04-03 19:22:42 -07:00
Mehdi Amini f0a328b6d5 Chapter 3 for Toy tutorial: introduction of a dialect
--

PiperOrigin-RevId: 241849162
2019-04-03 19:22:32 -07:00
Dan Zheng 393c77c5da [README] Fix links, minor edits.
Fix links without breaking g3doc.
    Minor stylistic edits.

--

PiperOrigin-RevId: 241846985
2019-04-03 19:22:23 -07:00
Dan Zheng 0737776200 [README] Minor edits.
Minor stylistic edits.
    Use standard "TensorFlow" spelling.

--

PiperOrigin-RevId: 241842272
2019-04-03 19:22:14 -07:00
Stella Laurenzo 7ce55ff7c2 Add CMakeLists.txt for Quantization and FxpMathOps dialects (and misc fixes to build with OSS setup).
Tested:
      cmake -G Ninja ../llvm/ -DLLVM_BUILD_EXAMPLES=ON
      ninja check-mlir

--

PiperOrigin-RevId: 241841296
2019-04-03 19:22:05 -07:00
Mehdi Amini 3a2955fa1f Rename UnknownType to OpaqueType (NFC)
This came up in a review of the tutorial, it was suggested that "opaque" is more
    descriptive than "unknown" here.

--

PiperOrigin-RevId: 241832927
2019-04-03 19:21:47 -07:00
Mehdi Amini a261ce5b40 Move the top-level `tutorial` as `Linalg` nested in the examples folder
--

PiperOrigin-RevId: 241831176
2019-04-03 19:21:38 -07:00
Stella Laurenzo 288bf2b5b9 Split the Quantization dialect.
- Retains Quantization types and predicates.
    - Retains utilities and example (testable) passes/ops.
    - Retains unit tests for example passes/ops.
    - Moves fixed point ops (and corresponding real ops) to FxpMathOps.
    - Moves real -> fixed point pass to FxpMathOps.
    - Sever the dependency on the TF dialect from Quantization. These dialects should now be open-sourcable.

--

PiperOrigin-RevId: 241825598
2019-04-03 19:21:28 -07:00
Feng Liu 1b56ce3087 Fix the alignment issue in the DenseElementsAttr buffer allocation
Currently, we only make the initial address aligned with 64-bit address but
    allocate the buffer with the real size. This can cause issue when we extract
    the value by the `readBits` method, which needs to read the memory in the
    granularity of APINT_WORD_SIZE. In this CL, we rounded the allocation size to
    the multiplies of APINT_WORD_SIZE to fix the issue.

--

PiperOrigin-RevId: 241816656
2019-04-03 19:21:18 -07:00
Rob Suderman 8d40302b34 Added memref to OpBase.td as specific memref types should be supported by default.
--

PiperOrigin-RevId: 241806461
2019-04-03 19:21:09 -07:00
Smit Hinsu f504b63f6f Remove links to internal google docs, updating them to point to GitHub.
PiperOrigin-RevId: 241801638
2019-04-03 19:21:00 -07:00
Chris Lattner 7bf06e6038 Remove links to internal google docs, updating them to point to GitHub.
--

PiperOrigin-RevId: 241800478
2019-04-03 19:20:50 -07:00
Stella Laurenzo c833d8a19d Refactor Quantization.md to separate TFLite native quantization scheme from the more experimental, generalized scheme.
PiperOrigin-RevId: 241785572
2019-04-03 19:20:40 -07:00
Nicolas Vasilache 50df91745d Linalg portion of the tutorial - part 3-2
This CL adds support for lowering tensor contractions to loops declaratively.
    This is done thanks to two properties of the such operations:
    1. the definition of an AffineMap getLoopsToOperandRangesMap for each op which maps iteration space dimensions to ranges of the view operands, in their order of occurrence;
    2. the definition of a scalar implementation for each op which creates the computation inside the loops given enclosing parallel and reduction loops,

    All the other properties are derived in a generic fashion from these 2 properties and a few analyses.

    A lowerToLoops transformation is added as well as a test that exercises it.

--

PiperOrigin-RevId: 241783992
2019-04-03 19:20:31 -07:00
Lei Zhang b9e3b2107b [TableGen] Allow additional result patterns not directly used for replacement
This CL looses the requirement that all result patterns in a rewrite rule must
    replace a result of the root op in the source pattern. Now only the last N
    result pattern-generated ops are used to replace a N-result source op.

    This allows to generate additional ops to aid building up final ops used to
    replace the source op.

--

PiperOrigin-RevId: 241783192
2019-04-03 19:20:22 -07:00
Stella Laurenzo 13bb8f491a Initial release of the Quantization dialect
Includes a draft of documentation for the quantization setup.

Given how many comments such docs have garnered in the past, I've biased towards a lightly edited first-draft so that people can argue about terminology, approach and structure without having spent too much time on it.

Note that the sections under "Uniform quantization" were cribbed nearly verbatim from internal documentation that Daniel wrote.

PiperOrigin-RevId: 241768668
2019-04-03 19:20:12 -07:00
Lei Zhang 3522c65d3b [TableGen] Fix convertFromStorage for OptionalAttr
OptionalAttr is just wrapping around the actual attribute; so it should just use
    the actual attribute's `convertFromStorage` to read the value and wrap it around
    with `Optional<>` to return. Previously it was mandating how the actual attribute
    reads the value with `{0}.getValue()`.

--

PiperOrigin-RevId: 241762355
2019-04-03 18:36:19 -07:00
Alex Zinenko 5fb62b47c3 Tutorial Linalg1: implement conversion to the LLVM Dialect
Implement conversion from the Linalg dialect to the LLVM dialect using a simple
    set of DialectOpConverters and by plugging them into the dialect conversion
    infrastructure.  View and Range Linalg types are converted into descriptors
    that store the dynamic values in an LLVM aggregate type, similarly to memrefs.
    Slice operations create new descriptors based on the original descriptors and
    thus remove the constraint on ViewTypes not being acceptable as function
    arguments.

--

PiperOrigin-RevId: 241760189
2019-04-03 18:36:09 -07:00
Mehdi Amini 4e972bd5a5 Add mention of the TensorFlow Code of Conduct in the Readme
PiperOrigin-RevId: 241748009
2019-04-03 09:44:41 -07:00
Mehdi Amini 8806745436 Add missing source file in CMakeLists.txt
--

PiperOrigin-RevId: 241746122
2019-04-03 09:31:06 -07:00
Lei Zhang 1ac49ce0bd [TableGen] Remove asserts for attributes in aggregate builders
Attributes can have default values or be optional. Checking the validity of
    attributes in aggregate builder should consider that. And to be accurate,
    we should check all required attributes are indeed provided in the list.
    This is actually duplicating the work done by verifier. Checking the validity
    of attributes should be the responsiblity of verifiers. This CL removes
    the assertion for attributes in aggregate builders for the above reason.
    (Assertions for operands/results are still kept since they are trivial.)

    Also added more tests for aggregate builders.

--

PiperOrigin-RevId: 241746059
2019-04-03 09:30:49 -07:00
Mehdi Amini 0e28cea4d4 Fix CMake build
Some files were not built anymore internally but still referenced
    from CMake. Delete them and unreference them in the CMake files.

--

PiperOrigin-RevId: 241744718
2019-04-03 09:21:46 -07:00
Mehdi Amini 67f49eed9a Update Readme to mention that the TensorFlow specific will be upstreamed later
--

PiperOrigin-RevId: 241735845
2019-04-03 08:30:54 -07:00
Alex Zinenko f50edc65cd Drop MLIREmitter-based version of the EDSC
This version has been deprecated and can now be removed completely since the
    last remaining user (Python bindings) migrated to declarative builders.
    Several functions in lib/EDSC/Types.cpp construct core IR objects for the C
    bindings.  Move these functions into lib/EDSC/CoreAPIs.cpp until we decide
    where they should live.

    This completes the migration from the delayed-construction EDSC to Declarative
    Builders.

--

PiperOrigin-RevId: 241716729
2019-04-03 08:30:38 -07:00
Alex Zinenko 7a30ac97c8 Python bindings: drop MLIREmitter and related functionality
This completes the transition of Python bindings to use the declarative
    builders infrastructure instead of the now-deprecated EDSC emitter
    infrastructure.  The relevant unit tests have been replicated using the new
    functionality and the remaining end-to-end compilation tests have been updated
    accordingly.  The latter show an improvement in brevity and readability.

--

PiperOrigin-RevId: 241713489
2019-04-03 08:30:24 -07:00
Alex Zinenko 509619829d Python bindings: support __floordiv__ for index types
The original reimplementation of EDSC as declarative builders and the
    subsequent rework of Python bindings forbade to use the (true) division
    operator for values of the index types without providing an alternative.  Index
    types only support floor and ceil division through affine maps.  Expose this to
    Python bindings through a `__floordiv__` function on `ValueHandle`s.

--

PiperOrigin-RevId: 241713093
2019-04-03 08:30:07 -07:00
Mehdi Amini 1e021cfbd7 Remove section of the README copied from the Rationale document, it does not fit here.
--

PiperOrigin-RevId: 241687723
2019-04-03 08:29:47 -07:00
Nicolas Vasilache f1b12f5a64 Fix test that fails on non-determinism in LowerVectorTransfers
This CL fixes the non-determinism across compilers in an edsc::select expression used in LowerVectorTransfers. This is achieved by factoring the expression out of the function call to ensure a deterministic order of evaluation.
    Since the expression is now factored out, fewer IR is generated and the test is updated accordingly.

--

PiperOrigin-RevId: 241679962
2019-04-03 01:09:13 -07:00
Mehdi Amini c2e9ab8ef1 Fix path for the examples in Toy tutorial Ch1
PiperOrigin-RevId: 241643625
2019-04-02 18:15:38 -07:00
Mehdi Amini 607b8851a8 Add link to the Toy tutorial in the Readme
--

PiperOrigin-RevId: 241642739
2019-04-02 18:09:14 -07:00
River Riddle e97ca1227a Add fake-use for variable in LLVMDialect.cpp to fix opt build.
--

PiperOrigin-RevId: 241620442
2019-04-02 16:32:34 -07:00
Mehdi Amini e01cccf34a Fix minor typo (triggered a GCC warning, NFC)
--

PiperOrigin-RevId: 241618796
2019-04-02 16:32:18 -07:00
Alex Zinenko 736bef7386 Introduce custom format for the LLVM IR Dialect
Historically, the LLVM IR dialect has been using the generic form of MLIR
    operation syntax.  It is verbose and often redundant.  Introduce the custom
    printing and parsing for all existing operations in the LLVM IR dialect.
    Update the relevant documentation and tests.

--

PiperOrigin-RevId: 241617393
2019-04-02 16:31:58 -07:00
Mehdi Amini 04f766c2ed Add -DLLVM_BUILD_EXAMPLES to the mlir build instruction: this enables the tutorial examples
Seems like a better default for getting started.

--

PiperOrigin-RevId: 241614043
2019-04-02 15:16:45 -07:00
Mehdi Amini 5854fb9b94 Fix Toy tutorial gcc 7 build (NFC)
--

PiperOrigin-RevId: 241613710
2019-04-02 15:16:30 -07:00
Nicolas Vasilache 72ccfcee1e Linalg portion of the tutorial - part 3
This CL starts the third part of the Linalg tutorial by adding support for ops to declare how they lower themselves to other ops.
    Tests are added that demonstrate matmul lowering to a loop over matvec and matvec lowering to a loop over dot.

    This is part of a list of CLs that add new Transforms and Analyses to Linalg3: it iseasier to integrate in small chunks.

    As part of working with the TensorContractionBase template class and in an effort to add pieces incrementally without copying code, it is easiest to define operations ahead of time in Linalg2/TensorOps.h and gradually implement them as needed. This CL performs the necessary refactoring for this to happen.

--

PiperOrigin-RevId: 241605869
2019-04-02 15:16:14 -07:00
River Riddle 7fa2864954 Update the dialect attribute verification hooks to return LogicalResult instead of bool. This updates Function::emitError to return LogicalResult as well.
--

PiperOrigin-RevId: 241598892
2019-04-02 15:15:56 -07:00
Mehdi Amini f457ab7fc9 Provide default `affineMapComposition` and memory space on `MemRefType::get()` (NFC)
This matches the builder API.

--

PiperOrigin-RevId: 241592869
2019-04-02 13:41:15 -07:00
Mehdi Amini 213dda687b Chapter 2 of the Toy tutorial
This introduces a basic MLIRGen through straight AST traversal,
    without dialect registration at this point.

--

PiperOrigin-RevId: 241588354
2019-04-02 13:41:00 -07:00
River Riddle 67a52c44b1 Rewrite the verify hooks on operations to use LogicalResult instead of bool. This also changes the return of Operation::emitError/emitOpError to LogicalResult as well.
--

PiperOrigin-RevId: 241588075
2019-04-02 13:40:47 -07:00
Nicolas Vasilache 8affb783a8 Linalg portion of the tutorial - part 2
The second part of the Linalg tutorial introduces:
    1. the TensorContractionBase type from which all tensor contractions derive;
    2. a basic set of operations DotOp, MatvecOp and MatmulOp;
    3. a helper function `createFullyComposedView` that walks the producers of a SliceOp up until the root ViewOp and returns a single ViewOp;
    4. programmatic examples to test MLIR construction involving these types.

    This CL also refactors file organization so that:
    1. clients only need to include Ops.h and Types.h while keeping independent small files separate for the purpose of the tutorial;
    2. each step of the tutorial has its own linalgxxx include directory and each include explicitly states in which part of the tutorial a particular concept was introduced.

    Lastly the following cleanups are applied:
    1. ValueOrSliceOp is removed in favor of simpler helper function.
    2. methods that walk back the chain of ops are removed from the core ops and added to a separate Analysis.
    3. various additional cleanups.

--

PiperOrigin-RevId: 241555769
2019-04-02 13:40:33 -07:00
River Riddle 0be6369176 Update the Function and Module verifiers to return LogicalResult instead of bool.
--

PiperOrigin-RevId: 241553930
2019-04-02 13:40:20 -07:00
Mehdi Amini 38b71d6b84 Initial version for chapter 1 of the Toy tutorial
--

PiperOrigin-RevId: 241549247
2019-04-02 13:40:06 -07:00
Andy Davis 7c1fc9e795 Enable producer-consumer fusion for liveout memrefs if consumer read region matches producer write region.
--

PiperOrigin-RevId: 241517207
2019-04-02 13:39:50 -07:00
River Riddle 0451403066 Update the pass ir-printing test to not rely on rtti type pretty printing.
--

PiperOrigin-RevId: 241498090
2019-04-02 13:39:31 -07:00
River Riddle 084669e005 Remove MLPatternLoweringPass and rewrite LowerVectorTransfers to use RewritePattern instead.
--

PiperOrigin-RevId: 241455472
2019-04-02 13:39:17 -07:00
Lei Zhang bae95d25e5 [TableGen] Add Confined, IntMinValue, and ArrayMinCount for attribute constraints
This CL introduces Confined as a general mechanism to compose complex attribute
    constraints out of more primitive ones. It's particularly useful for automatically
    generating op definitions from some external source, where we can have random
    combinations of primitive constraints and it would be impractical to define a case
    for each of such combination.

    Two primitive attribute constraints, IntMinValue and ArrayMinCount, are added to be
    used together with Confined.

--

PiperOrigin-RevId: 241435955
2019-04-02 13:39:03 -07:00
Nicolas Vasilache d7296a4ae3 Linalg portion of the tutorial - part 1
The first part of the Linalg tutorial introduces:
    1. the RangeType and ViewType;
    2. operations on those, namely RangeOp, ViewOp and SliceOp;
    3. programmatic examples to test MLIR construction involving these types, ops and affine.for loops (with a mock custom op called "some_consumer").

--

PiperOrigin-RevId: 241409949
2019-04-02 13:38:44 -07:00
Mehdi Amini 9089911daa Use `this->` to access inherited member from dependent type (Fix GCC7 build, NFC)
--

PiperOrigin-RevId: 241364505
2019-04-01 11:29:18 -07:00
Mehdi Amini be4f48d1e1 Minor fixes to README.md (NFC)
In particular fix the links to work on GitHub, and do not include RTTI to build.

--

PiperOrigin-RevId: 241362244
2019-04-01 11:19:58 -07:00