[PATCH] D88371: Introduce a LLVM_ENABLE_TENSORFLOW CMake option for users to opt-in instead of silently trying to enable it

Mehdi AMINI via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 26 20:21:03 PDT 2020


mehdi_amini created this revision.
mehdi_amini added a reviewer: mtrofin.
Herald added subscribers: llvm-commits, aaron.ballman, mgorny.
Herald added a project: LLVM.
mehdi_amini requested review of this revision.

At the moment the CMake script tries to figure if TensorFlow is
available on the system and enables support for it. This is in general
not desirable to customize build features this way and instead it is
preferrable to let the user opt-in explicitly into the features they want
to enable. This is in line with other optional external dependencies
like Z3.
There are a few reasons to this but amongst others:

- reproducibility: making features "magically" enabled based on whether

we find a package on the system or not makes it harder to handle bug
reports from users.

- user control: they can't have TensorFlow on the system and build LLVM

without TensorFlow right now. They also would suddenly distribute LLVM
with a different set of features unknowingly just because their build
machine environment would change subtly.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88371

Files:
  llvm/CMakeLists.txt


Index: llvm/CMakeLists.txt
===================================================================
--- llvm/CMakeLists.txt
+++ llvm/CMakeLists.txt
@@ -829,42 +829,46 @@
   ${LLVM_INCLUDE_DIR}/llvm/Config/Targets.def
   )
 
-# For up-to-date instructions for installing the Tensorflow dependency, refer to
-# the bot setup script: https://github.com/google/ml-compiler-opt/blob/master/buildbot/buildbot_init.sh
-# In this case, the latest C API library is available for download from
-# https://www.tensorflow.org/install/lang_c.
-# We will expose the conditional compilation variable,
-# LLVM_HAVE_TF_API, through llvm-config.h, so that a user of the LLVM library may
-# also leverage the dependency.
-set(TENSORFLOW_C_LIB_PATH "" CACHE PATH "Path to TensorFlow C library install")
-find_library(tensorflow_c_api tensorflow PATHS ${TENSORFLOW_C_LIB_PATH}/lib)
-
-if (tensorflow_c_api)
-  set(LLVM_HAVE_TF_API "ON" CACHE BOOL "Full Tensorflow API available")
-  include_directories(${TENSORFLOW_C_LIB_PATH}/include)
-endif()
-
 # They are not referenced. See set_output_directory().
 set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/bin )
 set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
 set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
 
-# For up-to-date instructions for installing the Tensorflow dependency, refer to
-# the bot setup script: https://github.com/google/ml-compiler-opt/blob/master/buildbot/buildbot_init.sh
-# Specifically, assuming python3 is installed:
-# python3 -m pip install --upgrade pip && python3 -m pip install --user tf_nightly==2.3.0.dev20200528
-# Then set TENSORFLOW_AOT_PATH to the package install - usually it's ~/.local/lib/python3.7/site-packages/tensorflow
-#
-set(TENSORFLOW_AOT_PATH "" CACHE PATH "Path to TensorFlow pip install dir")
-
-if (NOT TENSORFLOW_AOT_PATH STREQUAL "")
-  set(LLVM_HAVE_TF_AOT "ON" CACHE BOOL "Tensorflow AOT available")
-  set(TENSORFLOW_AOT_COMPILER
-    "${TENSORFLOW_AOT_PATH}/../../../../bin/saved_model_cli"
-    CACHE PATH "Path to the Tensorflow AOT compiler")
-  include_directories(${TENSORFLOW_AOT_PATH}/include)
-  add_subdirectory(${TENSORFLOW_AOT_PATH}/xla_aot_runtime_src
-    ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/tf_runtime)
+
+option(LLVM_ENABLE_TENSORFLOW "Enable TensorFlow support." OFF)
+if (LLVM_ENABLE_TENSORFLOW)
+  # For up-to-date instructions for installing the Tensorflow dependency, refer to
+  # the bot setup script: https://github.com/google/ml-compiler-opt/blob/master/buildbot/buildbot_init.sh
+  # In this case, the latest C API library is available for download from
+  # https://www.tensorflow.org/install/lang_c.
+  # We will expose the conditional compilation variable,
+  # LLVM_HAVE_TF_API, through llvm-config.h, so that a user of the LLVM library may
+  # also leverage the dependency.
+  set(TENSORFLOW_C_LIB_PATH "" CACHE PATH "Path to TensorFlow C library install")
+  find_library(tensorflow_c_api tensorflow PATHS ${TENSORFLOW_C_LIB_PATH}/lib)
+
+  if (tensorflow_c_api)
+    set(LLVM_HAVE_TF_API "ON" CACHE BOOL "Full Tensorflow API available")
+    include_directories(${TENSORFLOW_C_LIB_PATH}/include)
+  endif()
+
+  # For up-to-date instructions for installing the Tensorflow dependency, refer to
+  # the bot setup script: https://github.com/google/ml-compiler-opt/blob/master/buildbot/buildbot_init.sh
+  # Specifically, assuming python3 is installed:
+  # python3 -m pip install --upgrade pip && python3 -m pip install --user tf_nightly==2.3.0.dev20200528
+  # Then set TENSORFLOW_AOT_PATH to the package install - usually it's ~/.local/lib/python3.7/site-packages/tensorflow
+  #
+  set(TENSORFLOW_AOT_PATH "" CACHE PATH "Path to TensorFlow pip install dir")
+
+  if (NOT TENSORFLOW_AOT_PATH STREQUAL "")
+    set(LLVM_HAVE_TF_AOT "ON" CACHE BOOL "Tensorflow AOT available")
+    set(TENSORFLOW_AOT_COMPILER
+      "${TENSORFLOW_AOT_PATH}/../../../../bin/saved_model_cli"
+      CACHE PATH "Path to the Tensorflow AOT compiler")
+    include_directories(${TENSORFLOW_AOT_PATH}/include)
+    add_subdirectory(${TENSORFLOW_AOT_PATH}/xla_aot_runtime_src
+      ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/tf_runtime)
+  endif()
 endif()
 
 # Configure the three LLVM configuration header files.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88371.294533.patch
Type: text/x-patch
Size: 4271 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200927/8c2c206b/attachment.bin>


More information about the llvm-commits mailing list