[Mlir-commits] [mlir] [mlir][affine]make threadid op is valid symbol. (PR #118478)

Adam Siemieniuk llvmlistbot at llvm.org
Tue Dec 3 04:31:23 PST 2024


adam-smnk wrote:

Just a fly-by comment as I'm no affine expert.

Wouldn't it be sufficient to just define the thread ID outside the loop?
For example:
```
#map = affine_map<()[s0] -> (s0 mod 32)>

module {
  gpu.module @gpu {
    gpu.func @gemm(%arg0: memref<?x?xf32>) kernel {
      %c3 = arith.constant 3 : index
      %dim = memref.dim %arg0, %c3 : memref<?x?xf32>
      %c0 = arith.constant 0 : index
      %thread_id_x = gpu.thread_id  x // Move declaration here
      affine.for %arg3 = %c0 to %dim step 32 {
        %0 = affine.apply #map()[%thread_id_x]
        %c128 = arith.constant 128 : index
        affine.for %arg4 = %0 to %c128 step 8 {
          %c32 = arith.constant 32 : index
        }
      }
      gpu.return
    }
  }
}
```

Also, the proposed change seems super specific - it might be fine but if we go this route, would it reasonable to allow any other "special" symbols as well?

https://github.com/llvm/llvm-project/pull/118478


More information about the Mlir-commits mailing list