You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/01/17 23:48:24 UTC

[GitHub] cjolivier01 closed pull request #8900: Fix cuda cmake and cleanup

cjolivier01 closed pull request #8900: Fix cuda cmake and cleanup
URL: https://github.com/apache/incubator-mxnet/pull/8900
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/.gitignore b/.gitignore
index 9d2e8944f4..b3fc89d1e4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -149,11 +149,12 @@ bld
 ./tmp/*
 *.jar
 target
-
 bin/im2rec
-
 model/
 
+# VTune
+./r0*hs
+
 # generated function signature for IDE auto-complete
 python/mxnet/symbol/gen_*
 python/mxnet/ndarray/gen_*
diff --git a/.gitmodules b/.gitmodules
index 4ad3e407f9..0e0a50bb86 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -13,9 +13,9 @@
 [submodule "dlpack"]
 	path = dlpack
 	url = https://github.com/dmlc/dlpack
-[submodule "cub"]
-	path = 3rdparty/cub
-	url = https://github.com/dmlc/cub
 [submodule "3rdparty/openmp"]
 	path = 3rdparty/openmp
 	url = https://github.com/llvm-mirror/openmp
+[submodule "3rdparty/cub"]
+	path = 3rdparty/cub
+	url = https://github.com/dmlc/cub
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8211624a7d..a7ee15129e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,15 +1,15 @@
 cmake_minimum_required(VERSION 3.0.2)
 
-if((${CMAKE_VERSION} VERSION_GREATER "3.9.0") OR (${CMAKE_VERSION} VERSION_EQUAL "3.9.0"))
-  set(FIRST_CUDA TRUE)
-else()
-  set(FIRST_CUDA FALSE)
+if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/build/private/local_config.cmake)
+  include(${CMAKE_CURRENT_SOURCE_DIR}/build/private/local_config.cmake)
 endif()
+
 include(cmake/Utils.cmake)
 
 #Some things have order. This must be put in front alone
 mxnet_option(USE_CUDA             "Build with CUDA support"   ON)
-mxnet_option(USE_OLDCMAKECUDA           "Build with old cmake cuda" OFF)
+mxnet_option(USE_OLDCMAKECUDA     "Build with old cmake cuda" OFF)
+
 if(USE_CUDA)
   add_definitions(-DMSHADOW_USE_CUDA=1)
   IF(FIRST_CUDA AND (NOT USE_OLDCMAKECUDA))
@@ -27,7 +27,6 @@ else()
   add_definitions(-DMSHADOW_USE_CUDA=0)
 endif()
 
-
 mxnet_option(USE_OPENCV           "Build with OpenCV support" ON)
 mxnet_option(USE_OPENMP           "Build with Openmp support" ON)
 mxnet_option(USE_CUDNN            "Build with cudnn support"  ON) # one could set CUDNN_ROOT for search path
@@ -45,29 +44,30 @@ mxnet_option(USE_PLUGIN_CAFFE     "Use Caffe Plugin" OFF)
 mxnet_option(USE_CPP_PACKAGE      "Build C++ Package" OFF)
 mxnet_option(USE_MXNET_LIB_NAMING "Use MXNet library naming conventions." ON)
 mxnet_option(USE_GPROF            "Compile with gprof (profiling) flag" OFF)
+mxnet_option(USE_CXX14_IF_AVAILABLE "Build with C++14 if the compiler supports it" OFF)
 mxnet_option(USE_VTUNE            "Enable use of Intel Amplifier XE (VTune)" OFF) # one could set VTUNE_ROOT for search path
 mxnet_option(INSTALL_EXAMPLES     "Install the example source files." OFF)
 mxnet_option(USE_SIGNAL_HANDLER   "Print stack traces on segfaults." OFF)
 
-
-
-if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/build/private/local_config.cmake)
-  include(${CMAKE_CURRENT_SOURCE_DIR}/build/private/local_config.cmake)
+if(USE_CUDA)
+  project(mxnet C CXX CUDA)
+else()
+  project(mxnet C CXX)
 endif()
 
 if(MSVC)
   set(SYSTEM_ARCHITECTURE x86_64)
 else()
-  EXECUTE_PROCESS( COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE SYSTEM_ARCHITECTURE)
+  execute_process(COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE SYSTEM_ARCHITECTURE)
 endif()
 
-set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules;${CMAKE_MODULE_PATH}")
+set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules;${CMAKE_MODULE_PATH}")
 
 SET(EXTRA_OPERATORS "" CACHE PATH "EXTRA OPERATORS PATH")
 
 if("$ENV{VERBOSE}" STREQUAL "1")
   message(STATUS " Verbose Makefile ACTIVATED")
-  set(CMAKE_VERBOISE_MAKEFILE ON)
+  set(CMAKE_VERBOSE_MAKEFILE ON)
 endif()
 
 
@@ -84,6 +84,9 @@ if(MSVC)
   set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} /bigobj")
 else(MSVC)
   include(CheckCXXCompilerFlag)
+  if(USE_CXX14_IF_AVAILABLE)
+    check_cxx_compiler_flag("-std=c++14"   SUPPORT_CXX14)
+  endif()
   check_cxx_compiler_flag("-std=c++11"   SUPPORT_CXX11)
   check_cxx_compiler_flag("-std=c++0x"   SUPPORT_CXX0X)
   check_cxx_compiler_flag("-msse2"       SUPPORT_MSSE2)
@@ -104,7 +107,11 @@ else(MSVC)
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2")
   endif()
   set(CMAKE_CXX_FLAGS ${CMAKE_C_FLAGS})
-  if(SUPPORT_CXX11)
+  if(SUPPORT_CXX14)
+    add_definitions(-DDMLC_USE_CXX11=1)
+    add_definitions(-DDMLC_USE_CXX14=1)
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
+  elseif(SUPPORT_CXX11)
     add_definitions(-DDMLC_USE_CXX11=1)
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
   elseif(SUPPORT_CXX0X)
@@ -117,8 +124,8 @@ set(mxnet_LINKER_LIBS "")
 
 if(USE_GPROF)
   message(STATUS "Using GPROF")
-  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -pg")
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -pg")
+  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer -g -pg")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -g -pg")
   set(CMAKE_LINK_LIBRARY_FILE_FLAG "${CMAKE_LINK_LIBRARY_FILE_FLAG} -g -pg")
 endif()
 
@@ -167,12 +174,32 @@ endif()
 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
 
-if(FIRST_CUDA)
+if(USE_CUDA)
+  if(NOT MSVC AND ((${CMAKE_VERSION} VERSION_GREATER "3.9.0") OR (${CMAKE_VERSION} VERSION_EQUAL "3.9.0")))
+    set(FIRST_CUDA TRUE)
+  else()
+    set(FIRST_CUDA FALSE)
+    set(USE_OLDCMAKECUDA TRUE)
+  endif()
+  add_definitions(-DMSHADOW_USE_CUDA=1)
+  if(FIRST_CUDA AND (NOT USE_OLDCMAKECUDA))
+    set(__cuda_toolset "7.5" "8.0" "9.0")
+    set(CUDA_TOOLSET "8.0" CACHE STRING "Select CUDA Version.")
+    set_property( CACHE CUDA_TOOLSET PROPERTY STRINGS "" ${__cuda_toolset} )
+    set(CMAKE_GENERATOR_TOOLSET "cuda=${CUDA_TOOLSET},host=x64")
+  else()
+    set(FIRST_CUDA FALSE)
+  endif()
+else()
+  add_definitions(-DMSHADOW_USE_CUDA=0)
+endif()
+
+if(USE_CUDA AND FIRST_CUDA)
   include(cmake/ChooseBlas.cmake)
   include(mshadow/cmake/Utils.cmake)
   include(cmake/FirstClassLangCuda.cmake)
 else()
-  if(EXISTS ${PROJECT_SOURCE_DIR}/mshadow/cmake)
+  if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/mshadow/cmake)
     include(mshadow/cmake/mshadow.cmake)
     include(mshadow/cmake/Utils.cmake)
     include(mshadow/cmake/Cuda.cmake)
@@ -230,8 +257,8 @@ endif()
 
 # ---[ jemalloc
 if(USE_JEMALLOC)
-  if(USE_GPERFTOOLS)
-    message(ERROR "Only one of USE_JEMALLOC and USE_GPERFTOOLS can be defined at once")
+  if(GPERFTOOLS_FOUND)
+    message(ERROR " Only one of USE_JEMALLOC and USE_GPERFTOOLS can be defined at once")
   endif()
   find_package(JeMalloc)
   if(JEMALLOC_FOUND)
@@ -294,12 +321,12 @@ elseif(UNIX)
 endif()
 
 # ---[ LAPack
-if(USE_LAPACK)
+if(USE_LAPACK AND NOT MSVC)
   add_definitions(-DMXNET_USE_LAPACK=1)
   list(APPEND mxnet_LINKER_LIBS lapack)
 else(USE_LAPACK)
   # Workaround for Windows until using new Jenkinsfile.
-  if(BLAS STREQUAL "Open" OR BLAS STREQUAL "open")
+  if(BLAS STREQUAL "Open" OR BLAS STREQUAL "open" OR USE_BLAS STREQUAL "Open" OR USE_BLAS STREQUAL "open")
     add_definitions(-DMXNET_USE_LAPACK=1)
   endif()
 endif()
@@ -357,7 +384,8 @@ list(APPEND CUDA ${MSHADOW_CUDASOURCE})
 # add source group
 FILE(GLOB_RECURSE GROUP_SOURCE "src/*.cc" "nnvm/*.cc" "plugin/*.cc")
 FILE(GLOB_RECURSE GROUP_Include "src/*.h" "nnvm/*.h" "mshadow/mshadow/*.h" "plugin/*.h")
-FILE(GLOB_RECURSE GROUP_CUDA "src/*.cu" "src/*.cuh" "mshadow/mshadow/*.cuh" "plugin/*.cu" "plugin/*.cuh")
+FILE(GLOB_RECURSE GROUP_CUDA "src/*.cu" "src/*.cuh" "mshadow/mshadow/*.cuh" "plugin/*.cu"
+  "plugin/*.cuh" "3rdparty/cub/cub/*.cuh")
 assign_source_group("Source" ${GROUP_SOURCE})
 assign_source_group("Include" ${GROUP_Include})
 assign_source_group("CUDA" ${GROUP_CUDA})
@@ -389,7 +417,7 @@ if(USE_PLUGIN_CAFFE)
     if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/caffe)
       # Need newer FindCUDA.cmake that correctly handles -std=c++11
       cmake_minimum_required(VERSION 3.3)
-      set(CAFFE_PATH ${PROJECT_SOURCE_DIR}/caffe)
+      set(CAFFE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/caffe)
     else()
       set(CAFFE_PATH $ENV{CAFFE_PATH})
     endif()
@@ -436,6 +464,7 @@ endif()
 if(USE_CUDA)
   if(FIRST_CUDA)
     mshadow_select_nvcc_arch_flags(NVCC_FLAGS_ARCH)
+    message(STATUS " Cuda NVCC flags: ${NVCC_FLAGS_ARCH}")
     string(REPLACE ";" " " NVCC_FLAGS_ARCH "${NVCC_FLAGS_ARCH}")
     set(CMAKE_CUDA_FLAGS "${NVCC_FLAGS_ARCH}")
     set(CMAKE_CUDA_FLAGS_RELEASE "${NVCC_FLAGS_ARCH} -use_fast_math")
@@ -488,13 +517,7 @@ if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/nnvm/CMakeLists.txt")
   list(APPEND mxnet_LINKER_LIBS ${nnvm_LINKER_LIBS})
 endif()
 
-if(NOT MSVC)
-  # Only add c++11 flags and definitions after cuda compiling
-  add_definitions(-DDMLC_USE_CXX11)
-  add_definitions(-DMSHADOW_IN_CXX11)
-  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
-else()
+if(MSVC)
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
 endif()
 
@@ -584,13 +607,13 @@ if(AUTO_INSTALL_DIR)
   # ---[ Install Includes
   add_custom_command(TARGET mxnet POST_BUILD
     COMMAND ${CMAKE_COMMAND} -E copy_directory
-    ${PROJECT_SOURCE_DIR}/include ${AUTO_INSTALL_DIR}/include
+    ${CMAKE_CURRENT_SOURCE_DIR}/include ${AUTO_INSTALL_DIR}/include
     )
 
   # ---[ Install Examples
   add_custom_command(TARGET mxnet POST_BUILD
     COMMAND ${CMAKE_COMMAND} -E copy_directory
-    ${PROJECT_SOURCE_DIR}/example ${AUTO_INSTALL_DIR}/example
+    ${CMAKE_CURRENT_SOURCE_DIR}/example ${AUTO_INSTALL_DIR}/example
     )
 endif()
 
diff --git a/cmake/FirstClassLangCuda.cmake b/cmake/FirstClassLangCuda.cmake
index 2d2662d616..4d89fc1d04 100644
--- a/cmake/FirstClassLangCuda.cmake
+++ b/cmake/FirstClassLangCuda.cmake
@@ -19,6 +19,9 @@
 
 include(CheckCXXCompilerFlag)
 check_cxx_compiler_flag("-std=c++11"   SUPPORT_CXX11)
+if(USE_CXX14_IF_AVAILABLE)
+  check_cxx_compiler_flag("-std=c++14"   SUPPORT_CXX14)
+endif()
 
 ################################################################################################
 # Short command for cuDNN detection. Believe it soon will be a part of CUDA toolkit distribution.
@@ -73,9 +76,9 @@ function(mshadow_detect_installed_gpus out_variable)
       "}\n")
     enable_language(CUDA)
 
-    try_run(__nvcc_res __compile_result ${PROJECT_BINARY_DIR} ${file}
-            COMPILE_OUTPUT_VARIABLE __compile_out
-            RUN_OUTPUT_VARIABLE __nvcc_out)
+    try_run(__nvcc_res __compile_result ${PROJECT_BINARY_DIR} ${__cufile}
+      COMPILE_OUTPUT_VARIABLE __compile_out
+      RUN_OUTPUT_VARIABLE __nvcc_out)
 
     if(__nvcc_res EQUAL 0 AND __compile_result)
       # nvcc outputs text containing line breaks when building with MSVC.
@@ -90,8 +93,8 @@ function(mshadow_detect_installed_gpus out_variable)
   endif()
 
   if(NOT CUDA_gpu_detect_output)
-    message(WARNING "Automatic GPU detection failed. Building for all known architectures (${mshadow_known_gpu_archs}).")
-    set(${out_variable} ${mshadow_known_gpu_archs} PARENT_SCOPE)
+    message(WARNING "Automatic GPU detection failed. Building for all known architectures (${mxnet_known_gpu_archs}).")
+    set(${out_variable} ${mxnet_known_gpu_archs} PARENT_SCOPE)
   else()
     set(${out_variable} ${CUDA_gpu_detect_output} PARENT_SCOPE)
   endif()
@@ -121,12 +124,12 @@ endif ()
 # Usage:
 #   mshadow_select_nvcc_arch_flags(out_variable)
 function(mshadow_select_nvcc_arch_flags out_variable)
-  
-  set(CUDA_ARCH_LIST "Common" CACHE STRING "Select target NVIDIA GPU achitecture.")
+
+  set(CUDA_ARCH_LIST "Auto" CACHE STRING "Select target NVIDIA GPU achitecture.")
   set_property( CACHE CUDA_ARCH_LIST PROPERTY STRINGS "" "All" "Common" ${CUDA_KNOWN_GPU_ARCHITECTURES} )
   mark_as_advanced(CUDA_ARCH_NAME)
-    
-    
+
+
   if("X${CUDA_ARCH_LIST}" STREQUAL "X" )
     set(CUDA_ARCH_LIST "All")
   endif()
@@ -134,11 +137,13 @@ function(mshadow_select_nvcc_arch_flags out_variable)
   set(cuda_arch_bin)
   set(cuda_arch_ptx)
 
+  message(STATUS " CUDA_ARCH_LIST: ${CUDA_ARCH_LIST}")
   if("${CUDA_ARCH_LIST}" STREQUAL "All")
     set(CUDA_ARCH_LIST ${CUDA_KNOWN_GPU_ARCHITECTURES})
   elseif("${CUDA_ARCH_LIST}" STREQUAL "Common")
     set(CUDA_ARCH_LIST ${CUDA_COMMON_GPU_ARCHITECTURES})
-  elseif("${CUDA_ARCH_LIST}" STREQUAL "Auto")
+  elseif("${CUDA_ARCH_LIST}" STREQUAL "Auto" OR "${CUDA_ARCH_LIST}" STREQUAL "")
+    set(mxnet_known_gpu_archs ${CUDA_COMMON_GPU_ARCHITECTURES})
     mshadow_detect_installed_gpus(CUDA_ARCH_LIST)
     message(STATUS "Autodetected CUDA architecture(s): ${CUDA_ARCH_LIST}")
   endif()
@@ -204,7 +209,7 @@ function(mshadow_select_nvcc_arch_flags out_variable)
   if(cuda_arch_ptx)
     list(REMOVE_DUPLICATES cuda_arch_ptx)
   endif()
-    
+
   message(STATUS "cuda arch bin: ${cuda_arch_bin}")
   message(STATUS "cuda arch ptx: ${cuda_arch_ptx}")
   set(nvcc_flags "")
@@ -229,6 +234,25 @@ function(mshadow_select_nvcc_arch_flags out_variable)
     list(APPEND nvcc_archs_readable compute_${arch})
   endforeach()
 
+  if(NOT MSVC)
+    if(SUPPORT_CXX14)
+      list(APPEND nvcc_flags "-std=c++14")
+    elseif(SUPPORT_CXX11)
+      list(APPEND nvcc_flags "-std=c++11")
+    endif()
+  endif()
+
+  string (REPLACE " " ";" CMAKE_CXX_FLAGS_STR "${CMAKE_CXX_FLAGS}")
+  foreach(_flag ${CMAKE_CXX_FLAGS_STR})
+    # Remove -std=c++XX flags
+    if(NOT "${_flag}" MATCHES "-std=.+")
+      # Remove link flags
+      if(NOT "${_flag}" MATCHES "-Wl,.+")
+        list(APPEND nvcc_flags "-Xcompiler ${_flag}")
+      endif()
+    endif()
+  endforeach()
+
   string(REPLACE ";" " " nvcc_archs_readable "${nvcc_archs_readable}")
   set(${out_variable}          ${nvcc_flags}          PARENT_SCOPE)
   set(${out_variable}_readable ${nvcc_archs_readable} PARENT_SCOPE)


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services