Skip to content

Commit ee6ca95

Browse files
committed
[OpenMP] Change build of OpenMP device runtime to be a separate runtime
Summary: Currently we build the OpenMP device runtime as part of the `offload/` project. This is problematic because it has several restrictions when compared to the normal offloading runtime. It can only be built with an up-to-date clang and we need to set the target appropriately. Currently we hack around this by creating the compiler invocation manually, but this patch moves it into a separate runtimes build. This follows the same build we use for libc, libc++, compiler-rt, and flang-rt. This also moves it from `offload/` into `openmp/` because it is still the `openmp/` runtime and I feel it is more appropriate. We do want a generic `offload/` library at some point, but it would be trivial to then add that as a separate library now that we have the infrastructure that makes adding these new libraries trivial. This most importantly will require that users update their build configs, mostly adding the following lines at a minimum. I was debating whether or not I should 'auto-upgrade' this, but I just went with a warning. ``` -DLLVM_RUNTIME_TARGETS='default;amdgcn-amd-amdhsa;nvptx64-nvidia-cuda' \ -DRUNTIMES_nvptx64-nvidia-cuda_LLVM_ENABLE_RUNTIMES=openmp \ -DRUNTIMES_amdgcn-amd-amdhsa_LLVM_ENABLE_RUNTIMES=openmp \ ``` This also changed where the `.bc` version of the library lives, but it's still created.
1 parent a5cdbef commit ee6ca95

36 files changed

