Skip to content

Commit

Permalink
Revert "An attempt to abandon omptarget out-of-tree builds."
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kaz7 committed Jul 14, 2021
1 parent 1f06f50 commit af9c013
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 57 deletions.
16 changes: 16 additions & 0 deletions openmp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ else()
set(OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang.exe)
set(OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++.exe)
endif()

list(APPEND LIBOMPTARGET_LLVM_INCLUDE_DIRS ${LLVM_MAIN_INCLUDE_DIR} ${LLVM_BINARY_DIR}/include)
endif()

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

# Attempt to locate LLVM source, required by libomptarget
if (NOT LIBOMPTARGET_LLVM_INCLUDE_DIRS)
if (LLVM_MAIN_INCLUDE_DIR)
list(APPEND LIBOMPTARGET_LLVM_INCLUDE_DIRS ${LLVM_MAIN_INCLUDE_DIR})
elseif (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../llvm/include)
list(APPEND LIBOMPTARGET_LLVM_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../llvm/include)
endif()
endif()

if (NOT LIBOMPTARGET_LLVM_INCLUDE_DIRS)
message(STATUS "Missing definition for LIBOMPTARGET_LLVM_INCLUDE_DIRS, disabling libomptarget")
set(ENABLE_LIBOMPTARGET OFF)
endif()

