Fix cuda.framework error on OSX. (#8136)

When compiling OSX with CUDA, Caffe2's build system uses
find_package(cuda) to get its grubby hands on the CUDA driver
library (for some strange reason, FindCUDA doesn't save this
information as a variable).  Unfortunately, on OSX, sometimes
this picks up the cuda.framework folder, and then our build
system chokes to death because it doesn't try to link against
this as a framework.  (Is the folder even a framework?  I have
no idea).

This commit attempts to fix this in a two pronged fashion:

1. For some users, reducing the precedence of frameworks
using CMAKE_FIND_FRAMEWORK seems to help.  So we set these
variables.  However, this fix is not perfect; on my laptop
it doesn't actually solve the problem.

2. PyTorch doesn't actually need the CUDA driver API.  So we
only add the dep when building Caffe2.

Fixes #8022

Signed-off-by: Edward Z. Yang <ezyang@fb.com>
This commit is contained in:
Edward Z. Yang 2018-06-05 13:37:05 -04:00 committed by GitHub
parent 7c1e8c3c7a
commit bf58bb5e59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -30,6 +30,15 @@ if(NOT DEFINED BLAS_SET_BY_USER)
set(BLAS_SET_BY_USER ${BLAS_SET_BY_USER} CACHE STRING "Marks whether BLAS was manually set by user or auto-detected")
endif()
# These lines are an attempt to make find_package(cuda) pick up
# libcuda.dylib, and not cuda.framework. It doesn't work all
# the time, but it seems to help for some users.
# TODO: replace this with a more robust fix
if(APPLE)
set(CMAKE_FIND_FRAMEWORK LAST)
set(CMAKE_FIND_APPBUNDLE LAST)
endif()
# ---[ Options.
# Note to developers: if you add an option below, make sure you also add it to
# cmake/Summary.cmake so that the summary prints out the option values.

View File

@ -399,7 +399,20 @@ if(USE_CUDA)
# caffe2::cudart is dealt with separately, due to CUDA_ADD_LIBRARY
# design reason (it adds CUDA_LIBRARIES itself).
set(Caffe2_PUBLIC_CUDA_DEPENDENCY_LIBS
caffe2::cuda caffe2::cufft caffe2::curand caffe2::nvrtc)
caffe2::cufft caffe2::curand)
if(BUILD_CAFFE2)
# Don't be deceived! caffe2::cuda is the low-level DRIVER API,
# not the actual CUDA library. Caffe2 depends directly on nvrtc
# and needs it, but ATen doesn't use it at all, and so the
# dependency is unnecessary.
#
# BTW, if you change this so that PyTorch has this dependency
# again, make sure Mac OS X GPU builds still work; there's
# a decent chance the library finding algorithm picked up
# on cuda.framework, which is totally not going to work when
# linking.
list(APPEND Caffe2_PUBLIC_CUDA_DEPENDENCY_LIBS caffe2::cuda caffe2::nvrtc)
endif()
if(CAFFE2_FOUND_CUDNN)
LIST(APPEND Caffe2_PUBLIC_CUDA_DEPENDENCY_LIBS caffe2::cudnn)
else()