[all-commits] [llvm/llvm-project] 26d896: Fixes in 'tosa.reshape' lowering and folder (#85798)

Rafael Ubal via All-commits all-commits at lists.llvm.org
Tue Mar 26 07:53:16 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 26d896f3688a8bff6faf85ccce557e320108997f
      https://github.com/llvm/llvm-project/commit/26d896f3688a8bff6faf85ccce557e320108997f
  Author: Rafael Ubal <rubal at mathworks.com>
  Date:   2024-03-26 (Tue, 26 Mar 2024)

  Changed paths:
    M mlir/lib/Conversion/TosaToTensor/TosaToTensor.cpp
    M mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
    M mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
    M mlir/test/Conversion/TosaToTensor/tosa-to-tensor.mlir
    M mlir/test/Dialect/Tosa/canonicalize.mlir

  Log Message:
  -----------
  Fixes in 'tosa.reshape' lowering and folder (#85798)

- Revamped lowering conversion pattern for `tosa.reshape` to handle previously unsupported combinations of dynamic dimensions in input and output tensors. The lowering strategy continues to rely on pairs `tensor.collapse_shape` + `tensor.expand_shape`, which allow for downstream fusion with surrounding `linalg.generic` ops.

- Fixed bug in canonicalization pattern `ReshapeOp::fold()` in `TosaCanonicalizations.cpp`. The input and result types being equal is not a sufficient condition for folding. If there is more than 1 dynamic dimension in the input and result types, a productive reshape could still occur.

- This work exposed the fact that bufferization does not properly handle a `tensor.collapse_shape` op producing a 0D tensor from a dynamically shaped one due to a limitation in `memref.collapse_shape`. While the proper way to address this would involve releasing the `memref.collapse_shape` restriction and verifying correct bufferization, this is left as possible future work. For now, this scenario is avoided by casting the `tosa.reshape` input tensor to a static shape if necessary (see `inferReshapeInputType()`.

- An extended set of tests are intended to cover relevant conversion paths. Tests are named using pattern `test_reshape_<rank>_{up|down|same}_{s2s|s2d|d2s|d2d}_{explicit|auto}[_empty][_identity]`, where:
	
  - `<rank>` is the input rank (e.g., 3d, 6d)
  - `{up|down|same}` indicates whether the reshape increases, decreases, or retains the input rank.
  - `{s2s|s2d|d2s|d2d}` indicates whether reshape converts a statically shaped input to a statically shaped result (`s2s`), a statically shaped input to a dynamically shaped result (`s2d`), etc.
  - `{explicit|auto}` is used to indicate that all values in the `new_shape` attribute are >=0 (`explicit`) or that a -1 placeholder value is used (`auto`).
  - `empty` is used to indicate that `new_shape` includes a component set to 0.
  - `identity` is used when the input and result shapes are the same.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list