[Openmp-commits] [PATCH] D55588: [OpenMP] Fix nvidia-cuda-toolkit detection on Debian/Ubuntu

Joel E. Denny via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Tue Dec 11 17:11:47 PST 2018


jdenny created this revision.
jdenny added reviewers: ABataev, Hahnfeld, tra, sylvestre.ledru, grokos.
Herald added subscribers: guansong, kristof.beyls, javed.absar, mgorny.

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 <https://reviews.llvm.org/D55269>.  D40453 <https://reviews.llvm.org/D40453> added a
similar adjustment in clang, but reviewers of D55269 <https://reviews.llvm.org/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.
I made an attempt at reporting that at the following, but I have no
idea if that's a good place for it:

https://answers.launchpad.net/ubuntu/+question/676752

I'm a cmake novice, so I apologize for any glaring problems in this
patch.


Repository:
  rOMP OpenMP

https://reviews.llvm.org/D55588

Files:
  openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake


Index: openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake
===================================================================
--- openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake
+++ openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake
@@ -112,6 +112,9 @@
 ################################################################################
 # Looking for CUDA...
 ################################################################################
+if (CUDA_TOOLKIT_ROOT_DIR)
+  set(cuda_toolkit_root_dir_old TRUE)
+endif()
 find_package(CUDA QUIET)
 
 set(LIBOMPTARGET_DEP_CUDA_FOUND ${CUDA_FOUND})
@@ -158,3 +161,32 @@
   LIBOMPTARGET_DEP_CUDA_DRIVER_LIBRARIES)
 
 mark_as_advanced(LIBOMPTARGET_DEP_CUDA_DRIVER_LIBRARIES)
+
+################################################################################
+# 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(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 cuda_toolkit_root_dir_old AND
+    NOT EXISTS "${CUDA_TOOLKIT_ROOT_DIR}/${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}/${cuda_libdevice_subdir}")
+      set(CUDA_TOOLKIT_ROOT_DIR "${candidate_dir}" CACHE PATH
+          "Toolkit location." FORCE)
+    endif()
+  endif()
+endif()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55588.177801.patch
Type: text/x-patch
Size: 2014 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20181212/e881518b/attachment.bin>


More information about the Openmp-commits mailing list