aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Martin Wicke <wicke@google.com>2017-01-13 12:20:42 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-01-13 12:25:28 -0800
commitc4e3d4a74e86fce3a09badd20952f067ff340f32 (patch)
treea75c0492aeab9bd0d0e5abcf882f3000288a8778
parent1c5120141b2043c4e0721774c183cb01d23b0682 (diff)
Enable customization of architecture dependent compiler optimizations via configure, defaulting to -march=native.
Change: 144470919
-rwxr-xr-xconfigure15
-rw-r--r--tensorflow/contrib/cmake/CMakeLists.txt11
-rw-r--r--tensorflow/contrib/makefile/Makefile2
3 files changed, 26 insertions, 2 deletions
diff --git a/configure b/configure
index 1e4d786974..38079041d5 100755
--- a/configure
+++ b/configure
@@ -54,6 +54,15 @@ while true; do
# Retry
done
+## Set up architecture-dependent optimization flags.
+if [ -z "$CC_OPT_FLAGS" ]; then
+ default_cc_opt_flags="-march=native"
+ read -p "Please specify optimization flags to use during compilation [Default is $default_cc_opt_flags]: " CC_OPT_FLAGS
+ if [ -z "$CC_OPT_FLAGS" ]; then
+ CC_OPT_FLAGS=$default_cc_opt_flags
+ fi
+fi
+
if is_windows; then
TF_NEED_GCP=0
TF_NEED_HDFS=0
@@ -153,6 +162,12 @@ fi
# Invoke python_config and set up symlinks to python includes
./util/python/python_config.sh --setup "$PYTHON_BIN_PATH"
+# Append CC optimization flags to bazel.rc
+echo >> tools/bazel.rc
+for opt in $CC_OPT_FLAGS; do
+ echo "build --cxxopt=$opt --copt=$opt" >> tools/bazel.rc
+done
+
# Run the gen_git_source to create links where bazel can track dependencies for
# git hash propagation
GEN_GIT_SOURCE=tensorflow/tools/git/gen_git_source.py
diff --git a/tensorflow/contrib/cmake/CMakeLists.txt b/tensorflow/contrib/cmake/CMakeLists.txt
index 691c87457c..5ac9ec5681 100644
--- a/tensorflow/contrib/cmake/CMakeLists.txt
+++ b/tensorflow/contrib/cmake/CMakeLists.txt
@@ -27,6 +27,7 @@ option(tensorflow_BUILD_ALL_KERNELS "Build all OpKernels" ON)
option(tensorflow_BUILD_CONTRIB_KERNELS "Build OpKernels from tensorflow/contrib/..." ON)
option(tensorflow_BUILD_CC_TESTS "Build cc unit tests " OFF)
option(tensorflow_BUILD_PYTHON_TESTS "Build python unit tests " OFF)
+option(tensorflow_OPTIMIZE_FOR_NATIVE_ARCH "Enable compiler optimizations for the native processor architecture (if available)" ON)
if (NOT WIN32)
# Threads: defines CMAKE_THREAD_LIBS_INIT and adds -pthread compile option
@@ -67,7 +68,15 @@ if(WIN32)
endif()
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
- set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-fno-exceptions -std=c++11")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -std=c++11")
+endif()
+
+if (tensorflow_OPTIMIZE_FOR_NATIVE_ARCH)
+ include(CheckCXXCompilerFlag)
+ CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_OPT_ARCH_NATIVE_SUPPORTED)
+ if (COMPILER_OPT_ARCH_NATIVE_SUPPORTED)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
+ endif()
endif()
# External dependencies
diff --git a/tensorflow/contrib/makefile/Makefile b/tensorflow/contrib/makefile/Makefile
index 97d963ede2..bb22586264 100644
--- a/tensorflow/contrib/makefile/Makefile
+++ b/tensorflow/contrib/makefile/Makefile
@@ -137,7 +137,7 @@ $(shell mkdir -p $(DEPDIR) >/dev/null)
# Settings for the target compiler.
CXX := $(CC_PREFIX) gcc
-OPTFLAGS := -O2
+OPTFLAGS := -O2 -march=native
CXXFLAGS := --std=c++11 -DIS_SLIM_BUILD -fno-exceptions -DNDEBUG $(OPTFLAGS)
LDFLAGS := \
-L/usr/local/lib