Skip to content

Commit

Permalink
Fix static linkage cases and NO_DISTRIBUTED=1 + CUDA (pytorch#16705) (p…
Browse files Browse the repository at this point in the history
…ytorch#17337)

Summary:
Attempt pytorch#2 (attempt 1 is pytorch#16705 and got reverted because of CI failures)

Fixes pytorch#14805
Pull Request resolved: pytorch#17337

Differential Revision: D14175626

Pulled By: soumith

fbshipit-source-id: 66f2e10e219a1bf88ed342ec5c89da6f2994d8eb
  • Loading branch information
soumith authored and facebook-github-bot committed Feb 22, 2019
1 parent 290b2a1 commit 3a47d56
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions c10/cuda/CUDAException.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
do { \
cudaError_t __err = EXPR; \
if (__err != cudaSuccess) { \
cudaGetLastError(); \
AT_ERROR("CUDA error: ", cudaGetErrorString(__err)); \
} \
} while (0)
8 changes: 6 additions & 2 deletions cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,12 @@ if(USE_CUDA)
caffe2_update_option(USE_NVRTC OFF)
endif()
if(CAFFE2_USE_CUDNN)
list(APPEND Caffe2_PUBLIC_CUDA_DEPENDENCY_LIBS caffe2::cudnn)
IF(CUDNN_STATIC_LINKAGE)
LIST(APPEND Caffe2_PUBLIC_CUDA_DEPENDENCY_LIBS
caffe2::cudnn "${CUDA_TOOLKIT_ROOT_DIR}/lib64/libculibos.a" "dl")
ELSE()
list(APPEND Caffe2_PUBLIC_CUDA_DEPENDENCY_LIBS caffe2::cudnn)
ENDIF()
else()
caffe2_update_option(USE_CUDNN OFF)
endif()
Expand Down Expand Up @@ -1314,7 +1319,6 @@ if (NOT BUILD_ATEN_MOBILE)
SET(AT_CUDA_ENABLED 0)
else()
SET(AT_CUDA_ENABLED 1)
find_package(CUDA 5.5 REQUIRED)
endif()

IF (NOT AT_CUDA_ENABLED OR NOT CUDNN_FOUND)
Expand Down
11 changes: 10 additions & 1 deletion cmake/public/cuda.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ endif()
# release (3.11.3) yet. Hence we need our own Modules_CUDA_fix to enable sccache.
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../Modules_CUDA_fix)

# we dont want to statically link cudart, because we rely on it's dynamic linkage in
# python (follow along torch/cuda/__init__.py and usage of cudaGetErrorName).
# Technically, we can link cudart here statically, and link libtorch_python.so
# to a dynamic libcudart.so, but that's just wasteful
SET(CUDA_USE_STATIC_CUDA_RUNTIME OFF CACHE INTERNAL "")

# Find CUDA.
find_package(CUDA)
if(NOT CUDA_FOUND)
Expand Down Expand Up @@ -89,6 +95,9 @@ endif()

if(DEFINED ENV{CUDNN_LIBRARY})
set(CUDNN_LIBRARY $ENV{CUDNN_LIBRARY})
if (CUDNN_LIBRARY MATCHES ".*cudnn_static.a")
SET(CUDNN_STATIC_LINKAGE ON)
endif()
else()
find_library(CUDNN_LIBRARY ${CUDNN_LIBNAME}
HINTS ${CUDNN_ROOT_DIR} ${CUDA_TOOLKIT_ROOT_DIR}
Expand Down Expand Up @@ -186,7 +195,7 @@ add_library(caffe2::cudart INTERFACE IMPORTED)
if(CAFFE2_STATIC_LINK_CUDA)
set_property(
TARGET caffe2::cudart PROPERTY INTERFACE_LINK_LIBRARIES
"${CUDA_TOOLKIT_ROOT_DIR}/lib64/libcudart_static.a" rt)
"${CUDA_TOOLKIT_ROOT_DIR}/lib64/libcudart_static.a" rt dl)
else()
set_property(
TARGET caffe2::cudart PROPERTY INTERFACE_LINK_LIBRARIES
Expand Down

0 comments on commit 3a47d56

Please sign in to comment.