Commit Graph

529 Commits

Author SHA1 Message Date
Aart Bik 28ebb0b61d [mlir][sparse] migrate sparse rewriting to sparse transformations pass
The rules in the linalg file were very specific to sparse tensors so will
find a better home under sparse tensor dialect than linalg dialect. Also
moved some rewriting from sparsification into this new "pre-rewriting" file.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D129910
2022-07-18 09:29:22 -07:00
Alex Zinenko e0fc33eba5 [mlir] Fix Bazel for 5e83a5b475
Export the __init__.py from _mlir_libs.
2022-07-18 15:35:23 +02:00
Stella Laurenzo 5e83a5b475 [mlir] Overhaul C/Python registration APIs to properly scope registration/loading activities.
Since the very first commits, the Python and C MLIR APIs have had mis-placed registration/load functionality for dialects, extensions, etc. This was done pragmatically in order to get bootstrapped and then just grew in. Downstreams largely bypass and do their own thing by providing various APIs to register things they need. Meanwhile, the C++ APIs have stabilized around this and it would make sense to follow suit.

The thing we have observed in canonical usage by downstreams is that each downstream tends to have native entry points that configure its installation to its preferences with one-stop APIs. This patch leans in to this approach with `RegisterEverything.h` and `mlir._mlir_libs._mlirRegisterEverything` being the one-stop entry points for the "upstream packages". The `_mlir_libs.__init__.py` now allows customization of the environment and Context by adding "initialization modules" to the `_mlir_libs` package. If present, `_mlirRegisterEverything` is treated as such a module. Others can be added by downstreams by adding a `_site_initialize_{i}.py` module, where '{i}' is a number starting with zero. The number will be incremented and corresponding module loaded until one is not found. Initialization modules can:

* Perform load time customization to the global environment (i.e. registering passes, hooks, etc).
* Define a `register_dialects(registry: DialectRegistry)` function that can extend the `DialectRegistry` that will be used to bootstrap the `Context`.
* Define a `context_init_hook(context: Context)` function that will be added to a list of callbacks which will be invoked after dialect registration during `Context` initialization.

Note that the `MLIRPythonExtension.RegisterEverything` is not included by default when building a downstream (its corresponding behavior was prior). For downstreams which need the default MLIR initialization to take place, they must add this back in to their Python CMake build just like they add their own components (i.e. to `add_mlir_python_common_capi_library` and `add_mlir_python_modules`). It is perfectly valid to not do this, in which case, only the things explicitly depended on and initialized by downstreams will be built/packaged. If the downstream has not been set up for this, it is recommended to simply add this back for the time being and pay the build time/package size cost.

CMake changes:
* `MLIRCAPIRegistration` -> `MLIRCAPIRegisterEverything` (renamed to signify what it does and force an evaluation: a number of places were incidentally linking this very expensive target)
* `MLIRPythonSoure.Passes` removed (without replacement: just drop)
* `MLIRPythonExtension.AllPassesRegistration` removed (without replacement: just drop)
* `MLIRPythonExtension.Conversions` removed (without replacement: just drop)
* `MLIRPythonExtension.Transforms` removed (without replacement: just drop)

Header changes:
* `mlir-c/Registration.h` is deleted. Dialect registration functionality is now in `IR.h`. Registration of upstream features are in `mlir-c/RegisterEverything.h`. When updating MLIR and a couple of downstreams, I found that proper usage was commingled so required making a choice vs just blind S&R.

Python APIs removed:
  * mlir.transforms and mlir.conversions (previously only had an __init__.py which indirectly triggered `mlirRegisterTransformsPasses()` and `mlirRegisterConversionPasses()` respectively). Downstream impact: Remove these imports if present (they now happen as part of default initialization).
  * mlir._mlir_libs._all_passes_registration, mlir._mlir_libs._mlirTransforms, mlir._mlir_libs._mlirConversions. Downstream impact: None expected (these were internally used).

C-APIs changed:
  * mlirRegisterAllDialects(MlirContext) now takes an MlirDialectRegistry instead. It also used to trigger loading of all dialects, which was already marked with a TODO to remove -- it no longer does, and for direct use, dialects must be explicitly loaded. Downstream impact: Direct C-API users must ensure that needed dialects are loaded or call `mlirContextLoadAllAvailableDialects(MlirContext)` to emulate the prior behavior. Also see the `ir.c` test case (e.g. `  mlirContextGetOrLoadDialect(ctx, mlirStringRefCreateFromCString("func"));`).
  * mlirDialectHandle* APIs were moved from Registration.h (which now is restricted to just global/upstream registration) to IR.h, arguably where it should have been. Downstream impact: include correct header (likely already doing so).

