Commit Graph

1812 Commits

Author SHA1 Message Date
Jakub Kuderski
80d5400d92 [mlir][spirv] Account for type conversion failures in scf-to-spirv
Fixes: https://github.com/llvm/llvm-project/issues/59136

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D141292
2023-01-09 11:35:47 -05:00
Johannes Reifferscheid
059cf735a9 Lower math.cbrt to NVVM/ROCDL.
Reviewed By: pifon2a

Differential Revision: https://reviews.llvm.org/D141270
2023-01-09 13:17:35 +01:00
Alexander Shaposhnikov
9e1a344155 [MLIR][TOSA] Switch Tosa to DenseArrayAttr
This diff completes switching Tosa to DenseArrayAttr.

Test plan: ninja check-mlir check-all

Differential revision: https://reviews.llvm.org/D141111
2023-01-06 22:57:14 +00:00
Rob Suderman
7ce53e3102 [mlir][tosa] Add tosa.conv3d lowering to Linalg
Conv3D has an existing linalg operation for floating point. Adding a quantized
variant and corresponding lowering from TOSA. Numerical correctness was validated
using the TOSA conformance tests.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D140919
2023-01-06 10:47:45 -08:00
Thomas Raoux
7efdc117b1 [mlir][nvvm] Add lowering of gpu.printf to nvvm
When converting to nvvm lowering gpu.printf to vprintf allows us to
support printing when running on cuda.

Differential Revision: https://reviews.llvm.org/D141049
2023-01-06 17:29:30 +00:00
mariecwhite
76dc9a853a [mlir][tosa] Remove clamping behavior in tosa.cast for integer truncation
Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D141015
2023-01-04 15:10:06 -08:00
Alexander Shaposhnikov
11030c7d67 [MLIR][TOSA] Switch Tosa_IntArrayAttr[N], Tosa_IntArrayAttrUpto[N] to DenseI64ArrayAttr
Switch Tosa_IntArrayAttr[N], Tosa_IntArrayAttrUpto[N] to DenseI64ArrayAttr.

Test plan: ninja check-mlir check-all

Differential revision: https://reviews.llvm.org/D140748 https://reviews.llvm.org/D140829, https://reviews.llvm.org/D140832, https://reviews.llvm.org/D140833, https://reviews.llvm.org/D140834
2023-01-04 21:58:20 +00:00
Mehdi Amini
9f91b72dcc Apply clang-tidy fixes for llvm-else-after-return in GPUToSPIRV.cpp (NFC) 2023-01-04 20:57:40 +00:00
Robert Walker
ca21499526 [mlir][tosa] Fix floating point offset for tosa.resize
Offset is a signed value, so use `arith.sitofp`

See also https://github.com/llvm/llvm-project/issues/59585

Reviewed By: NatashaKnk, jpienaar

Differential Revision: https://reviews.llvm.org/D140958
2023-01-04 12:53:54 -08:00
Rob Suderman
b5a1de9c98 [mlir][tosa] Add broadcasting case for tosa.resize to linalg implementation
When lowering tosa.resize it is possible there is an unary input dimension.
Lowering to a new tosa.resize and explicit broadcast simplifies the
tosa.resize operation to avoid recomputing the identical broadcasted values.

This change reworks the broadcast optimization reuse the tosa.resize generic
implementation.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D139963
2023-01-03 14:29:06 -08:00
a.puschin
a315534e52 [mlir][tosa] Fix out-of-boundaries iteration for tosa-to-linalg
When the number of elements of two shapes are not equal, a Reshape operation cannot be used to transfer one into another

Function findIntermediateShape(...) can cause out-of-boundaries operator[] call if the abovementioned condition strikes

The test-case I used now causes no error as its root-cause was an issue in Tosa dialect with padded Conv2D operations lowering which is already solved in commit 69c984b6

Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D140013
2023-01-03 11:52:09 -08:00
Johannes Reifferscheid
998a3a3894 Add a math.cbrt instruction and lowering to libm.
There's currently no way to get accurate cube roots in the math dialect.
powf(x, 1/3.0) is too inaccurate in some cases.

Reviewed By: akuegel