option(OPENMP_ENABLE_LIBOMPTARGET "Enable building libomptarget for offloading."
${ENABLE_LIBOMPTARGET})
option(OPENMP_ENABLE_LIBOMPTARGET_PROFILING "Enable time profiling for libomptarget."
Expand Down
9 changes: 0 additions & 9 deletions openmp/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,6 @@ These flags are **appended**, they do not overwrite any of the preset flags.
Options for ``libomptarget``
----------------------------

An installed LLVM package is a prerequisite for building ``libomptarget``
library. So ``libomptarget`` may only be built in two cases:

- As a project of a regular LLVM build via **LLVM_ENABLE_PROJECTS**,
**LLVM_EXTERNAL_PROJECTS**, or **LLVM_ENABLE_RUNTIMES** or
- as a standalone project build that uses a pre-installed LLVM package.
In this mode one has to make sure that the default CMake
``find_package(LLVM)`` call `succeeds <https://cmake.org/cmake/help/latest/command/find_package.html#search-procedure>`_.

**LIBOMPTARGET_OPENMP_HEADER_FOLDER** = ``""``
Path of the folder that contains ``omp.h``. This is required for testing
out-of-tree builds.
Expand Down
44 changes: 24 additions & 20 deletions openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,6 @@

include (FindPackageHandleStandardArgs)

################################################################################
# Looking for LLVM...
################################################################################

if (OPENMP_STANDALONE_BUILD)
# Complete LLVM package is required for building libomptarget
# in an out-of-tree mode.
find_package(LLVM REQUIRED)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVM in: ${LLVM_DIR}")
list(APPEND LIBOMPTARGET_LLVM_INCLUDE_DIRS ${LLVM_INCLUDE_DIRS})
list(APPEND CMAKE_MODULE_PATH ${LLVM_CMAKE_DIR})
include(AddLLVM)
else()
list(APPEND LIBOMPTARGET_LLVM_INCLUDE_DIRS
${LLVM_MAIN_INCLUDE_DIR} ${LLVM_BINARY_DIR}/include
)
endif()

################################################################################
# Looking for libelf...
################################################################################
Expand Down Expand Up @@ -346,4 +327,27 @@ if (NOT LIBOMPTARGET_CUDA_TOOLKIT_ROOT_DIR_PRESET AND
endif()
endif()

set(OPENMP_PTHREAD_LIB ${LLVM_PTHREAD_LIB})
if (OPENMP_STANDALONE_BUILD)
# This duplicates code from llvm/cmake/config-ix.cmake
if( WIN32 AND NOT CYGWIN )
# We consider Cygwin as another Unix
set(PURE_WINDOWS 1)
endif()

# library checks
if( NOT PURE_WINDOWS )
check_library_exists(pthread pthread_create "" HAVE_LIBPTHREAD)
endif()

if(HAVE_LIBPTHREAD)
# We want to find pthreads library and at the moment we do want to
# have it reported as '-l<lib>' instead of '-pthread'.
# TODO: switch to -pthread once the rest of the build system can deal with it.
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_HAVE_PTHREAD_ARG Off)
find_package(Threads REQUIRED)
set(OPENMP_PTHREAD_LIB ${CMAKE_THREAD_LIBS_INIT})
endif()
else()
set(OPENMP_PTHREAD_LIB ${LLVM_PTHREAD_LIB})
endif()
47 changes: 30 additions & 17 deletions openmp/libomptarget/deviceRTLs/amdgcn/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,32 @@
#
##===----------------------------------------------------------------------===##

find_package(LLVM QUIET CONFIG
PATHS
$ENV{AOMP}
$ENV{HOME}/rocm/aomp
/opt/rocm/aomp
/usr/lib/rocm/aomp
${LIBOMPTARGET_NVPTX_CUDA_COMPILER_DIR}
${LIBOMPTARGET_NVPTX_CUDA_LINKER_DIR}
${CMAKE_CXX_COMPILER_DIR}
NO_DEFAULT_PATH)

if (LLVM_DIR)
libomptarget_say("Found LLVM ${LLVM_PACKAGE_VERSION}. Configure: ${LLVM_DIR}/LLVMConfig.cmake")
else()
libomptarget_say("Not building AMDGCN device RTL: AOMP not found")
return()
endif()

set(AOMP_INSTALL_PREFIX ${LLVM_INSTALL_PREFIX})

if (AOMP_INSTALL_PREFIX)
set(AOMP_BINDIR ${AOMP_INSTALL_PREFIX}/bin)
else()
set(AOMP_BINDIR ${LLVM_BUILD_BINARY_DIR}/bin)
endif()

# Copied from nvptx CMakeLists
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64")
set(aux_triple x86_64-unknown-linux-gnu)
Expand All @@ -22,20 +48,7 @@ else()
return()
endif()

if (LLVM_DIR)
# Builds that use pre-installed LLVM have LLVM_DIR set.
find_program(CLANG_TOOL clang PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)
find_program(LINK_TOOL llvm-link PATHS ${LLVM_TOOLS_BINARY_DIR}
NO_DEFAULT_PATH)
find_program(OPT_TOOL opt PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)
libomptarget_say("Building AMDGCN device RTL. Using clang: ${CLANG_TOOL}")
else()
# LLVM in-tree builds may use CMake target names to discover the tools.
set(CLANG_TOOL $<TARGET_FILE:clang>)
set(LINK_TOOL $<TARGET_FILE:llvm-link>)
set(OPT_TOOL $<TARGET_FILE:opt>)
libomptarget_say("Building AMDGCN device RTL. Using clang from in-tree build")
endif()
libomptarget_say("Building AMDGCN device RTL. LLVM_COMPILER_PATH=${AOMP_BINDIR}")

project(omptarget-amdgcn)

Expand Down Expand Up @@ -96,7 +109,7 @@ if (DEFINED LIBOMPTARGET_AMDGCN_GFXLIST)
endif()

macro(add_cuda_bc_library)
set(cu_cmd ${CLANG_TOOL}
set(cu_cmd ${AOMP_BINDIR}/clang++
-xc++
-c
-std=c++14
Expand Down Expand Up @@ -132,7 +145,7 @@ macro(add_cuda_bc_library)

add_custom_command(
OUTPUT linkout.cuda.${mcpu}.bc
COMMAND ${LINK_TOOL} ${bc1_files} -o linkout.cuda.${mcpu}.bc
COMMAND ${AOMP_BINDIR}/llvm-link ${bc1_files} -o linkout.cuda.${mcpu}.bc
DEPENDS ${bc1_files})

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

add_custom_target(lib${libname}-${mcpu} ALL DEPENDS ${bc_libname})
Expand Down
32 changes: 21 additions & 11 deletions openmp/libomptarget/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,29 @@ set(LIBOMPTARGET_SRC_FILES ${LIBOMPTARGET_SRC_FILES} PARENT_SCOPE)

include_directories(${LIBOMPTARGET_LLVM_INCLUDE_DIRS})

# Build libomptarget library with libdl dependency.
add_library(omptarget SHARED ${LIBOMPTARGET_SRC_FILES})
if (OPENMP_ENABLE_LIBOMPTARGET_PROFILING)
# Add LLVMSupport dependency if profiling is enabled.
# Linking with LLVM component libraries also requires
# aligning the compile flags.
llvm_update_compile_flags(omptarget)
# Build libomptarget library with libdl dependency. Add LLVMSupport
# dependency if building in-tree with profiling enabled.
if(OPENMP_STANDALONE_BUILD OR (NOT OPENMP_ENABLE_LIBOMPTARGET_PROFILING))
add_library(omptarget SHARED ${LIBOMPTARGET_SRC_FILES})
target_link_libraries(omptarget
${CMAKE_DL_LIBS}
"-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports")
else()
set(LLVM_LINK_COMPONENTS
Support
)
add_llvm_library(omptarget SHARED ${LIBOMPTARGET_SRC_FILES}
LINK_LIBS ${CMAKE_DL_LIBS}
"-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports"
)
target_compile_definitions(omptarget PUBLIC OMPTARGET_PROFILE_ENABLED)
target_link_libraries(omptarget PRIVATE LLVMSupport)
endif()
target_link_libraries(omptarget PRIVATE
${CMAKE_DL_LIBS}
"-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports")

# libomptarget needs to be set separately because add_llvm_library doesn't
# conform with location configuration of its parent scope.
set_target_properties(omptarget
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${LIBOMPTARGET_LIBRARY_DIR})

# Install libomptarget under the lib destination folder.
install(TARGETS omptarget LIBRARY COMPONENT omptarget
Expand Down

0 comments on commit af9c013

Please sign in to comment.