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/05/01 21:23:19 UTC

[GitHub] rahul003 closed pull request #10769: [PR for v1.2] F16C Build flags

rahul003 closed pull request #10769: [PR for v1.2] F16C Build flags
URL: https://github.com/apache/incubator-mxnet/pull/10769
 
 
   

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/3rdparty/mshadow b/3rdparty/mshadow
index 0b4cedd7015..5da1d9084e5 160000
--- a/3rdparty/mshadow
+++ b/3rdparty/mshadow
@@ -1 +1 @@
-Subproject commit 0b4cedd7015cc69191f8338a8feaacda90697758
+Subproject commit 5da1d9084e56bf1d7af246f632f4d59a995c76cd
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ffa4d6549d6..4b512529e37 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -16,6 +16,7 @@ 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
 mxnet_option(USE_SSE              "Build with x86 SSE instruction support" ON)
+mxnet_option(USE_F16C             "Build with x86 F16C instruction support" ON) # autodetects support if ON
 mxnet_option(USE_LAPACK           "Build with lapack support" ON IF NOT MSVC)
 mxnet_option(USE_MKL_IF_AVAILABLE "Use MKL if found" ON)
 mxnet_option(USE_MKLML_MKL        "Use MKLDNN variant of MKL (if MKL found)" ON IF USE_MKL_IF_AVAILABLE AND UNIX AND (NOT APPLE))
@@ -86,6 +87,8 @@ if(MSVC)
   add_definitions(-DNNVM_EXPORTS)
   add_definitions(-DDMLC_STRICT_CXX11)
   add_definitions(-DNOMINMAX)
+  set(SUPPORT_F16C FALSE)
+  message("F16C instruction set is not yet supported for MSVC")
   set(CMAKE_C_FLAGS "/MP")
   set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} /bigobj")
 else(MSVC)
@@ -102,6 +105,29 @@ 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_MF16C TRUE)
+    endif()
+  else()
+    set(SUPPORT_MF16C 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")
@@ -132,6 +158,13 @@ else(MSVC)
   endif()
 endif(MSVC)
 
+if(SUPPORT_MF16C)
+  add_definitions(-DMSHADOW_USE_F16C=1)
+  set(CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} -mf16c")
+else()
+  add_definitions(-DMSHADOW_USE_F16C=0)
+endif()
+
 if(NOT mxnet_LINKER_LIBS)
   set(mxnet_LINKER_LIBS "")
 endif(NOT mxnet_LINKER_LIBS)
@@ -584,9 +617,12 @@ endif()
 
 set(MXNET_INSTALL_TARGETS mxnet)
 if(UNIX)
+  # Create dummy file since we want an empty shared library before linking
+  set(DUMMY_SOURCE ${CMAKE_BINARY_DIR}/dummy.c)
+  file(WRITE ${DUMMY_SOURCE} "")
   list(APPEND MXNET_INSTALL_TARGETS mxnet_static)
   add_library(mxnet_static STATIC ${SOURCE})
-  add_library(mxnet SHARED)
+  add_library(mxnet SHARED ${DUMMY_SOURCE})
   target_link_libraries(mxnet PRIVATE ${BEGIN_WHOLE_ARCHIVE} $<TARGET_FILE:mxnet_static> ${END_WHOLE_ARCHIVE})
   target_link_libraries(mxnet PRIVATE mxnet_static)
   set_target_properties(mxnet_static PROPERTIES OUTPUT_NAME mxnet)
diff --git a/make/config.mk b/make/config.mk
index 9eded6f5080..dd67c33cc9e 100644
--- a/make/config.mk
+++ b/make/config.mk
@@ -132,10 +132,19 @@ endif
 ARCH := $(shell uname -a)
 ifneq (,$(filter $(ARCH), armv6l armv7l powerpc64le ppc64le aarch64))
 	USE_SSE=0
+	USE_F16C=0
 else
 	USE_SSE=1
 endif
 
+#----------------------------
+# F16C instruction support for faster arithmetic of fp16 on CPU
+#----------------------------
+# For distributed training with fp16, this helps even if training on GPUs
+# If left empty, checks CPU support and turns it on.
+# For cross compilation, please check support for F16C on target device and turn off if necessary.
+USE_F16C =
+
 #----------------------------
 # distributed computing
 #----------------------------
diff --git a/make/crosscompile.jetson.mk b/make/crosscompile.jetson.mk
index 31a1398c1b7..acc9c4a5a8a 100644
--- a/make/crosscompile.jetson.mk
+++ b/make/crosscompile.jetson.mk
@@ -132,7 +132,10 @@ endif
 # Settings for power and arm arch
 #----------------------------
 USE_SSE=0
+
+# Turn off F16C instruction set support
 USE_F16C=0
+
 #----------------------------
 # distributed computing
 #----------------------------


 

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