2017-01-26 05:27:24 +08:00
|
|
|
#
|
|
|
|
#//===----------------------------------------------------------------------===//
|
|
|
|
#//
|
2019-01-19 18:56:40 +08:00
|
|
|
#// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
#// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
#// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-01-26 05:27:24 +08:00
|
|
|
#//
|
|
|
|
#//===----------------------------------------------------------------------===//
|
|
|
|
#
|
|
|
|
|
|
|
|
# Try to detect in the system several dependencies required by the different
|
|
|
|
# components of libomptarget. These are the dependencies we have:
|
|
|
|
#
|
|
|
|
# libelf : required by some targets to handle the ELF files at runtime.
|
2021-01-27 09:21:27 +08:00
|
|
|
# libffi : required to launch target kernels given function and argument
|
2017-01-26 05:27:24 +08:00
|
|
|
# pointers.
|
|
|
|
# CUDA : required to control offloading to NVIDIA GPUs.
|
2020-05-12 16:05:00 +08:00
|
|
|
# VEOS : required to control offloading to NEC Aurora.
|
2017-01-26 05:27:24 +08:00
|
|
|
|
|
|
|
include (FindPackageHandleStandardArgs)
|
|
|
|
|
2021-05-08 03:42:04 +08:00
|
|
|
################################################################################
|
|
|
|
# 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()
|
2021-06-18 22:17:23 +08:00
|
|
|
# Note that OPENMP_STANDALONE_BUILD is FALSE, when
|
|
|
|
# openmp is built with -DLLVM_ENABLE_RUNTIMES="openmp" vs
|
|
|
|
# -DLLVM_ENABLE_PROJECTS="openmp", but openmp build
|
|
|
|
# is actually done as a standalone project build with many
|
|
|
|
# LLVM CMake variables propagated to it.
|
2021-05-08 03:42:04 +08:00
|
|
|
list(APPEND LIBOMPTARGET_LLVM_INCLUDE_DIRS
|
|
|
|
${LLVM_MAIN_INCLUDE_DIR} ${LLVM_BINARY_DIR}/include
|
|
|
|
)
|
2021-06-18 22:17:23 +08:00
|
|
|
message(STATUS
|
|
|
|
"Using LLVM include directories: ${LIBOMPTARGET_LLVM_INCLUDE_DIRS}")
|
2021-05-08 03:42:04 +08:00
|
|
|
endif()
|
|
|
|
|
2017-01-26 05:27:24 +08:00
|
|
|
################################################################################
|
|
|
|
# Looking for libelf...
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
find_path (
|
|
|
|
LIBOMPTARGET_DEP_LIBELF_INCLUDE_DIR
|
|
|
|
NAMES
|
|
|
|
libelf.h
|
|
|
|
PATHS
|
|
|
|
/usr/include
|
|
|
|
/usr/local/include
|
|
|
|
/opt/local/include
|
|
|
|
/sw/include
|
|
|
|
ENV CPATH
|
|
|
|
PATH_SUFFIXES
|
|
|
|
libelf)
|
|
|
|
|
|
|
|
find_library (
|
|
|
|
LIBOMPTARGET_DEP_LIBELF_LIBRARIES
|
|
|
|
NAMES
|
|
|
|
elf
|
|
|
|
PATHS
|
|
|
|
/usr/lib
|
|
|
|
/usr/local/lib
|
|
|
|
/opt/local/lib
|
|
|
|
/sw/lib
|
|
|
|
ENV LIBRARY_PATH
|
|
|
|
ENV LD_LIBRARY_PATH)
|
2021-01-27 09:21:27 +08:00
|
|
|
|
2017-01-26 05:27:24 +08:00
|
|
|
set(LIBOMPTARGET_DEP_LIBELF_INCLUDE_DIRS ${LIBOMPTARGET_DEP_LIBELF_INCLUDE_DIR})
|
|
|
|
find_package_handle_standard_args(
|
2021-01-27 09:21:27 +08:00
|
|
|
LIBOMPTARGET_DEP_LIBELF
|
2017-01-26 05:27:24 +08:00
|
|
|
DEFAULT_MSG
|
|
|
|
LIBOMPTARGET_DEP_LIBELF_LIBRARIES
|
|
|
|
LIBOMPTARGET_DEP_LIBELF_INCLUDE_DIRS)
|
|
|
|
|
|
|
|
mark_as_advanced(
|
2021-01-27 09:21:27 +08:00
|
|
|
LIBOMPTARGET_DEP_LIBELF_INCLUDE_DIRS
|
2017-01-26 05:27:24 +08:00
|
|
|
LIBOMPTARGET_DEP_LIBELF_LIBRARIES)
|
2021-01-27 09:21:27 +08:00
|
|
|
|
2017-01-26 05:27:24 +08:00
|
|
|
################################################################################
|
|
|
|
# Looking for libffi...
|
|
|
|
################################################################################
|
|
|
|
find_package(PkgConfig)
|
|
|
|
|
|
|
|
pkg_check_modules(LIBOMPTARGET_SEARCH_LIBFFI QUIET libffi)
|
|
|
|
|
|
|
|
find_path (
|
|
|
|
LIBOMPTARGET_DEP_LIBFFI_INCLUDE_DIR
|
|
|
|
NAMES
|
|
|
|
ffi.h
|
|
|
|
HINTS
|
|
|
|
${LIBOMPTARGET_SEARCH_LIBFFI_INCLUDEDIR}
|
|
|
|
${LIBOMPTARGET_SEARCH_LIBFFI_INCLUDE_DIRS}
|
|
|
|
PATHS
|
|
|
|
/usr/include
|
|
|
|
/usr/local/include
|
|
|
|
/opt/local/include
|
|
|
|
/sw/include
|
|
|
|
ENV CPATH)
|
|
|
|
|
|
|
|
# Don't bother look for the library if the header files were not found.
|
|
|
|
if (LIBOMPTARGET_DEP_LIBFFI_INCLUDE_DIR)
|
|
|
|
find_library (
|
|
|
|
LIBOMPTARGET_DEP_LIBFFI_LIBRARIES
|
|
|
|
NAMES
|
|
|
|
ffi
|
|
|
|
HINTS
|
|
|
|
${LIBOMPTARGET_SEARCH_LIBFFI_LIBDIR}
|
|
|
|
${LIBOMPTARGET_SEARCH_LIBFFI_LIBRARY_DIRS}
|
|
|
|
PATHS
|
|
|
|
/usr/lib
|
|
|
|
/usr/local/lib
|
|
|
|
/opt/local/lib
|
|
|
|
/sw/lib
|
|
|
|
ENV LIBRARY_PATH
|
|
|
|
ENV LD_LIBRARY_PATH)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(LIBOMPTARGET_DEP_LIBFFI_INCLUDE_DIRS ${LIBOMPTARGET_DEP_LIBFFI_INCLUDE_DIR})
|
|
|
|
find_package_handle_standard_args(
|
2021-01-27 09:21:27 +08:00
|
|
|
LIBOMPTARGET_DEP_LIBFFI
|
2017-01-26 05:27:24 +08:00
|
|
|
DEFAULT_MSG
|
|
|
|
LIBOMPTARGET_DEP_LIBFFI_LIBRARIES
|
|
|
|
LIBOMPTARGET_DEP_LIBFFI_INCLUDE_DIRS)
|
|
|
|
|
|
|
|
mark_as_advanced(
|
2021-01-27 09:21:27 +08:00
|
|
|
LIBOMPTARGET_DEP_LIBFFI_INCLUDE_DIRS
|
2017-01-26 05:27:24 +08:00
|
|
|
LIBOMPTARGET_DEP_LIBFFI_LIBRARIES)
|
2021-01-27 09:21:27 +08:00
|
|
|
|
2017-01-26 05:27:24 +08:00
|
|
|
################################################################################
|
|
|
|
# Looking for CUDA...
|
|
|
|
################################################################################
|
2019-01-04 10:07:13 +08:00
|
|
|
if (CUDA_TOOLKIT_ROOT_DIR)
|
|
|
|
set(LIBOMPTARGET_CUDA_TOOLKIT_ROOT_DIR_PRESET TRUE)
|
|
|
|
endif()
|
2017-01-26 05:27:24 +08:00
|
|
|
find_package(CUDA QUIET)
|
|
|
|
|
2020-10-08 04:40:47 +08:00
|
|
|
# Try to get the highest Nvidia GPU architecture the system supports
|
2021-01-31 04:14:41 +08:00
|
|
|
if (CUDA_FOUND)
|
2020-10-08 04:40:47 +08:00
|
|
|
cuda_select_nvcc_arch_flags(CUDA_ARCH_FLAGS)
|
|
|
|
string(REGEX MATCH "sm_([0-9]+)" CUDA_ARCH_MATCH_OUTPUT ${CUDA_ARCH_FLAGS})
|
|
|
|
if (NOT DEFINED CUDA_ARCH_MATCH_OUTPUT OR "${CMAKE_MATCH_1}" LESS 35)
|
|
|
|
libomptarget_warning_say("Setting Nvidia GPU architecture support for OpenMP target runtime library to sm_35 by default")
|
|
|
|
set(LIBOMPTARGET_DEP_CUDA_ARCH "35")
|
|
|
|
else()
|
|
|
|
set(LIBOMPTARGET_DEP_CUDA_ARCH "${CMAKE_MATCH_1}")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2017-01-26 05:27:24 +08:00
|
|
|
set(LIBOMPTARGET_DEP_CUDA_FOUND ${CUDA_FOUND})
|
|
|
|
set(LIBOMPTARGET_DEP_CUDA_INCLUDE_DIRS ${CUDA_INCLUDE_DIRS})
|
|
|
|
|
|
|
|
mark_as_advanced(
|
2021-01-27 09:21:27 +08:00
|
|
|
LIBOMPTARGET_DEP_CUDA_FOUND
|
2018-01-31 00:49:13 +08:00
|
|
|
LIBOMPTARGET_DEP_CUDA_INCLUDE_DIRS)
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Looking for CUDA Driver API... (needed for CUDA plugin)
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
find_library (
|
|
|
|
LIBOMPTARGET_DEP_CUDA_DRIVER_LIBRARIES
|
|
|
|
NAMES
|
|
|
|
cuda
|
|
|
|
PATHS
|
|
|
|
/lib64)
|
|
|
|
|
|
|
|
# There is a libcuda.so in lib64/stubs that can be used for linking.
|
|
|
|
if (NOT LIBOMPTARGET_DEP_CUDA_DRIVER_LIBRARIES AND CUDA_FOUND)
|
2020-09-05 23:27:04 +08:00
|
|
|
get_filename_component(CUDA_LIBDIR "${CUDA_cudart_static_LIBRARY}" DIRECTORY)
|
|
|
|
find_library(
|
2018-01-31 00:49:13 +08:00
|
|
|
LIBOMPTARGET_DEP_CUDA_DRIVER_LIBRARIES
|
|
|
|
NAMES
|
|
|
|
cuda
|
|
|
|
HINTS
|
|
|
|
"${CUDA_LIBDIR}/stubs")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
find_package_handle_standard_args(
|
|
|
|
LIBOMPTARGET_DEP_CUDA_DRIVER
|
|
|
|
DEFAULT_MSG
|
|
|
|
LIBOMPTARGET_DEP_CUDA_DRIVER_LIBRARIES)
|
|
|
|
|
|
|
|
mark_as_advanced(LIBOMPTARGET_DEP_CUDA_DRIVER_LIBRARIES)
|
2019-01-04 10:07:13 +08:00
|
|
|
|
|
|
|
################################################################################
|
2020-05-12 16:05:00 +08:00
|
|
|
# Looking for VEO...
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
find_path (
|
|
|
|
LIBOMPTARGET_DEP_VEO_INCLUDE_DIR
|
|
|
|
NAMES
|
|
|
|
ve_offload.h
|
|
|
|
PATHS
|
|
|
|
/usr/include
|
|
|
|
/usr/local/include
|
|
|
|
/opt/local/include
|
|
|
|
/sw/include
|
|
|
|
/opt/nec/ve/veos/include
|
|
|
|
ENV CPATH
|
|
|
|
PATH_SUFFIXES
|
|
|
|
libveo)
|
|
|
|
|
|
|
|
find_library (
|
|
|
|
LIBOMPTARGET_DEP_VEO_LIBRARIES
|
|
|
|
NAMES
|
|
|
|
veo
|
|
|
|
PATHS
|
|
|
|
/usr/lib
|
|
|
|
/usr/local/lib
|
|
|
|
/opt/local/lib
|
|
|
|
/sw/lib
|
|
|
|
/opt/nec/ve/veos/lib64
|
|
|
|
ENV LIBRARY_PATH
|
|
|
|
ENV LD_LIBRARY_PATH)
|
|
|
|
|
|
|
|
find_library(
|
|
|
|
LIBOMPTARGET_DEP_VEOSINFO_LIBRARIES
|
|
|
|
NAMES
|
|
|
|
veosinfo
|
|
|
|
PATHS
|
|
|
|
/usr/lib
|
|
|
|
/usr/local/lib
|
|
|
|
/opt/local/lib
|
|
|
|
/sw/lib
|
|
|
|
/opt/nec/ve/veos/lib64
|
|
|
|
ENV LIBRARY_PATH
|
|
|
|
ENV LD_LIBRARY_PATH)
|
|
|
|
|
|
|
|
set(LIBOMPTARGET_DEP_VEO_INCLUDE_DIRS ${LIBOMPTARGET_DEP_VEO_INCLUDE_DIR})
|
|
|
|
find_package_handle_standard_args(
|
|
|
|
LIBOMPTARGET_DEP_VEO
|
|
|
|
DEFAULT_MSG
|
|
|
|
LIBOMPTARGET_DEP_VEO_LIBRARIES
|
|
|
|
LIBOMPTARGET_DEP_VEOSINFO_LIBRARIES
|
|
|
|
LIBOMPTARGET_DEP_VEO_INCLUDE_DIRS)
|
|
|
|
|
|
|
|
mark_as_advanced(
|
|
|
|
LIBOMPTARGET_DEP_VEO_FOUND
|
|
|
|
LIBOMPTARGET_DEP_VEO_INCLUDE_DIRS)
|
|
|
|
|
2019-01-04 10:07:13 +08:00
|
|
|
# Looking for CUDA libdevice subdirectory
|
|
|
|
#
|
|
|
|
# Special case for Debian/Ubuntu to have nvidia-cuda-toolkit work
|
|
|
|
# out of the box. More info on http://bugs.debian.org/882505
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
set(LIBOMPTARGET_CUDA_LIBDEVICE_SUBDIR nvvm/libdevice)
|
|
|
|
|
|
|
|
# Don't alter CUDA_TOOLKIT_ROOT_DIR if the user specified it, if a value was
|
|
|
|
# already cached for it, or if it already has libdevice. Otherwise, on
|
|
|
|
# Debian/Ubuntu, look where the nvidia-cuda-toolkit package normally installs
|
|
|
|
# libdevice.
|
|
|
|
if (NOT LIBOMPTARGET_CUDA_TOOLKIT_ROOT_DIR_PRESET AND
|
|
|
|
NOT EXISTS
|
|
|
|
"${CUDA_TOOLKIT_ROOT_DIR}/${LIBOMPTARGET_CUDA_LIBDEVICE_SUBDIR}")
|
|
|
|
find_program(LSB_RELEASE lsb_release)
|
|
|
|
if (LSB_RELEASE)
|
|
|
|
execute_process(COMMAND ${LSB_RELEASE} -is
|
|
|
|
OUTPUT_VARIABLE LSB_RELEASE_ID
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
set(candidate_dir /usr/lib/cuda)
|
|
|
|
if ((LSB_RELEASE_ID STREQUAL "Debian" OR LSB_RELEASE_ID STREQUAL "Ubuntu")
|
|
|
|
AND EXISTS "${candidate_dir}/${LIBOMPTARGET_CUDA_LIBDEVICE_SUBDIR}")
|
|
|
|
set(CUDA_TOOLKIT_ROOT_DIR "${candidate_dir}" CACHE PATH
|
|
|
|
"Toolkit location." FORCE)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endif()
|
2021-01-28 07:41:44 +08:00
|
|
|
|
2021-05-08 03:42:04 +08:00
|
|
|
set(OPENMP_PTHREAD_LIB ${LLVM_PTHREAD_LIB})
|