Differential Revision: https://reviews.llvm.org/D140842
2023-01-03 08:44:12 +01:00
Krzysztof Drewniak
f6076bd81f [mlir][ROCDL] Translate known block size attributes to ROCDL
1. When converting from the GPU dialect to the ROCDL dialect, if the
function that contains a gpu.thread_id or gpu.block_id op is annotated
with gpu.known_{block,grid}_size, use that size to set a "range"
attribute on the corresponding rocdl intrinsic so that the LLVM
frontend can optimize based on that range information.
1b. When translating from the rocdl dialect to LLVM IR, use the
"range" attribute, if present, to set !range metadata on the relevant
function call.
2. Deprecate the old rocdl.max_flat_work_group_size attribute, which
was used in a tensorflow backend. Instead, use
rocdl.flat_work_group_size going forward to allow kernel generators to
specify the minimum and maximum work group sizes a kernel may be
launched with in one attribute, thus more closely matching the backend.
3. When translating from gpu.func to llvm.func within gpu-to-rocdl,
copy the known_block_size attribute as rocdl.reqd_work_group_size to
enable further translations to set the corresponding metadata on the
LLVM IR function. Also, set the rocdl.flat_work_group_size attribute
to ensure that the reqd_work_group_size metadata and the
amdgpu-flat-work-group-size metadata are consistent.
3b. Extend the ROCDL to LLVM IR translation to set the
!reqd_work_group_size metadata on LLVM functions

Also update tests and add functions to the ROCDL dialect to ensure
attribute names are used consistently.

Depends on D139865

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D139866
2023-01-02 21:04:13 +00:00
Ivan Butygin
2e4aa3bd83 [mlir][gpu][spirv] Lower gpu reduction ops to spirv
Supports only "add" and "mul" ops for now. More ops will be added later.

Differential Revision: https://reviews.llvm.org/D140576
2022-12-30 17:44:08 +01:00
Lei Zhang
56c069887b [mlir][spirv] Fail vector.bitcast conversion with different bitwidth
Depending on the target environment, we may need to emulate certain
types, which can cause issue with bitcast.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D140437
2022-12-29 15:43:55 -08:00
Ramkumar Ramachandra
e8bcc37fff mlir/{SPIRV,Bufferization}: use std::optional in .td files (NFC)
This is part of an effort to migrate from llvm::Optional to
std::optional. 22426110c5 changed the way mlir-tblgen generates .inc
files, emitting std::optional when an Optional attribute is specified in
a .td file. It also changed several .td files hard-coding llvm::Optional
to use std::optional. However, the patch excluded a few .td files in
SPIRV and Bufferization hard-coding llvm::Optional. This patch fixes
that defect, and after this patch, references to llvm::Optional in .cpp
and .h files can be replaced mechanically.

See also: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Signed-off-by: Ramkumar Ramachandra <r@artagnon.com>

Differential Revision: https://reviews.llvm.org/D140329
2022-12-20 09:23:58 +01:00
Ramkumar Ramachandra
0de16fafa5 mlir/DialectConversion: use std::optional (NFC)
This is part of an effort to migrate from llvm::Optional to
std::optional. This patch touches DialectConversion, and modifies
existing conversions and tests appropriately.

See also: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Signed-off-by: Ramkumar Ramachandra <r@artagnon.com>

Differential Revision: https://reviews.llvm.org/D140303
2022-12-19 18:48:59 +01:00
Fangrui Song
cbb0981388 [mlir] llvm::Optional::value => operator*/operator->
std::optional::value() has undesired exception checking semantics and is
unavailable in older Xcode (see _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS). The
call sites block std::optional migration.
2022-12-17 19:07:38 +00:00
Ramkumar Ramachandra
22426110c5 mlir/tblgen: use std::optional in generation
This is part of an effort to migrate from llvm::Optional to
std::optional. This patch changes the way mlir-tblgen generates .inc
files, and modifies tests and documentation appropriately. It is a "no
compromises" patch, and doesn't leave the user with an unpleasant mix of
llvm::Optional and std::optional.

A non-trivial change has been made to ControlFlowInterfaces to split one
constructor into two, relating to a build failure on Windows.