C-APIs added:
  * mlirContextLoadAllAvailableDialects(MlirContext): Corresponds to C++ API with the same purpose.

Python APIs added:
  * mlir.ir.DialectRegistry: Mapping for an MlirDialectRegistry.
  * mlir.ir.Context.append_dialect_registry(MlirDialectRegistry)
  * mlir.ir.Context.load_all_available_dialects()
  * mlir._mlir_libs._mlirAllRegistration: New native extension that exposes a `register_dialects(MlirDialectRegistry)` entry point and performs all upstream pass/conversion/transforms registration on init. In this first step, we eagerly load this as part of the __init__.py and use it to monkey patch the Context to emulate prior behavior.
  * Type caster and capsule support for MlirDialectRegistry

This should make it possible to build downstream Python dialects that only depend on a subset of MLIR. See: https://github.com/llvm/llvm-project/issues/56037

Here is an example PR, minimally adapting IREE to these changes: https://github.com/iree-org/iree/pull/9638/files In this situation, IREE is opting to not link everything, since it is already configuring the Context to its liking. For projects that would just like to not think about it and pull in everything, add `MLIRPythonExtension.RegisterEverything` to the list of Python sources getting built, and the old behavior will continue.

Reviewed By: mehdi_amini, ftynse

Differential Revision: https://reviews.llvm.org/D128593
2022-07-16 17:27:50 -07:00
Tue Ly 0f782b84cb [libc] Add nearest integer instructions to fputil.
Add round to nearest integer instructions to fputil.  This will be
used in sinf implementation https://reviews.llvm.org/D123154

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D129776
2022-07-14 13:20:35 -04:00
Amara Emerson 6e6be5f950 Revert "[llvm] add zstd to llvm::compression namespace"
This reverts commit d449c60076.

Breaks macOS builds with this:
llvm/lib/Support/Compression.cpp:24:10: fatal error: 'zstd.h' file not found
2022-07-14 01:23:20 -07:00
Cole Kissane d449c60076 [llvm] add zstd to llvm::compression namespace
- add `FindZSTD.cmake`
- add zstd to `llvm::compression` namespace
- add a CMake option `LLVM_ENABLE_ZSTD` with behavior mirroring that of `LLVM_ENABLE_ZLIB`
- add tests for zstd to `llvm/unittests/Support/CompressionTest.cpp`

Reviewed By: leonardchan, MaskRay

Differential Revision: https://reviews.llvm.org/D128465
2022-07-13 19:58:42 -07:00
Cole Kissane 5ecb161c64 Revert "[llvm] add zstd to `llvm::compression` namespace"
This reverts commit cef07169ec.
2022-07-13 19:48:29 -07:00
Cole Kissane cef07169ec [llvm] add zstd to `llvm::compression` namespace
- add `FindZSTD.cmake`
- add zstd to `llvm::compression` namespace
- add a CMake option `LLVM_ENABLE_ZSTD` with behavior mirroring that of `LLVM_ENABLE_ZLIB`
- add tests for zstd to `llvm/unittests/Support/CompressionTest.cpp`

Reviewed By: leonardchan, MaskRay

Differential Revision: https://reviews.llvm.org/D128465
2022-07-13 19:06:27 -07:00
Jorge Gorbe Moya d6071fa52d [bazel] add missing gmock dependency to //clang/unittests:format_tests 2022-07-12 18:13:42 -07:00
Krzysztof Drewniak d6ef3d20b4 [mlir] Remove VectorToROCDL
Between issues such as
https://github.com/llvm/llvm-project/issues/56323, the fact that this
lowering (unlike the code in amdgpu-to-rocdl) does not correctly set
up bounds checks (and thus will cause page faults on reads that might
need to be padded instead), and that fixing these problems would,
essentially, involve replicating amdgpu-to-rocdl, remove
--vector-to-rocdl for being broken. In addition, the lowering does not
support many aspects of transfer_{read,write}, like supervectors, and
may not work correctly in their presence.

We (the MLIR-based convolution generator at AMD) do not use this
conversion pass, nor are we aware of any other clients.

Migration strategies:
- Use VectorToLLVM
- If buffer ops are particularly needed in your application, use
amdgpu.raw_buffer_{load,store}

