384 Commits

Author SHA1 Message Date
Dimple Prajapati
f8ba021e64
[mlir][spirv] Add gpu printf op lowering to spirv.CL.printf op (#78510)
This change contains following:
	- adds lowering of printf op to spirv.CL.printf op in GPUToSPIRV pass.
	- Fixes Constant decoration parsing for spirv GlobalVariable.
	- minor modification to spirv.CL.printf op assembly format.

---------

Co-authored-by: Jakub Kuderski <kubakuderski@gmail.com>
2024-09-30 15:39:13 -04:00
Angel Zhang
dde8280ded
[mlir][spirv] Add GroupNonUniformBallotFindLSB and GroupNonUniformBallotFindMSB ops (#104791) 2024-08-19 13:52:18 -04:00
Andrea Faulds
b719ab4eef
[mlir][spirv] Drop support for SPV_INTEL_joint_matrix (#102332)
This was a "preview" extension, never formalized, that has now been
supplanted by SPV_KHR_cooperative_matrix.
2024-08-13 19:14:07 -04:00
Mehdi Amini
a506279e5c
[mlir] Do not merge blocks during canonicalization by default (#95057)
This is a heavy process, and it can trigger a massive explosion in
adding block arguments. While potentially reducing the code size, the
resulting merged blocks with arguments are hiding some of the def-use
chain and can even hinder some further analyses/optimizations: a merge
block does not have it's own path-sensitive context, instead the context
is merged from all the predecessors.

Previous behavior can be restored by passing:

  {test-convergence region-simplify=aggressive}

to the canonicalize pass.
2024-06-14 22:38:56 +02:00
klensy
f0b0c02504
[mlir][test] Fix filecheck annotation typos (#92897)
Moved fixes for mlir from
https://github.com/llvm/llvm-project/pull/91854, plus few additional in
second commit.

---------

Co-authored-by: klensy <nightouser@gmail.com>
2024-05-24 09:24:59 +02:00
Jakub Kuderski
d61ec513c4
[mlir][spirv] Add IsInf/IsNan expansion for WebGPU (#86903)
These non-finite math ops are supported by SPIR-V but not by WGSL.
Assume finite floating point values and expand these ops into `false`.

Previously, this worked by adding fast math flags during conversion from
arith to spirv, but this got removed in
https://github.com/llvm/llvm-project/pull/86578.

Also do some misc cleanups in the surrounding code.
2024-03-28 14:13:04 -04:00
Finn Plummer
cc3b6f9495
[mlir][spirv] Add folding for [S|U|GreaterThan[Equal] (#85434)
Add missing constant propogation folder for [S|U]GreaterThan[Equal].

Implement additional folding when the operands are equal for all ops.

Allows for constant folding in the IndexToSPIRV pass.

Part of work #70704
2024-03-25 19:49:12 -07:00
Finn Plummer
230b1895c4
[mlir][spirv] Add folding for [S|U|LessThan[Equal] (#85435)
Add missing constant propogation folder for [S|U]LessThan[Equal].

Implement additional folding when the operands are equal for all ops.

Allows for constant folding in the IndexToSPIRV pass.

Part of work #70704
2024-03-24 18:56:47 -07:00
Finn Plummer
8cbb8ac02c
[mlir][spirv] Add folding for SelectOp (#85430)
Add missing constant propogation folder for spirv.Select

Implement additional folding when both selections are equivalent or the
condition is a constant Scalar/SplatVector.

Allows for constant folding in the IndexToSPIRV pass.

Part of work #70704
2024-03-19 13:27:35 -07:00
Mehdi Amini
e5332482c6
[MLIR][Spirv] Use StringAttr for linkage_name (NFC) (#82953)
std::string was used here, likely by mistake. The usual convention for
attributes is to use StringAttr.
2024-02-25 20:47:08 -08:00
Artem Tyurin
9a5fb74fd1
[mlir][spirv] Handle a missing case when inlining spirv.ReturnValue (#80733)
Fixes https://github.com/llvm/llvm-project/issues/73285.
2024-02-05 19:10:39 -08:00
Jakub Kuderski
6e90f13cc9
[mlir][spirv] Drop support for SPV_NV_cooperative_matrix (#76782)
This extension has been superseded by SPV_KHR_cooperative_matrix which
is supported across major vendors GPU like Nvidia, AMD, and Intel.

Given that the KHR version has been supported for nearly half a year,
drop the NV-specific extension to reduce the maintenance burden and code
duplication.
2024-01-08 17:57:52 -05:00
Alex Beloi
c63febb102
[mlir][spirv] Use assemblyFormat to define atomic op assembly (#76323)
see #73359

Declarative assemblyFormat ODS is more concise and requires less
boilerplate than filling out CPP interfaces.

Changes:
* updates the Ops defined in `SPIRVAtomicOps.td` to use assemblyFormat.
* Removes print/parse from`AtomcOps.cpp` which is now generated by
assemblyFormat
* Adds `Trait` to verify that a pointer operand `foo`'s pointee type
matches operand `bar`'s type
* * Updates error message expected in tests from new Trait
* Updates tests to updated format (largely using <operand> in place of
"operand")
2024-01-06 19:55:55 -08:00
Kohei Yamaguchi
747d8fb01c
[mlir][spirv] Support alias/restrict function argument decorations (#76353)
Closes #76106

---------

Co-authored-by: Lei Zhang <antiagainst@gmail.com>
2024-01-06 11:51:23 -08:00
Dimple Prajapati
5e54319b7b
[mlir][spirv] Support spec constants as GlobalVar initializer (#75660)
Changes include:

- spirv serialization and deserialization needs handling in cases when
GlobalVariableOp initializer is defined using spirv SpecConstant or
SpecConstantComposite op, currently even though it allows SpecConst, it
only looked up in for GlobalVariable Map to find initializer symbol
reference, change is fixing this and extending the support to
SpecConstantComposite as an initializer.
- Adds tests to make sure GlobalVariable can be initialized using
specialized constants.

---------

Co-authored-by: Lei Zhang <antiagainst@gmail.com>
2024-01-05 16:27:30 -08:00
Finn Plummer
88151dd428
[mlir][spirv] Add folding for SNegate, [Logical]Not (#74992)
Add missing constant propogation folder for SNegate, [Logical]Not.

Implement additional folding when !(!x) for all ops.

This helps for readability of lowered code into SPIR-V.

Part of work for #70704
2023-12-21 18:24:01 +01:00
Finn Plummer
4c83c27c91
[mlir][spirv] Add folding for [I|Logical][Not]Equal (#74194) 2023-12-20 11:00:28 +01:00
Finn Plummer
40e2bb5330
[mlir][spirv] Add folding for Bitwise[Or|And|Xor] (#74193)
Add missing constant propogation folder for Bitwise[Or|And|Xor].

Move previous Bitwise[Or|And] fold implementations to
SPIRVCanonicalization for consistency.

Implement additional folding when lhs == rhs and rhs = 0 for Xor. As
well as, update an Xor testcase to account for this introduced folding.

This helps for readability of lowered code into SPIR-V.

Part of work for #70704
2023-12-11 13:09:40 -05:00
Finn Plummer
2ba9720a76
[mlir][spirv] Add folding for SPIR-V Shifting ops (#74192)
Add missing constant propogation folder for LeftShiftLogical,
RightShift[Logical|Arithmetic].

Implement additional folding when Shift value is 0.

This helps for readability of lowered code into SPIR-V.

Part of work for #70704
2023-12-06 18:00:44 -05:00
Finn Plummer
14028ec0a6
[mlir][spirv] Add canon patterns for IAddCarry/[S|U]MulExtended (#73340)
Add missing constant propogation folder for IAddCarry and
[S|U]MulExtended. Due to currently missing constant value for
spirv.struct the folding is done using canonicalization patterns.

Implement additional folding when rhs is 0 for all ops and when rhs is 1
for UMulExt.

This helps for readability of lowered code into SPIR-V.

Part of work for #70704
2023-11-29 14:32:13 -05:00
Finn Plummer
5259e14e7d
[mlir][spirv] Add folding for [S|U]Mod, [S|U]Div, SRem (#73341)
Add missing constant propogation folder for [S|U]Mod, [S|U]Div, SRem

Implement additional folding when rhs is 1 for all ops.

This helps for readability of lowered code into SPIR-V.

Part of work for #70704
2023-11-29 13:40:14 -05:00
Jakub Kuderski
771676878a
[mlir][spirv] Add missing group non-uniform bitwise and logical ops (#73475)
This covers the following ops:
`spirv.GroupNonUniform` x {`Bitwise`, `Logical`} x {`And`, `Or`, `Xor`}

We need these to efficiently lower from the `gpu.subgroup_reduce` op.
2023-11-26 23:23:19 -05:00
Jakub Kuderski
1b70587ca1
[mlir][spirv] Update integer dot product op syntax (#73468)
Make the syntax more concise and aligned with the `spirv.Dot` syntax in
https://github.com/llvm/llvm-project/pull/73466.

Move some type verification from C++ to ODS.

Regexes to update existing code and tests:
`(\s*\{format\s+=\s+#spirv.packed_vector_format([^}]+)\})`
==>
`, $2`

`(spirv.[SU]+Dot[a-zA-Z]*[^:]+:)(\s*\(([^,]+),[^\)]+\))(.+)`
==>
`$1 $3$4`
2023-11-26 19:42:56 -05:00
Jakub Kuderski
897141449e
[mlir][spirv] Add floating point dot product (#73466)
Because `OpDot` does not require any extra capabilities or extensions,
enable it by default in the vector to spirv conversion.
2023-11-26 19:27:16 -05:00
Ivan Butygin
61835152ca
[mlir][spirv] Add more CL math ops (#72995)
tan
atan
atanh
sinh
cosh
asin
asinh
acos
acosh
atan2
2023-11-21 18:42:45 +03:00
Ivan Butygin
521277cd1a
[mlir][spirv] Add CL.mix op (#72800) 2023-11-21 15:31:38 +03:00
Jakub Kuderski
c6f7b631a9
[mlir][spirv] Fix VectorShuffle assembly format (#72568)
Align with the rest of the spirv dialect by using a functional type
syntax.

Regex for updating existing code:
`spirv\.VectorShuffle (\[.+\]) (%[^:]+): ([^,]+), (%[^:]+): ([^\s]+) ->(.+)`
 ==>
`spirv.VectorShuffle $1 $2, $4 : $3, $5 ->$6`
2023-11-16 19:34:00 -05:00
Lei Zhang
6d9eb31c31
[mlir][spirv] Fix spirv.Select min version requirement (#72173)
Per the spec, "Before version 1.4, results are only computed per
component." So using scalar condition to select composite needs SPIR-V
v1.4 at least.
2023-11-13 15:53:53 -08:00
Sang Ik Lee
2dace04521
[mlir][spirv] Implement gpu::TargetAttrInterface (#69949)
This commit implements gpu::TargetAttrInterface for SPIR-V target
attribute. The plan is to use this to enable GPU compilation pipeline
for OpenCL kernels later.

The changes do not impact Vulkan shaders using milr-vulkan-runner.
New GPU Dialect transform pass spirv-attach-target is implemented for
attaching attribute from CLI.

gpu-module-to-binary pass now works with GPU module that has SPIR-V
module with OpenCL kernel functions inside.
2023-11-05 08:11:53 -08:00
Finn Plummer
6ddc03d97c
[mlir][spirv][webgpu] Add lowering of IAddCarry to IAdd (#68495)
WebGPU does not currently support extended arithmetic, this is an issue
when we want to lower from SPIR-V. This commit adds a pattern to
transform and emulate spirv.IAddCarry with spirv.IAdd operations

Fixes #65154
2023-10-19 15:59:04 -07:00
Jakub Kuderski
94189e101c
[mlir][spirv] Implement missing validation rules for ptr variables (#67871)
Variables that point to physical storage buffer require aliasing
decorations. This is specified by the `SPV_KHR_physical_storage_buffer`
extension.

Also add an example of a variable with a decoration attribute.
2023-09-30 00:21:28 -04:00
Jakub Kuderski
d13da154a7
[mlir][spirv] Define KHR cooperative matrix properties (#66823) 2023-09-19 17:50:22 -04:00
Jakub Kuderski
ab2c104518
[mlir][spirv] Suffix NV cooperative matrix props with _nv (#66820)
This is in preparation for adding a KHR variant which does not share the
same parameters and needs a separate attribute.
2023-09-19 17:45:14 -04:00
Jakub Kuderski
12175bcbce
[mlir][spirv] Support coop matrix in spirv.CompositeConstruct (#66399)
Also improve the documentation (code and website).
2023-09-14 16:57:59 -04:00
Jakub Kuderski
4c4bdf0c3a
[mlir][spirv] Fix remaining coop matrix verification corner cases (#66137)
- Check `MakePointer*` load/store attribute values.
- Support coop matrix types in `MatrixTimesScalar` verification.
- Add test cases for all the remaining ops that accept coop matrix types.
- Split NV and KHR tests.
2023-09-12 17:04:03 -04:00
Jakub Kuderski
08425def7d
[mlir][spirv] Improve coop matrix attribute handling (#66020)
- Fix values of Matrix Operand bit enums.
- Add verification for the aligned Memory Operand attributes. Mark the
'Aligned' enumerant as not supported.

The target test passes validation with `spirv-val`.
2023-09-12 11:05:08 -04:00
Jakub Kuderski
1258c3f214
[mlir][spirv] Support spirv.coopmatrix type (de-)serialization (#65831)
Extend SPIR-V target serialization and deserialization to handle coop
matrix types. Add a roundtrip test. In addition to `FileCheck` checks,
the resulting spirv binary also passes `spir-val` (external tool).

Also fix a type attribute bug surfaced by the `CooperativeMatrixLength`
op.

Multiple matrix operand attributes will be handled in a future patch to
reduce the scope.
2023-09-11 12:23:18 -04:00
Jakub Kuderski
af9dafeb38
[mlir][spirv] Fix coop matrix store (#65709)
- Fix operand/attribute order
- Use ODS for parsing/printing
- Allow for stride to be any integer type
2023-09-08 13:58:29 -04:00
Jakub Kuderski
53b3be7ecb
[mlir][spirv] Fix coop matrix load (#65712)
- Fix order of operands/attributes
- Allow for stride to be any integer type
- Use ODS for parsing/printing
- Update examples and tests
- Fix a typo in SPIR-V tblgen code
2023-09-08 13:29:12 -04:00
Jakub Kuderski
c10434bbb5
[mlir][spirv] Add CooperativeMatrixMulAdd op (#65617)
This is the last remaining op from the `SPV_KHR_cooperative_matrix`
extension.
2023-09-07 12:44:20 -04:00
Ivan Butygin
5dce74817b [mlir][ub] Add poison support to CommonFolders.h
Return poison from foldBinary/unary if argument(s) is poison. Add ub dialect as dependency to affected dialects (arith, math, spirv, shape).
Add poison materialization to dialects. Add tests for some ops from each dialect.
Not all affected ops are covered as it will involve a huge copypaste.

Differential Revision: https://reviews.llvm.org/D159013
2023-09-07 12:30:29 +02:00
Jakub Kuderski
f1162fb677 [mlir][spirv] Add folds for BitwiseAnd and BitwiseOr
The newly folded patterns get produced by type emulation code, so we
cannot rely on the Arith folders handling these folds.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D159394
2023-09-04 13:12:40 -04:00
Mehdi Amini
363b655920 Finish renaming getOperandSegmentSizeAttr() from operand_segment_sizes to operandSegmentSizes
This renaming started with the native ODS support for properties, this is completing it.

A mass automated textual rename seems safe for most codebases.
Drop also the ods prefix to keep the accessors the same as they were before
this change:
 properties.odsOperandSegmentSizes
reverts back to:
 properties.operandSegementSizes

The ODS prefix was creating divergence between all the places and make it harder to
be consistent.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D157173
2023-08-09 19:37:01 -07:00
Jakub Kuderski
07f9a0ddd6 [mlir][spirv] Do not introduce vector<1xT> in UnifyAliasedResource
1-element vectors are not valid in SPIR-V and fail `Bitcast` op verification.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D156207
2023-07-25 11:30:18 -04:00
Jakub Kuderski
68cd1dbc2e [mlir][spirv] Add cooperative matrix store op
Implement cooperative matrix store for the `SPV_KHR_cooperative_matrix`
extension: https://github.com/KhronosGroup/SPIRV-Registry/blob/master/extensions/KHR/SPV_KHR_cooperative_matrix.html.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D155631
2023-07-19 11:01:09 -04:00
Jakub Kuderski
1fa9e150b4 [mlir][spirv] Add cooperative matrix load op
Implement cooperative matrix load for the `SPV_KHR_cooperative_matrix`
extension: https://github.com/KhronosGroup/SPIRV-Registry/blob/master/extensions/KHR/SPV_KHR_cooperative_matrix.html.

Also some minor fixes in common code for custom parsing.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D155616
2023-07-19 10:55:27 -04:00
Jakub Kuderski
4ba61f5a30 [mlirv][spirv] Add KHR Cooperative Matrix type and extension
Start plumbing through support for the `SPV_KHR_cooperative_matrix`
extension: https://github.com/KhronosGroup/SPIRV-Registry/blob/master/extensions/KHR/SPV_KHR_cooperative_matrix.html.

Register the extension, add new coop matrix type, and add
`spirv.KHR.CooperativeMatrixLength` op to exercise it.

Make sure that mixing of the KHR and NV coop matrix extensions is not
allowed. Make cast verification more robust.

Reviewed By: antiagainst, qedawkins

Differential Revision: https://reviews.llvm.org/D154877
2023-07-12 21:11:08 -04:00
Jakub Kuderski
1d51597870 [mlir][spirv] Add missing NV prefix/suffix for coop matrix
This is in preparation for adding the KHR version of the cooperative
matrix extension, `SPV_KHR_cooperative_matrix`, that comes with
equivalent ops and type. These are not cross-extension compatible,
so it's better to add prefixes/suffixes to the Nvidia one,
`SPV_NV_cooperative_matrix`, before adding the KHR counterparts.

In near future, I plan for these two extensions to co-exist in
the SPIR-V dialect, but we may want to remove the NV one at some point.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D154799
2023-07-10 10:06:24 -04:00
Nishant Patel
0e3426f3fe [mlir][spirv] Add a canonicalization pattern for UModOp
Add a transformation for a pattern like

%6 = "spirv.Constant"() <{value = 32 : i32}> : () -> i32
%7 = "spirv.UMod"(%5, %6) : (i32, i32) -> i32
%8 = "spirv.Constant"() <{value = 4 : i32}> : () -> i32
%9 = "spirv.UMod"(%7, %8) : (i32, i32) -> i32

to transform to

%6 = "spirv.Constant"() <{value = 32 : i32}> : () -> i32
%7 = "spirv.UMod"(%5, %6) : (i32, i32) -> i32
%8 = "spirv.Constant"() <{value = 4 : i32}> : () -> i32
%9= "spirv.UMod"(%5, %8) : (i32, i32) -> i32

Patch By: nbpatel
Reviewed By: antiagainst, kuhar

Differential Revision: https://reviews.llvm.org/D152341
2023-06-08 10:32:01 -04:00
Dimple Prajapati
8939b5f5d2 [mlir][spirv] Add printf op from SPIRV OpenCL extension set spec
This change adds op to support printf instruction from OpenCL extensions set.
This op helps writing out debug details from SPIRV kernel in a given format.

Patch By: drprajap
Reviewed By: antiagainst, kuhar

Differential Revision: https://reviews.llvm.org/D151731
2023-05-31 16:44:14 -04:00