191 Commits

Author SHA1 Message Date
Jerry-Ge
64b060f129
[mlir][tosa] Update URLs to TOSA specification (#134449)
- The existing URLs are no longer valid, updated to the current one

Signed-off-by: Jerry Ge <jerry.ge@arm.com>
2025-04-04 15:41:05 -07:00
Elen Kalda
c2355892a4
[mlir][tosa] Add ERROR_IF checks to TRANSPOSE_CONV2D verifier (#133234)
This patch extends the verifier with following checks:

ERROR_IF(out_pad_top <= -KH || out_pad_bottom <= -KH);
ERROR_IF(out_pad_left <= -KW || out_pad_right <= -KW); ERROR_IF(stride_y
< 1 || stride_x < 1);
ERROR_IF(OH != (IH - 1) * stride_y + out_pad_top + out_pad_bottom + KH);
ERROR_IF(OW != (IW - 1) * stride_x + out_pad_left + out_pad_right + KW);
ERROR_IF(BC != OC && BC != 1);

Signed-off-by: Elen Kalda <elen.kalda@arm.com>
2025-04-03 14:04:28 +01:00
Jack Frankland
6f324bd39b
[mlir][tosa] Remove Convolution Type Verifiers (#134077)
Remove the test in the convolution verifier that checks the input and
output element types of convolution operations conform to the
constraints imposed by the TOSA 1.0 specification.

These checks are too strict for users of the TOSA dialect who wish to
allow more types than those allowed by the spec and provide
compatibility issues with earlier TOSA implementation which allowed more
type combinations.

Users who do wish to constrain the convolution types combination to only
those allowed by the TOSA 1.0 spec should run the TOSA validation pass
which already performs these checks.

Signed-off-by: Jack Frankland <jack.frankland@arm.com>
2025-04-03 10:30:10 +01:00
Luke Hutton
0c34d7a9e7
[mlir][tosa] Require operand/result tensors of at least rank 1 for some operations (#131335)
This commit updates the following operations (operands/results) to be of
at least rank 1 such that it aligns with the expectations of the
specification:
- ARGMAX (input)
- REDUCE_ALL (input/output)
- REDUCE_ANY (input/output)
- REDUCE_MAX (input/output)
- REDUCE_MIN (input/output)
- REDUCE_PRODUCT (input/output)
- REDUCE_SUM (input/output)
- CONCAT (each input in input1/output)
- PAD (input1/output)
- REVERSE (input1/output)
- SLICE (input1/output)
- TILE (input1/output)
- TRANSPOSE (input1/output)

In addition to this change, PAD has been updated to allow unranked
tensors for input1/output, inline with other operations.
2025-03-17 10:22:52 +00:00
Luke Hutton
1c45514748
[mlir][tosa] Fix bug causing quantized pad const creation crash (#131125)
This commit ensures the storage type is retrieved correctly which fixes
a crash when creating a quantized pad const tensor.

Testing is completed via the `tosa-optional-decompositions` pass which
makes use of the `createPadConstTensor` function.

Also includes some cleanup.
2025-03-13 13:17:47 -07:00
Luke Hutton
c44c905174
[mlir][tosa] Add error if verification to pooling operators (#130052)
This commit adds the following checks to avg_pool2d and max_pool2d TOSA
operations:
- check kernel values are >= 1
- check stride values are >= 1
- check padding values are >= 0
- check padding values are less than kernel sizes
- check output shape matches the expected output shape

Signed-off-by: Luke Hutton <luke.hutton@arm.com>
2025-03-12 10:48:33 -07:00
Tai Ly
913d077f29
[mlir][tosa] Change Rescale zero points to be inputs (#130340)
*Update RescaleOp to use zero-point as operands instead of attributes.
 *Check input_zp data type against the input and output_zp data type
   against the output.

Signed-off-by: Peng Sun <peng.sun@arm.com>
Co-authored-by: Peng Sun <peng.sun@arm.com>
2025-03-11 13:19:49 +00:00
Tai Ly
483c23f6e8
[mlir][tosa] Switch zero point of negate to input variable type (#129758)
This commit changes the zero point attribute to an input to align with
the 1.0 spec.

Signed-off-by: Tai Ly <tai.ly@arm.com>
Co-authored-by: Luke Hutton <luke.hutton@arm.com>
2025-03-10 18:34:16 +00:00
Luke Hutton
933221e55a
[mlir][tosa] Rename RFFT2D input to input_real (#130614)
This is to align to the input name as defined in the specification.

Signed-off-by: Luke Hutton <luke.hutton@arm.com>
2025-03-10 18:14:49 +00:00
Tai Ly
dfbadfc5e5
[mlir][tosa] Change MatMul zero-point to inputs (#130332)
* Change zero-point attributes to inputs
* Fix relevant mlir tests
* Enhance ShardingInterface in MatMul

Signed-off-by: Udaya Ranga <udaya.ranga@arm.com>
Co-authored-by: Udaya Ranga <udaya.ranga@arm.com>
2025-03-07 12:37:28 -08:00
Jerry-Ge
2619c2ed58
Revert "[mlir][tosa] Change MatMul zero-point to inputs" (#130330)
Reverts llvm/llvm-project#129785. Need rebase.
2025-03-07 11:03:38 -08:00
Tai Ly
106c96462f
[mlir][tosa] Change MatMul zero-point to inputs (#129785)
* Change zero-point attributes to inputs
* Fix relevant mlir tests
* Enhance ShardingInterface in MatMul

Signed-off-by: Udaya Ranga <udaya.ranga@arm.com>
Co-authored-by: Udaya Ranga <udaya.ranga@arm.com>
2025-03-07 10:46:25 -08:00
Jerry-Ge
ca582b1684
[mlir][tosa] Add FP8 lit tests (#127730)
Add FP8 lit tests to the following operators:

ARGMAX
AVGPOOL
CONV2D
CONV3D
DEPTHWISE_CONV2D
MATMUL
MAX_POOL2D
TRANSPOSE_CONV2D
CONST
CAST
CONCAT
PAD
RESHAPE
REVERSE
SLICE
TILE
TRANSPOSE
GATHER
SCATTER

Signed-off-by: Tai Ly <tai.ly@arm.com>
Signed-off-by: Jerry Ge <jerry.ge@arm.com>
Co-authored-by: Tai Ly <tai.ly@arm.com>
2025-03-07 10:36:27 -08:00
Peng Sun
5685def507
[mlir][tosa] Convert RESCALE op multiplier and shift from attributes to inputs (#129720) 2025-03-07 15:59:29 +00:00
Thomas Preud'homme
9d191f1182
[mlir][tosa] Fix RFFT2D verifier for width=1 (#130279)
Current formula assumes width is a multiple of 2 but TOSA only requires
a power of 2, which 1 is.
2025-03-07 13:14:55 +00:00
Jerry-Ge
472c2e3578
[mlir][tosa] Update value to values for ConstOp and ConstShapeOp (#129943)
Updated the dialect to match TOSA v1.0 specification for ConstOp and
ConstShapeOp (https://www.mlplatform.org/tosa/tosa_spec.html#_const).

Also updated lit tests

---------

Signed-off-by: Jerry Ge <jerry.ge@arm.com>
2025-03-06 14:55:50 -08:00
Luke Hutton
4f46b75fb0
[mlir][tosa] Add expected output shape check to argmax verifier (#129870)
Fixes some test cases which incorrectly declared the output shape and
added a negative test case.

Signed-off-by: Luke Hutton <luke.hutton@arm.com>
2025-03-06 09:40:19 +00:00
Jerry-Ge
db70d76082
[mlir][tosa] Add more verifiers for the following operators (#127923)
For ConcatOp this commit also enhances the verifier by
checking 4 another conditions:
- The input list is not empty
- The axis value is within range of the input shapes
- All inputs have the same rank
- All non concatenate axis dims have the same value

For MatmulOp:
- Checked input a, bs tensor type, element types

For the following operators, added the verifySameElementTypes check.
- PadOp
- SliceOp
- TileOp
- ReshapeOp
- TransposeOp
- GatherOp
- ScatterOp
- MaxPool2dOp
- ReverseOp
- SelectOp

Signed-off-by: Jerry Ge <jerry.ge@arm.com>
Co-authored-by: Tai Ly <tai.ly@arm.com>
Co-authored-by: Luke Hutton <luke.hutton@arm.com>
2025-03-05 10:12:20 -08:00
Jerry-Ge
7e10ecd29a
[mlir][tosa] Remove optional for pad_const and remove input_zp attr for PadOp (#129336)
Always generated pad_const and remove input_zp attr for PadOp. 

- Co-authored-by: Udaya Ranga <udaya.ranga@arm.com>
- Co-authored-by: Tai Ly <tai.ly@arm.com>

Signed-off-by: Jerry Ge <jerry.ge@arm.com>
2025-03-05 08:33:13 -08:00
Jerry-Ge
2ae5dedd7a
[mlir][tosa] Update ControlFlow variable names to match with TOSA v1.0 spec (#129790) 2025-03-05 01:17:42 +00:00
Tai Ly
25a29cef31
[mlir][tosa] Switch zero point of avgpool2d to input variable type (#128983)
This commit changes the TOSA operator AvgPool2d's zero point attributes
to inputs to align with TOSA 1.0 spec.

Signed-off-by: Luke Hutton <luke.hutton@arm.com>
Co-authored-by: Luke Hutton <luke.hutton@arm.com>
2025-03-04 09:34:23 -08:00
Luke Hutton
079557c3d4
[mlir][tosa] Add verifiers for FFT2d and RFFT2d (#129273)
Adds checks for element types and input/output shapes.

Signed-off-by: Luke Hutton <luke.hutton@arm.com>
2025-03-03 10:26:19 -08:00
Jerry-Ge
f5749e7893
[mlir][tosa] Remove out_shape from transpose_conv2d (#129133) 2025-02-28 18:38:12 +00:00
Tai Ly
177ede2122
[mlir][tosa] Rename ReduceProd to ReduceProduct (#128751)
This patch renames TOSA ReduceProd operator to ReduceProduct to align
with the TOSA Spec 1.0

Signed-off-by: Tai Ly <tai.ly@arm.com>
2025-02-26 12:54:07 -08:00
Tai Ly
ca5bb238d0
[mlir][tosa] Change zero points of convolution ops to required inputs (#127679)
This patch changes the input_zp and weight_zp for convolution operators
to be required inputs
in order to align with the TOSA Spec 1.0.

Convolution operators affected are:
	CONV2D, CONV3D, DEPTHWISE_CONV2D, and TRANSPOSE_CONV2D.


Signed-off-by: Tai Ly <tai.ly@arm.com>
2025-02-26 12:50:20 -08:00
Luke Hutton
0ba2000b3c
[mlir][tosa] Enhance the conv2d verifier (#128693)
This commit adds additional checks to the conv2d verifier that check
error_if conditions from the tosa specification. Notably, it adds
padding, stride and dilation invalid value checking, output height and
width checking and bias size checking.

Signed-off-by: Luke Hutton <luke.hutton@arm.com>
2025-02-26 10:59:30 +00:00
Tai Ly
48db4e8377
[mlir][tosa] Change Transpose perms operand to attribute (#128115)
This patch changes the perms operand for Tosa Transpose operator to an
i32 array attribute

Signed-off-by: Tai Ly <tai.ly@arm.com>
2025-02-25 10:00:26 -08:00
Luke Hutton
a4656bbc59
[mlir][tosa] Allow conv ops zero point to be variable (#128533)
The TOSA specification allows the zero point of conv ops to be variable
when the dynamic extension is being used, but information about which
extensions are in use is only known when the validation pass is run. A
variable zero point should be allowed in the conv ops verifiers.

In terms of testing, there didn't seem to be an existing set of tests
for the verifiers to add this check to, so the opportunity has been
taken to run the verifiers on the tests in `ops.mlir`. Since the conv2d
test there had variable zero points, this change in functionality is
being tested.

Signed-off-by: Luke Hutton <luke.hutton@arm.com>
Co-authored-by: Georgios Pinitas <georgios.pinitas@arm.com>
2025-02-25 09:38:05 +00:00
TatWai Chong
11468c3b07
[mlir][tosa] Add profile-based operation validation (#126992)
TOSA MLIR profile-based validation is designed to identify the
profile/extension requirements for each operation in TOSA MLIR graph,
ensuring that TOSA operators conform to the profiles and extensions
enabled by the target implementation.

The available profiles/extensions are reflected in the availability
property attached to each TOSA operator in the dialect. The design of
availability, the profile/extension classes, and their interface, is
inspired by the SPIRV implementation.

This patch includes the following changes:
- Introduces profile and extension knowledge within the dialect and
establishes an interface to query this information.
 - Implements profile-based validation logic in the pass.
- Adds a TargetEnv class that represents the capabilities enabled in the
target implementation, such as profiles, extensions, and levels.
- Adds a set of tests to ensure that profile and extension requirements
are properly attached to the operations and that validation correctly
verifies the requirements of a given operation against the target
implementation.
2025-02-20 11:47:01 -08:00
Hsiangkai Wang
3430bc31a7
[mlir][tosa] Make TOSA RESIZE's scale, offset, border as Input (#124956)
Move the `scale`, `offset`, and `border` parameters of the RESIZE
operator in the MLIR TOSA dialect from attributes to inputs and update
lit tests appropriately.

Add the verifier of the `tosa::ResizeOp` operation.

---------

Co-authored-by: Tai Ly <tai.ly@arm.com>
Co-authored-by: Luke Hutton <luke.hutton@arm.com>
2025-02-18 16:01:50 -08:00
Jerry-Ge
4ec199035e
[mlir][tosa] Remove FullyConnectedOp from TOSA Dialect (#126152)
This patch removes FullyConncected Operator from the TOSA Dialect and
all associated tests and transforms.

This is part of the TOSA v1.0 alignment effort:
https://discourse.llvm.org/t/rfc-tosa-dialect-increment-to-v1-0/83708

Signed-off-by: Tai Ly <tai.ly@arm.com>
Co-authored-by: Tai Ly <tai.ly@arm.com>
2025-02-13 14:26:38 -08:00
Amir Bishara
51c847d8f3
[mlir][tosa]-Edit the verifier of tosa constShapeOp (#126962)
Add verification for rank 1 for the elements' attribute of the tosa
const_shape operation.
2025-02-12 15:06:00 -08:00
Tai Ly
20ae283d08
[mlir][tosa] Change the shift of mul to be required (#125297)
Change the shift operand for the mul operator to be a required operand.

Also defined shift to be Tosa_ScalarInt8Tensor which requires that it is
a rank-1 tensor
whose shape is [1] (ie, tensor containing a single element)

Signed-off-by: Tai Ly <tai.ly@arm.com>
2025-02-11 11:02:44 -08:00
Hsiangkai Wang
ab93bd6959
[mlir][tosa] Change ClampOp's min/max attributes (#125197)
This changes Tosa ClampOp attributes to min_val and max_val which are
either integer attributes or float attributes, and adds verify checks
that these attribute element types must match element types of input and
output

Co-authored-by: Tai Ly <tai.ly@arm.com>
2025-02-11 08:02:52 -08:00
Tai Ly
1a8d2a4016
[mlir][tosa] Use generic QuantizedType in Conv verifiers (#126275)
Replace UniformQuantizedType by the more generic QuantizedType in Conv verifiers.

Change-Id: Ie1961af931864f801914a62976bc988881ee075e

Signed-off-by: Tai Ly <tai.ly@arm.com>
Co-authored-by: Thibaut Goetghebuer-Planchon <thibaut.goetghebuer-planchon@arm.com>
2025-02-11 10:58:16 +00:00
Tai Ly
62ae876b1b
[mlir][tosa] Fix conv op build functions (#126321)
This patch fixes several issues:
  - buildConvOpWithQuantInfo: 
       call buildConvOpResultTypeInfo to get final output type
  - buildTransConvOpWithQuantInfo:
       add input_zp and weight_zp operands
       remove input_zp/weight_zp attributes
  - createZeroPointTensor:
       add getElementTypeOrSelf to get element type just in case
       remove bad auto-merge lines


Change-Id: Idbf88f500ce57a865da4b7be7b7b8bf2ba194b24

Signed-off-by: Tai Ly <tai.ly@arm.com>
2025-02-10 08:36:29 -08:00
TatWai Chong
571a98722f
[mlir][tosa] Change 'shape' of RESHAPE from attribute to input shape … (#125789)
The shape operand is changed to input shape type since V1.0

Change-Id: I508cc1d67e9b017048b3f29fecf202cb7d707110

Co-authored-by: Won Jeon <won.jeon@arm.com>
2025-02-07 10:24:52 -08:00
Jack Frankland
f0b8ff1251
[mlir][tosa] Remove Quantization Attribute (#125479)
Removed the TOSA quantization attribute used in various MLIR TOSA
dialect operations in favour of using builtin attributes.

Update any lit tests, conversions and transformations appropriately.

Signed-off-by: Tai Ly <tai.ly@arm.com>
Co-authored-by: Tai Ly <tai.ly@arm.com>
2025-02-05 11:27:17 +00:00
Jack Frankland
cc72042a94
[mlir][tosa] Make Convolution Zero Points Inputs (#122939)
The TOSA-v1.0 specification moves the "zero point" parameters of the
convolution operators CONV2D, CONV3D, DEPTHWISE_CONV2D, and
TRANSPOSE_CONV2D from attributes to inputs.

Make the zero points of the convolutions in the MLIR TOSA dialect inputs
and update any transformations, materializations and lit tests
appropriately.

Rename the "filter" argument of `tosa.transpose_conv2d` to weight to
align with the TOSA specification.

Remove the quantization_info attribute on the convolution operations.

Co-authored-by: TatWai Chong <tatwai.chong@arm.com>
2025-02-03 09:36:50 +00:00
Tai Ly
79df1c3c41
[mlir][tosa] Fix merge problems with mul shift (#125129)
This patch fixes merge issues in TosaOpBase.td and TosaOps.td wrt traits
on tosa elementwise ops and multiply op which, with the optional shift
operand, is no longer strictly an elementwise op.

fixed up inferReturnTypeComponents to be based on only the first two
operands (ie, ignoring shift, if present)

also fixed up TosaReduceTransposes to special handle tosa mul op now
that it is not an elementwise op.

Signed-off-by: Tai Ly <tai.ly@arm.com>
2025-01-30 19:59:12 -08:00
Jerry-Ge
956c0707d9
[mlir][tosa] Change the start and size of slice to tosa shape type (#124209)
Update to use getConstShapeValue to collect shape information along the
graph.

Change-Id: Ic6fc2341e3bcfbec06a1d08986e26dd08573bd9c

Co-authored-by: TatWai Chong <tatwai.chong@arm.com>
2025-01-29 13:43:35 -08:00
Jack Frankland
a58e774fba
[mlir][tosa] Make TOSA MUL's Shift an Input (#121953)
The TOSA-v1.0 specification makes the shift attribute of the MUL
(Hammard product) operator an input. Move the `shift` parameter of the
MUL operator in the MILR TOSA dialect from an attribute to an input and
update any lit tests appropriately.

Expand the verifier of the `tosa::MulOp` operation to check the various
constraints defined in the TOSA-v1.0 specification. Specifically, ensure
that all input operands (excluding the optional shift) are of the same
rank. This means that broadcasting tests which previously checked rank-0
tensors would be broadcast are no longer valid and are removed.

Signed-off-by: Jack Frankland <jack.frankland@arm.com>
Co-authored-by: TatWai Chong <tatwai.chong@arm.com>
2025-01-28 16:25:22 +00:00
Jerry-Ge
7e622b6132
[TOSA] Change PadOp padding to tosa.shape (#123133)
This patch changes PadOp's padding input to type !tosa.shape<2 * rank>,
(where rank is the rank of the PadOp's input), instead of a <rank x 2>
tensor.

This patch is also a part of TOSA v1.0 effort:
https://discourse.llvm.org/t/rfc-tosa-dialect-increment-to-v1-0/83708

This patch updates the PadOp to match all against the TOSA v1.0 form. 

Original Authors include: 
@Tai78641 
@wonjeon

Co-authored-by: Tai Ly <tai.ly@arm.com>
2025-01-22 12:36:48 -08:00
Tai Ly
7986e0cad1
[TOSA] bug fix infer shape for slice (#113497)
This fixes the infer output shape of TOSA slice op for start/size values
that are out-of-bound or -1

added tests to check:
  - size = -1
  - size is out of bound
  - start is out of bound

Signed-off-by: Tai Ly <tai.ly@arm.com>
2025-01-22 13:29:44 +00:00
Matthias Springer
7a77f14c0a
[mlir][IR] Remove isF...() type API for low-precision FP types (#123326)
Remove `type.isFloat4E2M1FN()` etc. Use `isa<Float4E2M1FNType>(type)`
instead.

For details, see:
https://discourse.llvm.org/t/rethink-on-approach-to-low-precision-fp-types/82361/28
2025-01-20 09:22:53 +01:00
Jerry-Ge
f09db6a3af
[TOSA] Add Tosa_Shape type and ConstShapeOp (#122547)
Adds:
1. tosa shape type to Tosa dialect e.g., !tosa.shape<4> is a type for
rank-4 shape values (size-4 array of index values)
 2. const_shape operator
3. trait TosaShapeOperator, added to tosa shape operators, and a
verifier that all operands and results of operator are tosa shapes
4. trait TosaResolvableShapeOperands, added to all tosa operators, and a
verifier that every tosa shape operand is produced by a tosa shape
operator (indicated by trait TosaShapeOperator)
5. trait TosaShapeOperatorWithSameRanks, added to
Tosa_ElementwiseShapeOp and a verifier that all operands and result
shapes have same ranks
5. changed TileOp's multiples from attribute to input, of !tosa.shape
type.
 6. add folder for tosa ConstShape operator

This patch was originally authored by Tai Ly <tai.ly@arm.com>

Signed-off-by: Jerry Ge <Jerry.Ge@arm.com>
Signed-off-by: Tai Ly <tai.ly@arm.com>
2025-01-14 13:41:08 -08:00
Jack Frankland
360a03c980
[mlir][tosa] Add acc_type to Tosa-v1.0 Conv Ops (#121466)
Tosa v1.0 adds accumulator type attributes to the various convolution
operations defined in the spec. Update the dialect and any lit tests to
include these attributes.

Signed-off-by: Tai Ly <tai.ly@arm.com>
Co-authored-by: Tai Ly <tai.ly@arm.com>
2025-01-08 12:12:26 +02:00
Longsheng Mou
c1d01b2fc2
[mlir][tosa] Add missing verifier for tosa.pad (#120934)
This PR adds a missing verifier for `tosa.pad`, ensuring that the
padding shape matches [2*rank(shape1)] according to V1.0.0
Specification. Fixes #119840.
2025-01-08 10:45:59 +02:00
Georgios Pinitas
8ad8db973e
Revert "[TOSA] bug fix infer shape for slice" (#113413)
Reverts llvm/llvm-project#108306
2024-10-23 04:37:21 +01:00
Tai Ly
3b9526b231
[TOSA] bug fix infer shape for slice (#108306)
This fixes the infer output shape of TOSA slice op for start/size values
that are out-of-bound or -1

added tests to check:
  - size = -1
  - size is out of bound
  - start is out of bound

Signed-off-by: Tai Ly <tai.ly@arm.com>
2024-10-23 04:25:41 +01:00