This is an archive of the discontinued LLVM Phabricator instance.

[openmp][mlir] Parallel reduction LLVM IR generation
ClosedPublic

Authored by elmcdonough on Jul 12 2023, 11:35 PM.

Details

Summary

This patch extends the existing WsLoop reduction IR generation to parallel blocks.

Diff Detail

Event Timeline

elmcdonough created this revision.Jul 12 2023, 11:35 PM
Herald added a project: Restricted Project. · View Herald Transcript
elmcdonough requested review of this revision.Jul 12 2023, 11:35 PM
elmcdonough retitled this revision from [openmp] Parallel reduction LLVM IR generation to [openmp][mlir] Parallel reduction LLVM IR generation.Jul 12 2023, 11:35 PM
kiranchandramohan requested changes to this revision.Jul 13 2023, 6:32 AM

Thanks @elmcdonough for the patch.

The reduction for the parallel construct should happen inside the parallel region (outlined function). At the moment, the code generated does this outside it.

Could you also check the case where the reduction happens in a nested region?

      subroutine diff(nelt)
      implicit none

      integer :: ie, nelt, rho1

      r1 = 0
!$OMP PARALLEL DEFAULT(SHARED) PRIVATE(ie) REDUCTION(+:r1)
!$OMP DO
       do ie=1,nelt
               r1            = r1 + ie
       end do
!$OMP END DO
!$OMP END PARALLEL

      end
This revision now requires changes to proceed.Jul 13 2023, 6:32 AM

Ensure that reduction happens in outlined function + account for nested WsLoopOp.

kiranchandramohan accepted this revision.Aug 3 2023, 6:26 AM

LG.

Could you check that the tests in gfortran testuite pass for parallel reduction before submitting?
https://github.com/llvm/llvm-test-suite/blob/745f3fdfe3f2f28dcea34e3e55fdc55aca06c00d/Fortran/gfortran/regression/gomp/DisabledFiles.cmake#L111

mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
355–368

Nit: Would this change work?

This revision is now accepted and ready to land.Aug 3 2023, 6:26 AM
This revision was landed with ongoing or failed builds.Aug 15 2023, 10:59 PM
This revision was automatically updated to reflect the committed changes.