Skip to content

Commit af9c013

Browse files
committed
Revert "An attempt to abandon omptarget out-of-tree builds."
This reverts commit f2f88f3. Because our libomptarget implementation for VE requries out-of-tree builds at the moemnt. TODO: need to apply this patch with updates of libomptarget for VE.
1 parent 1f06f50 commit af9c013

File tree

5 files changed

+91
-57
lines changed

5 files changed

+91
-57
lines changed

openmp/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ else()
3939
set(OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang.exe)
4040
set(OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++.exe)
4141
endif()
42+
43+
list(APPEND LIBOMPTARGET_LLVM_INCLUDE_DIRS ${LLVM_MAIN_INCLUDE_DIR} ${LLVM_BINARY_DIR}/include)
4244
endif()
4345

4446
# Check and set up common compiler flags.
@@ -62,6 +64,20 @@ if (APPLE OR WIN32 OR NOT OPENMP_HAVE_STD_CPP14_FLAG)
6264
set(ENABLE_LIBOMPTARGET OFF)
6365
endif()
6466

67+
# Attempt to locate LLVM source, required by libomptarget
68+
if (NOT LIBOMPTARGET_LLVM_INCLUDE_DIRS)
69+
if (LLVM_MAIN_INCLUDE_DIR)
70+
list(APPEND LIBOMPTARGET_LLVM_INCLUDE_DIRS ${LLVM_MAIN_INCLUDE_DIR})
71+
elseif (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../llvm/include)
72+
list(APPEND LIBOMPTARGET_LLVM_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../llvm/include)
73+
endif()
74+
endif()
75+
76+
if (NOT LIBOMPTARGET_LLVM_INCLUDE_DIRS)
77+
message(STATUS "Missing definition for LIBOMPTARGET_LLVM_INCLUDE_DIRS, disabling libomptarget")
78+
set(ENABLE_LIBOMPTARGET OFF)
79+
endif()
80+
6581
option(OPENMP_ENABLE_LIBOMPTARGET "Enable building libomptarget for offloading."
6682
${ENABLE_LIBOMPTARGET})
6783
option(OPENMP_ENABLE_LIBOMPTARGET_PROFILING "Enable time profiling for libomptarget."

openmp/README.rst

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,15 +243,6 @@ These flags are **appended**, they do not overwrite any of the preset flags.
243243
Options for ``libomptarget``
244244
----------------------------
245245

246-
An installed LLVM package is a prerequisite for building ``libomptarget``
247-
library. So ``libomptarget`` may only be built in two cases:
248-
249-
- As a project of a regular LLVM build via **LLVM_ENABLE_PROJECTS**,
250-
**LLVM_EXTERNAL_PROJECTS**, or **LLVM_ENABLE_RUNTIMES** or
251-
- as a standalone project build that uses a pre-installed LLVM package.
252-
In this mode one has to make sure that the default CMake
253-
``find_package(LLVM)`` call `succeeds <https://cmake.org/cmake/help/latest/command/find_package.html#search-procedure>`_.
254-
255246
**LIBOMPTARGET_OPENMP_HEADER_FOLDER** = ``""``
256247
Path of the folder that contains ``omp.h``. This is required for testing
257248
out-of-tree builds.

openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,6 @@
2121

2222
include (FindPackageHandleStandardArgs)
2323

24-
################################################################################
25-
# Looking for LLVM...
26-
################################################################################
27-
28-
if (OPENMP_STANDALONE_BUILD)
29-
# Complete LLVM package is required for building libomptarget
30-
# in an out-of-tree mode.
31-
find_package(LLVM REQUIRED)
32-
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
33-
message(STATUS "Using LLVM in: ${LLVM_DIR}")
34-
list(APPEND LIBOMPTARGET_LLVM_INCLUDE_DIRS ${LLVM_INCLUDE_DIRS})
35-
list(APPEND CMAKE_MODULE_PATH ${LLVM_CMAKE_DIR})
36-
include(AddLLVM)
37-
else()
38-
list(APPEND LIBOMPTARGET_LLVM_INCLUDE_DIRS
39-
${LLVM_MAIN_INCLUDE_DIR} ${LLVM_BINARY_DIR}/include
40-
)
41-
endif()
42-
4324
################################################################################
4425
# Looking for libelf...
4526
################################################################################
@@ -346,4 +327,27 @@ if (NOT LIBOMPTARGET_CUDA_TOOLKIT_ROOT_DIR_PRESET AND
346327
endif()
347328
endif()
348329

349-
set(OPENMP_PTHREAD_LIB ${LLVM_PTHREAD_LIB})
330+
if (OPENMP_STANDALONE_BUILD)
331+
# This duplicates code from llvm/cmake/config-ix.cmake
332+
if( WIN32 AND NOT CYGWIN )
333+
# We consider Cygwin as another Unix
334+
set(PURE_WINDOWS 1)
335+
endif()
336+
337+
# library checks
338+
if( NOT PURE_WINDOWS )
339+
check_library_exists(pthread pthread_create "" HAVE_LIBPTHREAD)
340+
endif()
341+
342+
if(HAVE_LIBPTHREAD)
343+
# We want to find pthreads library and at the moment we do want to
344+
# have it reported as '-l<lib>' instead of '-pthread'.
345+
# TODO: switch to -pthread once the rest of the build system can deal with it.
346+
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
347+
set(THREADS_HAVE_PTHREAD_ARG Off)
348+
find_package(Threads REQUIRED)
349+
set(OPENMP_PTHREAD_LIB ${CMAKE_THREAD_LIBS_INIT})
350+
endif()
351+
else()
352+
set(OPENMP_PTHREAD_LIB ${LLVM_PTHREAD_LIB})
353+
endif()

openmp/libomptarget/deviceRTLs/amdgcn/CMakeLists.txt

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,32 @@
1010
#
1111
##===----------------------------------------------------------------------===##
1212

13+
find_package(LLVM QUIET CONFIG
14+
PATHS
15+
$ENV{AOMP}
16+
$ENV{HOME}/rocm/aomp
17+
/opt/rocm/aomp
18+
/usr/lib/rocm/aomp
19+
${LIBOMPTARGET_NVPTX_CUDA_COMPILER_DIR}
20+
${LIBOMPTARGET_NVPTX_CUDA_LINKER_DIR}
21+
${CMAKE_CXX_COMPILER_DIR}
22+
NO_DEFAULT_PATH)
23+
24+
if (LLVM_DIR)
25+
libomptarget_say("Found LLVM ${LLVM_PACKAGE_VERSION}. Configure: ${LLVM_DIR}/LLVMConfig.cmake")
26+
else()
27+
libomptarget_say("Not building AMDGCN device RTL: AOMP not found")
28+
return()
29+
endif()
30+
31+
set(AOMP_INSTALL_PREFIX ${LLVM_INSTALL_PREFIX})
32+
33+
if (AOMP_INSTALL_PREFIX)
34+
set(AOMP_BINDIR ${AOMP_INSTALL_PREFIX}/bin)
35+
else()
36+
set(AOMP_BINDIR ${LLVM_BUILD_BINARY_DIR}/bin)
37+
endif()
38+
1339
# Copied from nvptx CMakeLists
1440
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64")
1541
set(aux_triple x86_64-unknown-linux-gnu)
@@ -22,20 +48,7 @@ else()
2248
return()
2349
endif()
2450

25-
if (LLVM_DIR)
26-
# Builds that use pre-installed LLVM have LLVM_DIR set.
27-
find_program(CLANG_TOOL clang PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)
28-
find_program(LINK_TOOL llvm-link PATHS ${LLVM_TOOLS_BINARY_DIR}
29-
NO_DEFAULT_PATH)
30-
find_program(OPT_TOOL opt PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)
31-
libomptarget_say("Building AMDGCN device RTL. Using clang: ${CLANG_TOOL}")
32-
else()
33-
# LLVM in-tree builds may use CMake target names to discover the tools.
34-
set(CLANG_TOOL $<TARGET_FILE:clang>)
35-
set(LINK_TOOL $<TARGET_FILE:llvm-link>)
36-
set(OPT_TOOL $<TARGET_FILE:opt>)
37-
libomptarget_say("Building AMDGCN device RTL. Using clang from in-tree build")
38-
endif()
51+
libomptarget_say("Building AMDGCN device RTL. LLVM_COMPILER_PATH=${AOMP_BINDIR}")
3952

4053
project(omptarget-amdgcn)
4154

@@ -96,7 +109,7 @@ if (DEFINED LIBOMPTARGET_AMDGCN_GFXLIST)
96109
endif()
97110

98111
macro(add_cuda_bc_library)
99-
set(cu_cmd ${CLANG_TOOL}
112+
set(cu_cmd ${AOMP_BINDIR}/clang++
100113
-xc++
101114
-c
102115
-std=c++14
@@ -132,7 +145,7 @@ macro(add_cuda_bc_library)
132145

133146
add_custom_command(
134147
OUTPUT linkout.cuda.${mcpu}.bc
135-
COMMAND ${LINK_TOOL} ${bc1_files} -o linkout.cuda.${mcpu}.bc
148+
COMMAND ${AOMP_BINDIR}/llvm-link ${bc1_files} -o linkout.cuda.${mcpu}.bc
136149
DEPENDS ${bc1_files})
137150

138151
list(APPEND bc_files linkout.cuda.${mcpu}.bc)
@@ -147,7 +160,7 @@ foreach(mcpu ${mcpus})
147160
set(bc_libname lib${libname}-${mcpu}.bc)
148161
add_custom_command(
149162
OUTPUT ${bc_libname}
150-
COMMAND ${LINK_TOOL} ${bc_files} | ${OPT_TOOL} --always-inline -o ${OUTPUTDIR}/${bc_libname}
163+
COMMAND ${AOMP_BINDIR}/llvm-link ${bc_files} | ${AOMP_BINDIR}/opt --always-inline -o ${OUTPUTDIR}/${bc_libname}
151164
DEPENDS ${bc_files})
152165

153166
add_custom_target(lib${libname}-${mcpu} ALL DEPENDS ${bc_libname})

openmp/libomptarget/src/CMakeLists.txt

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,29 @@ set(LIBOMPTARGET_SRC_FILES ${LIBOMPTARGET_SRC_FILES} PARENT_SCOPE)
2424

2525
include_directories(${LIBOMPTARGET_LLVM_INCLUDE_DIRS})
2626

27-
# Build libomptarget library with libdl dependency.
28-
add_library(omptarget SHARED ${LIBOMPTARGET_SRC_FILES})
29-
if (OPENMP_ENABLE_LIBOMPTARGET_PROFILING)
30-
# Add LLVMSupport dependency if profiling is enabled.
31-
# Linking with LLVM component libraries also requires
32-
# aligning the compile flags.
33-
llvm_update_compile_flags(omptarget)
27+
# Build libomptarget library with libdl dependency. Add LLVMSupport
28+
# dependency if building in-tree with profiling enabled.
29+
if(OPENMP_STANDALONE_BUILD OR (NOT OPENMP_ENABLE_LIBOMPTARGET_PROFILING))
30+
add_library(omptarget SHARED ${LIBOMPTARGET_SRC_FILES})
31+
target_link_libraries(omptarget
32+
${CMAKE_DL_LIBS}
33+
"-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports")
34+
else()
35+
set(LLVM_LINK_COMPONENTS
36+
Support
37+
)
38+
add_llvm_library(omptarget SHARED ${LIBOMPTARGET_SRC_FILES}
39+
LINK_LIBS ${CMAKE_DL_LIBS}
40+
"-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports"
41+
)
3442
target_compile_definitions(omptarget PUBLIC OMPTARGET_PROFILE_ENABLED)
35-
target_link_libraries(omptarget PRIVATE LLVMSupport)
3643
endif()
37-
target_link_libraries(omptarget PRIVATE
38-
${CMAKE_DL_LIBS}
39-
"-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports")
44+
45+
# libomptarget needs to be set separately because add_llvm_library doesn't
46+
# conform with location configuration of its parent scope.
47+
set_target_properties(omptarget
48+
PROPERTIES
49+
LIBRARY_OUTPUT_DIRECTORY ${LIBOMPTARGET_LIBRARY_DIR})
4050

4151
# Install libomptarget under the lib destination folder.
4252
install(TARGETS omptarget LIBRARY COMPONENT omptarget

0 commit comments

Comments
 (0)