[Openmp-commits] [openmp] a0e3418 - [flang][OpenMP] Add fortran test with basic target region

Jan Leyonberg via Openmp-commits openmp-commits at lists.llvm.org
Fri Sep 1 06:27:49 PDT 2023


Author: Jan Leyonberg
Date: 2023-09-01T09:26:36-04:00
New Revision: a0e3418bc84c5cf88b0370f57155beae9ff985f2

URL: https://github.com/llvm/llvm-project/commit/a0e3418bc84c5cf88b0370f57155beae9ff985f2
DIFF: https://github.com/llvm/llvm-project/commit/a0e3418bc84c5cf88b0370f57155beae9ff985f2.diff

LOG: [flang][OpenMP] Add fortran test with basic target region

This patch adds a test that uses a target region to set a scalar value. It also
adds rules in lit.cfg to handle fortran testing.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D159216

Added: 
    openmp/libomptarget/test/Inputs/basic_array.f90
    openmp/libomptarget/test/offloading/fortran/basic_target_region.f90

Modified: 
    openmp/libomptarget/test/lit.cfg
    openmp/libomptarget/test/offloading/fortran/basic_array.c

Removed: 
    openmp/libomptarget/test/offloading/fortran/basic_array.f90


################################################################################
diff  --git a/openmp/libomptarget/test/offloading/fortran/basic_array.f90 b/openmp/libomptarget/test/Inputs/basic_array.f90
similarity index 100%
rename from openmp/libomptarget/test/offloading/fortran/basic_array.f90
rename to openmp/libomptarget/test/Inputs/basic_array.f90

diff  --git a/openmp/libomptarget/test/lit.cfg b/openmp/libomptarget/test/lit.cfg
index 2406aaf44e39ea..f54edf91574671 100644
--- a/openmp/libomptarget/test/lit.cfg
+++ b/openmp/libomptarget/test/lit.cfg
@@ -58,7 +58,10 @@ def evaluate_bool_env(env):
 config.name = 'libomptarget :: ' + config.libomptarget_current_target
 
 # suffixes: A list of file extensions to treat as test files.
-config.suffixes = ['.c', '.cpp', '.cc']
+config.suffixes = ['.c', '.cpp', '.cc', '.f90']
+
+# excludes: A list of directories to exclude from the testuites.
+config.excludes = ['Inputs']
 
 # test_source_root: The root path where tests are located.
 config.test_source_root = os.path.dirname(__file__)
@@ -162,6 +165,8 @@ for libomptarget_target in config.libomptarget_all_targets:
             "%libomptarget-compilexx-run-and-check-" + libomptarget_target))
         config.substitutions.append(("%libomptarget-compile-run-and-check-generic",
             "%libomptarget-compile-run-and-check-" + libomptarget_target))
+        config.substitutions.append(("%libomptarget-compile-fortran-run-and-check-generic",
+            "%libomptarget-compile-fortran-run-and-check-" + libomptarget_target))
         config.substitutions.append(("%libomptarget-compilexx-and-run-generic",
             "%libomptarget-compilexx-and-run-" + libomptarget_target))
         config.substitutions.append(("%libomptarget-compile-and-run-generic",
@@ -170,6 +175,8 @@ for libomptarget_target in config.libomptarget_all_targets:
             "%libomptarget-compilexx-" + libomptarget_target))
         config.substitutions.append(("%libomptarget-compile-generic",
             "%libomptarget-compile-" + libomptarget_target))
+        config.substitutions.append(("%libomptarget-compile-fortran-generic",
+            "%libomptarget-compile-fortran-" + libomptarget_target))
         config.substitutions.append(("%libomptarget-compileoptxx-run-and-check-generic",
             "%libomptarget-compileoptxx-run-and-check-" + libomptarget_target))
         config.substitutions.append(("%libomptarget-compileopt-run-and-check-generic",
@@ -204,6 +211,10 @@ for libomptarget_target in config.libomptarget_all_targets:
             libomptarget_target, \
             "%libomptarget-compile-and-run-" + libomptarget_target + \
             " | " + config.libomptarget_filecheck + " %s"))
+        config.substitutions.append(("%libomptarget-compile-fortran-run-and-check-" + \
+            libomptarget_target, \
+            "%libomptarget-compile-fortran-and-run-" + libomptarget_target + \
+            " | " + config.libomptarget_filecheck + " %s"))
         config.substitutions.append(("%libomptarget-compilexx-and-run-" + \
             libomptarget_target, \
             "%libomptarget-compilexx-" + libomptarget_target + " && " + \
@@ -212,6 +223,10 @@ for libomptarget_target in config.libomptarget_all_targets:
             libomptarget_target, \
             "%libomptarget-compile-" + libomptarget_target + " && " + \
             "%libomptarget-run-" + libomptarget_target))
