<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62304>62304</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[mlir][TosaToLinalg] miss encoding parameter when build tensor.empty in TosaToLinalg Pass
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Sinclair-Dee
</td>
</tr>
</table>
<pre>
When TOSA' ElementOp lowered to linalg, we first build tensor.empty. The current code is as follows:
```cpp
for (auto result : results) {
auto resultTy = result.getType().template cast<ShapedType>();
emptyTensors.push_back(rewriter.create<tensor::EmptyOp>(
loc, resultTy.getShape(), resultTy.getElementType(), filteredDims));
opResultTypes.push_back(result.getType());
}
```
However, the "Encoding" info in RankTensorType seems to be ignored.
Insofar as I can see, the `result`(tosa elementOp's result) here is definitely the RankTensorType, matching the type constraints in tensor.empty's Def.
So, maybe the code could be changed to:
for (auto result : results) {
RankedTensorType rankedType = result.getType().dyn_cast<RankedTensorType>();
emptyTensors.push_back(rewriter.create<tensor::EmptyOp>(loc, rankedType, filteredDims));
opResultTypes.push_back(result.getType());
}
```
In rare cases, the encoding parameter may be needed to pass some important information.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzElU-P4ygTxj8NuZTaciB_nIMP6Xaid6RX6tV0pD2OMC7b7GCwKDxRvv0K7PSke3YvK6221XIMFA9PFT-wJNKdRSzZ9pltq5WcQu98-aatMlL7pwpxVbvmVv7eo4XL69uR8T2cDA5ow-sIxl3RYwPBgdFWmo7xF7gitNpTgHrSpoGAlpzPcBjDLYNLj6Am79EGUK5B0ASSoHXGuCsxcWR5xfIj2-XzvxrHuQegdR4YL-QUHHikyQRg4ri8EuMHYPvnezDAQ9zlBkxUSyPrMFxuIzJeMH7IAg6jkQFBSQpMvLz1csQmBYjTHMPEg2zK45JyomycqP9WS_Wd8cLj1euAPlMeZUAmXubMY07ieIrTXsdF810t_hmnYtnuVqO_ZGJZ_NPQUvyfGcSAVpsQN6LSA6Wuj57d-HVRGPGz6V9L8nE221eftmRu_s9d8Qf6uHroERjnJ6tco23HOAdtWwfawldpv8_FivpAiANFWmoE3VnnsclmuS-WXCt9ZOELKGlj6Lv2Lp99xsV5ERxJwDuDjO9pKVBEoEefmGqw1VYHNLck8dFHFB5kUL22XRoO0ZxyloKX2gaK1h-5TYtU2C5m5-ebm3VuNSaRhLNyk2lieqqXtktHg53O7PmFHY7_EOToHZuHKvq5I77-LdbNzX5biP48_9_j-k7yu7__iM07UuClTwcb6c4SLpDCKL0cMKCPOxg3zCI22ECkc5REQG5A0MPofJA2JKL9IIN29gMF8NiYn6umFM1BHOQKy_Wu4Hy93xVi1ZcKFe5xX683m80hl7VodjUWh926EPt2jWKlS55zkW-4yPlmzUXWrLfr3a7Y1Hu5bmuRs02Og9QmM-bHkDnfrTTRhOUuzloZWaOhdJlzbvEKaZBxHu92X8Y5T_XUEdvkRlOgnypBB5O-AoPRnm0rtn2-OJIX9__5Wt9WMGiivyrfNX4afr3q4xF6lIDfJNFq8qbsQxjTTc_PjJ87HfqpzpQbGD9HP8vP0-jdH6gC4-eUBTF-Tln-GQAA__8ouSKM">