See also: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Signed-off-by: Ramkumar Ramachandra <r@artagnon.com>

Differential Revision: https://reviews.llvm.org/D138934
2022-12-17 11:13:26 +01:00
Fangrui Song
4913e5da3c [mlir] std::optional::value => operator*/operator->
value() has undesired exception checking semantics and calls
__throw_bad_optional_access in libc++. Moreover, the API is unavailable without
_LIBCPP_NO_EXCEPTIONS on older Mach-O platforms (see
_LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS).
2022-12-17 04:38:27 +00:00
Rob Suderman
b37a0318cb [mlir][tosa] Make tosa.resize to linalg avoid redundant loads for unit width
When using a tosa resize for ?x1x1x? to ?x1x?x? we should avoid doing a 2D
interpolation as only two unique values are loaded. As the extract operation
performance numerical computation on its values the superfluous extracts may
fail to be coalesced. Instead we only interpolate between the values if there
are multiple values to interpolate between.

For the integer case we also perform scaling by the scaling-factor to apply
the same integer scaling behavior as interpolation.

Reviewed By: jpienaar, NatashaKnk

Differential Revision: https://reviews.llvm.org/D139979
2022-12-15 16:22:46 -08:00
Lei Zhang
f1db4aec30 [mlir][VectorToGPU] Support transposed+broadcasted 2D MMA load
This is loading from 2-D memref, in addition to D139655 where we
load from 1-D memref cases.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D140136
2022-12-15 19:34:32 +00:00
Lei Zhang
dbddd4f6a4 [mlir][VectorToGPU] Support transposed+broadcasted 1D MMA load
This is now possible with transpose semantics on subgroup MMA
load ops.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D139655
2022-12-15 19:22:35 +00:00
Matthias Springer
325b58d59f [mlir][cf] Print message in cf.assert to LLVM lowering
The assert message was previously ignored. The lowered IR now calls `puts` it in case of a failed assertion.

Differential Revision: https://reviews.llvm.org/D138647
2022-12-15 17:45:34 +01:00
Quinn Dawkins
b05b8970d8 [mlir][gpu][spirv] Verify elementwise op type as mulf when converting to spirv.MatrixTimesScalar
Conversion from gpu.subgroup_mma_constant_matrix to spirv.MatrixTimesScalar didn't check that the op type was a multiplication and thus would incorrectly convert other elementwise scalar operations.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D140081
2022-12-15 03:15:04 +00:00
Jakub Kuderski
4f47677dee [mlir][arith][spirv] Account for possible type conversion failures
Check results of all type conversions in `--convert-arith-to-spirv`.

Fixes: https://github.com/llvm/llvm-project/issues/59496

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D140033
2022-12-14 19:32:40 -05:00
Slava Zakharin
70174b8035 [mlir][math] Added math::FPowI conversion to LLVM dialect.
The operations are converted into LLVM::PowIOp.

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D129812
2022-12-14 10:15:05 -08:00
Slava Zakharin
22702cc76c [mlir][math] Added math::FPowI conversion to calls of outlined implementations.
Power functions are implemented as linkonce_odr scalar functions
for FPowI operations met in a module.
Vector form of FPowI is linearized into a sequence of calls
of the scalar functions.

Option {min-width-of-fpowi-exponent} controls which FPowI operations
are converted by MathToFuncs: if the width of the exponent's integer
type is less than the specified value, then the operation is not converted.

Flang will specify {min-width-of-fpowi-exponent=33} to make sure that
math::FPowI operations with exponent wider than 32 bits will be converted
by MathToFuncs, and operations with more narrow exponent will be left
for MathToLLVM to convert them to LLVM::PowIOp.

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D139804
2022-12-13 12:15:35 -08:00
Rob Suderman
78503e1a2f [mlir][tosa] Refactor tosa.resize
Moved to using helper lambdas to avoid code repetition. IR needed to be reordered to
accommodate which should be the only changes to the existing tests.

This changes the quantized test to target `i48` types to guarantee types are extended
correctly when necessary.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D136500
2022-12-12 14:38:38 -08:00
Jakub Kuderski
f39b47264e [mlir][arith][tosa] Use extended mul in 32-bit tosa.apply_scale
To not introduce 64-bit types that may be difficult to handle for some
targets.

