439 Commits

Author SHA1 Message Date
Amy Wang
334873fe2d
[MLIR][Python] Python binding support for IntegerSet attribute (#107640)
Support IntegerSet attribute python binding.
2024-09-11 07:37:35 -04:00
Sergey Kozub
918222ba43
[MLIR] Add f6E3M2FN type (#105573)
This PR adds `f6E3M2FN` type to mlir.

`f6E3M2FN` type is proposed in [OpenCompute MX
Specification](https://www.opencompute.org/documents/ocp-microscaling-formats-mx-v1-0-spec-final-pdf).
It defines a 6-bit floating point number with bit layout S1E3M2. Unlike
IEEE-754 types, there are no infinity or NaN values.

```c
f6E3M2FN
- Exponent bias: 3
- Maximum stored exponent value: 7 (binary 111)
- Maximum unbiased exponent value: 7 - 3 = 4
- Minimum stored exponent value: 1 (binary 001)
- Minimum unbiased exponent value: 1 − 3 = −2
- Has Positive and Negative zero
- Doesn't have infinity
- Doesn't have NaNs

Additional details:
- Zeros (+/-): S.000.00
- Max normal number: S.111.11 = ±2^(4) x (1 + 0.75) = ±28
- Min normal number: S.001.00 = ±2^(-2) = ±0.25
- Max subnormal number: S.000.11 = ±2^(-2) x 0.75 = ±0.1875
- Min subnormal number: S.000.01 = ±2^(-2) x 0.25 = ±0.0625
```

Related PRs:
- [PR-94735](https://github.com/llvm/llvm-project/pull/94735) [APFloat]
Add APFloat support for FP6 data types
- [PR-97118](https://github.com/llvm/llvm-project/pull/97118) [MLIR] Add
f8E4M3 type - was used as a template for this PR
2024-09-10 10:41:05 +02:00
Matt Hofmann
ad89e617c7
[MLIR][Python] Fix detached operation coming from IfOp constructor (#107286)
Without this fix, `scf.if` operations would be created without a parent.
Since `scf.if` operations often have no results, this caused silent bugs
where the generated code was straight-up missing the operation.
2024-09-05 00:12:03 -04:00
Kasper Nielsen
3766ba44a8
[mlir][python] Fix how the mlir variadic Python accessor _ods_equally_sized_accessor is used (#101132) (#106003)
As reported in https://github.com/llvm/llvm-project/issues/101132, this
fixes two bugs:

1. When accessing variadic operands inside an operation, it must be
accessed as `self.operation.operands` instead of `operation.operands`
2. The implementation of the `equally_sized_accessor` function is doing
wrong arithmetics when calculating the resulting index and group sizes.

I have added a test for the `equally_sized_accessor` function, which did
not have a test previously.
2024-08-31 03:17:33 -04:00
PhrygianGates
c8cac33ad2
[MLIR][Python] add f8E5M2 and tests for np_to_memref (#106028)
add f8E5M2 and tests for np_to_memref

---------

Co-authored-by: Zhicheng Xiong <zhichengx@dc2-sim-c01-215.nvidia.com>
2024-08-26 21:40:38 -05:00
Christopher Bate
92e00af432
[mlir] NFC: add missing 'FloatType' to core Python stub file (#105554)
The stub class for `FloatType` is present in `ir.pyi`, but it is missing
from the `__all__` export list.
2024-08-25 18:51:22 -06:00
Bimo
f5f0055a77
[MLIR][Python] remove unused init python file (#104890)
remove unused `__init__.py` under `mlir/python/mlir/extras`
2024-08-20 16:13:08 +08:00
Bimo
4eefc8d4ce
[MLIR][Python] enhance python api for tensor.empty (#103087)
Since we have extended `EmptyOp`, maybe we should also provide a
corresponding `tensor.empty` method. In the downstream usage, I tend to
use APIs with all lowercase letters to create ops, so having a
`tensor.empty` to replace the extended `tensor.EmptyOp` would keep my
code style consistent.
2024-08-19 09:06:48 +08:00
zhicong zhong
558d7adaae
[mlir][linalg] fix linalg.batch_reduce_matmul auto cast (#102585)
Fix the auto-cast of `linalg.batch_reduce_matmul` from `cast_to_T(A *
cast_to_T(B)) + C` to `cast_to_T(A) * cast_to_T(B) + C`
2024-08-12 14:37:57 +08:00
Nhat Nguyen
d60008d861
[mlir] [python] Update PyYAML minimum version to 5.4 and limit ml_dtypes to 0.4.0 (#102178)
PyYAML 5.3.1 has a security vulnerability as described here:
https://nvd.nist.gov/vuln/detail/CVE-2020-14343. Update the minimum
PyYAML version to 5.4. Also limit ml_dtypes version to 0.4.0.
2024-08-07 08:24:15 -07:00
Alexander Pivovarov
eef1d7e377
[MLIR] Add f8E3M4 IEEE 754 type (#101230)
This PR adds `f8E3M4` type to mlir.

`f8E3M4` type  follows IEEE 754 convention

```c
f8E3M4 (IEEE 754)
- Exponent bias: 3
- Maximum stored exponent value: 6 (binary 110)
- Maximum unbiased exponent value: 6 - 3 = 3
- Minimum stored exponent value: 1 (binary 001)
- Minimum unbiased exponent value: 1 − 3 = −2
- Precision specifies the total number of bits used for the significand (mantissa), 
    including implicit leading integer bit = 4 + 1 = 5
- Follows IEEE 754 conventions for representation of special values
- Has Positive and Negative zero
- Has Positive and Negative infinity
- Has NaNs

Additional details:
- Max exp (unbiased): 3
- Min exp (unbiased): -2
- Infinities (+/-): S.111.0000
- Zeros (+/-): S.000.0000
- NaNs: S.111.{0,1}⁴ except S.111.0000
- Max normal number: S.110.1111 = +/-2^(6-3) x (1 + 15/16) = +/-2^3 x 31 x 2^(-4) = +/-15.5
- Min normal number: S.001.0000 = +/-2^(1-3) x (1 + 0) = +/-2^(-2)
- Max subnormal number: S.000.1111 = +/-2^(-2) x 15/16 = +/-2^(-2) x 15 x 2^(-4) = +/-15 x 2^(-6)
- Min subnormal number: S.000.0001 = +/-2^(-2) x 1/16 =  +/-2^(-2) x 2^(-4) = +/-2^(-6)
```

Related PRs:
- [PR-99698](https://github.com/llvm/llvm-project/pull/99698) [APFloat]
Add support for f8E3M4 IEEE 754 type
- [PR-97118](https://github.com/llvm/llvm-project/pull/97118) [MLIR] Add
f8E4M3 IEEE 754 type
2024-08-02 00:22:11 -07:00
Bimo
5ef087b705
Reapply "[MLIR][Python] add ctype python binding support for bf16" (#101271)
Reapply the PR which was reverted due to built-bots, and now the bots
get updated.
https://discourse.llvm.org/t/need-a-help-with-the-built-bots/79437
original PR: https://github.com/llvm/llvm-project/pull/92489, reverted
in https://github.com/llvm/llvm-project/pull/93771
2024-07-31 10:24:27 +02:00
Alexander Pivovarov
019136e30f
[MLIR] Add f8E4M3 IEEE 754 type (#97118)
This PR adds `f8E4M3` type to mlir.

`f8E4M3` type  follows IEEE 754 convention

```c
f8E4M3 (IEEE 754)
- Exponent bias: 7
- Maximum stored exponent value: 14 (binary 1110)
- Maximum unbiased exponent value: 14 - 7 = 7
- Minimum stored exponent value: 1 (binary 0001)
- Minimum unbiased exponent value: 1 − 7 = −6
- Precision specifies the total number of bits used for the significand (mantisa), 
    including implicit leading integer bit = 3 + 1 = 4
- Follows IEEE 754 conventions for representation of special values
- Has Positive and Negative zero
- Has Positive and Negative infinity
- Has NaNs

Additional details:
- Max exp (unbiased): 7
- Min exp (unbiased): -6
- Infinities (+/-): S.1111.000
- Zeros (+/-): S.0000.000
- NaNs: S.1111.{001, 010, 011, 100, 101, 110, 111}
- Max normal number: S.1110.111 = +/-2^(7) x (1 + 0.875) = +/-240
- Min normal number: S.0001.000 = +/-2^(-6)
- Max subnormal number: S.0000.111 = +/-2^(-6) x 0.875 = +/-2^(-9) x 7
- Min subnormal number: S.0000.001 = +/-2^(-6) x 0.125 = +/-2^(-9)
```

Related PRs:
- [PR-97179](https://github.com/llvm/llvm-project/pull/97179) [APFloat]
Add support for f8E4M3 IEEE 754 type
2024-07-22 23:20:28 -07:00
Renato Golin
de3e9d4138
[MLIR][Linalg] Fix named structured ops yaml file (#98865)
Added missing reciprocal to Python file and fixed ErfOp name in yaml
file. Now running the bash script yields the same output.
2024-07-15 09:30:56 +01:00
Renato Golin
80e61e3842
Remove redundant linalg.matmul_signed (#98615)
`linalg.matmul` already has an attribute for casts, defaults to signed
but allowed unsigned, so the operation `linalg.matmul_unsigned` is
redundant. The generalization test has an example on how to lower to
unsigned matmul in linalg.

This is the first PR in a list of many that will simplify the linalg
operations by using similar attributes.

Ref:
https://discourse.llvm.org/t/rfc-transpose-attribute-for-linalg-matmul-operations/80092
2024-07-13 14:46:44 +01:00
Bimo
bfa762a5a5
[MLIR][Python] fix class name of powf and negf in linalg (#97696)
The following logic can lead to a class name mismatch when using
`linalg.powf` in Python. This PR fixed the issue and also renamed
`NegfOp` to `NegFOp` in linalg to adhere to the naming convention, as
exemplified by `arith::NegFOp`.


173514d58e/mlir/python/mlir/dialects/linalg/opdsl/lang/dsl.py (L140-L143)
```
# linalg.powf(arg0, arg1, outs=[init_result.result])
NotImplementedError: Unknown named op_name / op_class_name: powf / PowfOp
```
2024-07-05 09:23:12 +08:00
Alexander Pivovarov
2628a5fd24
Rename f8E4M3 to f8E4M3FN in mlir.extras.types py package (#97102)
Currently `f8E4M3` is mapped to `Float8E4M3FNType`.

This PR renames `f8E4M3` to `f8E4M3FN` to accurately reflect the actual
type.

This PR is needed to avoid names conflict in upcoming PR which will add
IEEE 754 `Float8E4M3Type`.
https://github.com/llvm/llvm-project/pull/97118 Add f8E4M3 IEEE 754 type

Maksim, can you review this PR? @makslevental ?
2024-06-29 12:48:11 -07:00
muneebkhan85
a9efcbf490
[MLIR] Add continuous tiling to transform dialect (#82792)
This patch enables continuous tiling of a target structured op using
diminishing tile sizes. In cases where the tensor dimensions are not
exactly divisible by the tile size, we are left with leftover tensor
chunks that are irregularly tiled. This approach enables tiling of the
leftover chunk with a smaller tile size and repeats this process
recursively using exponentially diminishing tile sizes. This eventually
generates a chain of loops that apply tiling using diminishing tile
sizes.

Adds `continuous_tile_sizes` op to the transform dialect. This op, when
given a tile size and a dimension, computes a series of diminishing tile
sizes that can be used to tile the target along the given dimension.
Additionally, this op also generates a series of chunk sizes that the
corresponding tile sizes should be applied to along the given dimension.

Adds `multiway` attribute to `transform.structured.split` that enables
multiway splitting of a single target op along the given dimension, as
specified in a list enumerating the chunk sizes.
2024-06-21 16:39:43 +02:00
Jonas Rickert
abad8455ab
[mlir] Expose skipRegions option for Op printing in the C and Python bindings (#96150)
The MLIR C and Python Bindings expose various methods from
`mlir::OpPrintingFlags` . This PR adds a binding for the `skipRegions`
method, which allows to skip the printing of Regions when printing Ops.
It also exposes this option as parameter in the python `get_asm` and
`print` methods
2024-06-20 10:15:08 -05:00
Maksim Levental
91175313d4
[MLIR][python] include Rewrite.h (#95226) 2024-06-12 07:17:13 -05:00
Jacques Pienaar
18cf1cd92b
[mlir] Add PDL C & Python usage (#94714)
Following a rather direct approach to expose PDL usage from C and then
Python. This doesn't yes plumb through adding support for custom
matchers through this interface, so constrained to basics initially.

This also exposes greedy rewrite driver. Only way currently to define
patterns is via PDL (just to keep small). The creation of the PDL
pattern module could be improved to avoid folks potentially accessing
the module used to construct it post construction. No ergonomic work
done yet.

---------

Signed-off-by: Jacques Pienaar <jpienaar@google.com>
2024-06-11 07:45:12 -07:00
Sergei Lebedev
bc5ced54cc
Updated the annotations of Python bindings (#92733) 2024-06-11 08:46:43 -05:00
Egor Ospadov
367d50278a
[mlir][python] Fix attribute registration in ir.py (#94615)
This PR fixes attribute registration for `SI8Attr` and `UI8Attr` in
`ir.py`.
2024-06-09 22:06:46 -05:00
Mehdi Amini
e6821dd8c8
Revert "[MLIR][Python] add ctype python binding support for bf16" (#93771)
Reverts llvm/llvm-project#92489

This broke the bots.
2024-05-29 23:21:04 -06:00
Bimo
89801c74c3
[MLIR][Python] add ctype python binding support for bf16 (#92489)
Since bf16 is supported by mlir, similar to
complex128/complex64/float16, we need an implementation of bf16 ctype in
Python binding. Furthermore, to resolve the absence of bf16 support in
NumPy, a third-party package [ml_dtypes
](https://github.com/jax-ml/ml_dtypes) is introduced to add bf16
extension, and the same approach was used in `torch-mlir` project.

See motivation and discussion in:
https://discourse.llvm.org/t/how-to-run-executionengine-with-bf16-dtype-in-mlir-python-bindings/79025
2024-05-29 22:01:40 -07:00
zjgarvey
42a0fb2333
[mlir][linalg] Add linalg.conv_2d_ngchw_gfchw_q to named ops (#92136)
Adds a named op: linalg.conv_2d_ngchw_gfchw_q. This op is similar to
linalg.conv_2d_ngchw_gfchw, but additionally incorporates zero point
offset corrections.
2024-05-29 12:55:05 +02:00
Guray Ozen
7f58ffd09b
[mlir][python] Yield results of scf.for_ (#93610)
Using `for_` is very hand with python bindings. Currently, it doesn't
support results, we had to fallback to two lines scf.for.

This PR yields results of scf.for in `for_`

---------

Co-authored-by: Maksim Levental <maksim.levental@gmail.com>
2024-05-29 08:43:13 +02:00
Oleksandr "Alex" Zinenko
04c94ba65f
[mlir][py] NFC: remove exception-based isa from linalg module (#92556)
When this code was written, we didn't have proper isinstance support for
operation classes in Python. Now we do, so there is no reason to keep
the expensive exception-based flow.
2024-05-24 09:02:17 +02:00
Petr Kurapov
e7d09cecc9
[MLIR][Linalg] Ternary Op & Linalg select (#91461)
Following #90236, adding `select` to linalg as `arith.select`. No
implicit type casting.
OpDSL doesn't expose a type restriction for bool, but I saw no reason in
adding it (put a separate symbolic type and check the semantics in the
builder).

---------

Co-authored-by: Renato Golin <rengolin@systemcall.eu>
Co-authored-by: Maksim Levental <maksim.levental@gmail.com>
2024-05-14 10:50:35 +01:00
tyb0807
baa5beecc0
[NFC] Make NVGPU casing consistent (#91903) 2024-05-13 09:08:04 +02:00
Yuanqiang Liu
10ec0d2089
[MLIR] fix _f64ElementsAttr in ir.py (#91176) 2024-05-06 20:08:47 +08:00
srcarroll
f2f65eddc5
[mlir][transform] Add support for transform.param pad multiples in PadOp (#90755)
This patch modifies the definition of `PadOp` to take transform params
and handles for the `pad_to_multiple_of` operand.

---------

Co-authored-by: Oleksandr "Alex" Zinenko <ftynse@gmail.com>
2024-05-04 17:34:40 -05:00
Renato Golin
5e3032638e
[MLIR][Linalg] Left over Linalg named ops from previous PR (#90405)
Adding `erf` as unary and `powf` as binary.

Same as `max(arg, 0.0)` for `ReLU`, `powf(arg, const)` can be either a
generic (with broadcast) or a pair (`linalg.broadcast + linalg.powf`)
and then lowered "correctly". Either way, the lower dialects need to
know what kind of broadcast anyway, so no materialization of the
constant tensors should remain.

I want to flush the easy ones before we start working on type cast &
softmax.
2024-04-29 15:42:35 +01:00
Renato Golin
4cec3b36f6
[MLIR][Linalg] More Linalg named ops (#90236)
Adding `min` that was already implemented but not exposed.

Adding a few additional unary ops:
* Reciprocal as `arith.div(1,arg)`
* Round as `math.round(arg)`
* Sqrt as `math.sqrt(arg)`
* Rsqrt as `math.rsqrt(arg)`
* Square as `math.powf(arg, 2)`
* TanH as `math.tanh(arg)`

All with the agreed semantics at the round table: no implicit
broadcast/type cast.
2024-04-28 15:25:24 +01:00
Oleksandr "Alex" Zinenko
ff57f40673
[mlir][py] fix option passing in transform interpreter (#89922)
There was a typo in dispatch trampoline.
2024-04-24 19:40:53 +02:00
Maksim Levental
79d4d16563
[mlir][python] extend LLVM bindings (#89797)
Add bindings for LLVM pointer type.
2024-04-24 07:43:05 -05:00
Abhishek Kulkarni
37fe3c6788
[mlir][python] Fix generation of Python bindings for async dialect (#75960)
The Python bindings generated for "async" dialect didn't include any of
the "async" dialect ops. This PR fixes issues with generation of Python
bindings for "async" dialect and adds a test case to use them.
2024-04-20 20:49:39 -05:00
Maksim Levental
7c3dfb29dc
[mlir][python] fix memref._is_constant_int_like (#89447) 2024-04-19 16:52:04 -05:00
Maksim Levental
6e6da74c8b
[mlir][python] add binding to #gpu.object (#88992) 2024-04-18 16:31:55 -05:00
Guray Ozen
4f88c23111
[mlir][py] Add NVGPU's TensorMapDescriptorType in py bindings (#88855)
This PR adds NVGPU dialects' TensorMapDescriptorType in the py bindings.

This is a follow-up issue from [this
PR](https://github.com/llvm/llvm-project/pull/87153#discussion_r1546193095)
2024-04-17 15:59:18 +02:00
Oleksandr "Alex" Zinenko
73140daebb
[mlir] expose transform dialect symbol merge to python (#87690)
This functionality is available in C++, make it available in Python
directly to operate on transform modules.
2024-04-17 15:01:59 +02:00
Kirill Podoprigora
4cd7bb07c7
[mlir] Remove `dataclasses package from mlir requirements.txt` (#87223)
The ``dataclasses`` package makes sense for Python 3.6, becauses
``dataclasses`` is only included in the standard library with 3.7
version. Now, 3.6 has reached EOL, so all current supported versions of
Python (3.8, 3.9, 3.10, 3.11, 3.12) have this feature in their standard
libraries.

Therefore there's no need to install the ``dataclasses`` package now.
2024-04-01 12:07:10 -07:00
Steven Varoumas
eb861acd49
[mlir][python] Enable python bindings for Index dialect (#85827)
This small patch enables python bindings for the index dialect.

---------

Co-authored-by: Steven Varoumas <steven.varoumas1@huawei.com>
2024-03-20 16:56:22 +01:00
Oleksandr "Alex" Zinenko
5d59fa90ce
Reapply "[mlir][py] better support for arith.constant construction" (#84142)
Arithmetic constants for vector types can be constructed from objects
implementing Python buffer protocol such as `array.array`. Note that
until Python 3.12, there is no typing support for buffer protocol
implementers, so the annotations use array explicitly.

Reverts llvm/llvm-project#84103
2024-03-07 17:14:08 +01:00
Mehdi Amini
96fc54828a
Revert "[mlir][py] better support for arith.constant construction" (#84103)
Reverts llvm/llvm-project#83259

This broke an integration test on Windows
2024-03-05 18:57:45 -08:00
Oleksandr "Alex" Zinenko
a691f65a84
[mlir][py] better support for arith.constant construction (#83259)
Arithmetic constants for vector types can be constructed from objects
implementing Python buffer protocol such as `array.array`. Note that
until Python 3.12, there is no typing support for buffer protocol
implementers, so the annotations use array explicitly.
2024-03-05 16:09:59 +01:00
Sergei Lebedev
6ce5159945
[MLIR][Python] Use ir.Value directly instead of _SubClassValueT (#82341)
_SubClassValueT is only useful when it is has >1 usage in a signature.
This was not true for the signatures produced by tblgen.

For example

def call(result, callee, operands_, *, loc=None, ip=None) ->
_SubClassValueT:
        ...

here a type checker does not have enough information to infer a type
argument for _SubClassValueT, and thus effectively treats it as Any.
2024-02-21 12:59:23 +01:00
Oleksandr "Alex" Zinenko
91f1161133
[mlir] expose transform interpreter to Python (#82365)
Transform interpreter functionality can be used standalone without going
through the interpreter pass, make it available in Python.
2024-02-21 11:01:00 +01:00
Oleksandr "Alex" Zinenko
bd8fcf75df
[mlir][python] expose LLVMStructType API (#81672)
Expose the API for constructing and inspecting StructTypes from the LLVM
dialect. Separate constructor methods are used instead of overloads for
better readability, similarly to IntegerType.
2024-02-14 15:03:04 +01:00
Sergei Lebedev
82f3cbc860
[MLIR][Python] Added a base class to all builtin floating point types (#81720)
This allows to

* check if a given ir.Type is a floating point type via isinstance() or
issubclass()
* get the bitwidth of a floating point type

See motivation and discussion in
https://discourse.llvm.org/t/add-floattype-to-mlir-python-bindings/76959.
2024-02-14 13:02:49 +01:00