llvm-project
d9e4a78a - [mlir][acc] Introduce acc-partition-kernel-loops pass (#248659)

Commit
4 hours ago
[mlir][acc] Introduce acc-partition-kernel-loops pass (#248659) Add a pass that maps the parallel loops of an acc.compute_region onto the GPU dimensions they were assigned. Each scf.parallel loop carries an acc.par_dims attribute that lists the dimensions it runs over. The pass splits the loop so that each loop carries a single dimension, which is the form the GPU lowering expects. For every non-sequential dimension, the loop gets an outer loop over the launch width of that dimension. The original loop becomes sequential and walks the iterations of one lane, so that neighboring lanes work on neighboring iterations. ``` acc.compute_region launch(%w = %pw_x) { scf.parallel (%i) = (%lb) to (%ub) step (%s) { ... } {acc.par_dims = #acc<par_dims[thread_x]>} } ``` becomes ``` acc.compute_region launch(%w = %pw_x) { scf.parallel (%t) = (%c0) to (%w) step (%c1) { %off = arith.muli %t, %s %lb2 = arith.addi %lb, %off %s2 = arith.muli %s, %w scf.parallel (%i) = (%lb2) to (%ub) step (%s2) { ... } {acc.par_dims = #acc<par_dims[sequential]>} scf.reduce } {acc.par_dims = #acc<par_dims[thread_x]>} } ``` The pass also handles gang(static:N) chunking and keeps reductions correct when a loop is split. Assisted-by: Cursor --------- Co-authored-by: Scott Manley <rscottmanley@gmail.com> Co-authored-by: Kazuaki Matsumura <kmatsumura@nvidia.com>
Parents
Loading