<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/55223>55223</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
MLIR: Failed to lower affine.for to gpu dialect
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
CONGCONGLEEE
</td>
</tr>
</table>
<pre>
Recently I'm studying how to convert affine.for to gpu dialect. The following is part of the `test.mlir`,
```
#map11 = affine_map<(d0) -> (-d0 + 1176, 256)>
#map13 = affine_map<(d0, d1) -> (-d1 + 10, 64)>
affine.for %arg1 = 0 to 10 step 64 {
affine.for %arg2 = 0 to 1176 step 256 {
affine.for %arg3 = 0 to min #map11(%arg2) {
affine.for %arg4 = 0 to min #map13(%arg2, %arg1) {
%15 = affine.apply #map14(%arg1, %arg4)
%16 = affine.apply #map15(%arg1, %arg4, %arg2, %arg3)
%17 = memref.load %6[%15, %16] : memref<10x1176xf32>
memref.store %17, %10[%arg3, %arg4] : memref<256x64xf32>
}
}
}
}
```
when I using the command `mlir-opt -pass-pipeline="builtin.func(convert-affine-for-to-gpu{gpu-block-dims=1 gpu-thread-dims=1})" test.mlir ` , the error occurs:
```
test.mlir:82:9: error: 'affine.for' op operand cannot be used as a dimension id
affine.for %arg3 = 0 to min #map11(%arg2) {
^
test.mlir:82:9: note: see current operation: "affine.for"(%33) ({
^bb0(%arg16: index):
"affine.for"(%33, %31) ({
^bb0(%arg17: index):
%45 = "affine.apply"(%31, %arg17) {map = affine_map<(d0, d1) -> (d1 + d0)>} : (index, index) -> index
%46 = "affine.apply"(%31, %arg17, %33, %arg16) {map = affine_map<(d0, d1, d2, d3) -> (d3 + d2)>} : (index, index, index, index) -> index
%47 = "memref.load"(%0, %45, %46) : (memref<10x1176xf32>, index, index) -> f32
"memref.store"(%47, %18, %arg16, %arg17) : (f32, memref<256x64xf32>, index, index) -> ()
"affine.yield"() : () -> ()
}) {lower_bound = affine_map<() -> (0)>, step = 1 : index, upper_bound = affine_map<(d0, d1) -> (-d1 + 10, 64)>} : (index, index) -> ()
"affine.yield"() : () -> ()
}) {lower_bound = affine_map<() -> (0)>, step = 1 : index, upper_bound = affine_map<(d0) -> (-d0 + 1176, 256)>} : (index) -> ()
```
I read the documentation in https://mlir.llvm.org/docs/Dialects/Affine/#restrictions-on-dimensions-and-symbols, but I can't find the syntax errors in `affine.for %arg3 = 0 to min #map11(%arg2) ` . What should I do to make the `convert-affine-for-to-gpu` pass work?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzFV1tvozgU_jXkxQKBzaV5yEOapKNKs7vSaKV9HAE2iaeAkW2mzb_fY5sQSMNMZ6TVVmnwhfOd7xyfi1MIet58YSVrdX1Gzx7OGqR0T8-8PaKTeEVaoFK035nUKK8q3rKgEtKsHrseUZ7XrNQB-vvEUCXqWrwaOa5Ql4OAqJCGDeSloWZKB03NJYw9vPPCvRduzdh93BSTJu-iCHlkPyj7Cgse2Xn4gYLYGvkeOSCY-TSExyOKoiwFOIQTeKxhc4ZEFpF2iEZzvMjh2b00noHZbwR_Ewd4OMnl0VENjTuiEPzGOpBFXvZ4lbkjhSdSwN_JgQW3gndEyVW04S26eAwsGKCNUe9g7gDFd4HIFGh3MXIBE5n9KJn4OMi7DqJoAItHsOgKZj17FyhdBEoWgC7DCVeyCJ9Z-IY1klVBLXJqVlMvebRGDAgRLOzhxe3wIgRMFL6ZQ3qrCB4jYoo9ICotJHOKLlihA3esrrRvFQCLtzRewPey_XzpZmE2HSc3efV6Yi16Rr0yuWkSshRNk7fUJqbJSV90GvldrpTf8Y7VcALgLA_joue15m1Q9W0JhzAUAt8dkg_R5GvhQyGA6IBvv6hF-eJT3igQj5ApEb4-SZbTcdFwhCPCGPiONcHwQMZHhhyTEqJUlGUvQWI7zcEbu641hWwfwHvbtXGslTcDqGXXsIcJEh18mDSWl3nbCo0KBl5hFOUK5VDM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