Skip to content

Commit a8657b1

Browse files
saiislamronlieb
authored andcommitted
[Offload] Move /openmp/libomptarget to /offload
Based on PR llvm#75125 In a nutshell, this moves our libomptarget code to create the offload subproject. For now, we allow LLVM/Offload only as runtime. 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, I needed to adjust some CMake files. Nothing is intended to change semantics but some of the things likely broke other build configurations. Testers are needed. 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: llvm#75124 Change-Id: Ie1d7a9805309c63292e6378f077ad319b42dd279
1 parent 15f6d14 commit a8657b1

File tree

441 files changed

+461
-60
lines changed

Some content is hidden

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

441 files changed

+461
-60
lines changed

clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ const char *amdgpu::dlr::getLinkCommandArgs(
263263
if (LibSuffix != "lib" || llvm::sys::fs::exists(Path)) {
264264
BCLibs.push_back(Args.MakeArgString(Path));
265265
} else {
266-
std::string RtDir = "/../runtimes/runtimes-bins/openmp/libomptarget";
266+
std::string RtDir = "/../runtimes/runtimes-bins/offload";
267267
BCLibs.push_back(Args.MakeArgString(libpath + RtDir + LibDeviceName));
268268
}
269269

clang/test/Driver/openmp-runtimelib.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@
3333

3434
// Debug: /lib-debug/libomptarget
3535
// Perf: /lib-perf/libomptarget
36-
// Devel: /lib/../runtimes/runtimes-bins/openmp/libomptarget/libomptarget
37-
// Default: /lib/../runtimes/runtimes-bins/openmp/libomptarget/libomptarget
36+
// Devel: /lib/../runtimes/runtimes-bins/offload/libomptarget
37+
// Default: /lib/../runtimes/runtimes-bins/offload/libomptarget
3838
// Error: clang: error: unsupported argument

llvm/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ endif()
163163
# As we migrate runtimes to using the bootstrapping build, the set of default runtimes
164164
# should grow as we remove those runtimes from LLVM_ENABLE_PROJECTS above.
165165
set(LLVM_DEFAULT_RUNTIMES "libcxx;libcxxabi;libunwind")
166-
set(LLVM_SUPPORTED_RUNTIMES "libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;openmp;llvm-libgcc")
166+
set(LLVM_SUPPORTED_RUNTIMES "libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;openmp;llvm-libgcc;offload")
167167
set(LLVM_ENABLE_RUNTIMES "" CACHE STRING
168168
"Semicolon-separated list of runtimes to build, or \"all\" (${LLVM_DEFAULT_RUNTIMES}). Supported runtimes are ${LLVM_SUPPORTED_RUNTIMES}.")
169169
if(LLVM_ENABLE_RUNTIMES STREQUAL "all")

llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2071,7 +2071,7 @@ class OpenMPIRBuilder {
20712071
/// The `omp target` interface
20722072
///
20732073
/// For more information about the usage of this interface,
2074-
/// \see openmp/libomptarget/deviceRTLs/common/include/target.h
2074+
/// \see offload/deviceRTLs/common/include/target.h
20752075
///
20762076
///{
20772077

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4683,7 +4683,7 @@ OpenMPIRBuilder::createTargetInit(const LocationDescription &Loc, bool IsSPMD,
46834683
UI->eraseFromParent();
46844684

46854685
// Continue in the "user_code" block, see diagram above and in
4686-
// openmp/libomptarget/deviceRTLs/common/include/target.h .
4686+
// offload/deviceRTLs/common/include/target.h .
46874687
return InsertPointTy(UserCodeEntryBB, UserCodeEntryBB->getFirstInsertionPt());
46884688
}
46894689

mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ using OpenACCIRBuilder = llvm::OpenMPIRBuilder;
3333
// Utility functions
3434
//===----------------------------------------------------------------------===//
3535

36-
/// Flag values are extracted from openmp/libomptarget/include/omptarget.h and
36+
/// Flag values are extracted from offload/include/omptarget.h and
3737
/// mapped to corresponding OpenACC flags.
3838
static constexpr uint64_t kCreateFlag = 0x000;
3939
static constexpr uint64_t kDeviceCopyinFlag = 0x001;

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

Lines changed: 158 additions & 20 deletions
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)
27+
endif()
28+
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()
1540
endif()
1641

17-
# Add cmake directory to search for custom cmake functions.
18-
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules ${CMAKE_MODULE_PATH})
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")
@@ -113,6 +210,58 @@ if (LIBOMPTARGET_USE_LTO)
113210
list(APPEND offload_link_flags ${CMAKE_CXX_COMPILE_OPTIONS_IPO})
114211
endif()
115212

