Skip to content

Commit

Permalink
[openmp] Fix flang detection for offloading test
Browse files Browse the repository at this point in the history
This patch fixes the flang detection in the openmp fortran offloading test.

Reviewed By: jsjodin

Differential Revision: https://reviews.llvm.org/D158546
  • Loading branch information
EthanLuisMcDonough committed Aug 29, 2023
1 parent a43bf8a commit 9e3d59e
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 25 deletions.
7 changes: 7 additions & 0 deletions openmp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ if (OPENMP_STANDALONE_BUILD)
"C compiler to use for testing OpenMP runtime libraries.")
set(OPENMP_TEST_CXX_COMPILER ${CMAKE_CXX_COMPILER} CACHE STRING
"C++ compiler to use for testing OpenMP runtime libraries.")
set(OPENMP_TEST_Fortran_COMPILER ${CMAKE_Fortran_COMPILER} CACHE STRING
"FORTRAN compiler to use for testing OpenMP runtime libraries.")
set(OPENMP_LLVM_TOOLS_DIR "" CACHE PATH "Path to LLVM tools for testing.")

set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
Expand All @@ -54,6 +56,11 @@ else()
set(OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++.exe)
endif()

find_program(OPENMP_TEST_Fortran_COMPILER flang-new PATHS LLVM_RUNTIME_OUTPUT_INTDIR)
if (NOT OPENMP_TEST_Fortran_COMPILER)
unset(OPENMP_TEST_Fortran_COMPILER CACHE)
endif()

# If not standalone, set CMAKE_CXX_STANDARD but don't set the global cache value,
# only set it locally for OpenMP.
set(CMAKE_CXX_STANDARD 17)
Expand Down
10 changes: 4 additions & 6 deletions openmp/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ Options for all Libraries
Compiler to use for testing. Defaults to the compiler that was also used for
building.

**OPENMP_TEST_Fortran_COMPILER** = ``${CMAKE_Fortran_COMPILER}``
Compiler to use for testing. Defaults to the compiler that was also used for
building. Will default to flang if build is in-tree.

**OPENMP_LLVM_TOOLS_DIR** = ``/path/to/built/llvm/tools``
Additional path to search for LLVM tools needed by tests.

Expand Down Expand Up @@ -165,12 +169,6 @@ Options for ``libomp``
**LIBOMP_FORTRAN_MODULES** = ``OFF|ON``
Create the Fortran modules (requires Fortran compiler).

.. note::

If libomptarget is built in-tree with both flang and openmp in
`LLVM_ENABLE_PROJECTS`, flang will be used for Fortran offloading
tests.

macOS* Fat Libraries
""""""""""""""""""""
On macOS* machines, it is possible to build universal (or fat) libraries which
Expand Down
5 changes: 1 addition & 4 deletions openmp/libomptarget/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,10 @@ foreach(CURRENT_TARGET IN LISTS SYSTEM_TARGETS)
configure_file(lit.site.cfg.in ${CURRENT_TARGET}/lit.site.cfg @ONLY)
endforeach()

if ("flang" IN_LIST LLVM_ENABLE_PROJECTS)
SET(FORTRAN_TEST_DEPS flang-new)
endif()

add_openmp_testsuite(check-libomptarget
"Running libomptarget tests"
${LIBOMPTARGET_LIT_TESTSUITES}
EXCLUDE_FROM_CHECK_ALL
DEPENDS omptarget omp ${LIBOMPTARGET_TESTED_PLUGINS} ${FORTRAN_TEST_DEPS}
DEPENDS omptarget omp ${LIBOMPTARGET_TESTED_PLUGINS}
ARGS ${LIBOMPTARGET_LIT_ARG_LIST})
16 changes: 5 additions & 11 deletions openmp/libomptarget/test/lit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
import os
import lit.formats

from lit.llvm import llvm_config
from lit.llvm.subst import ToolSubst
from lit.llvm.subst import FindTool

# Tell pylint that we know config and lit_config exist somewhere.
if 'PYLINT_IMPORT' in os.environ:
config = object()
Expand Down Expand Up @@ -70,8 +66,6 @@ config.test_source_root = os.path.dirname(__file__)
# test_exec_root: The root object directory where output is placed
config.test_exec_root = config.libomptarget_obj_root

tools = []

# test format
config.test_format = lit.formats.ShTest()

Expand Down Expand Up @@ -100,10 +94,6 @@ if config.has_libomptarget_ompt:

config.available_features.add(config.libomptarget_current_target)

if 'flang' in config.llvm_enabled_projects:
config.available_features.add('flang')
tools.append(ToolSubst('%flang', command=FindTool('flang-new'), unresolved='fatal'))

if config.libomptarget_has_libc:
config.available_features.add('libc')

Expand Down Expand Up @@ -320,11 +310,15 @@ for libomptarget_target in config.libomptarget_all_targets:

config.substitutions.append(("%clangxx", config.test_cxx_compiler))
config.substitutions.append(("%clang", config.test_c_compiler))

if config.test_fortran_compiler:
config.available_features.add('flang')
config.substitutions.append(("%flang", config.test_fortran_compiler))

config.substitutions.append(("%openmp_flags", config.test_openmp_flags))
if config.libomptarget_current_target.startswith('nvptx') and config.cuda_path:
config.substitutions.append(("%cuda_flags", "--cuda-path=" + config.cuda_path))
else:
config.substitutions.append(("%cuda_flags", ""))
config.substitutions.append(("%flags", config.test_flags))
config.substitutions.append(("%not", config.libomptarget_not))
llvm_config.add_tool_substitutions(tools, config.bin_llvm_tools_dir)
5 changes: 1 addition & 4 deletions openmp/libomptarget/test/lit.site.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
config.bin_llvm_tools_dir = "@CMAKE_BINARY_DIR@/bin"
config.test_c_compiler = "@OPENMP_TEST_C_COMPILER@"
config.test_cxx_compiler = "@OPENMP_TEST_CXX_COMPILER@"
config.test_fortran_compiler="@OPENMP_TEST_Fortran_COMPILER@"
config.test_compiler_features = @OPENMP_TEST_COMPILER_FEATURES@
config.test_openmp_flags = "@OPENMP_TEST_OPENMP_FLAGS@"
config.test_extra_flags = "@OPENMP_TEST_FLAGS@"
Expand All @@ -21,11 +22,7 @@ config.libomptarget_filecheck = "@OPENMP_FILECHECK_EXECUTABLE@"
config.libomptarget_not = "@OPENMP_NOT_EXECUTABLE@"
config.libomptarget_debug = @LIBOMPTARGET_DEBUG@
config.has_libomptarget_ompt = @LIBOMPTARGET_OMPT_SUPPORT@
config.llvm_enabled_projects = "@LLVM_ENABLE_PROJECTS@".split(";")
config.libomptarget_has_libc = @LIBOMPTARGET_GPU_LIBC_SUPPORT@

import lit.llvm
lit.llvm.initialize(lit_config, config)

# Let the main config do the real work.
lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg")
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
subroutine increment_at(c_index, arr) bind(C, name="increment_at")
use ISO_C_BINDING
!$omp declare target
integer (C_INT), dimension(*), intent(inout) :: arr
integer (C_INT), value :: c_index
arr(c_index+1) = arr(c_index+1) + 1
Expand Down

0 comments on commit 9e3d59e

Please sign in to comment.