Skip to content

Commit

Permalink
[flang][OpenMP] Add fortran test with basic target region
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jsjodin committed Sep 1, 2023
1 parent 03f338e commit a0e3418
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
34 changes: 33 additions & 1 deletion openmp/libomptarget/test/lit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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 + " && " + \
Expand All @@ -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" + \
Expand All @@ -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 + \
Expand Down Expand Up @@ -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"))
Expand All @@ -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"))
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion openmp/libomptarget/test/offloading/fortran/basic_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a0e3418

Please sign in to comment.