Skip to content

Commit f17f7a5

Browse files
committedJan 4, 2019
[OpenMP] Fix nvidia-cuda-toolkit detection on Debian/Ubuntu
The OpenMP runtime's cmake scripts do not correctly locate the libdevice that the Debian/Ubuntu package nvidia-cuda-toolkit currently includes, at least on my Ubuntu 18.04.1 installation. This patch fixes that for me. This problem was discussed at length in D55269. D40453 added a similar adjustment in clang, but reviewers of D55269 concluded that, for the OpenMP runtime, the right place to address this problem is in cmake's CUDA support. However, it was also suggested we could add a workaround to OpenMP's cmake scripts now. This patch contains such a workaround, which I've tried to design so that it will have no harmful effect if cmake improves in the future. nvidia-cuda-toolkit also needs improvements because its intended monolithic CUDA tree shim, /usr/lib/cuda, has many empty directories, such as bin. I reported that at: <https://bugs.launchpad.net/ubuntu/+source/nvidia-cuda-toolkit/+bug/1808999> Reviewed By: grokos Differential Revision: https://reviews.llvm.org/D55588 llvm-svn: 350377
1 parent 961fbf2 commit f17f7a5

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
 

Diff for: ‎openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake

+33
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ mark_as_advanced(
112112
################################################################################
113113
# Looking for CUDA...
114114
################################################################################
115+
if (CUDA_TOOLKIT_ROOT_DIR)
116+
set(LIBOMPTARGET_CUDA_TOOLKIT_ROOT_DIR_PRESET TRUE)
117+
endif()
115118
find_package(CUDA QUIET)
116119

117120
set(LIBOMPTARGET_DEP_CUDA_FOUND ${CUDA_FOUND})
@@ -158,3 +161,33 @@ find_package_handle_standard_args(
158161
LIBOMPTARGET_DEP_CUDA_DRIVER_LIBRARIES)
159162

160163
mark_as_advanced(LIBOMPTARGET_DEP_CUDA_DRIVER_LIBRARIES)
164+
165+
################################################################################
166+
# Looking for CUDA libdevice subdirectory
167+
#
168+
# Special case for Debian/Ubuntu to have nvidia-cuda-toolkit work
169+
# out of the box. More info on http://bugs.debian.org/882505
170+
################################################################################
171+
172+
set(LIBOMPTARGET_CUDA_LIBDEVICE_SUBDIR nvvm/libdevice)
173+
174+
# Don't alter CUDA_TOOLKIT_ROOT_DIR if the user specified it, if a value was
175+
# already cached for it, or if it already has libdevice. Otherwise, on
176+
# Debian/Ubuntu, look where the nvidia-cuda-toolkit package normally installs
177+
# libdevice.
178+
if (NOT LIBOMPTARGET_CUDA_TOOLKIT_ROOT_DIR_PRESET AND
179+
NOT EXISTS
180+
"${CUDA_TOOLKIT_ROOT_DIR}/${LIBOMPTARGET_CUDA_LIBDEVICE_SUBDIR}")
181+
find_program(LSB_RELEASE lsb_release)
182+
if (LSB_RELEASE)
183+
execute_process(COMMAND ${LSB_RELEASE} -is
184+
OUTPUT_VARIABLE LSB_RELEASE_ID
185+
OUTPUT_STRIP_TRAILING_WHITESPACE)
186+
set(candidate_dir /usr/lib/cuda)
187+
if ((LSB_RELEASE_ID STREQUAL "Debian" OR LSB_RELEASE_ID STREQUAL "Ubuntu")
188+
AND EXISTS "${candidate_dir}/${LIBOMPTARGET_CUDA_LIBDEVICE_SUBDIR}")
189+
set(CUDA_TOOLKIT_ROOT_DIR "${candidate_dir}" CACHE PATH
190+
"Toolkit location." FORCE)
191+
endif()
192+
endif()
193+
endif()

0 commit comments

Comments
 (0)
Please sign in to comment.