Support /d2ReducedOptimizeHugeFunctions on Windows when TF_VC_VERSION=16.4
See https://groups.google.com/a/tensorflow.org/g/build/c/SsW98Eo7l3o
PiperOrigin-RevId: 281412015
Change-Id: Icdea77fe0677ad6b0e1c5cf8f053a81a14cb402e
diff --git a/configure.py b/configure.py
index cd59e90..a28a543 100644
--- a/configure.py
+++ b/configure.py
@@ -1197,6 +1197,34 @@
write_to_bazelrc('build --define=INCLUDEDIR=%s' % environ_cp['INCLUDEDIR'])
+def is_reduced_optimize_huge_functions_available(environ_cp):
+ """Check to see if the system supports /d2ReducedOptimizeHugeFunctions.
+
+ The above compiler flag is a new compiler flag introduced to the Visual Studio
+ compiler in version 16.4 (available in Visual Studio 2019, Preview edition
+ only, as of 2019-11-19). TensorFlow needs this flag to massively reduce
+ compile times, but until 16.4 is officially released, we can't depend on it.
+
+ See also https://groups.google.com/a/tensorflow.org/g/build/c/SsW98Eo7l3o
+
+ Because it's very annoying to check this manually (to check the MSVC installed
+ versions, you need to use the registry, and it's not clear if Bazel will be
+ using that install version anyway), we expect enviroments who know they may
+ use this flag to export TF_VC_VERSION=16.4
+
+ TODO(angerson, gunan): Remove this function when TensorFlow's minimum VS
+ version is upgraded to 16.4.
+
+ Arguments:
+ environ_cp: Environment of the current execution
+
+ Returns:
+ boolean, whether or not /d2ReducedOptimizeHugeFunctions is available on this
+ machine.
+ """
+ return float(environ_cp.get('TF_VC_VERSION', '0')) >= 16.4
+
+
def set_windows_build_flags(environ_cp):
"""Set Windows specific build options."""
# The non-monolithic build is not supported yet
@@ -1213,6 +1241,11 @@
# have to distinct them. This avoids building the same targets twice.
write_to_bazelrc('build --distinct_host_configuration=false')
+ if is_reduced_optimize_huge_functions_available(environ_cp):
+ write_to_bazelrc(
+ 'build --copt=/d2ReducedOptimizeHugeFunctions --host_copt=/d2ReducedOptimizeHugeFunctions'
+ )
+
if get_var(
environ_cp, 'TF_OVERRIDE_EIGEN_STRONG_INLINE', 'Eigen strong inline',
True, ('Would you like to override eigen strong inline for some C++ '