onnx-mlir icon indicating copy to clipboard operation
onnx-mlir copied to clipboard

Lower onnx.transpose to memref.transpose for better performance

Open tungld opened this issue 2 years ago • 1 comments

Given that the current implementation of onnx.transpose by actually shuffling data is expensive, it is better to use memref.transpose that just doest metadata changes.

This is description of memref.transpose:

let summary = "`transpose` produces a new strided memref (metadata-only)";
  let description = [{
    The `transpose` op produces a strided memref whose sizes and strides
    are a permutation of the original `in` memref. This is purely a metadata
    transformation.

    Example:

    ```mlir
    %1 = memref.transpose %0 (i, j) -> (j, i) : memref<?x?xf32> to memref<?x?xf32, affine_map<(d0, d1)[s0] -> (d1 * s0 + d0)>>
    ```
  }];

It looks like memref.transpose will give a better performance.

tungld avatar May 12 '22 05:05 tungld

I assume that this approach works only when the transpose is the only user for the input tenor.

chentong319 avatar May 18 '22 00:05 chentong319