+160
-210
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2794,6 +2794,11 @@ void tools::addOpenMPDeviceRTL(const Driver &D,
27942794
for (const auto &LibPath : HostTC.getFilePaths())
27952795
LibraryPaths.emplace_back(LibPath);
27962796

2797+
// Check the target specific library path for the triple as well.
2798+
SmallString<128> P(D.Dir);
2799+
llvm::sys::path::append(P, "..", "lib", Triple.getTriple());
2800+
LibraryPaths.emplace_back(P);
2801+
27972802
OptSpecifier LibomptargetBCPathOpt =
27982803
Triple.isAMDGCN() ? options::OPT_libomptarget_amdgpu_bc_path_EQ
27992804
: Triple.isNVPTX() ? options::OPT_libomptarget_nvptx_bc_path_EQ

offload/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ else()
113113
set(CMAKE_CXX_EXTENSIONS NO)
114114
endif()
115115

116+
# Emit a warning for people who haven't updated their build.
117+
if(NOT "openmp" IN_LIST RUNTIMES_amdgcn-amd-amdhsa_LLVM_ENABLE_RUNTIMES AND
118+
NOT "openmp" IN_LIST RUNTIMES_nvptx64-nvidia-cuda_LLVM_ENABLE_RUNTIMES)
119+
message(WARNING "Building the offloading runtime with no device library. See "
120+
"https://openmp.llvm.org//SupportAndFAQ.html for help.")
121+
endif()
122+
116123
# Set the path of all resulting libraries to a unified location so that it can
117124
# be used for testing.
118125
set(LIBOMPTARGET_LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
@@ -373,7 +380,6 @@ set(LIBOMPTARGET_LLVM_LIBRARY_INTDIR "${LIBOMPTARGET_INTDIR}" CACHE STRING
373380

374381
# Build offloading plugins and device RTLs if they are available.
375382
add_subdirectory(plugins-nextgen)
376-
add_subdirectory(DeviceRTL)
377383
add_subdirectory(tools)
378384

379385
# Build target agnostic offloading library.

offload/DeviceRTL/CMakeLists.txt

Lines changed: 0 additions & 181 deletions
This file was deleted.

offload/cmake/caches/Offload.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON CACHE BOOL "")
55
set(LLVM_RUNTIME_TARGETS default;amdgcn-amd-amdhsa;nvptx64-nvidia-cuda CACHE STRING "")
66
set(RUNTIMES_nvptx64-nvidia-cuda_CACHE_FILES "${CMAKE_SOURCE_DIR}/../libcxx/cmake/caches/NVPTX.cmake" CACHE STRING "")
77
set(RUNTIMES_amdgcn-amd-amdhsa_CACHE_FILES "${CMAKE_SOURCE_DIR}/../libcxx/cmake/caches/AMDGPU.cmake" CACHE STRING "")
8-
set(RUNTIMES_nvptx64-nvidia-cuda_LLVM_ENABLE_RUNTIMES "compiler-rt;libc;libcxx;libcxxabi" CACHE STRING "")
9-
set(RUNTIMES_amdgcn-amd-amdhsa_LLVM_ENABLE_RUNTIMES "compiler-rt;libc;libcxx;libcxxabi" CACHE STRING "")
8+
set(RUNTIMES_nvptx64-nvidia-cuda_LLVM_ENABLE_RUNTIMES "compiler-rt;libc;openmp;libcxx;libcxxabi" CACHE STRING "")
9+
set(RUNTIMES_amdgcn-amd-amdhsa_LLVM_ENABLE_RUNTIMES "compiler-rt;libc;openmp;libcxx;libcxxabi" CACHE STRING "")

openmp/CMakeLists.txt

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ else()
8888
set(CMAKE_CXX_EXTENSIONS NO)
8989
endif()
9090

91+
# Targeting the GPU directly requires a few flags to make CMake happy.
92+
if("${CMAKE_CXX_COMPILER_TARGET}" MATCHES "^amdgcn")
93+
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nogpulib")
94+
elseif("${CMAKE_CXX_COMPILER_TARGET}" MATCHES "^nvptx")
95+
set(CMAKE_REQUIRED_FLAGS
96+
"${CMAKE_REQUIRED_FLAGS} -flto -c -Wno-unused-command-line-argument")
97+
endif()
98+
9199
# Check and set up common compiler flags.
92100
include(config-ix)
93101
include(HandleOpenMPOptions)
@@ -122,35 +130,41 @@ else()
122130
get_clang_resource_dir(LIBOMP_HEADERS_INSTALL_PATH SUBDIR include)
123131
endif()
124132

125-
# Build host runtime library, after LIBOMPTARGET variables are set since they are needed
126-
# to enable time profiling support in the OpenMP runtime.
127-
add_subdirectory(runtime)
128-
129-
set(ENABLE_OMPT_TOOLS ON)
130-
# Currently tools are not tested well on Windows or MacOS X.
131-
if (APPLE OR WIN32)
132-
set(ENABLE_OMPT_TOOLS OFF)
133-
endif()
133+
# Use the current compiler target to determine the appropriate runtime to build.
134+
if("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^amdgcn|^nvptx" OR
135+
"${CMAKE_CXX_COMPILER_TARGET}" MATCHES "^amdgcn|^nvptx")
136+
add_subdirectory(device)
137+
else()
138+
# Build host runtime library, after LIBOMPTARGET variables are set since they
139+
# are needed to enable time profiling support in the OpenMP runtime.
140+
add_subdirectory(runtime)
141+
142+
set(ENABLE_OMPT_TOOLS ON)
143+
# Currently tools are not tested well on Windows or MacOS X.
144+
if (APPLE OR WIN32)
145+
set(ENABLE_OMPT_TOOLS OFF)
146+
endif()
134147

135-
option(OPENMP_ENABLE_OMPT_TOOLS "Enable building ompt based tools for OpenMP."
136-
${ENABLE_OMPT_TOOLS})
137-
if (OPENMP_ENABLE_OMPT_TOOLS)
138-
add_subdirectory(tools)
139-
endif()
148+
option(OPENMP_ENABLE_OMPT_TOOLS "Enable building ompt based tools for OpenMP."
149+
${ENABLE_OMPT_TOOLS})
150+
if (OPENMP_ENABLE_OMPT_TOOLS)
151+
add_subdirectory(tools)
152+
endif()
140153

141-
# Propagate OMPT support to offload
142-
if(NOT ${OPENMP_STANDALONE_BUILD})
143-
set(LIBOMP_HAVE_OMPT_SUPPORT ${LIBOMP_HAVE_OMPT_SUPPORT} PARENT_SCOPE)
144-
set(LIBOMP_OMP_TOOLS_INCLUDE_DIR ${LIBOMP_OMP_TOOLS_INCLUDE_DIR} PARENT_SCOPE)
145-
endif()
154+
# Propagate OMPT support to offload
155+
if(NOT ${OPENMP_STANDALONE_BUILD})
156+
set(LIBOMP_HAVE_OMPT_SUPPORT ${LIBOMP_HAVE_OMPT_SUPPORT} PARENT_SCOPE)
157+
set(LIBOMP_OMP_TOOLS_INCLUDE_DIR ${LIBOMP_OMP_TOOLS_INCLUDE_DIR} PARENT_SCOPE)
158+
endif()
146159

147-
option(OPENMP_MSVC_NAME_SCHEME "Build dll with MSVC naming scheme." OFF)
160+
option(OPENMP_MSVC_NAME_SCHEME "Build dll with MSVC naming scheme." OFF)
148161

149-
# Build libompd.so
150-
add_subdirectory(libompd)
162+
# Build libompd.so
163+
add_subdirectory(libompd)
151164

152-
# Build documentation
153-
add_subdirectory(docs)
165+
# Build documentation
166+
add_subdirectory(docs)
154167

155-
# Now that we have seen all testsuites, create the check-openmp target.
156-
construct_check_openmp_target()
168+
# Now that we have seen all testsuites, create the check-openmp target.
169+
construct_check_openmp_target()
170+
endif()

0 commit comments

Comments
 (0)