Remove linker and dlopen flags that allowed undefined symbols in rocm build (#15091)
authorbddppq <bai@in.tum.de>
Wed, 12 Dec 2018 07:20:31 +0000 (23:20 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Wed, 12 Dec 2018 07:23:47 +0000 (23:23 -0800)
Summary:
Previously the undefined symbols were caused by disabled_modules in tools/amd_build/disabled_features.json (now it's cleared).
Pull Request resolved: https://github.com/pytorch/pytorch/pull/15091

Differential Revision: D13429595

Pulled By: bddppq

fbshipit-source-id: b341e83f9e5a8d16440a364e837b045a8a4fd6e1

aten/src/ATen/CMakeLists.txt
caffe2/python/_import_c_extension.py
cmake/Dependencies.cmake
tools/amd_build/build_amd.py

index 8edb2eb..765ac38 100644 (file)
@@ -59,6 +59,7 @@ FILE(GLOB native_sparse_cuda_cpp "native/sparse/cuda/*.cpp")
 FILE(GLOB native_hip_hip "native/hip/*.hip")
 FILE(GLOB native_hip_cpp "native/hip/*.cpp")
 FILE(GLOB native_miopen_cpp "native/miopen/*.cpp")
+FILE(GLOB native_cudnn_hip_cpp "native/cudnn/hip/*.cpp")
 FILE(GLOB native_sparse_hip_hip "native/sparse/hip/*.hip")
 FILE(GLOB native_sparse_hip_cpp "native/sparse/hip/*.cpp")
 
@@ -89,7 +90,7 @@ IF(USE_ROCM)
   set(ATen_HIP_SRCS ${ATen_HIP_SRCS} ${hip_hip} ${native_hip_hip} ${native_sparse_hip_hip})
   # TODO: Codegen separate files for HIP and use those (s/cuda_generated_cpp/hip_generated_cpp)
   set(all_hip_cpp ${native_sparse_hip_cpp} ${hip_cpp} ${native_hip_cpp} ${cuda_generated_cpp} ${ATen_HIP_SRCS})
-  set(all_hip_cpp ${native_miopen_cpp} ${miopen_cpp} ${all_hip_cpp})
+  set(all_hip_cpp ${native_miopen_cpp} ${native_cudnn_hip_cpp} ${miopen_cpp} ${all_hip_cpp})
 endif()
 
 filter_list(generated_h generated_cpp "\\.h$")
index aca9e52..ba2cbe1 100644 (file)
@@ -19,9 +19,7 @@ with extension_loader.DlopenGuard():
     except ImportError as gpu_e:
         logging.info('Failed to import cuda module: {}'.format(gpu_e))
         try:
-            RTLD_LAZY = 1
-            with extension_loader.DlopenGuard(RTLD_LAZY):
-                from caffe2.python.caffe2_pybind11_state_hip import *  # noqa
+            from caffe2.python.caffe2_pybind11_state_hip import *  # noqa
             if num_hip_devices():
                 has_hip_support = True
                 logging.info('This caffe2 python run has AMD GPU support!')
index a0853a4..28ffacd 100644 (file)
@@ -760,25 +760,14 @@ if(USE_ROCM)
     hip_include_directories(${Caffe2_HIP_INCLUDE})
 
     set(Caffe2_HIP_DEPENDENCY_LIBS
-      ${rocrand_LIBRARIES} ${hiprand_LIBRARIES} ${PYTORCH_HIP_HCC_LIBRARIES} ${PYTORCH_MIOPEN_LIBRARIES})
-    # Additional libraries required by PyTorch AMD that aren't used by Caffe2 (not in Caffe2's docker image)
-    if(NOT BUILD_ATEN_MOBILE)
-      set(Caffe2_HIP_DEPENDENCY_LIBS ${Caffe2_HIP_DEPENDENCY_LIBS} ${hipsparse_LIBRARIES})
-    endif()
-    # Note [rocblas cmake bug]
-    # ~~~~~~~~~~~~~~~~~~~~~~~~
-    # TODO: There is a bug in rocblas's cmake files that exports the wrong targets name in ${rocblas_LIBRARIES}
+      ${rocrand_LIBRARIES} ${hiprand_LIBRARIES} ${hipsparse_LIBRARIES} ${PYTORCH_HIP_HCC_LIBRARIES} ${PYTORCH_MIOPEN_LIBRARIES})
+
+    # Note [rocblas & rocfft cmake bug]
+    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    # TODO: There is a bug in rocblas's & rocfft's cmake files that exports the wrong targets name in ${rocblas_LIBRARIES}
     # If you get this wrong, you'll get a complaint like 'ld: cannot find -lrocblas-targets'
     list(APPEND Caffe2_HIP_DEPENDENCY_LIBS
-      roc::rocblas)
-
-    # TODO: Currently pytorch hipify script uses a feature called
-    # "disabled_modules" that effectively ifdef out a file, but
-    # without doing extra processing in the callers, which results in
-    # some unresolved symbols in the shared lib
-    # (libcaffe2_hip.so). Remove this when all disabled_modules are
-    # eliminated.
-    set(CMAKE_EXE_LINKER_FLAGS "-Wl,--unresolved-symbols=ignore-in-shared-libs ${CMAKE_EXE_LINKER_FLAGS}")
+      roc::rocblas roc::rocfft)
   else()
     caffe2_update_option(USE_ROCM OFF)
   endif()
index 2927e36..f5d1351 100644 (file)
@@ -41,6 +41,7 @@ includes = [
     # Keep this synchronized with is_pytorch_file in hipify_python.py
     "aten/src/ATen/cuda/*",
     "aten/src/ATen/native/cuda/*",
+    "aten/src/ATen/native/cudnn/*",
     "aten/src/ATen/native/sparse/cuda/*",
     "aten/src/THC/*",
     "aten/src/THCUNN/*",