[all-commits] [llvm/llvm-project] 53e8ff: [MLIR] Fixing the memref linearization size comput...

Zhuoran Yin via All-commits all-commits at lists.llvm.org
Thu May 8 10:14:53 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 53e8ff13bd3c1061af01a1508881575db81ce900
      https://github.com/llvm/llvm-project/commit/53e8ff13bd3c1061af01a1508881575db81ce900
  Author: Zhuoran Yin <zhuoryin at amd.com>
  Date:   2025-05-08 (Thu, 08 May 2025)

  Changed paths:
    M mlir/lib/Dialect/AMDGPU/Transforms/TransferReadToLoad.cpp
    M mlir/lib/Dialect/MemRef/Utils/MemRefUtils.cpp
    M mlir/test/Dialect/AMDGPU/transfer-read-to-load.mlir
    M mlir/test/Dialect/MemRef/emulate-narrow-type.mlir
    M mlir/test/Dialect/Vector/vector-emulate-narrow-type.mlir

  Log Message:
  -----------
  [MLIR] Fixing the memref linearization size computation for non-packed memref (#138922)

Credit to @krzysz00 who discovered this subtle bug in `MemRefUtils`. The
problem is in `getLinearizedMemRefOffsetAndSize()` utility. In
particular, how this subroutine computes the linearized size of a memref
is incorrect when given a non-packed memref.

### Background

As context, in a packed memref of `memref<8x8xf32>`, we'd compute the
size by multiplying the size of dimensions together. This is implemented
by composing an affine_map of `affine_map<()[s0, s1] -> (s0 * s1)>` and
then computing the result of size via `%size = affine.apply #map()[%c8,
%c8]`.

However, this is wrong for a non-packed memref of `memref<8x8xf32,
strided<[1024, 1]>>`. Since the previous computed multiplication map
will only consider the dimension sizes, it'd continue to conclude that
the size of the non-packed memref to be 64.

### Solution

This PR come up with a fix such that the linearized size computation
take strides into consideration. It computes the maximum of (dim size *
dim stride) for each dimension. We'd compute the size via the affine_map
of `affine_map<()[stride0, size0, stride1] -> ((stride0 * size0), 1 *
size1)>` and then computing the size via `%size = affine.max
#map()[%stride0, %size0, %size1]`. In particular for the new non-packed
memref, the size will be derived as max(1024\*8, 1\*8) = 8192 (rather
than the wrong size 64 computed by packed memref equation).



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