Reviewed By: rsuderman, antiagainst

Differential Revision: https://reviews.llvm.org/D139777
2022-12-12 14:39:58 -05:00
Jeff Niu
53406427cd [mlir] FunctionOpInterface: turn required attributes into interface methods (Reland)
Reland D139447, D139471 With flang actually working

- FunctionOpInterface: make get/setFunctionType interface methods

This patch removes the concept of a `function_type`-named type attribute
as a requirement for implementors of FunctionOpInterface. Instead, this
type should be provided through two interface methods, `getFunctionType`
and `setFunctionTypeAttr` (*Attr because functions may use different
concrete function types), which should be automatically implemented by
ODS for ops that define a `$function_type` attribute.

This also allows FunctionOpInterface to materialize function types if
they don't carry them in an attribute, for example.

Importantly, all the function "helper" still accept an attribute name to
use in parsing and printing functions, for example.

- FunctionOpInterface: arg and result attrs dispatch to interface

This patch removes the `arg_attrs` and `res_attrs` named attributes as a
requirement for FunctionOpInterface and replaces them with interface
methods for the getters, setters, and removers of the relevent
attributes. This allows operations to use their own storage for the
argument and result attributes.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D139736
2022-12-10 15:17:09 -08:00
Kazu Hirata
a9a1b45b3c [VectorToLLVM] Use std::optional in ConvertVectorToLLVM.cpp (NFC)
This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-10 10:43:39 -08:00
Kazu Hirata
7d2b180e68 [MemRefToLLVM] Use std::optional in MemRefToLLVM.cpp (NFC)
This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-10 10:41:43 -08:00
Kazu Hirata
1adfdab399 [ComplexToLibm] Use std::optional in ComplexToLibm.cpp (NFC)
This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-10 10:40:35 -08:00
Jakub Kuderski
285d321a85 [mlir][arith] Define mulsi_extended op
Extend D139688 with the signed version of the extended multiplication
op. Add conversion to the SPIR-V and LLVM dialects.

This was originally proposed in:
https://discourse.llvm.org/t/rfc-arith-add-extended-multiplication-ops/66869.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D139743
2022-12-09 20:25:31 -05:00
Jakub Kuderski
b4bdcea214 [mlir][arith] Define mului_extended op
Add conversion to the SPIR-V and LLVM dialects.

This was originally proposed in:
https://discourse.llvm.org/t/rfc-arith-add-extended-multiplication-ops/66869.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D139688
2022-12-09 17:37:06 -05:00
David Spickett
cf98e8273c Revert "[mlir] FunctionOpInterface: make get/setFunctionType interface methods"
and "[mlir] Fix examples build"

This reverts commit fbc253fe81 and
96cf183bcc.

Which I missed in the first revert in f3379feabe.
2022-12-09 15:36:48 +00:00
David Spickett
f3379feabe Revert "[mlir] FunctionOpInterface: arg and result attrs dispatch to interface"
and "[flang] Fix flang after MLIR update"

This reverts commit dd74e6b6f4 and
1897b67ae8 due to ongoing test failures on flang
bots e.g. https://lab.llvm.org/buildbot/#/builders/179/builds/5050
2022-12-09 15:02:39 +00:00
Jeff Niu
dd74e6b6f4 [mlir] FunctionOpInterface: arg and result attrs dispatch to interface
This patch removes the `arg_attrs` and `res_attrs` named attributes as a
requirement for FunctionOpInterface and replaces them with interface
methods for the getters, setters, and removers of the relevent
attributes. This allows operations to use their own storage for the
argument and result attributes.

Depends on D139471

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D139472
2022-12-08 11:32:38 -08:00
Jeff Niu
fbc253fe81 [mlir] FunctionOpInterface: make get/setFunctionType interface methods
This patch removes the concept of a `function_type`-named type attribute
as a requirement for implementors of FunctionOpInterface. Instead, this
type should be provided through two interface methods, `getFunctionType`
and `setFunctionTypeAttr` (*Attr because functions may use different
concrete function types), which should be automatically implemented by
ODS for ops that define a `$function_type` attribute.