A VectorToAMDGPU pass may be introduced in the future.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D129308
2022-07-12 15:21:22 +00:00
Alex Zinenko 3963b4d0dc [mlir] Transform op for multitile size generation
Introduce a structured transform op that emits IR computing the multi-tile
sizes with requested parameters (target size and divisor) for the given
structured op. The sizes may fold to arithmetic constant operations when the
shape is constant. These operations may then be used to call the existing
tiling transformation with a single non-zero dynamic size (i.e. perform
strip-mining) for each of the dimensions separately, thus achieving multi-size
tiling with optional loop interchange. A separate test exercises the entire
script.

Depends On D129217

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D129287
2022-07-12 12:36:28 +00:00
Alex Zinenko 4e4a4c0576 [mlir] Allow Tile transform op to take dynamic sizes
Extend the definition of the Tile structured transform op to enable it
accepting handles to operations that produce tile sizes at runtime. This is
useful by itself and prepares for more advanced tiling strategies. Note that
the changes are relevant only to the transform dialect, the tiling
transformation itself already supports dynamic sizes.

Depends On D129216

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D129217
2022-07-12 12:21:54 +00:00
Leonard Chan 474c873148 Revert "[llvm] cmake config groundwork to have ZSTD in LLVM"
This reverts commit f07caf20b9 which seems to break upstream https://lab.llvm.org/buildbot/#/builders/109/builds/42253.
2022-07-08 13:48:05 -07:00
Cole Kissane f07caf20b9 [llvm] cmake config groundwork to have ZSTD in LLVM
- added `FindZSTD.cmake`
- added a CMake option `LLVM_ENABLE_ZSTD` with behavior mirroring that of `LLVM_ENABLE_ZLIB`
- likewise added have_zstd to compiler-rt/test/lit.common.cfg.py, clang-tools-extra/clangd/test/lit.cfg.py, and several lit.site.cfg.py.in files mirroring have_zlib behavior

Reviewed By: leonardchan, MaskRay

Differential Revision: https://reviews.llvm.org/D128465
2022-07-08 11:46:52 -07:00
Jacques Pienaar e60cc52b79 [mlir][bzl] Update for 1a92dbcfa8 and cab44c515c 2022-07-07 17:36:28 -07:00
Adrian Kuegel f066a0cd21 [llvm][Debuginfod][Bazel] Match dependencies in CMakeLists.txt.
Also update llvm-config.h and llvm-config.h.cmake to match 484b1aa611

Differential Revision: https://reviews.llvm.org/D129252
2022-07-07 09:25:52 +02:00
NAKAMURA Takumi 71c9757474 [Bazel] Fixup to llvmorg-15-init-15618-ge0b520865026, s/dxil/dx/ 2022-07-07 07:03:16 +09:00
Adrian Kuegel 3decc2f04d [mlir][Bazel] Fix Bazel build after a2158374ba 2022-07-06 08:47:48 +02:00
Christian Sigg 3e01af093f [mlir] Add InferIntRangeInterface to gpu.launch
Infers block/grid dimensions/indices or ranges of such dimensions/indices.

Reviewed By: krzysz00

Differential Revision: https://reviews.llvm.org/D129036
2022-07-05 07:14:54 +02:00
Nicolas Vasilache 7fbf55c927 [mlir][Tensor] Move ParallelInsertSlice to the tensor dialect
This is moslty NFC and will allow tensor.parallel_insert_slice to gain
rank-reducing semantics by reusing the vast majority of the tensor.insert_slice impl.

Depends on D128857

Differential Revision: https://reviews.llvm.org/D128920
2022-07-04 01:53:12 -07:00
NAKAMURA Takumi 1ecfc12b0c [Bazel] Make `builtin_headers_gen` as subset of CMake's `clang-resource-headers`
At the moment, two files are not installed by CMake.

- `lib/Headers/openmp_wrappers/time.h`
- `lib/Headers/ppc_wrappers/nmmintrin.h`

