Skip to content

Commit 330d898

Browse files
jdoerfertsaiislam
andauthored
[Offload] Move /openmp/libomptarget to /offload (#75125)
In a nutshell, this moves our libomptarget code to populate the offload subproject. With this commit, users need to enable the new LLVM/Offload subproject as a runtime in their cmake configuration. No further changes are expected for downstream code. Tests and other components still depend on OpenMP and have also not been renamed. The results below are for a build in which OpenMP and Offload are enabled runtimes. In addition to the pure `git mv`, we needed to adjust some CMake files. Nothing is intended to change semantics. ``` ninja check-offload ``` Works with the X86 and AMDGPU offload tests ``` ninja check-openmp ``` Still works but doesn't build offload tests anymore. ``` ls install/lib ``` Shows all expected libraries, incl. - `libomptarget.devicertl.a` - `libomptarget-nvptx-sm_90.bc` - `libomptarget.rtl.amdgpu.so` -> `libomptarget.rtl.amdgpu.so.18git` - `libomptarget.so` -> `libomptarget.so.18git` Fixes: #75124 --------- Co-authored-by: Saiyedul Islam <[email protected]>
1 parent b6628c2 commit 330d898

File tree

353 files changed

+442
-73
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

353 files changed

+442
-73
lines changed

llvm/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ endif()
147147
# As we migrate runtimes to using the bootstrapping build, the set of default runtimes
148148
# should grow as we remove those runtimes from LLVM_ENABLE_PROJECTS above.
149149
set(LLVM_DEFAULT_RUNTIMES "libcxx;libcxxabi;libunwind")
150-
set(LLVM_SUPPORTED_RUNTIMES "libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;openmp;llvm-libgcc")
150+
set(LLVM_SUPPORTED_RUNTIMES "libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;openmp;llvm-libgcc;offload")
151151
set(LLVM_ENABLE_RUNTIMES "" CACHE STRING
152152
"Semicolon-separated list of runtimes to build, or \"all\" (${LLVM_DEFAULT_RUNTIMES}). Supported runtimes are ${LLVM_SUPPORTED_RUNTIMES}.")
153153
if(LLVM_ENABLE_RUNTIMES STREQUAL "all")

openmp/libomptarget/CMakeLists.txt renamed to offload/CMakeLists.txt

+156-10
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,106 @@
1010
#
1111
##===----------------------------------------------------------------------===##
1212

13-
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
14-
message(FATAL_ERROR "Direct configuration not supported, please use parent directory!")
13+
cmake_minimum_required(VERSION 3.20.0)
14+
15+
if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
16+
set(OPENMP_STANDALONE_BUILD TRUE)
17+
project(offload C CXX ASM)
18+
endif()
19+
20+
set(ENABLE_LIBOMPTARGET ON)
21+
# Currently libomptarget cannot be compiled on Windows or MacOS X.
22+
# Since the device plugins are only supported on Linux anyway,
23+
# there is no point in trying to compile libomptarget on other OSes.
24+
# 32-bit systems are not supported either.
25+
if (APPLE OR WIN32 OR NOT "cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES OR NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
26+
set(ENABLE_LIBOMPTARGET OFF)
1527
endif()
1628

17-
# Add cmake directory to search for custom cmake functions.
18-
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules ${CMAKE_MODULE_PATH})
29+
option(OPENMP_ENABLE_LIBOMPTARGET "Enable building libomptarget for offloading."
30+
${ENABLE_LIBOMPTARGET})
31+
if (OPENMP_ENABLE_LIBOMPTARGET)
32+
# Check that the library can actually be built.
33+
if (APPLE OR WIN32)
34+
message(FATAL_ERROR "libomptarget cannot be built on Windows and MacOS X!")
35+
elseif (NOT "cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
36+
message(FATAL_ERROR "Host compiler must support C++17 to build libomptarget!")
37+
elseif (NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
38+
message(FATAL_ERROR "libomptarget on 32-bit systems are not supported!")
39+
endif()
40+
endif()
41+
42+
# TODO: Leftover from the move, could probably be just LLVM_LIBDIR_SUFFIX everywhere.
43+
set(OFFLOAD_INSTALL_LIBDIR "lib${LLVM_LIBDIR_SUFFIX}")
44+
45+
set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
46+
47+
# Add path for custom modules
48+
list(INSERT CMAKE_MODULE_PATH 0
49+
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
50+
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
51+
"${LLVM_COMMON_CMAKE_UTILS}/Modules"
52+
)
53+
54+
if (OPENMP_STANDALONE_BUILD)
55+
# CMAKE_BUILD_TYPE was not set, default to Release.
56+
if (NOT CMAKE_BUILD_TYPE)
57+
set(CMAKE_BUILD_TYPE Release)
58+
endif()
59+
60+
# Group common settings.
61+
set(OPENMP_ENABLE_WERROR FALSE CACHE BOOL
62+
"Enable -Werror flags to turn warnings into errors for supporting compilers.")
63+
set(OPENMP_LIBDIR_SUFFIX "" CACHE STRING
64+
"Suffix of lib installation directory, e.g. 64 => lib64")
65+
# Do not use OPENMP_LIBDIR_SUFFIX directly, use OPENMP_INSTALL_LIBDIR.
66+
set(OPENMP_INSTALL_LIBDIR "lib${OPENMP_LIBDIR_SUFFIX}")
67+
68+
# Group test settings.
69+
set(OPENMP_TEST_C_COMPILER ${CMAKE_C_COMPILER} CACHE STRING
70+
"C compiler to use for testing OpenMP runtime libraries.")
71+
set(OPENMP_TEST_CXX_COMPILER ${CMAKE_CXX_COMPILER} CACHE STRING
72+
"C++ compiler to use for testing OpenMP runtime libraries.")
73+
set(OPENMP_TEST_Fortran_COMPILER ${CMAKE_Fortran_COMPILER} CACHE STRING
74+
"FORTRAN compiler to use for testing OpenMP runtime libraries.")
75+
set(OPENMP_LLVM_TOOLS_DIR "" CACHE PATH "Path to LLVM tools for testing.")
76+
77+
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
78+
set(CMAKE_CXX_STANDARD_REQUIRED NO)
79+
set(CMAKE_CXX_EXTENSIONS NO)
80+
else()
81+
set(OPENMP_ENABLE_WERROR ${LLVM_ENABLE_WERROR})
82+
# If building in tree, we honor the same install suffix LLVM uses.
83+
set(OPENMP_INSTALL_LIBDIR "lib${LLVM_LIBDIR_SUFFIX}")
84+
85+
if (NOT MSVC)
86+
set(OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)
87+
set(OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++)
88+
else()
89+
set(OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang.exe)
90+
set(OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++.exe)
91+
endif()
92+
93+
# Check for flang
94+
if (NOT MSVC)
95+
set(OPENMP_TEST_Fortran_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/flang-new)
96+
else()
97+
set(OPENMP_TEST_Fortran_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/flang-new.exe)
98+
endif()
99+
100+
# Set fortran test compiler if flang is found
101+
if (EXISTS "${OPENMP_TEST_Fortran_COMPILER}")
102+
message("Using local flang build at ${OPENMP_TEST_Fortran_COMPILER}")
103+
else()
104+
unset(OPENMP_TEST_Fortran_COMPILER)
105+
endif()
106+
107+
# If not standalone, set CMAKE_CXX_STANDARD but don't set the global cache value,
108+
# only set it locally for OpenMP.
109+
set(CMAKE_CXX_STANDARD 17)
110+
set(CMAKE_CXX_STANDARD_REQUIRED NO)
111+
set(CMAKE_CXX_EXTENSIONS NO)
112+
endif()
19113

20114
# Set the path of all resulting libraries to a unified location so that it can
21115
# be used for testing.
@@ -36,6 +130,9 @@ include(LibomptargetUtils)
36130
# Get dependencies for the different components of the project.
37131
include(LibomptargetGetDependencies)
38132

133+
# Set up testing infrastructure.
134+
include(OpenMPTesting)
135+
39136
# LLVM source tree is required at build time for libomptarget
40137
if (NOT LIBOMPTARGET_LLVM_INCLUDE_DIRS)
41138
message(FATAL_ERROR "Missing definition for LIBOMPTARGET_LLVM_INCLUDE_DIRS")
@@ -101,6 +198,58 @@ if (LIBOMPTARGET_USE_LTO)
101198
list(APPEND offload_link_flags ${CMAKE_CXX_COMPILE_OPTIONS_IPO})
102199
endif()
103200

201+
if(OPENMP_STANDALONE_BUILD)
202+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
203+
execute_process(
204+
OUTPUT_STRIP_TRAILING_WHITESPACE
205+
COMMAND ${CMAKE_CXX_COMPILER} --print-resource-dir
206+
RESULT_VARIABLE COMMAND_RETURN_CODE
207+
OUTPUT_VARIABLE COMPILER_RESOURCE_DIR
208+
)
209+
endif()
210+
211+
set(LIBOMP_HAVE_OMPT_SUPPORT FALSE)
212+
set(LIBOMP_OMPT_SUPPORT FALSE)
213+
214+
find_path (
215+
LIBOMP_OMP_TOOLS_INCLUDE_DIR
216+
NAMES
217+
omp-tools.h
218+
HINTS
219+
${COMPILER_RESOURCE_DIR}/include
220+
${CMAKE_INSTALL_PREFIX}/include
221+
)
222+
223+
if(LIBOMP_OMP_TOOLS_INCLUDE_DIR)
224+
set(LIBOMP_HAVE_OMPT_SUPPORT TRUE)
225+
set(LIBOMP_OMPT_SUPPORT TRUE)
226+
endif()
227+
228+
# LLVM_LIBRARY_DIRS set by find_package(LLVM) in LibomptargetGetDependencies
229+
find_library (
230+
LIBOMP_STANDALONE
231+
NAMES
232+
omp
233+
HINTS
234+
${CMAKE_INSTALL_PREFIX}/lib
235+
${LLVM_LIBRARY_DIRS}
236+
REQUIRED
237+
)
238+
# Check LIBOMP_HAVE_VERSION_SCRIPT_FLAG
239+
include(LLVMCheckCompilerLinkerFlag)
240+
if(NOT APPLE)
241+
llvm_check_compiler_linker_flag(C "-Wl,--version-script=${CMAKE_CURRENT_LIST_DIR}/../openmp/runtime/src/exports_test_so.txt" LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
242+
endif()
243+
244+
macro(pythonize_bool var)
245+
if (${var})
246+
set(${var} True)
247+
else()
248+
set(${var} False)
249+
endif()
250+
endmacro()
251+
endif()
252+
104253
# OMPT support for libomptarget
105254
# Follow host OMPT support and check if host support has been requested.
106255
# LIBOMP_HAVE_OMPT_SUPPORT indicates whether host OMPT support has been implemented.
@@ -127,13 +276,10 @@ pythonize_bool(LIBOMPTARGET_GPU_LIBC_SUPPORT)
127276

128277
set(LIBOMPTARGET_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
129278
message(STATUS "OpenMP tools dir in libomptarget: ${LIBOMP_OMP_TOOLS_INCLUDE_DIR}")
130-
include_directories(${LIBOMP_OMP_TOOLS_INCLUDE_DIR})
279+
if(LIBOMP_OMP_TOOLS_INCLUDE_DIR)
280+
include_directories(${LIBOMP_OMP_TOOLS_INCLUDE_DIR})
281+
endif()
131282

132-
# Definitions for testing, for reuse when testing libomptarget-nvptx.
133-
set(LIBOMPTARGET_OPENMP_HEADER_FOLDER "${LIBOMP_INCLUDE_DIR}" CACHE STRING
134-
"Path to folder containing omp.h")
135-
set(LIBOMPTARGET_OPENMP_HOST_RTL_FOLDER "${LIBOMP_LIBRARY_DIR}" CACHE STRING
136-
"Path to folder containing libomp.so, and libLLVMSupport.so with profiling enabled")
137283
set(LIBOMPTARGET_LLVM_LIBRARY_DIR "${LLVM_LIBRARY_DIR}" CACHE STRING
138284
"Path to folder containing llvm library libomptarget.so")
139285
set(LIBOMPTARGET_LLVM_LIBRARY_INTDIR "${LIBOMPTARGET_INTDIR}" CACHE STRING

openmp/libomptarget/DeviceRTL/CMakeLists.txt renamed to offload/DeviceRTL/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ function(compileDeviceRTLLibrary target_cpu target_name target_triple)
233233
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${bclib_name} ${LIBOMPTARGET_LIBRARY_DIR}/${bclib_name})
234234

235235
# Install bitcode library under the lib destination folder.
236-
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${bclib_name} DESTINATION "${OPENMP_INSTALL_LIBDIR}")
236+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${bclib_name} DESTINATION "${OFFLOAD_INSTALL_LIBDIR}")
237237

238238
set(target_feature "")
239239
if("${target_triple}" STREQUAL "nvptx64-nvidia-cuda")
@@ -312,4 +312,4 @@ set_target_properties(omptarget.devicertl PROPERTIES
312312
)
313313
target_link_libraries(omptarget.devicertl PRIVATE omptarget.devicertl.all_objs)
314314

315-
install(TARGETS omptarget.devicertl ARCHIVE DESTINATION ${OPENMP_INSTALL_LIBDIR})
315+
install(TARGETS omptarget.devicertl ARCHIVE DESTINATION ${OFFLOAD_INSTALL_LIBDIR})
File renamed without changes.

0 commit comments

Comments
 (0)