This also allows FunctionOpInterface to materialize function types if
they don't carry them in an attribute, for example.

Importantly, all the function "helper" still accept an attribute name to
use in parsing and printing functions, for example.

Reviewed By: rriddle, lattner

Differential Revision: https://reviews.llvm.org/D139447
2022-12-08 11:32:27 -08:00
Guray Ozen
b2bba5b65c [mlir][spirv] Support conversion of CopySignOp to spirv for 1D vector with 1 element
Conversion of CopySignOp to SPIRV is supported for scalar and vectors but not 1D vectors with 1 element (aka vector<1xf32>). This revisions adds supports this by treating them as scalars.

An alternative solution would be to allow 0D vectors for SPIRV, but the spec [0] strictly defines the vector type as non-0D.
"Vector: An ordered homogeneous collection of two or more scalars. Vector sizes are quite restrictive and dependent on the execution model."

[0] https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_types

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D139518
2022-12-08 09:11:27 +01:00
Kazu Hirata
15ae99647c [mlir] Use std::nullopt instead of None in comments (NFC)
This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-07 20:17:39 -08:00
Jakub Kuderski
28246b7e75 [mlir][arith] Rename addui_carry to addui_extended
The goal is to make the naming of the future `_extended` ops more
consistent. With unsigned addition, the carry value/flag and overflow
bit are the same, but this is not true when it comes to signed addition.

Also rename the second result from `carry` to `overflow`.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D139569
2022-12-07 17:15:56 -05:00
Rob Suderman
8e7630ece1 [mlir][tosa] Fix tosa.resize for i48 accumulator
Implementation assumed a i32 accumulator. Fixed the implementation to
work with an i32 accumulator.

Reviewed By: NatashaKnk

Differential Revision: https://reviews.llvm.org/D139365
2022-12-07 11:27:33 -08:00
Quentin Colombet
9cbd136db4 [mlir][NFC] Add a new getStridesAndOffset function
The new function is a wrapper around the regular `getStridesAndOffset`
that offers a more compact way (as in writing less code) of getting the
relevant information.

This method is intended to be used only when it is known that the
LogicalResult of the regular `getStridesAndOffset` must be "succeeded".

This warpper will assert on that.

Differential Revision: https://reviews.llvm.org/D139529
2022-12-07 13:58:28 +00:00
Ramkumar Ramachandra
2a19625424 mlir/tosa: move tosa.pad from Linalg to Tensor conversion
Since tosa.pad is lowered strictly to artih and tensor ops, move
ConvertPad from TosaToLinalg to TosaToTensor, benefitting non-Linalg
Tosa targets. TensorToLinalg exists, and is trivial, so nothing is lost.

Signed-off-by: Ramkumar Ramachandra <r@artagnon.com>

Differential Revision: https://reviews.llvm.org/D139091
2022-12-06 07:39:29 +01:00
Lei Zhang
50882b4daf [mlir] List more elementwise ops in VectorToGPU MMA conversion
Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D139244
2022-12-05 22:51:19 +00:00
Lei Zhang
2c7827da4f [mlir][spirv] Add GPU subgroup MMA to spirv.MMAMatrixTimesScalar
Along the way, make the default pattern fail instead of crashing
when an elementwise op is not supported yet.

Reviewed By: kuhar

Differential Revision: https://reviews.llvm.org/D139280
2022-12-05 22:30:50 +00:00
Rob Suderman
58fa8426ff [mlir][tosa] Handle tosa.resize nearest rounding correctly
Rounding of tosa.resize did not handle rounding to the nearest pixel correctly.
Rather than dividing the scale by 2 we should double the partial pixel to
guarantee we include a check on the lowest bit.

Reviewed By: NatashaKnk

Differential Revision: https://reviews.llvm.org/D139162
2022-12-05 13:10:08 -08:00
Ramkumar Ramachandra
d246bf4199 mlir/TosaToLinalg: improve debugging during conversion
Make systematic use of notifyMatchFailure.

Signed-off-by: Ramkumar Ramachandra <r@artagnon.com>

Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D139190
2022-12-05 11:40:08 -08:00