`builtin_headers_gen` is available as the source of rules_pkg.
The difference of the layout of installed headers makes cache hit harder.
2022-07-03 15:46:38 +09:00
Arthur Eubanks bcd153485e [bazel] Fix invalid characters 2022-07-01 13:47:56 -07:00
Arthur Eubanks 5a65c5180e [bazel] Port 43dc3190, adding rules to generate dxil intrinsics 2022-07-01 13:38:43 -07:00
Mikhail Goncharov de3fb0f29e [fix/build] bazel rule for ParallelCombiningOpInterface 2022-07-01 10:34:15 +02:00
rdzhabarov 8e82bc840d [fix/build] Fix bazel build rule. 2022-06-30 21:43:09 +00:00
rdzhabarov c9be90986f [Fix/Build] Fixing missing dependency for bazel. 2022-06-29 20:44:20 +00:00
Jacques Pienaar 701051a8c2 [mlir][shape] Switch types to ODS generated (NFC)
These were already pretty simple, so just switching to generated.
2022-06-25 09:06:52 -07:00
Aart Bik 9a3d60e0d3 [mlir][bufferization][sparse] put restriction on sparse tensor allocation
Putting some direct use restrictions on tensor allocations in the
sparse case enables the use of simplifying assumptions in the
bufferization analysis.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D128463
2022-06-24 10:58:43 -07:00
Siva Chandra Reddy 300f8da8e8 [libc] Add Uint128 type as a fallback when __uint128_t is not available.
Also, the unused specializations of __int128_t have been removed.

Differential Revision: https://reviews.llvm.org/D128304
2022-06-24 16:03:35 +00:00
Matthias Springer 3798678bd1 [mlir][sparse][bufferize] Implement BufferizableOpInterface
Only the analysis part of the interface is implemented. The bufferization itself is performed by the SparseTensorConversion pass.

Differential Revision: https://reviews.llvm.org/D128138
2022-06-24 13:47:01 +02:00
Okwan Kwon 1dd2c93a66 [mlir][linalg] move isElementwise() to Linalg/Utils (NFC)
Differential Revision: https://reviews.llvm.org/D128398
2022-06-22 18:55:45 -07:00
Guillaume Chatelet aeccc16497 Re-land [libc] Apply no-builtin everywhere, remove unnecessary flags
This is a reland of D126773 / b2a9ea4420.

The removal of `-mllvm -combiner-global-alias-analysis` has landed separately
in D128051 / 7b73f53790.

And the removal of `-mllvm --tail-merge-threshold=0` is scheduled for
removal in a subsequent patch.
2022-06-22 12:30:20 +00:00
Mahesh Ravishankar 2f637fe730 [mlir][TilingInterface] Enable tile and fuse using TilingInterface.
This patch implements tile and fuse transformation for ops that
implement the tiling interface. To do so,
- `TilingInterface` needs a new method that generates a tiled
  implementation of the operation based on the tile of the result
  needed.
- A pattern is added that replaces a `tensor.extract_slice` whose
  source is defined by an operation that implements the
  `TilingInterface` with a tiled implementation that produces the
  extracted slice in-place (using the method added to
  `TilingInterface`).
- A pattern is added that takes a sequence of operations that
  implement the `TilingInterface` (for now `LinalgOp`s), tiles the
  consumer, and greedily fuses its producers iteratively.

Differential Revision: https://reviews.llvm.org/D127809
2022-06-21 17:22:58 +00:00
Mahesh Ravishankar c584771f54 Revert "[mlir][TilingInterface] Enable tile and fuse using TilingInterface."
This reverts commit ea75511319 due to build failures.
2022-06-21 16:56:59 +00:00
Mahesh Ravishankar ea75511319 [mlir][TilingInterface] Enable tile and fuse using TilingInterface.
This patch implements tile and fuse transformation for ops that
implement the tiling interface. To do so,
- `TilingInterface` needs a new method that generates a tiled
  implementation of the operation based on the tile of the result
  needed.
- A pattern is added that replaces a `tensor.extract_slice` whose
  source is defined by an operation that implements the
  `TilingInterface` with a tiled implementation that produces the
  extracted slice in-place (using the method added to
  `TilingInterface`).
- A pattern is added that takes a sequence of operations that
  implement the `TilingInterface` (for now `LinalgOp`s), tiles the
  consumer, and greedily fuses its producers iteratively.

Differential Revision: https://reviews.llvm.org/D127809
2022-06-21 16:47:14 +00:00
Matthias Springer 858be16670 [mlir][memref] Fix layout map computation in inferRankReducedResultType
Differential Revision: https://reviews.llvm.org/D128160
2022-06-21 10:08:26 +02:00
Mogball d883a02a7c [mlir][ods] Remove StructAttr
Depends on D127373

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D127375
2022-06-21 01:10:05 +00:00
Alex Zinenko 8b68da2c7d [mlir] move SCF headers to SCF/{IR,Transforms} respectively
This aligns the SCF dialect file layout with the majority of the dialects.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D128049
2022-06-20 10:18:01 +02:00
NAKAMURA Takumi 0716b3ec09 [Bazel] Rename generated *_main.cpp to [tool-name]-driver.cpp which CMake uses.
Fixup to llvmorg-15-init-12347-gf06abbb39380
The difference of basename affects its emitted object file.