213+
if(OPENMP_STANDALONE_BUILD)
214+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
215+
execute_process(
216+
OUTPUT_STRIP_TRAILING_WHITESPACE
217+
COMMAND ${CMAKE_CXX_COMPILER} --print-resource-dir
218+
RESULT_VARIABLE COMMAND_RETURN_CODE
219+
OUTPUT_VARIABLE COMPILER_RESOURCE_DIR
220+
)
221+
endif()
222+
223+
set(LIBOMP_HAVE_OMPT_SUPPORT FALSE)
224+
set(LIBOMP_OMPT_SUPPORT FALSE)
225+
226+
find_path (
227+
LIBOMP_OMP_TOOLS_INCLUDE_DIR
228+
NAMES
229+
omp-tools.h
230+
HINTS
231+
${COMPILER_RESOURCE_DIR}/include
232+
${CMAKE_INSTALL_PREFIX}/include
233+
)
234+
235+
if(LIBOMP_OMP_TOOLS_INCLUDE_DIR)
236+
set(LIBOMP_HAVE_OMPT_SUPPORT TRUE)
237+
set(LIBOMP_OMPT_SUPPORT TRUE)
238+
endif()
239+
240+
# LLVM_LIBRARY_DIRS set by find_package(LLVM) in LibomptargetGetDependencies
241+
find_library (
242+
LIBOMP_STANDALONE
243+
NAMES
244+
omp
245+
HINTS
246+
${CMAKE_INSTALL_PREFIX}/lib
247+
${LLVM_LIBRARY_DIRS}
248+
REQUIRED
249+
)
250+
# Check LIBOMP_HAVE_VERSION_SCRIPT_FLAG
251+
include(LLVMCheckCompilerLinkerFlag)
252+
if(NOT APPLE)
253+
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)
254+
endif()
255+
256+
macro(pythonize_bool var)
257+
if (${var})
258+
set(${var} True)
259+
else()
260+
set(${var} False)
261+
endif()
262+
endmacro()
263+
endif()
264+
116265
# OMPT support for libomptarget
117266
# Follow host OMPT support and check if host support has been requested.
118267
# LIBOMP_HAVE_OMPT_SUPPORT indicates whether host OMPT support has been implemented.
@@ -140,17 +289,6 @@ pythonize_bool(LIBOMPTARGET_GPU_LIBC_SUPPORT)
140289

141290
set(LIBOMPTARGET_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
142291

143-
find_path (
144-
LIBOMP_OMP_TOOLS_INCLUDE_DIR
145-
NAMES
146-
omp-tools.h
147-
PATHS
148-
${CMAKE_BINARY_DIR}/openmp/runtime/src
149-
${CMAKE_BINARY_DIR}/runtime/src
150-
)
151-
152-
include_directories(${LIBOMPTARGET_INCLUDE_DIR} ${LIBOMP_OMP_TOOLS_INCLUDE_DIR})
153-
154292
# Various LLVM_TOOLS are needed to build libomptarget
155293
find_package(LLVM QUIET CONFIG PATHS
156294
${LLVM_INSTALL_PREFIX}
@@ -177,11 +315,11 @@ else()
177315
message(" ====== WARNING! no LLVM found! some libomptarget components may be skipped")
178316
endif()
179317

180-
# Definitions for testing, for reuse when testing libomptarget-nvptx.
181-
set(LIBOMPTARGET_OPENMP_HEADER_FOLDER "${LIBOMP_INCLUDE_DIR}" CACHE STRING
182-
"Path to folder containing omp.h")
183-
set(LIBOMPTARGET_OPENMP_HOST_RTL_FOLDER "${LIBOMP_LIBRARY_DIR}" CACHE STRING
184-
"Path to folder containing libomp.so, and libLLVMSupport.so with profiling enabled")
318+
message(STATUS "OpenMP tools dir in libomptarget: ${LIBOMP_OMP_TOOLS_INCLUDE_DIR}")
319+
if(LIBOMP_OMP_TOOLS_INCLUDE_DIR)
320+
include_directories(${LIBOMP_OMP_TOOLS_INCLUDE_DIR})
321+
endif()
322+
185323
set(LIBOMPTARGET_LLVM_LIBRARY_DIR "${LLVM_LIBRARY_DIR}" CACHE STRING
186324
"Path to folder containing llvm library libomptarget.so")
187325
set(LIBOMPTARGET_LLVM_LIBRARY_INTDIR "${LIBOMPTARGET_INTDIR}" CACHE STRING

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,11 @@ function(compileDeviceRTLLibrary target_cpu target_name target_triple)
220220
if("${target_name}" STREQUAL "amdgpu")
221221
if(OPENMP_STANDALONE_BUILD)
222222
list(APPEND extra_bc_files
223-
${CMAKE_BINARY_DIR}/libomptarget/hostexec/libhostexec-${target_cpu}.bc
223+
${CMAKE_BINARY_DIR}/hostexec/libhostexec-${target_cpu}.bc
224224
)
225225
else()
226226
list(APPEND extra_bc_files
227-
${CMAKE_BINARY_DIR}/openmp/libomptarget/hostexec/libhostexec-${target_cpu}.bc
227+
${CMAKE_BINARY_DIR}/offload/hostexec/libhostexec-${target_cpu}.bc
228228
)
229229
endif()
230230
add_custom_target(libhostexec-${target_cpu}
@@ -307,7 +307,7 @@ function(compileDeviceRTLLibrary target_cpu target_name target_triple)
307307
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${bclib_name} ${LIBOMPTARGET_LIBRARY_DIR}/${bclib_name})
308308

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

312312
# ----------------- end steps for bc file installation for opaque-linker ----------------- #
313313

@@ -406,4 +406,4 @@ set_target_properties(omptarget.devicertl PROPERTIES
406406
)
407407
target_link_libraries(omptarget.devicertl PRIVATE omptarget.devicertl.all_objs)
408408

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

0 commit comments

Comments
 (0)