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 22:24:26 UTC
[GitHub] rahul003 closed pull request #10771: [MXNET-372] Add build flag for
USE_F16C in CMake and clarify flag in make
rahul003 closed pull request #10771: [MXNET-372] Add build flag for USE_F16C in CMake and clarify flag in make
URL: https://github.com/apache/incubator-mxnet/pull/10771
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 e051c2c91c1..5da1d9084e5 160000
--- a/3rdparty/mshadow
+++ b/3rdparty/mshadow
@@ -1 +1 @@
-Subproject commit e051c2c91c1ac4a3a8fed3e90ef2fb549220d972
+Subproject commit 5da1d9084e56bf1d7af246f632f4d59a995c76cd
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 363237f909e..e08d644348b 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,10 @@ if(MSVC)
add_definitions(-DNNVM_EXPORTS)
add_definitions(-DDMLC_STRICT_CXX11)
add_definitions(-DNOMINMAX)
+ set(SUPPORT_F16C FALSE)
+ 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)
@@ -102,6 +107,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_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")
@@ -132,6 +160,13 @@ else(MSVC)
endif()
endif(MSVC)
+if(SUPPORT_F16C)
+ 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)
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