FIXME: Each rule's name is left as origin.
2022-06-18 13:35:23 +09:00
Benjamin Kramer d5c29b23e1 [mlir][sparse] Inline the definition of LLVM_ATTRIBUTE_WEAK
This library is supposed not to have a dependency on LLVM, and linking
LLVMSupport into it breaks its shared library setup.
2022-06-17 22:41:10 +02:00
Benjamin Kramer feb8313fbf [bazel] Add missing dependency after 455679413
This is supposed to be header-only. Don't know how to express that in
bazel.
2022-06-17 22:09:13 +02:00
Frederik Gossen e694b22344 [mlir][nvgpu] Fix Bazel BUILD file
Differential Revision: https://reviews.llvm.org/D128078
2022-06-17 14:35:30 -04:00
Christopher Bate 51b925df94 [mlir][nvgpu] shared memory access optimization pass
This change adds a transformation and pass to the NvGPU dialect that
attempts to optimize reads/writes from a  memref representing GPU shared
memory in order to avoid bank conflicts. Given a value representing a
shared memory memref, it traverses all reads/writes within the parent op
and, subject to suitable conditions, rewrites all last dimension index
values such that element locations in the final (col) dimension are
given by
`newColIdx = col % vecSize + perm[row](col/vecSize,row)`
where `perm` is a permutation function indexed by `row` and `vecSize`
is the vector access size in elements (currently assumes 128bit
vectorized accesses, but this can be made a parameter). This specific
transformation can help optimize typical distributed & vectorized accesses
common to loading matrix multiplication operands to/from shared memory.

Differential Revision: https://reviews.llvm.org/D127457
2022-06-17 09:31:05 -06:00
Guillaume Chatelet 7b73f53790 [libc] Rely on __builtin_memcpy_inline for memcpy implementation
This patch removes usage of `-mllvm -combiner-global-alias-analysis`
and relies on compiler builtin to implement `memcpy`.

Note that `-mllvm -combiner-global-alias-analysis` is actually only useful for
functions where buffers can alias (namely `memcpy` and `memmove`). The other
memory functions where not benefiting from the flag anyways.

The upside is that the memory functions can now be compiled from source with
thinlto (thinlto would not be able to carry on the flag when doing inlining).

The downside is that for compilers other than clang (i.e. not providing
`__builtin_memcpy_inline`) the codegen may be worse.

Differential Revision: https://reviews.llvm.org/D128051
2022-06-17 14:22:26 +00:00
Alex Zinenko 610139d2d9 [mlir] replace 'emit_c_wrappers' func->llvm conversion option with a pass
The 'emit_c_wrappers' option in the FuncToLLVM conversion requests C interface
wrappers to be emitted for every builtin function in the module. While this has
been useful to bootstrap the interface, it is problematic in the longer term as
it may unintentionally affect the functions that should retain their existing
interface, e.g., libm functions obtained by lowering math operations (see
D126964 for an example). Since D77314, we have a finer-grain control over
interface generation via an attribute that avoids the problem entirely. Remove
the 'emit_c_wrappers' option. Introduce the '-llvm-request-c-wrappers' pass
that can be run in any pipeline that needs blanket emission of functions to
annotate all builtin functions with the attribute before performing the usual
lowering that accounts for the attribute.

Reviewed By: chelini

Differential Revision: https://reviews.llvm.org/D127952
2022-06-17 11:10:31 +02:00
Guillaume Chatelet c26366979b [libc][bazel] Remove memcpy dependency in memmove 2022-06-17 09:07:24 +00:00
bixia1 bbb73ade43 [mlir][complex] Add Python bindings for complex ops.
Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D127916
2022-06-16 14:19:11 -07:00
Guillaume Chatelet 4a6929f811 Revert "[libc] Apply no-builtin everywhere, remove unnecessary flags"
This reverts commit b2a9ea4420.
2022-06-16 09:28:17 +00:00
Jacques Pienaar 02e32708bd [mlir][bzl] Export textmate grammar file 2022-06-15 11:28:43 -07:00
Rob Suderman 640973f2b9 [tosa] Lower tosa.slice to tensor.slice for dynamic case
Existing slice lowering only supporting static shapes.

Reviewed By: NatashaKnk

Differential Revision: https://reviews.llvm.org/D127704
2022-06-15 09:54:36 -07:00