[prev in list] [next in list] [prev in thread] [next in thread] 

List:       llvm-bugs
Subject:    [llvm-bugs] [Bug 65145] [mlir] Bug in MemrefToLLVM lowering pattern for memref.transpose
From:       LLVM Bugs via llvm-bugs <llvm-bugs () lists ! llvm ! org>
Date:       2023-08-31 15:56:16
Message-ID: 20230831155616.784c76de14473f9a () email ! llvm ! org
[Download RAW message or body]

[Attachment #2 (text/html)]

<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/65145>65145</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [mlir] Bug in MemrefToLLVM lowering pattern for memref.transpose
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          ubfx
      </td>
    </tr>
</table>

<pre>
    Permutation maps can sometimes be confusing because it&apos;s easy to mix up the \
source and the target dimensions. I think this is what happened with the lowering \
Pattern for memref.transpose: \
https://github.com/llvm/llvm-project/blob/main/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp#L1562


For the testcase to demonstrate the problem I will use the textual representation of \
verified Ops where it is clear what the shape and strides should be as the reference:

test.mlir:
```mlir
func.func @transpose(%arg0: memref&lt;1x2x3xf32, strided&lt;[6, 3, 1], offset: \
?&gt;&gt;) -&gt; memref&lt;3x1x2xf32, strided&lt;[1, 6, 3], offset: ?&gt;&gt; {  %0 = \
memref.transpose %arg0 (i, j, k) -&gt; (k, i, j) : memref&lt;1x2x3xf32, \
strided&lt;[6, 3, 1], offset: ?&gt;&gt; to memref&lt;3x1x2xf32, strided&lt;[1, 6, 3], \
offset: ?&gt;&gt;  return %0 : memref&lt;3x1x2xf32, strided&lt;[1, 6, 3], offset: \
?&gt;&gt; }
```

test.cpp:
```c++
#include &lt;mlir/ExecutionEngine/CRunnerUtils.h&gt;
#include &lt;iostream&gt;

extern &quot;C&quot; void _mlir_ciface_transpose(StridedMemRefType&lt;float, 3&gt; *, \
StridedMemRefType&lt;float, 3&gt; *);

int main() {
 StridedMemRefType&lt;float, 3&gt; in, out;

    in.sizes[0] = 1;
 in.sizes[1] = 2;
    in.sizes[2] = 3;
    in.strides[0] = 6;
 in.strides[1] = 3;
    in.strides[2] = 1;
 _mlir_ciface_transpose(&amp;out, &amp;in);

    std::cout &lt;&lt; &quot;output has sizes: [&quot; &lt;&lt; out.sizes[0] &lt;&lt; \
                &quot;, &quot; &lt;&lt; 
        out.sizes[1] &lt;&lt; &quot;, &quot; &lt;&lt; out.sizes[2] &lt;&lt; &quot;] \
strides : [&quot; &lt;&lt; out.strides[0] &lt;&lt; &quot;, &quot; &lt;&lt;   \
out.strides[1] &lt;&lt; &quot;, &quot; &lt;&lt; out.strides[2] &lt;&lt; \
&quot;]\n&quot;;  return 0;
}
```

```
$ mlir-opt --normalize-memrefs --memref-expand --finalize-memref-to-llvm \
--llvm-request-c-wrappers --convert-func-to-llvm --reconcile-unrealized-casts \
--llvm-legalize-for-export test.mlir -o test.llvm.mlir $ mlir-translate \
--mlir-to-llvmir test.llvm.mlir -o test.ll $ clang++-17 \
                -I/mnt/build_llvm/llvm-project/mlir/include/ test.cpp test.ll
warning: overriding the module target triple with x86_64-pc-linux-gnu \
[-Woverride-module] 1 warning generated.
$ ./a.out 
output has sizes: [2, 3, 1] strides : [3, 1, 6]
```

We can see that instead of doing the (i,j,k)-&gt;(k,i,j) transposition, the lowering \
pass actually did it the other way around, i.e. (k,i,j)-&gt;(i,j,k). </pre>
<img width="1px" height="1px" alt="" \
src="http://email.email.llvm.org/o/eJysV1lv2z4S_zT0y4CCRVk-HvwQ2zFQoMX-0T36GNDSyGZLkVo \
esdNPvxhKPuI02f6BBgYlDefmcOYX6b3aG8QlK1es3IxkDAfrlnHXnEY7W78s_0LXxiCDsgZa2XmopAFvWwyqR \
Q87hMqaJnpl9rDDSkaPoAITMw8o_QsEC606QewgHBC8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j3nPaE3rdyd3I2mq4pKS7PvGyT \
PZ8A_EUgxCbhEpeunX4OaoW8OvZCJLZzb72sLR-mMMnuqMfuMzqmagBZhg9bWUV9gW3Cq09hjstN8-jSd8K7iW \
pl44nsTqUD5t0ED8l6WSiUZyWEwA3s0SMinzq4BZkxsZZauZ6K9czXFq5l5fzuGjTSqyo8q7xv2qBYJZskAyvi \
AsiZgVdtz7MO8p3FP054nBJJm_UBewLkTqZDQ4fo1Uu2k9yArQnD6BWpVE0QjDhsO6OAoX0A6G02d4EOGGdzpH \
0zeepGN6mVRL4qFHOEyny6KyWJWzKajw3IqmrLJSykWsp6Nd9WswVnTNPmu3pVigfORWoqxKMbzIs_LcppPs9l \
8Us2mNeaTyaxoFpJNxthKpftatG4_Ut5HXE7LfFKOtNyh9su-CRk8Qtrsm8HILVPp7eLes8lYKx_8VUtQQaf_N1I9lhtYxT0oA1_Spe3B823W3sf3o-j08m9j--SoZ2KbAvlfAAAA___9QuGH">



[Attachment #3 (text/plain)]

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic