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/11/19 16:28:09 UTC

[GitHub] lebeg closed pull request #10564: Simplified CUDA language detection in cmake

lebeg closed pull request #10564: Simplified CUDA language detection in cmake
URL: https://github.com/apache/incubator-mxnet/pull/10564
 
 
   

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/CMakeLists.txt b/CMakeLists.txt
index 246ae995e90..3c22a7b7cb7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,7 +1,11 @@
 cmake_minimum_required(VERSION 3.0.2)
 
+message(STATUS "CMake version '${CMAKE_VERSION}' using generator '${CMAKE_GENERATOR}'")
+
 project(mxnet C CXX)
 
+include(CheckLanguage)
+
 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/build/private/local_config.cmake)
   include(${CMAKE_CURRENT_SOURCE_DIR}/build/private/local_config.cmake)
 endif()
@@ -39,27 +43,29 @@ mxnet_option(INSTALL_EXAMPLES     "Install the example source files." OFF)
 mxnet_option(USE_SIGNAL_HANDLER   "Print stack traces on segfaults." OFF)
 
 if(USE_CUDA AND NOT USE_OLDCMAKECUDA)
-  message(STATUS "CMake version '${CMAKE_VERSION}' using generator '${CMAKE_GENERATOR}'")
-  if(
-      (
-        (${CMAKE_GENERATOR} MATCHES "Visual Studio.*")
-        OR (${CMAKE_GENERATOR} MATCHES "Xcode.*")
-        OR (${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")
-      ) AND (
-        (${CMAKE_VERSION} VERSION_GREATER "3.9.0") OR (${CMAKE_VERSION} VERSION_EQUAL "3.9.0")
-      )
-    )
+  check_language(CUDA)
+  if(CMAKE_CUDA_COMPILER)
     set(FIRST_CUDA TRUE)
     project(mxnet C CXX CUDA)
   else()
+    message(STATUS "No first class CUDA language support in this cmake version")
+
     set(FIRST_CUDA FALSE)
     set(USE_OLDCMAKECUDA TRUE)
+
     project(mxnet C CXX)
   endif()
-else()
-  project(mxnet C CXX)
 endif()
 
+# f16 support
+
+include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/F16.cmake)
+
+if(USE_F16C AND SUPPORT_F16C)
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mf16c")
+else()
+  add_definitions(-DMSHADOW_USE_F16C=0)
+endif()
 
 if(MSVC)
   set(SYSTEM_ARCHITECTURE x86_64)
@@ -87,9 +93,6 @@ if(MSVC)
   add_definitions(-DNNVM_EXPORTS)
   add_definitions(-DDMLC_STRICT_CXX11)
   add_definitions(-DNOMINMAX)
-  if(USE_F16C)
-    message("F16C instruction set is not yet supported for MSVC")
-  endif()
   set(CMAKE_C_FLAGS "/MP")
   set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} /bigobj")
 else(MSVC)
@@ -106,29 +109,6 @@ else(MSVC)
   else()
     set(SUPPORT_MSSE2 FALSE)
   endif()
-  # For cross complication, turn off flag if target device does not support it
-  if(USE_F16C)
-    check_cxx_compiler_flag("-mf16c"     COMPILER_SUPPORT_MF16C)
-    if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
-      execute_process(COMMAND cat /proc/cpuinfo
-              COMMAND grep flags
-              COMMAND grep f16c
-              OUTPUT_VARIABLE CPU_SUPPORT_F16C)
-    elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
-      execute_process(COMMAND sysctl -a
-              COMMAND grep machdep.cpu.features
-              COMMAND grep F16C
-              OUTPUT_VARIABLE CPU_SUPPORT_F16C)
-    endif()
-    if(NOT CPU_SUPPORT_F16C)
-      message("CPU does not support F16C instructions")
-    endif()
-    if(CPU_SUPPORT_F16C AND COMPILER_SUPPORT_MF16C)
-      set(SUPPORT_F16C TRUE)
-    endif()
-  else()
-    set(SUPPORT_F16C FALSE)
-  endif()
   set(CMAKE_C_FLAGS "-Wall -Wno-unknown-pragmas -fPIC -Wno-sign-compare")
   if ("${CMAKE_CXX_COMPILER_ID}" MATCHES ".*Clang$")
     set(CMAKE_C_FLAGS "-Wno-braced-scalar-init")
@@ -208,14 +188,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
 if(USE_CUDA)
   find_package(CUDA REQUIRED)
   add_definitions(-DMSHADOW_USE_CUDA=1)
-  if(FIRST_CUDA AND (NOT USE_OLDCMAKECUDA))
-    if(CUDA_TOOLSET STREQUAL "")
-      set(CUDA_TOOLSET "${CUDA_VERSION_STRING}")
-    endif()
-    set(CMAKE_GENERATOR_TOOLSET "cuda=${CUDA_TOOLSET},host=x64")
-  else()
-    set(FIRST_CUDA FALSE)
-  endif()
+  
   if(USE_NCCL)
     find_package(NCCL)
     if(NCCL_FOUND)
@@ -339,7 +312,8 @@ if(USE_OPENMP)
   find_package(OpenMP REQUIRED)
   # This should build on Windows, but there's some problem and I don't have a Windows box, so
   # could a Windows user please fix?
-  if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/openmp/CMakeLists.txt AND SYSTEM_ARCHITECTURE STREQUAL "x86_64" AND NOT MSVC)
+  if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/openmp/CMakeLists.txt
+          AND SYSTEM_ARCHITECTURE STREQUAL "x86_64" AND NOT MSVC)
     # Intel/llvm OpenMP: https://github.com/llvm-mirror/openmp
     set(OPENMP_STANDALONE_BUILD TRUE)
     set(LIBOMP_ENABLE_SHARED TRUE)
diff --git a/Jenkinsfile b/Jenkinsfile
index e45bea7f456..8702c72243d 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -322,6 +322,17 @@ try {
         }
       }
     },
+    'GPU: CMake with USE_OLDCMAKECUDA': {
+      node('mxnetlinux-cpu') {
+        ws('workspace/build-cmake-gpu') {
+          timeout(time: max_time, unit: 'MINUTES') {
+            init_git()
+            docker_run('ubuntu_gpu', 'build_ubuntu_gpu_cmake_oldcmakecuda', false)
+            pack_lib('cmake_gpu', mx_cmake_lib)
+          }
+        }
+      }
+    },
     'Build CPU windows':{
       node('mxnetwindows-cpu') {
         timeout(time: max_time, unit: 'MINUTES') {
diff --git a/ci/docker/runtime_functions.sh b/ci/docker/runtime_functions.sh
index 7abe767c869..7bd3281d8b2 100755
--- a/ci/docker/runtime_functions.sh
+++ b/ci/docker/runtime_functions.sh
@@ -344,6 +344,22 @@ build_ubuntu_gpu_cmake() {
     ninja -v
 }
 
+build_ubuntu_gpu_cmake_oldcmakecuda() {
+    set -ex
+    cd /work/build
+    cmake \
+        -DUSE_CUDA=1               \
+        -DUSE_OLDCMAKECUDA=1        \
+        -DUSE_CUDNN=1              \
+        -DUSE_MKLML_MKL=0          \
+        -DUSE_MKLDNN=0             \
+        -DUSE_DIST_KVSTORE=1       \
+        -DCMAKE_BUILD_TYPE=Release \
+        -G Ninja                   \
+        /work/mxnet
+
+    ninja -v
+}
 
 # Testing
 
diff --git a/cmake/F16.cmake b/cmake/F16.cmake
new file mode 100644
index 00000000000..c37dd4de798
--- /dev/null
+++ b/cmake/F16.cmake
@@ -0,0 +1,62 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+if (DEFINED SUPPORT_F16C)
+    return()
+endif ()
+
+# set to false as default and overwrite later if possible
+set(SUPPORT_F16C FALSE)
+
+if (MSVC)
+    message(INFO "\
+F16C instructions are not supported with MSVC for now, skipping...")
+    return()
+endif ()
+
+include(CheckCXXCompilerFlag)
+
+check_cxx_compiler_flag("-mf16c" COMPILER_SUPPORT_MF16C)
+
+if (NOT COMPILER_SUPPORT_MF16C)
+    message(INFO "\
+F16C instructions are not supported by the compiler, skipping...")
+    return()
+endif ()
+
+if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
+    execute_process(COMMAND cat /proc/cpuinfo
+            COMMAND grep flags
+            COMMAND grep f16c
+            OUTPUT_VARIABLE CPU_SUPPORT_F16C)
+elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+    execute_process(COMMAND sysctl -a
+            COMMAND grep machdep.cpu.features
+            COMMAND grep F16C
+            OUTPUT_VARIABLE CPU_SUPPORT_F16C)
+endif ()
+
+if (NOT CPU_SUPPORT_F16C)
+    message(INFO "\
+F16C instructions are not supported by the CPU, skipping...")
+    return()
+endif ()
+
+
+set(SUPPORT_F16C TRUE)
+
+


 

----------------------------------------------------------------
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