llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[flang][OpenMP] Support reduction and in_reduction on taskloop

Open Saieiei opened this issue 6 months ago • 4 comments

Flang currently parses, semantically checks, and lowers OpenMP taskloop reduction / in_reduction clauses to OpenMP MLIR, but LLVM IR translation is still missing for the full taskloop reduction path.

A minimal taskloop reduction case currently fails during OpenMP MLIR -> LLVM IR translation with:

not yet implemented: Unhandled clause reduction in omp.taskloop.context operation

The implementation is being split into smaller reviewable patches:

  1. #199565 translates task_reduction on omp.taskgroup. This is the prerequisite task-reduction setup needed by the later taskloop in_reduction path.

  2. #199670 translates reduction and in_reduction on omp.taskloop.context. It is currently stacked on #199565.

The taskloop follow-up covers the scalar/non-byref path. For taskloop reduction, the lowering emits the implicit taskgroup reduction setup and maps each generated task to runtime-provided private reduction storage through __kmpc_task_reduction_get_th_data.

For taskloop in_reduction, the lowering uses the same runtime lookup path with a null descriptor so the runtime can find the enclosing task-reduction context.

Byref reductions, reductions with cleanup regions, and two-argument initializer forms remain unsupported and are kept as diagnosed follow-up cases.

Saieiei avatar May 25 '26 17:05 Saieiei

check issue #199418 more than like related i submitted a pr on that ticket yesterday

corbettknowles avatar May 25 '26 18:05 corbettknowles

check issue #199418

Thanks for the pointer. I checked #199418, but that looks like a LoopFusion/LCSSA issue in LLVM transforms, while this issue is for Flang/OpenMP taskloop reduction/in_reduction translation.

The related upstream work I found is #110008, which tracks this as an unsupported OpenMP/Flang item, and #139704, which added TODO tests for taskloop reduction and in_reduction. This issue is intended to track the implementation work, split into smaller patches.

If you meant another taskloop/taskgroup reduction PR or issue, please point me to it and I can link it here.

Saieiei avatar May 25 '26 18:05 Saieiei

The main taskloop reduction / in_reduction support tracked here has landed through the task-reduction translation stack:

  • #199565 added task_reduction translation for omp.taskgroup.
  • #199670 added reduction / in_reduction translation for omp.taskloop.context.
  • #202611 added the related explicit omp.task in_reduction translation.

The remaining unsupported richer cases such as byref reductions, cleanup regions, and two-argument initializer forms are still diagnosed and can be tracked separately if needed.

Closing this as implemented.

Saieiei avatar Jun 24 '26 09:06 Saieiei

@llvm/issue-subscribers-mlir

Author: Sairudra More (Saieiei)

Flang currently parses, semantically checks, and lowers OpenMP taskloop `reduction` / `in_reduction` clauses to OpenMP MLIR, but LLVM IR translation is still missing for the full taskloop reduction path.

A minimal taskloop reduction case currently fails during OpenMP MLIR -> LLVM IR translation with:

not yet implemented: Unhandled clause reduction in omp.taskloop.context operation

The implementation is being split into smaller reviewable patches:

  1. #199565 translates task_reduction on omp.taskgroup. This is the prerequisite task-reduction setup needed by the later taskloop in_reduction path.

  2. #199670 translates reduction and in_reduction on omp.taskloop.context. It is currently stacked on #199565.

The taskloop follow-up covers the scalar/non-byref path. For taskloop reduction, the lowering emits the implicit taskgroup reduction setup and maps each generated task to runtime-provided private reduction storage through __kmpc_task_reduction_get_th_data.

For taskloop in_reduction, the lowering uses the same runtime lookup path with a null descriptor so the runtime can find the enclosing task-reduction context.

Byref reductions, reductions with cleanup regions, and two-argument initializer forms remain unsupported and are kept as diagnosed follow-up cases.