• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2#//===----------------------------------------------------------------------===//
3#//
4#// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5#// See https://llvm.org/LICENSE.txt for license information.
6#// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7#//
8#//===----------------------------------------------------------------------===//
9#
10
11# Try to detect in the system several dependencies required by the different
12# components of libomptarget. These are the dependencies we have:
13#
14# libelf : required by some targets to handle the ELF files at runtime.
15# libffi : required to launch target kernels given function and argument
16#          pointers.
17# CUDA : required to control offloading to NVIDIA GPUs.
18# VEOS : required to control offloading to NEC Aurora.
19
20include (FindPackageHandleStandardArgs)
21
22################################################################################
23# Looking for libelf...
24################################################################################
25
26find_path (
27  LIBOMPTARGET_DEP_LIBELF_INCLUDE_DIR
28  NAMES
29    libelf.h
30  PATHS
31    /usr/include
32    /usr/local/include
33    /opt/local/include
34    /sw/include
35    ENV CPATH
36  PATH_SUFFIXES
37    libelf)
38
39find_library (
40  LIBOMPTARGET_DEP_LIBELF_LIBRARIES
41  NAMES
42    elf
43  PATHS
44    /usr/lib
45    /usr/local/lib
46    /opt/local/lib
47    /sw/lib
48    ENV LIBRARY_PATH
49    ENV LD_LIBRARY_PATH)
50
51set(LIBOMPTARGET_DEP_LIBELF_INCLUDE_DIRS ${LIBOMPTARGET_DEP_LIBELF_INCLUDE_DIR})
52find_package_handle_standard_args(
53  LIBOMPTARGET_DEP_LIBELF
54  DEFAULT_MSG
55  LIBOMPTARGET_DEP_LIBELF_LIBRARIES
56  LIBOMPTARGET_DEP_LIBELF_INCLUDE_DIRS)
57
58mark_as_advanced(
59  LIBOMPTARGET_DEP_LIBELF_INCLUDE_DIRS
60  LIBOMPTARGET_DEP_LIBELF_LIBRARIES)
61
62################################################################################
63# Looking for libffi...
64################################################################################
65find_package(PkgConfig)
66
67pkg_check_modules(LIBOMPTARGET_SEARCH_LIBFFI QUIET libffi)
68
69find_path (
70  LIBOMPTARGET_DEP_LIBFFI_INCLUDE_DIR
71  NAMES
72    ffi.h
73  HINTS
74    ${LIBOMPTARGET_SEARCH_LIBFFI_INCLUDEDIR}
75    ${LIBOMPTARGET_SEARCH_LIBFFI_INCLUDE_DIRS}
76  PATHS
77    /usr/include
78    /usr/local/include
79    /opt/local/include
80    /sw/include
81    ENV CPATH)
82
83# Don't bother look for the library if the header files were not found.
84if (LIBOMPTARGET_DEP_LIBFFI_INCLUDE_DIR)
85  find_library (
86      LIBOMPTARGET_DEP_LIBFFI_LIBRARIES
87    NAMES
88      ffi
89    HINTS
90      ${LIBOMPTARGET_SEARCH_LIBFFI_LIBDIR}
91      ${LIBOMPTARGET_SEARCH_LIBFFI_LIBRARY_DIRS}
92    PATHS
93      /usr/lib
94      /usr/local/lib
95      /opt/local/lib
96      /sw/lib
97      ENV LIBRARY_PATH
98      ENV LD_LIBRARY_PATH)
99endif()
100
101set(LIBOMPTARGET_DEP_LIBFFI_INCLUDE_DIRS ${LIBOMPTARGET_DEP_LIBFFI_INCLUDE_DIR})
102find_package_handle_standard_args(
103  LIBOMPTARGET_DEP_LIBFFI
104  DEFAULT_MSG
105  LIBOMPTARGET_DEP_LIBFFI_LIBRARIES
106  LIBOMPTARGET_DEP_LIBFFI_INCLUDE_DIRS)
107
108mark_as_advanced(
109  LIBOMPTARGET_DEP_LIBFFI_INCLUDE_DIRS
110  LIBOMPTARGET_DEP_LIBFFI_LIBRARIES)
111
112################################################################################
113# Looking for CUDA...
114################################################################################
115if (CUDA_TOOLKIT_ROOT_DIR)
116  set(LIBOMPTARGET_CUDA_TOOLKIT_ROOT_DIR_PRESET TRUE)
117endif()
118find_package(CUDA QUIET)
119
120# Try to get the highest Nvidia GPU architecture the system supports
121if (CUDA_FOUND)
122  cuda_select_nvcc_arch_flags(CUDA_ARCH_FLAGS)
123  string(REGEX MATCH "sm_([0-9]+)" CUDA_ARCH_MATCH_OUTPUT ${CUDA_ARCH_FLAGS})
124  if (NOT DEFINED CUDA_ARCH_MATCH_OUTPUT OR "${CMAKE_MATCH_1}" LESS 35)
125    libomptarget_warning_say("Setting Nvidia GPU architecture support for OpenMP target runtime library to sm_35 by default")
126    set(LIBOMPTARGET_DEP_CUDA_ARCH "35")
127  else()
128    set(LIBOMPTARGET_DEP_CUDA_ARCH "${CMAKE_MATCH_1}")
129  endif()
130endif()
131
132set(LIBOMPTARGET_DEP_CUDA_FOUND ${CUDA_FOUND})
133set(LIBOMPTARGET_DEP_CUDA_INCLUDE_DIRS ${CUDA_INCLUDE_DIRS})
134
135mark_as_advanced(
136  LIBOMPTARGET_DEP_CUDA_FOUND
137  LIBOMPTARGET_DEP_CUDA_INCLUDE_DIRS)
138
139################################################################################
140# Looking for CUDA Driver API... (needed for CUDA plugin)
141################################################################################
142
143find_library (
144    LIBOMPTARGET_DEP_CUDA_DRIVER_LIBRARIES
145  NAMES
146    cuda
147  PATHS
148    /lib64)
149
150# There is a libcuda.so in lib64/stubs that can be used for linking.
151if (NOT LIBOMPTARGET_DEP_CUDA_DRIVER_LIBRARIES AND CUDA_FOUND)
152  get_filename_component(CUDA_LIBDIR "${CUDA_cudart_static_LIBRARY}" DIRECTORY)
153  find_library(
154      LIBOMPTARGET_DEP_CUDA_DRIVER_LIBRARIES
155    NAMES
156      cuda
157    HINTS
158      "${CUDA_LIBDIR}/stubs")
159endif()
160
161find_package_handle_standard_args(
162  LIBOMPTARGET_DEP_CUDA_DRIVER
163  DEFAULT_MSG
164  LIBOMPTARGET_DEP_CUDA_DRIVER_LIBRARIES)
165
166mark_as_advanced(LIBOMPTARGET_DEP_CUDA_DRIVER_LIBRARIES)
167
168################################################################################
169# Looking for VEO...
170################################################################################
171
172find_path (
173  LIBOMPTARGET_DEP_VEO_INCLUDE_DIR
174  NAMES
175    ve_offload.h
176  PATHS
177    /usr/include
178    /usr/local/include
179    /opt/local/include
180    /sw/include
181    /opt/nec/ve/veos/include
182    ENV CPATH
183  PATH_SUFFIXES
184    libveo)
185
186find_library (
187  LIBOMPTARGET_DEP_VEO_LIBRARIES
188  NAMES
189    veo
190  PATHS
191    /usr/lib
192    /usr/local/lib
193    /opt/local/lib
194    /sw/lib
195    /opt/nec/ve/veos/lib64
196    ENV LIBRARY_PATH
197    ENV LD_LIBRARY_PATH)
198
199find_library(
200  LIBOMPTARGET_DEP_VEOSINFO_LIBRARIES
201  NAMES
202    veosinfo
203  PATHS
204    /usr/lib
205    /usr/local/lib
206    /opt/local/lib
207    /sw/lib
208    /opt/nec/ve/veos/lib64
209    ENV LIBRARY_PATH
210    ENV LD_LIBRARY_PATH)
211
212set(LIBOMPTARGET_DEP_VEO_INCLUDE_DIRS ${LIBOMPTARGET_DEP_VEO_INCLUDE_DIR})
213find_package_handle_standard_args(
214  LIBOMPTARGET_DEP_VEO
215  DEFAULT_MSG
216  LIBOMPTARGET_DEP_VEO_LIBRARIES
217  LIBOMPTARGET_DEP_VEOSINFO_LIBRARIES
218  LIBOMPTARGET_DEP_VEO_INCLUDE_DIRS)
219
220mark_as_advanced(
221  LIBOMPTARGET_DEP_VEO_FOUND
222  LIBOMPTARGET_DEP_VEO_INCLUDE_DIRS)
223
224# Looking for CUDA libdevice subdirectory
225#
226# Special case for Debian/Ubuntu to have nvidia-cuda-toolkit work
227# out of the box. More info on http://bugs.debian.org/882505
228################################################################################
229
230set(LIBOMPTARGET_CUDA_LIBDEVICE_SUBDIR nvvm/libdevice)
231
232# Don't alter CUDA_TOOLKIT_ROOT_DIR if the user specified it, if a value was
233# already cached for it, or if it already has libdevice.  Otherwise, on
234# Debian/Ubuntu, look where the nvidia-cuda-toolkit package normally installs
235# libdevice.
236if (NOT LIBOMPTARGET_CUDA_TOOLKIT_ROOT_DIR_PRESET AND
237    NOT EXISTS
238      "${CUDA_TOOLKIT_ROOT_DIR}/${LIBOMPTARGET_CUDA_LIBDEVICE_SUBDIR}")
239  find_program(LSB_RELEASE lsb_release)
240  if (LSB_RELEASE)
241    execute_process(COMMAND ${LSB_RELEASE} -is
242      OUTPUT_VARIABLE LSB_RELEASE_ID
243      OUTPUT_STRIP_TRAILING_WHITESPACE)
244    set(candidate_dir /usr/lib/cuda)
245    if ((LSB_RELEASE_ID STREQUAL "Debian" OR LSB_RELEASE_ID STREQUAL "Ubuntu")
246        AND EXISTS "${candidate_dir}/${LIBOMPTARGET_CUDA_LIBDEVICE_SUBDIR}")
247      set(CUDA_TOOLKIT_ROOT_DIR "${candidate_dir}" CACHE PATH
248          "Toolkit location." FORCE)
249    endif()
250  endif()
251endif()
252