[Openmp-commits] [PATCH] D148393: [OpenMP] Additional APIs used by MSVC compiler for loop collapse (rectangular and non-rectangular loops)

Natalia Glagoleva via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Fri Apr 14 16:18:05 PDT 2023


natgla created this revision.
natgla added reviewers: jdoerfert, vadikp-intel, jlpeyton.
natgla added a project: OpenMP.
Herald added subscribers: sunshaoce, guansong, yaxunl.
Herald added a project: All.
natgla requested review of this revision.
Herald added subscribers: openmp-commits, jplehr, sstefan1.

For MSVC compiler we moved the heavy-lifting of loop collapse feature into runtime. 
For rectangular loops __kmpc_process_loop_nest_rectang calculates total number of iterations, so that then loop nest can be processed as one 'openmp for' loop. __kmpc_calc_original_ivs_rectang calculates original IVs from the overall IV for new for loop.
For non-rectangular loops __kmpc_for_collapsed_init on each thread returns a chunk to execute, formulated in terms of original IVs. So the loops are re-written to look ~like this (example with <=):

      fetch iLBnew, iUBnew, jA0new, jUBnew, kA0new, kUBnew for the chunk;
      jA1new = kA1new = 0;
      for (i = iLBnew; i <= iUBnew; i += iStep) {  
          for (j = i * jA1new + jA0new; j <= i * jB1 + jB0; j += jStep) {
              if ((i >= iUBnew) && (j > jUBnew)) goto done;
              for (k = j * kA1new + kA0new; k <= j * kB1 + kB0; k += kStep) {
                  if ((i >= iUBnew) && (j >= jUBnew) && (k > kUBnew)) goto done;
                     LOOP BODY
              }
              kA0new = kA0;
              kA1new = kA1;
          }
          jA0new = jA0;
          jA1new = jA1;
      }
  done:

I expect that it'll be easier to experiment with different implementations for non-rectangular loop collapse this way. E.g. pick different algorithms for triangular loops, or for when there are many threads available.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148393

Files:
  openmp/runtime/src/CMakeLists.txt
  openmp/runtime/src/dllexports
  openmp/runtime/src/kmp_collapse.cpp
  openmp/runtime/src/kmp_collapse.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148393.513780.patch
Type: text/x-patch
Size: 64382 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20230414/b15eaa4f/attachment-0001.bin>


More information about the Openmp-commits mailing list