+        config.substitutions.append(("%libomptarget-compile-fortran-and-run-" + \
+            libomptarget_target, \
+            "%libomptarget-compile-fortran-" + libomptarget_target + " && " + \
+            "%libomptarget-run-" + libomptarget_target))
         config.substitutions.append(("%libomptarget-compilexx-" + \
             libomptarget_target, \
             "%clangxx-" + libomptarget_target + " %s -o %t" + \
@@ -220,6 +235,9 @@ for libomptarget_target in config.libomptarget_all_targets:
             libomptarget_target, \
             "%clang-" + libomptarget_target + " %s -o %t" +
             (" -lcgpu" if config.libomptarget_has_libc else "")))
+        config.substitutions.append(("%libomptarget-compile-fortran-" + \
+            libomptarget_target, \
+            "%flang-" + libomptarget_target + " %s -o %t"))
         config.substitutions.append(("%libomptarget-compileoptxx-run-and-check-" + \
             libomptarget_target, \
             "%libomptarget-compileoptxx-and-run-" + libomptarget_target + \
@@ -256,18 +274,27 @@ for libomptarget_target in config.libomptarget_all_targets:
         config.substitutions.append(("%clang-" + libomptarget_target, \
                                      "%clang %openmp_flags %cuda_flags %flags -fopenmp-targets=" +\
                                      remove_suffix_if_present(libomptarget_target)))
+        config.substitutions.append(("%flang-" + libomptarget_target, \
+                                     "%flang %openmp_flags %flags -fopenmp-targets=" +\
+                                     remove_suffix_if_present(libomptarget_target)))
         config.substitutions.append(("%fcheck-" + libomptarget_target, \
             config.libomptarget_filecheck + " %s"))
     else:
         config.substitutions.append(("%libomptarget-compile-run-and-check-" + \
             libomptarget_target, \
             "echo ignored-command"))
+        config.substitutions.append(("%libomptarget-compile-fortran-run-and-check-" + \
+            libomptarget_target, \
+            "echo ignored-command"))
         config.substitutions.append(("%libomptarget-compilexx-run-and-check-" + \
             libomptarget_target, \
             "echo ignored-command"))
         config.substitutions.append(("%libomptarget-compile-and-run-" + \
             libomptarget_target, \
             "echo ignored-command"))
+        config.substitutions.append(("%libomptarget-compile-fortran-and-run-" + \
+            libomptarget_target, \
+            "echo ignored-command"))
         config.substitutions.append(("%libomptarget-compilexx-and-run-" + \
             libomptarget_target, \
             "echo ignored-command"))
@@ -277,6 +304,9 @@ for libomptarget_target in config.libomptarget_all_targets:
         config.substitutions.append(("%libomptarget-compile-" + \
             libomptarget_target, \
             "echo ignored-command"))
+        config.substitutions.append(("%libomptarget-compile-fortran-" + \
+            libomptarget_target, \
+            "echo ignored-command"))
         config.substitutions.append(("%libomptarget-compileopt-run-and-check-" + \
             libomptarget_target, \
             "echo ignored-command"))
@@ -307,6 +337,8 @@ for libomptarget_target in config.libomptarget_all_targets:
             "echo ignored-command"))
         config.substitutions.append(("%fcheck-" + libomptarget_target, \
             "echo ignored-command"))
+        config.substitutions.append(("%flang-" + libomptarget_target, \
+            "echo ignored-command"))
 
 config.substitutions.append(("%clangxx", config.test_cxx_compiler))
 config.substitutions.append(("%clang", config.test_c_compiler))

diff  --git a/openmp/libomptarget/test/offloading/fortran/basic_array.c b/openmp/libomptarget/test/offloading/fortran/basic_array.c
index 20334e87930564..4daf1d4b0a998a 100644
--- a/openmp/libomptarget/test/offloading/fortran/basic_array.c
+++ b/openmp/libomptarget/test/offloading/fortran/basic_array.c
@@ -2,7 +2,7 @@
 // REQUIRES: flang, amdgcn-amd-amdhsa
 
 // RUN: %flang -c -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa \
-// RUN:   %S/basic_array.f90 -o basic_array.o
+// RUN:   %S/../../Inputs/basic_array.f90 -o basic_array.o
 // RUN: %libomptarget-compile-generic basic_array.o
 // RUN: %t | %fcheck-generic
 

diff  --git a/openmp/libomptarget/test/offloading/fortran/basic_target_region.f90 b/openmp/libomptarget/test/offloading/fortran/basic_target_region.f90
new file mode 100644
index 00000000000000..295452b0698a66
--- /dev/null
+++ b/openmp/libomptarget/test/offloading/fortran/basic_target_region.f90
@@ -0,0 +1,21 @@
+! Basic offloading test with a target region
+! REQUIRES: flang, amdgcn-amd-amdhsa
+! UNSUPPORTED: nvptx64-nvidia-cuda
+! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
+! UNSUPPORTED: aarch64-unknown-linux-gnu
+! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
+! UNSUPPORTED: x86_64-pc-linux-gnu
+! UNSUPPORTED: x86_64-pc-linux-gnu-LTO
+
+! RUN: %libomptarget-compile-fortran-run-and-check-generic
+program main
+  integer :: x;
+  x = 0
+!$omp target map(from:x)
+    x = 5
+!$omp end target
+  print *, "x = ", x
+end program main
+
+! CHECK: x = 5
+


        


More information about the Openmp-commits mailing list