[flang-commits] [flang] [openmp] [WIP][flang] Compile proper `omp_lib.mod` from the `openmp/src/include` sources (PR #80874)

Michael Klemm via flang-commits flang-commits at lists.llvm.org
Tue Feb 20 06:22:33 PST 2024


https://github.com/mjklemm updated https://github.com/llvm/llvm-project/pull/80874

>From 75b7a1cd869d9aec3f6e034d4c3e892babbe9ae3 Mon Sep 17 00:00:00 2001
From: Michael Klemm <michael.klemm at amd.com>
Date: Tue, 6 Feb 2024 17:59:36 +0100
Subject: [PATCH 1/9] Guard '!$dir if' with '#ifdef __INTEL_COMPILER'

Flang does not yet support '!$dir if' directives.  So, to make
this file compilable with Flang, they need to be guarded with
__INTEL_COMPILER (since the if is targeting the intel compiler
anyways)
---
 openmp/runtime/src/include/omp_lib.f90.var | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/openmp/runtime/src/include/omp_lib.f90.var b/openmp/runtime/src/include/omp_lib.f90.var
index 1ca542db3767ef..cc031a653d80a5 100644
--- a/openmp/runtime/src/include/omp_lib.f90.var
+++ b/openmp/runtime/src/include/omp_lib.f90.var
@@ -37,7 +37,7 @@
         integer, parameter :: omp_interop_kind = c_intptr_t
         integer, parameter :: omp_interop_fr_kind = omp_integer_kind
 
-        type omp_alloctrait
+        type omp_alloctrait!
           integer(kind=omp_alloctrait_key_kind) key
           integer(kind=omp_alloctrait_val_kind) value
         end type omp_alloctrait
@@ -392,82 +392,102 @@
           end subroutine omp_fulfill_event
 
           subroutine omp_init_lock(svar) bind(c)
+#ifdef __INTEL_COMPILER
 !DIR$ IF(__INTEL_COMPILER.GE.1400)
 !DIR$ attributes known_intrinsic :: omp_init_lock
 !DIR$ ENDIF
+#endif
             use omp_lib_kinds
             integer (kind=omp_lock_kind) svar
           end subroutine omp_init_lock
 
           subroutine omp_destroy_lock(svar) bind(c)
+#ifdef __INTEL_COMPILER
 !DIR$ IF(__INTEL_COMPILER.GE.1400)
 !DIR$ attributes known_intrinsic :: omp_destroy_lock
 !DIR$ ENDIF
+#endif
             use omp_lib_kinds
             integer (kind=omp_lock_kind) svar
           end subroutine omp_destroy_lock
 
           subroutine omp_set_lock(svar) bind(c)
+#ifdef __INTEL_COMPILER
 !DIR$ IF(__INTEL_COMPILER.GE.1400)
 !DIR$ attributes known_intrinsic :: omp_set_lock
 !DIR$ ENDIF
+#endif
             use omp_lib_kinds
             integer (kind=omp_lock_kind) svar
           end subroutine omp_set_lock
 
           subroutine omp_unset_lock(svar) bind(c)
+#ifdef __INTEL_COMPILER
 !DIR$ IF(__INTEL_COMPILER.GE.1400)
 !DIR$ attributes known_intrinsic :: omp_unset_lock
 !DIR$ ENDIF
+#endif
             use omp_lib_kinds
             integer (kind=omp_lock_kind) svar
           end subroutine omp_unset_lock
 
           function omp_test_lock(svar) bind(c)
+#ifdef __INTEL_COMPILER
 !DIR$ IF(__INTEL_COMPILER.GE.1400)
 !DIR$ attributes known_intrinsic :: omp_test_lock
 !DIR$ ENDIF
+#endif
             use omp_lib_kinds
             logical (kind=omp_logical_kind) omp_test_lock
             integer (kind=omp_lock_kind) svar
           end function omp_test_lock
 
           subroutine omp_init_nest_lock(nvar) bind(c)
+#ifdef __INTEL_COMPILER
 !DIR$ IF(__INTEL_COMPILER.GE.1400)
 !DIR$ attributes known_intrinsic :: omp_init_nest_lock
 !DIR$ ENDIF
+#endif
             use omp_lib_kinds
             integer (kind=omp_nest_lock_kind) nvar
           end subroutine omp_init_nest_lock
 
           subroutine omp_destroy_nest_lock(nvar) bind(c)
+#ifdef __INTEL_COMPILER
 !DIR$ IF(__INTEL_COMPILER.GE.1400)
 !DIR$ attributes known_intrinsic :: omp_destroy_nest_lock
 !DIR$ ENDIF
+#endif
             use omp_lib_kinds
             integer (kind=omp_nest_lock_kind) nvar
           end subroutine omp_destroy_nest_lock
 
           subroutine omp_set_nest_lock(nvar) bind(c)
+#ifdef __INTEL_COMPILER
 !DIR$ IF(__INTEL_COMPILER.GE.1400)
 !DIR$ attributes known_intrinsic :: omp_set_nest_lock
 !DIR$ ENDIF
+#endif
             use omp_lib_kinds
             integer (kind=omp_nest_lock_kind) nvar
           end subroutine omp_set_nest_lock
 
           subroutine omp_unset_nest_lock(nvar) bind(c)
+#ifdef __INTEL_COMPILER
 !DIR$ IF(__INTEL_COMPILER.GE.1400)
 !DIR$ attributes known_intrinsic :: omp_unset_nest_lock
 !DIR$ ENDIF
+#endif
             use omp_lib_kinds
             integer (kind=omp_nest_lock_kind) nvar
           end subroutine omp_unset_nest_lock
 
           function omp_test_nest_lock(nvar) bind(c)
+#ifdef __INTEL_COMPILER
 !DIR$ IF(__INTEL_COMPILER.GE.1400)
 !DIR$ attributes known_intrinsic :: omp_test_nest_lock
 !DIR$ ENDIF
+#endif
             use omp_lib_kinds
             integer (kind=omp_integer_kind) omp_test_nest_lock
             integer (kind=omp_nest_lock_kind) nvar

>From 38f20849c912866d95002cb4829fb3f5f439948b Mon Sep 17 00:00:00 2001
From: Michael Klemm <michael.klemm at amd.com>
Date: Tue, 6 Feb 2024 22:33:03 +0100
Subject: [PATCH 2/9] Remove accidental typo

---
 openmp/runtime/src/include/omp_lib.f90.var | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/openmp/runtime/src/include/omp_lib.f90.var b/openmp/runtime/src/include/omp_lib.f90.var
index cc031a653d80a5..68799fc52ff020 100644
--- a/openmp/runtime/src/include/omp_lib.f90.var
+++ b/openmp/runtime/src/include/omp_lib.f90.var
@@ -37,7 +37,7 @@
         integer, parameter :: omp_interop_kind = c_intptr_t
         integer, parameter :: omp_interop_fr_kind = omp_integer_kind
 
-        type omp_alloctrait!
+        type omp_alloctrait
           integer(kind=omp_alloctrait_key_kind) key
           integer(kind=omp_alloctrait_val_kind) value
         end type omp_alloctrait

>From d9482466ce3cbdfed295c65f61955cb15f7c72bd Mon Sep 17 00:00:00 2001
From: Michael Klemm <michael.klemm at amd.com>
Date: Wed, 7 Feb 2024 14:21:15 +0100
Subject: [PATCH 3/9] Rename omp_lib.f90.var to omp_lib.F90.var, incl it's
 processed output

---
 openmp/runtime/src/CMakeLists.txt                           | 6 +++---
 .../src/include/{omp_lib.f90.var => omp_lib.F90.var}        | 0
 2 files changed, 3 insertions(+), 3 deletions(-)
 rename openmp/runtime/src/include/{omp_lib.f90.var => omp_lib.F90.var} (100%)

diff --git a/openmp/runtime/src/CMakeLists.txt b/openmp/runtime/src/CMakeLists.txt
index b0ecf1213dabe5..7e2a05e003b8d9 100644
--- a/openmp/runtime/src/CMakeLists.txt
+++ b/openmp/runtime/src/CMakeLists.txt
@@ -18,7 +18,7 @@ if(${LIBOMP_OMPT_SUPPORT})
   configure_file(${LIBOMP_INC_DIR}/omp-tools.h.var omp-tools.h @ONLY)
 endif()
 
-# Generate message catalog files: kmp_i18n_id.inc and kmp_i18n_default.inc
+# Generate message catalog fioles: kmp_i18n_id.inc and kmp_i18n_default.inc
 add_custom_command(
   OUTPUT  kmp_i18n_id.inc
   COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/message-converter.pl --os=${LIBOMP_PERL_SCRIPT_OS}
@@ -314,7 +314,7 @@ endif()
 # One compilation step creates both omp_lib.mod and omp_lib_kinds.mod
 if(${LIBOMP_FORTRAN_MODULES})
   configure_file(${LIBOMP_INC_DIR}/omp_lib.h.var omp_lib.h @ONLY)
-  configure_file(${LIBOMP_INC_DIR}/omp_lib.f90.var omp_lib.f90 @ONLY)
+  configure_file(${LIBOMP_INC_DIR}/omp_lib.F90.var omp_lib.F90 @ONLY)
   # Workaround for gfortran to build modules with the
   # omp_sched_monotonic integer parameter
   if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
@@ -323,7 +323,7 @@ if(${LIBOMP_FORTRAN_MODULES})
   add_custom_target(libomp-mod ALL DEPENDS omp_lib.mod omp_lib_kinds.mod)
   libomp_get_fflags(LIBOMP_CONFIGURED_FFLAGS)
   if(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
-    set(LIBOMP_FORTRAN_SOURCE_FILE omp_lib.f90)
+    set(LIBOMP_FORTRAN_SOURCE_FILE omp_lib.F90)
   else()
     message(FATAL_ERROR "Fortran module build requires Fortran 90 compiler")
   endif()
diff --git a/openmp/runtime/src/include/omp_lib.f90.var b/openmp/runtime/src/include/omp_lib.F90.var
similarity index 100%
rename from openmp/runtime/src/include/omp_lib.f90.var
rename to openmp/runtime/src/include/omp_lib.F90.var

>From 3f6d1eb04cbc9529deb85d8053a27782a0cc0436 Mon Sep 17 00:00:00 2001
From: Michael Klemm <michael.klemm at amd.com>
Date: Thu, 8 Feb 2024 16:06:00 +0100
Subject: [PATCH 4/9] Remove old .h and .f90 file

---
 flang/module/omp_lib.f90 |  13 --
 flang/module/omp_lib.h   | 454 ---------------------------------------
 2 files changed, 467 deletions(-)
 delete mode 100644 flang/module/omp_lib.f90
 delete mode 100644 flang/module/omp_lib.h

diff --git a/flang/module/omp_lib.f90 b/flang/module/omp_lib.f90
deleted file mode 100644
index 2ca15da6891591..00000000000000
--- a/flang/module/omp_lib.f90
+++ /dev/null
@@ -1,13 +0,0 @@
-!===-- module/omp_lib.f90 --------------------------------------------------===!
-!
-! Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-! See https://llvm.org/LICENSE.txt for license information.
-! SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-!
-!===------------------------------------------------------------------------===!
-
-module omp_lib
-
-include "omp_lib.h"
-
-end module omp_lib
diff --git a/flang/module/omp_lib.h b/flang/module/omp_lib.h
deleted file mode 100644
index efc9ceb16968bb..00000000000000
--- a/flang/module/omp_lib.h
+++ /dev/null
@@ -1,454 +0,0 @@
-!===-- module/omp_lib.h ------------------------------------------*- F90 -*-===!
-!
-! Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-! See https://llvm.org/LICENSE.txt for license information.
-! SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-!
-!===------------------------------------------------------------------------===!
-
-!dir$ free
-
-  integer, parameter :: omp_integer_kind = selected_int_kind(9) ! 32-bit int
-  integer, parameter :: omp_logical_kind = 1 ! C_BOOL
-
-  integer, parameter :: omp_sched_kind = omp_integer_kind
-  integer, parameter :: omp_proc_bind_kind = omp_integer_kind
-  integer, parameter :: omp_pause_resource_kind = omp_integer_kind
-  integer, parameter :: omp_sync_hint_kind = omp_integer_kind
-  integer, parameter :: omp_lock_hint_kind = omp_sync_hint_kind
-  integer, parameter :: omp_event_handle_kind = omp_integer_kind
-  integer, parameter :: omp_alloctrait_key_kind = omp_integer_kind
-  integer, parameter :: omp_alloctrait_val_kind = omp_integer_kind
-  integer, parameter :: omp_allocator_handle_kind = omp_integer_kind
-  integer, parameter :: omp_memspace_handle_kind = omp_integer_kind
-  integer, parameter :: omp_lock_kind = int_ptr_kind()
-  integer, parameter :: omp_nest_lock_kind = int_ptr_kind()
-  integer, parameter :: omp_depend_kind = omp_integer_kind
-
-  integer(kind=omp_sched_kind), parameter :: &
-    omp_sched_static = 1, &
-    omp_sched_dynamic = 2, &
-    omp_sched_guided = 3, &
-    omp_sched_auto = 4
-
-  integer(kind=omp_proc_bind_kind), parameter :: &
-    omp_proc_bind_false = 0, &
-    omp_proc_bind_true = 1, &
-    omp_proc_bind_master = 2, &
-    omp_proc_bind_close = 3, &
-    omp_proc_bind_spread = 4
-
-  integer(kind=omp_pause_resource_kind), parameter :: &
-    omp_pause_soft = 1, &
-    omp_pause_hard = 2
-
-  integer(kind=omp_sync_hint_kind), parameter :: &
-    omp_sync_hint_none = 0, &
-    omp_sync_hint_uncontended = 1, &
-    omp_sync_hint_contended = 2, &
-    omp_sync_hint_nonspeculative = 4, &
-    omp_sync_hint_speculative = 8
-  integer(kind=omp_lock_hint_kind), parameter :: &
-    omp_lock_hint_none = omp_sync_hint_none, &
-    omp_lock_hint_uncontended = omp_sync_hint_uncontended, &
-    omp_lock_hint_contended = omp_sync_hint_contended, &
-    omp_lock_hint_nonspeculative = omp_sync_hint_nonspeculative, &
-    omp_lock_hint_speculative = omp_sync_hint_speculative
-
-  integer(kind=omp_event_handle_kind), parameter :: &
-    omp_allow_completion_event = 0, &
-    omp_task_fulfill_event = 1
-
-  integer(kind=omp_alloctrait_key_kind), parameter :: &
-    omp_atk_sync_hint = 1, &
-    omp_atk_alignment = 2, &
-    omp_atk_access = 3, &
-    omp_atk_pool_size = 4, &
-    omp_atk_fallback = 5, &
-    omp_atk_fb_data = 6, &
-    omp_atk_pinned = 7, &
-    omp_atk_partition = 8
-
-  integer(kind=omp_alloctrait_val_kind), parameter :: &
-    omp_atv_false = 0, &
-    omp_atv_true = 1, &
-    omp_atv_default = 2, &
-    omp_atv_contended = 3, &
-    omp_atv_uncontended = 4, &
-    omp_atv_sequential = 5, &
-    omp_atv_private = 6, &
-    omp_atv_all = 7, &
-    omp_atv_thread = 8, &
-    omp_atv_pteam = 9, &
-    omp_atv_cgroup = 10, &
-    omp_atv_default_mem_fb = 11, &
-    omp_atv_null_fb = 12, &
-    omp_atv_abort_fb = 13, &
-    omp_atv_allocator_fb = 14, &
-    omp_atv_environment = 15, &
-    omp_atv_nearest = 16, &
-    omp_atv_blocked = 17, &
-    omp_atv_interleaved = 18
-
-  type, bind(c) :: omp_alloctrait
-    integer(kind=omp_alloctrait_key_kind) :: key, value
-  end type omp_alloctrait
-
-  integer(kind=omp_allocator_handle_kind), parameter :: omp_null_allocator = 0
-
-  integer(kind=omp_memspace_handle_kind), parameter :: &
-    omp_default_mem_space = 0, &
-    omp_large_cap_mem_space = 0, &
-    omp_const_mem_space = 0, &
-    omp_high_bw_mem_space = 0, &
-    omp_low_lat_mem_space = 0, &
-    omp_default_mem_alloc = 1, &
-    omp_large_cap_mem_alloc = omp_default_mem_alloc, &
-    omp_const_mem_alloc = 1, &
-    omp_high_bw_mem_alloc = 1, &
-    omp_low_lat_mem_alloc = 1, &
-    omp_thread_mem_alloc = omp_atv_thread, &
-    omp_pteam_mem_alloc = omp_atv_pteam, &
-    omp_cgroup_mem_alloc = omp_atv_cgroup
-
-  integer(kind=omp_integer_kind), parameter :: openmp_version = 200805
-
-  interface
-
-    subroutine omp_set_num_threads(nthreads) bind(c)
-      import
-      integer(kind=omp_integer_kind), value :: nthreads
-    end subroutine omp_set_num_threads
-
-    function omp_get_num_threads() bind(c)
-      import
-      integer(kind=omp_integer_kind) :: omp_get_num_threads
-    end function omp_get_num_threads
-
-    function omp_get_max_threads() bind(c)
-      import
-      integer(kind=omp_integer_kind) :: omp_get_max_threads
-    end function omp_get_max_threads
-
-    function omp_get_thread_num() bind(c)
-      import
-      integer(kind=omp_integer_kind) :: omp_get_thread_num
-    end function omp_get_thread_num
-
-    function omp_get_num_procs() bind(c)
-      import
-      integer(kind=omp_integer_kind) :: omp_get_num_procs
-    end function omp_get_num_procs
-
-    function omp_in_parallel() bind(c)
-      import
-      logical(kind=omp_logical_kind) :: omp_in_parallel
-    end function omp_in_parallel
-
-    subroutine omp_set_dynamic(enable) bind(c)
-      import
-      logical(kind=omp_logical_kind), value :: enable
-    end subroutine omp_set_dynamic
-
-    function omp_get_dynamic() bind(c)
-      import
-      logical(kind=omp_logical_kind) :: omp_get_dynamic
-    end function omp_get_dynamic
-
-    function omp_get_cancelation() bind(c)
-      import
-      logical(kind=omp_logical_kind) :: omp_get_cancelation
-    end function omp_get_cancelation
-
-    subroutine omp_set_nested(enable) bind(c)
-      import
-      logical(kind=omp_logical_kind), value :: enable
-    end subroutine omp_set_nested
-
-    function omp_get_nested() bind(c)
-      import
-      logical(kind=omp_logical_kind) ::omp_get_nested
-    end function omp_get_nested
-
-    subroutine omp_set_schedule(kind, modifier) bind(c)
-      import
-      integer(kind=omp_integer_kind), value :: kind, modifier
-    end subroutine omp_set_schedule
-
-    subroutine omp_get_schedule(kind, modifier) bind(c)
-      import
-      integer(kind=omp_integer_kind), intent(out) :: kind, modifier
-    end subroutine omp_get_schedule
-
-    function omp_get_thread_limit() bind(c)
-      import
-      integer(kind=omp_integer_kind) :: omp_get_thread_limit
-    end function omp_get_thread_limit
-
-    function omp_get_supported_active_levels() bind(c)
-      import
-      integer(kind=omp_integer_kind) :: omp_get_supported_active_levels
-    end function omp_get_supported_active_levels
-
-    subroutine omp_set_max_active_levels(max_levels) bind(c)
-      import
-      integer(kind=omp_integer_kind), value :: max_levels
-    end subroutine omp_set_max_active_levels
-
-    function omp_get_max_active_levels() bind(c)
-      import
-      integer(kind=omp_integer_kind) :: omp_get_max_active_levels
-    end function omp_get_max_active_levels
-
-    function omp_get_level() bind(c)
-      import
-      integer(kind=omp_integer_kind) :: omp_get_level
-    end function omp_get_level
-
-    function omp_get_ancestor_thread_num(level) bind(c)
-      import
-      integer(kind=omp_integer_kind), value :: level
-      integer(kind=omp_integer_kind) :: omp_get_ancestor_thread_num
-    end function omp_get_ancestor_thread_num
-
-    function omp_get_team_size(level) bind(c)
-      import
-      integer(kind=omp_integer_kind), value :: level
-      integer(kind=omp_integer_kind) :: omp_get_team_size
-    end function omp_get_team_size
-
-    function omp_get_active_level() bind(c)
-      import
-      integer(kind=omp_integer_kind) :: omp_get_active_level
-    end function omp_get_active_level
-
-    function omp_in_final() bind(c)
-      import
-      logical(kind=omp_logical_kind) :: omp_in_final
-    end function omp_in_final
-
-    function omp_get_proc_bind() bind(c)
-      import
-      integer(kind=omp_proc_bind_kind) :: omp_get_proc_bind
-    end function omp_get_proc_bind
-
-    function omp_get_num_places() bind(c)
-      import
-      integer(kind=omp_integer_kind) :: omp_get_num_places
-    end function omp_get_num_places
-
-    function omp_get_place_num_procs(place_num) bind(c)
-      import
-      integer(kind=omp_integer_kind), value :: place_num
-      integer(kind=omp_integer_kind) omp_get_place_num_procs
-    end function omp_get_place_num_procs
-
-    subroutine omp_get_place_proc_ids(place_num, ids) bind(c)
-      import
-      integer(kind=omp_integer_kind), value :: place_num
-      integer(kind=omp_integer_kind), intent(out) :: ids(*)
-    end subroutine omp_get_place_proc_ids
-
-    function omp_get_place_num() bind(c)
-      import
-      integer(kind=omp_integer_kind) :: omp_get_place_num
-    end function omp_get_place_num
-
-    function omp_get_partition_num_places() bind(c)
-      import
-      integer(kind=omp_integer_kind) :: omp_get_partition_num_places
-    end function omp_get_partition_num_places
-
-    subroutine omp_get_partition_place_nums(place_nums) bind(c)
-      import
-      integer(kind=omp_integer_kind), intent(out) :: place_nums(*)
-    end subroutine omp_get_partition_place_nums
-
-    subroutine omp_set_affinity_format(format) bind(c)
-      import
-      character(len=*), intent(in) :: format
-    end subroutine omp_set_affinity_format
-
-    function omp_get_affinity_format(buffer) bind(c)
-      import
-      character(len=*), intent(out) :: buffer
-      integer(kind=omp_integer_kind) :: omp_get_affinity_format
-    end function omp_get_affinity_format
-
-    subroutine omp_display_affinity(format) bind(c)
-      import
-      character(len=*), intent(in) :: format
-    end subroutine omp_display_affinity
-
-    function omp_capture_affinity(buffer, format) bind(c)
-      import
-      character(len=*), intent(out) :: buffer
-      character(len=*), intent(in) :: format
-      integer(kind=omp_integer_kind) omp_capture_affinity
-    end function omp_capture_affinity
-
-    subroutine omp_set_default_device(device_num) bind(c)
-      import
-      integer(kind=omp_integer_kind), value :: device_num
-    end subroutine omp_set_default_device
-
-    function omp_get_default_device() bind(c)
-      import
-      integer(kind=omp_integer_kind) :: omp_get_default_device
-    end function omp_get_default_device
-
-    function omp_get_num_devices() bind(c)
-      import
-      integer(kind=omp_integer_kind) :: omp_get_num_devices
-    end function omp_get_num_devices
-
-    function omp_get_device_num() bind(c)
-      import
-      integer(kind=omp_integer_kind) :: omp_get_device_num
-    end function omp_get_device_num
-
-    function omp_get_num_teams() bind(c)
-      import
-      integer(kind=omp_integer_kind) :: omp_get_num_teams
-    end function omp_get_num_teams
-
-    function omp_get_team_num() bind(c)
-      import
-      integer(kind=omp_integer_kind) :: omp_get_team_num
-    end function omp_get_team_num
-
-    function omp_is_initial_device() bind(c)
-      import
-      integer(kind=omp_logical_kind) :: omp_is_initial_device ! TODO: should this be LOGICAL?
-    end function omp_is_initial_device
-
-    function omp_get_initial_device() bind(c)
-      import
-      integer(kind=omp_integer_kind) :: omp_get_initial_device
-    end function omp_get_initial_device
-
-    function omp_get_max_task_priority() bind(c)
-      import
-      integer(kind=omp_integer_kind) :: omp_get_max_task_priority
-    end function omp_get_max_task_priority
-
-    function omp_pause_resource(kind, device_num) bind(c)
-      import
-      integer(kind=omp_pause_resource_kind), value :: kind
-      integer(kind=omp_integer_kind), value :: device_num
-      integer(kind=omp_integer_kind) :: omp_pause_resource
-    end function omp_pause_resource
-
-    function omp_pause_resource_all(kind) bind(c)
-      import
-      integer(kind=omp_pause_resource_kind), value :: kind
-      integer(kind=omp_integer_kind) :: omp_pause_resource_all
-    end function omp_pause_resource_all
-
-! Lock routines
-    subroutine omp_init_lock(lockvar) bind(c, name="omp_init_lock_")
-      import
-      integer(kind=omp_lock_kind), intent(out) :: lockvar
-    end subroutine omp_init_lock
-
-    subroutine omp_init_lock_with_hint(lockvar, hint) bind(c, name="omp_init_lock_with_hint_")
-      import
-      integer(kind=omp_lock_kind), intent(out) :: lockvar
-      integer(kind=omp_sync_hint_kind), value :: hint
-    end subroutine omp_init_lock_with_hint
-
-    subroutine omp_destroy_lock(lockvar) bind(c, name="omp_destroy_lock_")
-      import
-      integer(kind=omp_lock_kind), intent(inout) :: lockvar
-    end subroutine omp_destroy_lock
-
-    subroutine omp_set_lock(lockvar) bind(c, name="omp_set_lock_")
-      import
-      integer(kind=omp_lock_kind), intent(inout) :: lockvar
-    end subroutine omp_set_lock
-
-    subroutine omp_unset_lock(lockvar) bind(c, name="omp_unset_lock_")
-      import
-      integer(kind=omp_lock_kind), intent(inout) :: lockvar
-    end subroutine omp_unset_lock
-
-    function omp_test_lock(lockvar) bind(c, name="omp_test_lock_")
-      import
-      integer(kind=omp_lock_kind), intent(inout) :: lockvar
-      logical(kind=omp_logical_kind) :: omp_test_lock
-    end function omp_test_lock
-
-    subroutine omp_init_nest_lock(lockvar) bind(c, name="omp_init_nest_lock_")
-      import
-      integer(kind=omp_nest_lock_kind), intent(out) :: lockvar
-    end subroutine omp_init_nest_lock
-
-    subroutine omp_init_nest_lock_with_hint(lockvar, hint) bind(c, name="omp_init_nest_lock_with_hint_")
-      import
-      integer(kind=omp_nest_lock_kind), intent(out) :: lockvar
-      integer(kind=omp_sync_hint_kind), value :: hint
-    end subroutine omp_init_nest_lock_with_hint
-
-    subroutine omp_destroy_nest_lock(lockvar) bind(c, name="omp_destroy_nest_lock_")
-      import
-      integer(kind=omp_nest_lock_kind), intent(inout) :: lockvar
-    end subroutine omp_destroy_nest_lock
-
-    subroutine omp_set_nest_lock(lockvar) bind(c, name="omp_set_nest_lock_")
-      import
-      integer(kind=omp_nest_lock_kind), intent(inout) :: lockvar
-    end subroutine omp_set_nest_lock
-
-    subroutine omp_unset_nest_lock(lockvar) bind(c, name="omp_unset_nest_lock_")
-      import
-      integer(kind=omp_nest_lock_kind), intent(inout) :: lockvar
-    end subroutine omp_unset_nest_lock
-
-    function omp_test_nest_lock(lockvar) bind(c, name="omp_test_nest_lock_")
-      import
-      integer(kind=omp_integer_kind) :: omp_test_nest_lock
-      integer(kind=omp_nest_lock_kind), intent(inout) :: lockvar
-    end function omp_test_nest_lock
-
-! Timing routines
-    function omp_get_wtime() bind(c)
-      double precision omp_get_wtime
-    end function omp_get_wtime
-
-    function omp_get_wtick() bind(c)
-      double precision omp_get_wtick
-    end function omp_get_wtick
-
-! Event routine
-    subroutine omp_fullfill_event(event) bind(c) ! TODO: is this the correct spelling?
-      import
-      integer(kind=omp_event_handle_kind) :: event
-    end subroutine omp_fullfill_event
-
-! Device Memory Routines
-
-! Memory Management Routines
-    function omp_init_allocator(memspace, ntraits, traits) bind(c)
-      import
-      integer(kind=omp_memspace_handle_kind), value :: memspace
-      integer, value :: ntraits
-      type(omp_alloctrait), intent(in) :: traits(*)
-      integer(kind=omp_allocator_handle_kind) :: omp_init_allocator
-    end function omp_init_allocator
-
-    subroutine omp_destroy_allocator(allocator) bind(c)
-      import
-      integer(kind=omp_allocator_handle_kind), value :: allocator
-    end subroutine omp_destroy_allocator
-
-    subroutine omp_set_default_allocator(allocator) bind(c)
-      import
-      integer(kind=omp_allocator_handle_kind), value :: allocator
-    end subroutine omp_set_default_allocator
-
-    function omp_get_default_allocator() bind(c)
-      import
-      integer(kind=omp_allocator_handle_kind) :: omp_get_default_allocator
-    end function omp_get_default_allocator
-
-  end interface

>From f09d582b07009831010dc3ad473e5df0ffe8399d Mon Sep 17 00:00:00 2001
From: Michael Klemm <michael.klemm at amd.com>
Date: Thu, 8 Feb 2024 16:06:28 +0100
Subject: [PATCH 5/9] Implement CMakery to produce .mod files from OpenMP
 runtime sources

---
 flang/tools/f18/CMakeLists.txt    | 22 ++++++++++++++++++++--
 openmp/runtime/src/CMakeLists.txt |  5 +++--
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/flang/tools/f18/CMakeLists.txt b/flang/tools/f18/CMakeLists.txt
index ba6c6642c0b62e..8369eae39994d0 100644
--- a/flang/tools/f18/CMakeLists.txt
+++ b/flang/tools/f18/CMakeLists.txt
@@ -17,10 +17,10 @@ set(MODULES
   "ieee_features"
   "iso_c_binding"
   "iso_fortran_env"
-  "omp_lib"
   "__fortran_builtins"
   "__fortran_type_info"
 )
+#"omp_lib"
 
 # Create module files directly from the top-level module source directory.
 # If CMAKE_CROSSCOMPILING, then the newly built flang-new executable was
@@ -71,6 +71,22 @@ if (NOT CMAKE_CROSSCOMPILING)
     list(APPEND MODULE_FILES ${base}.mod ${base}.f18.mod)
     install(FILES ${base}.mod ${base}.f18.mod DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/flang")
   endforeach()
+
+  # Special case for omp_lib.mod, because its source comes from openmp/runtime/src/include.
+  # It also produces to module files: omp_lib.mod and omp_lib_kinds.mod.
+  message("MK: ${CMAKE_BINARY_DIR}")
+  set(base ${FLANG_INTRINSIC_MODULES_DIR}/omp_lib)
+  add_custom_command(OUTPUT ${base}.mod
+    COMMAND ${CMAKE_COMMAND} -E make_directory ${FLANG_INTRINSIC_MODULES_DIR}
+    COMMAND flang-new -cpp -fsyntax-only ${opts} -module-dir ${FLANG_INTRINSIC_MODULES_DIR}
+      ${CMAKE_BINARY_DIR}/projects/openmp/runtime/src/omp_lib.F90
+    DEPENDS flang-new ${CMAKE_BINARY_DIR}/projects/openmp/runtime/src/omp_lib.F90 ${depends}
+  )
+  add_custom_command(OUTPUT ${base}.f18.mod
+    DEPENDS ${base}.mod
+    COMMAND ${CMAKE_COMMAND} -E copy ${base}.mod ${base}.f18.mod)
+  list(APPEND MODULE_FILES ${base}.mod ${base}.f18.mod)
+  install(FILES ${base}.mod ${base}.f18.mod ${base}_kinds.mod ${base}_kinds.f18.mod DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/flang")
 endif()
 
 add_custom_target(module_files ALL DEPENDS ${MODULE_FILES})
@@ -86,6 +102,8 @@ if (NOT WIN32)
   install(PROGRAMS ${CMAKE_BINARY_DIR}/bin/flang-to-external-fc DESTINATION "${CMAKE_INSTALL_BINDIR}")
 endif()
 
+# TODO: Is this the right file coming from the OpenMP runtime or is this a copy of it?
 # TODO Move this to a more suitable location
+#file(COPY ${FLANG_SOURCE_DIR}/module/omp_lib.h DESTINATION "${CMAKE_BINARY_DIR}/include/flang/OpenMP/" FILE_PERMISSIONS OWNER_READ OWNER_WRITE)
 file(COPY ${FLANG_SOURCE_DIR}/module/omp_lib.h DESTINATION "${CMAKE_BINARY_DIR}/include/flang/OpenMP/" FILE_PERMISSIONS OWNER_READ OWNER_WRITE)
-install(FILES ${CMAKE_BINARY_DIR}/include/flang/OpenMP/omp_lib.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/flang/OpenMP")
+install(FILES ${CMAKE_BINARY_DIR}/projects/openmp/runtime/src/omp_lib.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/flang/OpenMP")
diff --git a/openmp/runtime/src/CMakeLists.txt b/openmp/runtime/src/CMakeLists.txt
index 7e2a05e003b8d9..54203730ecc91f 100644
--- a/openmp/runtime/src/CMakeLists.txt
+++ b/openmp/runtime/src/CMakeLists.txt
@@ -312,9 +312,10 @@ endif()
 
 # Building the Fortran module files
 # One compilation step creates both omp_lib.mod and omp_lib_kinds.mod
+configure_file(${LIBOMP_INC_DIR}/omp_lib.h.var omp_lib.h @ONLY)
+configure_file(${LIBOMP_INC_DIR}/omp_lib.F90.var omp_lib.F90 @ONLY)
+message("LIBOMP: produce omp_lib.h omp_lib.F90")
 if(${LIBOMP_FORTRAN_MODULES})
-  configure_file(${LIBOMP_INC_DIR}/omp_lib.h.var omp_lib.h @ONLY)
-  configure_file(${LIBOMP_INC_DIR}/omp_lib.F90.var omp_lib.F90 @ONLY)
   # Workaround for gfortran to build modules with the
   # omp_sched_monotonic integer parameter
   if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")

>From ee7baef5bcd9205ffdbe7ce787eb1f0ff6542fa0 Mon Sep 17 00:00:00 2001
From: Michael Klemm <michael.klemm at amd.com>
Date: Thu, 8 Feb 2024 16:34:31 +0100
Subject: [PATCH 6/9] Add dependecy for ISO_S_BINDING, as needed by omp_lib.mod

---
 flang/tools/f18/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/flang/tools/f18/CMakeLists.txt b/flang/tools/f18/CMakeLists.txt
index 8369eae39994d0..514fc6387addbb 100644
--- a/flang/tools/f18/CMakeLists.txt
+++ b/flang/tools/f18/CMakeLists.txt
@@ -80,7 +80,7 @@ if (NOT CMAKE_CROSSCOMPILING)
     COMMAND ${CMAKE_COMMAND} -E make_directory ${FLANG_INTRINSIC_MODULES_DIR}
     COMMAND flang-new -cpp -fsyntax-only ${opts} -module-dir ${FLANG_INTRINSIC_MODULES_DIR}
       ${CMAKE_BINARY_DIR}/projects/openmp/runtime/src/omp_lib.F90
-    DEPENDS flang-new ${CMAKE_BINARY_DIR}/projects/openmp/runtime/src/omp_lib.F90 ${depends}
+    DEPENDS flang-new ${FLANG_INTRINSIC_MODULES_DIR}/iso_c_binding.mod ${CMAKE_BINARY_DIR}/projects/openmp/runtime/src/omp_lib.F90 ${depends}
   )
   add_custom_command(OUTPUT ${base}.f18.mod
     DEPENDS ${base}.mod

>From 6aa43813c3f0d73dfd11f2edc6a27a90f251b0e9 Mon Sep 17 00:00:00 2001
From: Michael Klemm <michael.klemm at amd.com>
Date: Thu, 8 Feb 2024 16:49:00 +0100
Subject: [PATCH 7/9] Correct a few things about copying and installing files

---
 flang/tools/f18/CMakeLists.txt | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/flang/tools/f18/CMakeLists.txt b/flang/tools/f18/CMakeLists.txt
index 514fc6387addbb..0e3cfbcfc00001 100644
--- a/flang/tools/f18/CMakeLists.txt
+++ b/flang/tools/f18/CMakeLists.txt
@@ -59,6 +59,7 @@ if (NOT CMAKE_CROSSCOMPILING)
       endif()
     endif()
 
+    # TODO: We may need to flag this with conditional, in case Flang is built w/o OpenMP support
     add_custom_command(OUTPUT ${base}.mod
       COMMAND ${CMAKE_COMMAND} -E make_directory ${FLANG_INTRINSIC_MODULES_DIR}
       COMMAND flang-new -cpp -fsyntax-only ${opts} -module-dir ${FLANG_INTRINSIC_MODULES_DIR}
@@ -85,7 +86,10 @@ if (NOT CMAKE_CROSSCOMPILING)
   add_custom_command(OUTPUT ${base}.f18.mod
     DEPENDS ${base}.mod
     COMMAND ${CMAKE_COMMAND} -E copy ${base}.mod ${base}.f18.mod)
-  list(APPEND MODULE_FILES ${base}.mod ${base}.f18.mod)
+    add_custom_command(OUTPUT ${base}_kinds.f18.mod
+      DEPENDS ${base}.mod
+      COMMAND ${CMAKE_COMMAND} -E copy ${base}_kinds.mod ${base}_kinds.f18.mod)
+  list(APPEND MODULE_FILES ${base}.mod ${base}.f18.mod ${base}_kinds.mod ${base}_kinds.f18.mod)
   install(FILES ${base}.mod ${base}.f18.mod ${base}_kinds.mod ${base}_kinds.f18.mod DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/flang")
 endif()
 
@@ -105,5 +109,6 @@ endif()
 # TODO: Is this the right file coming from the OpenMP runtime or is this a copy of it?
 # TODO Move this to a more suitable location
 #file(COPY ${FLANG_SOURCE_DIR}/module/omp_lib.h DESTINATION "${CMAKE_BINARY_DIR}/include/flang/OpenMP/" FILE_PERMISSIONS OWNER_READ OWNER_WRITE)
-file(COPY ${FLANG_SOURCE_DIR}/module/omp_lib.h DESTINATION "${CMAKE_BINARY_DIR}/include/flang/OpenMP/" FILE_PERMISSIONS OWNER_READ OWNER_WRITE)
-install(FILES ${CMAKE_BINARY_DIR}/projects/openmp/runtime/src/omp_lib.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/flang/OpenMP")
+file(COPY ${CMAKE_BINARY_DIR}/projects/openmp/runtime/src/omp_lib.h DESTINATION "${CMAKE_BINARY_DIR}/include/flang/OpenMP/" FILE_PERMISSIONS OWNER_READ OWNER_WRITE)
+install(FILES ${CMAKE_BINARY_DIR}/include/flang/OpenMP/omp_lib.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/flang/OpenMP")
+

>From 29eb7a4f1e4de7927f8b30f56f60f4640dd3aa9d Mon Sep 17 00:00:00 2001
From: Michael Klemm <michael.klemm at amd.com>
Date: Tue, 20 Feb 2024 15:18:27 +0100
Subject: [PATCH 8/9] Add missing generated dependence

---
 flang/tools/f18/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/flang/tools/f18/CMakeLists.txt b/flang/tools/f18/CMakeLists.txt
index 0e3cfbcfc00001..a867edb8b4a493 100644
--- a/flang/tools/f18/CMakeLists.txt
+++ b/flang/tools/f18/CMakeLists.txt
@@ -77,7 +77,7 @@ if (NOT CMAKE_CROSSCOMPILING)
   # It also produces to module files: omp_lib.mod and omp_lib_kinds.mod.
   message("MK: ${CMAKE_BINARY_DIR}")
   set(base ${FLANG_INTRINSIC_MODULES_DIR}/omp_lib)
-  add_custom_command(OUTPUT ${base}.mod
+  add_custom_command(OUTPUT ${base}.mod ${base}_kinds.mod
     COMMAND ${CMAKE_COMMAND} -E make_directory ${FLANG_INTRINSIC_MODULES_DIR}
     COMMAND flang-new -cpp -fsyntax-only ${opts} -module-dir ${FLANG_INTRINSIC_MODULES_DIR}
       ${CMAKE_BINARY_DIR}/projects/openmp/runtime/src/omp_lib.F90

>From 6b32f374cf818e6669b0404bea1efe31d5b23330 Mon Sep 17 00:00:00 2001
From: Michael Klemm <michael.klemm at amd.com>
Date: Tue, 20 Feb 2024 15:18:42 +0100
Subject: [PATCH 9/9] Cleanup CMake debugging code

---
 flang/tools/f18/CMakeLists.txt | 2 --
 1 file changed, 2 deletions(-)

diff --git a/flang/tools/f18/CMakeLists.txt b/flang/tools/f18/CMakeLists.txt
index a867edb8b4a493..396c85df150229 100644
--- a/flang/tools/f18/CMakeLists.txt
+++ b/flang/tools/f18/CMakeLists.txt
@@ -20,7 +20,6 @@ set(MODULES
   "__fortran_builtins"
   "__fortran_type_info"
 )
-#"omp_lib"
 
 # Create module files directly from the top-level module source directory.
 # If CMAKE_CROSSCOMPILING, then the newly built flang-new executable was
@@ -75,7 +74,6 @@ if (NOT CMAKE_CROSSCOMPILING)
 
   # Special case for omp_lib.mod, because its source comes from openmp/runtime/src/include.
   # It also produces to module files: omp_lib.mod and omp_lib_kinds.mod.
-  message("MK: ${CMAKE_BINARY_DIR}")
   set(base ${FLANG_INTRINSIC_MODULES_DIR}/omp_lib)
   add_custom_command(OUTPUT ${base}.mod ${base}_kinds.mod
     COMMAND ${CMAKE_COMMAND} -E make_directory ${FLANG_INTRINSIC_MODULES_DIR}



More information about the flang-commits mailing list