Step 4/n: Integrate TensorFlow compiler build and tests into CMake.
* New option: 'IREE_BUILD_TENSORFLOW_COMPILER'
* Adds some cmake hackery to find and configure bazel, scoping it under the build directory.
* Adds an iree_add_bazel_invocation() function that executes bazel and creates cmake targets for some built executables.
* Adds the cmake target 'integrations_iree_tensorflow_importers' as a bazel invocation.
* Wires up the build for pyiree.tools.tf to link the binary from the bazel side. The result is a built bindings/python directory that can be used for tests and such with no further build required (or deployed directly).
* Once I'm done with this transition, we can completely remove all of the python building from bazel, likely just replacing tests with a shell script runner, since they can just run standalone.
* Also had to fix some issues with the python config (it wasn't detecting virtual envs properly due to using the old FindPython vars).
* Added yet another hack to run_lit.sh because with bazel's out directory living in the build directory, it was taking 2m+ to scan files for things to add to the path. We shouldn't have been doing that, but also... Bazel, WTF?
* Note that old build/tests of the integrations directory were double building almost everything because Bazel was differentiating between objects bound for binaries and for shared libraries. In addition, since it included the complete IREE compiler, it was building all of LLVM.
* In the new world, we only build one static binary, and since it is just the frontend, the amount of things it needs to compile from LLVM are minimal. Most of the time is in compiling eigen kernels.
* This will probably take some tweaking before it is ready for prime time.
Stats:
Clean build:
configure: ~1m
ninja build: ~10m (includes TF)
ctest -E 'vulkan|benchmark': 14s (includes new TF tests but not the whole e2e directory yet)
On a rebuild with CCache and Bazel's disk cache enabled from the above, a rebuild of everything took 18s.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b37f0e0..9f08720 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -46,6 +46,7 @@
option(IREE_BUILD_PYTHON_BINDINGS "Builds the IREE python bindings" OFF)
option(IREE_BUILD_JAVA_BINDINGS "Builds the IREE java bindings." OFF)
option(IREE_BUILD_EXPERIMENTAL "Builds experimental projects." OFF)
+option(IREE_BUILD_TENSORFLOW_COMPILER "Builds TensorFlow compiler." OFF)
set(IREE_HAL_DRIVERS_TO_BUILD "all"
CACHE STRING "Semicolon-separated list of HAL drivers to build, or \"all\".")
@@ -268,6 +269,18 @@
include(iree_setup_toolchain)
#-------------------------------------------------------------------------------
+# Configure python early if there are any features that need it.
+# Note that doing this early ensures that dependencies that make incidental
+# use of Python (such as LLVM) resolve the same version.
+#-------------------------------------------------------------------------------
+
+if(${IREE_BUILD_COMPILER} OR
+ ${IREE_BUILD_PYTHON_BINDINGS} OR
+ ${IREE_BUILD_TENSORFLOW_COMPILER})
+ find_package(Python3 COMPONENTS Interpreter REQUIRED)
+endif()
+
+#-------------------------------------------------------------------------------
# MLIR/LLVM Dependency
# We treat the LLVM dependency specially because we support several different
# ways to use it:
@@ -371,22 +384,28 @@
endif()
#-------------------------------------------------------------------------------
-# Non-LLVM Dependencies
+# Python bindings.
#-------------------------------------------------------------------------------
-# Use the FindPython functions before any of our dependencies do. See
-# https://pybind11.readthedocs.io/en/stable/faq.html#inconsistent-detection-of-python-version-in-cmake-and-pybind11
-# If one dependency finds Python 2 (the default),
-# any others that try to find Python 3 will fail.
-# (Also come on, it's $CURRENT_YEAR - please just use Python 3 already.)
-if(${IREE_BUILD_COMPILER} OR ${IREE_BUILD_PYTHON_BINDINGS})
- find_package(Python3 COMPONENTS Interpreter REQUIRED)
-endif()
if(${IREE_BUILD_PYTHON_BINDINGS})
# Note: Optional because python libs can be manually specified.
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
endif()
+#-------------------------------------------------------------------------------
+# Bazel setup (conditional on whether features need it)
+# Depends on python configuration.
+#-------------------------------------------------------------------------------
+
+if(${IREE_BUILD_TENSORFLOW_COMPILER})
+ include(configure_bazel)
+ iree_configure_bazel()
+endif()
+
+#-------------------------------------------------------------------------------
+# Other dependencies.
+#-------------------------------------------------------------------------------
+
include(external_cc_library)
include(flatbuffer_c_library)
@@ -516,6 +535,10 @@
add_subdirectory(experimental)
endif()
+if(${IREE_BUILD_TENSORFLOW_COMPILER})
+ add_subdirectory(integrations/tensorflow)
+endif()
+
if(${IREE_BUILD_PYTHON_BINDINGS})
iree_complete_py_extension_link_options()
endif()
diff --git a/bindings/python/pyiree/compiler2/tf.py b/bindings/python/pyiree/compiler2/tf.py
index 5d92550..17d098e 100644
--- a/bindings/python/pyiree/compiler2/tf.py
+++ b/bindings/python/pyiree/compiler2/tf.py
@@ -16,6 +16,7 @@
# limitations under the License.
from enum import Enum
+import logging
import tempfile
from typing import List, Optional, Sequence, Set, Union
@@ -39,10 +40,12 @@
try:
import tensorflow as tf
except ModuleNotFoundError:
+ logging.warn("Unable to import tensorflow")
return False
try:
find_tool(_TF_IMPORT_TOOL)
except ValueError:
+ logging.warning("Unable to find IREE tool %s", _TF_IMPORT_TOOL)
return False
return True
diff --git a/bindings/python/pyiree/tools/core/CMakeLists.txt b/bindings/python/pyiree/tools/core/CMakeLists.txt
index 94027d3..9e4364c 100644
--- a/bindings/python/pyiree/tools/core/CMakeLists.txt
+++ b/bindings/python/pyiree/tools/core/CMakeLists.txt
@@ -19,36 +19,8 @@
"__init__.py"
)
-# Adds a command to TARGET which symlinks a tool from elsewhere
-# (FROM_TOOL_TARGET_NAME) to a local file name (TO_EXE_NAME).
-function(_symlink_tool)
- cmake_parse_arguments(
- ARG
- ""
- "TARGET;FROM_TOOL_TARGET;TO_EXE_NAME"
- ""
- ${ARGN}
- )
-
- # Transform TARGET
- iree_package_ns(_PACKAGE_NS)
- iree_package_name(_PACKAGE_NAME)
- set(_TARGET "${_PACKAGE_NAME}_${ARG_TARGET}")
- set(_FROM_TOOL_TARGET ${ARG_FROM_TOOL_TARGET})
-
- add_custom_command(
- TARGET "${_TARGET}"
- BYPRODUCTS
- "${CMAKE_CURRENT_BINARY_DIR}/${ARG_TO_EXE_NAME}${CMAKE_EXECUTABLE_SUFFIX}"
- COMMAND
- ${CMAKE_COMMAND} -E create_symlink
- "$<TARGET_FILE:${_FROM_TOOL_TARGET}>"
- "${CMAKE_CURRENT_BINARY_DIR}/${ARG_TO_EXE_NAME}${CMAKE_EXECUTABLE_SUFFIX}"
- )
-endfunction()
-
if(${IREE_BUILD_COMPILER})
- _symlink_tool(
+ iree_symlink_tool(
TARGET core
FROM_TOOL_TARGET iree_tools_iree-translate
TO_EXE_NAME iree-translate
diff --git a/bindings/python/tests/CMakeLists.txt b/bindings/python/tests/CMakeLists.txt
index e70629a..701bb72 100644
--- a/bindings/python/tests/CMakeLists.txt
+++ b/bindings/python/tests/CMakeLists.txt
@@ -17,9 +17,6 @@
compiler_core_test
SRCS
"compiler_core_test.py"
- DEPS
- bindings::python::pyiree::compiler2
- bindings::python::pyiree::tools::core
)
iree_py_test(
@@ -27,7 +24,4 @@
compiler_tf_test
SRCS
"compiler_tf_test.py"
- DEPS
- bindings::python::pyiree::compiler2
- bindings::python::pyiree::tools::tf
)
diff --git a/bindings/python/tests/compiler_tf_test.py b/bindings/python/tests/compiler_tf_test.py
index ec5111b..41fc94e 100644
--- a/bindings/python/tests/compiler_tf_test.py
+++ b/bindings/python/tests/compiler_tf_test.py
@@ -23,7 +23,8 @@
from pyiree.compiler2.tf import *
if not is_available():
- print(f"Skipping test {__file__} because TensorFlow is not installed")
+ print(f"Skipping test {__file__} because the IREE TensorFlow compiler "
+ f"is not installed")
sys.exit(0)
import tensorflow as tf
diff --git a/build_tools/cmake/bazel.bat.in b/build_tools/cmake/bazel.bat.in
new file mode 100644
index 0000000..2d2bfb2
--- /dev/null
+++ b/build_tools/cmake/bazel.bat.in
@@ -0,0 +1,3 @@
+@echo off
+cd /d "@_bazel_src_root@"
+@IREE_BAZEL_EXECUTABLE@ @_bazel_startup_options@ %* || exit /b
diff --git a/build_tools/cmake/bazel.sh.in b/build_tools/cmake/bazel.sh.in
new file mode 100644
index 0000000..65385e2
--- /dev/null
+++ b/build_tools/cmake/bazel.sh.in
@@ -0,0 +1,3 @@
+#!/bin/bash
+cd "@_bazel_src_root@"
+exec '@IREE_BAZEL_EXECUTABLE@' @_bazel_startup_options@ "$@"
diff --git a/build_tools/cmake/configure_bazel.cmake b/build_tools/cmake/configure_bazel.cmake
new file mode 100644
index 0000000..528d244
--- /dev/null
+++ b/build_tools/cmake/configure_bazel.cmake
@@ -0,0 +1,158 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set(IREE_BAZEL_EXECUTABLE "bazel"
+ CACHE STRING "Bazel executable to use for bazel builds")
+
+# iree_configure_bazel
+#
+# Configures the CMake binary directory to also contain a bazel build root.
+# The following files will be created:
+# bazel (shell script): Shell wrapper to invoke bazel
+# bazel.bat: Windows batch file to invoke bazel
+# bazelrc: The bazelrc to use for the build
+# bazel-out/: Bazel output directory
+# bazel-bin/: Symlink to the bin directory appropriate for the build mode
+#
+# Variables will be set in the parent scope:
+# IREE_BAZEL_WRAPPER: Executable wrapper to invoke to run bazel
+# IREE_BAZEL_BIN: Path to the bazel-bin directory
+function(iree_configure_bazel)
+ set(_bazel_output_base "${CMAKE_BINARY_DIR}/bazel-out")
+ set(_bazel_src_root "${CMAKE_SOURCE_DIR}")
+
+ # Use the utility to emit _bazelrc_file configuration options.
+ set(_bazelrc_file "${CMAKE_BINARY_DIR}/bazelrc")
+ execute_process(
+ RESULT_VARIABLE RC
+ COMMAND
+ "${Python3_EXECUTABLE}"
+ "${_bazel_src_root}/configure_bazel.py"
+ "${_bazelrc_file}"
+ )
+ if(NOT RC EQUAL 0)
+ message(FATAL_ERROR "Error running ${_bazel_src_root}/configure_bazel.py script")
+ endif()
+
+ # Now add an import to the configured.bazelrc to load the project-wide
+ # bazelrc file.
+ file(APPEND "${_bazelrc_file}" "
+import ${_bazel_src_root}/build_tools/bazel/iree.bazelrc
+")
+
+ # Note that we do allow a .bazelrc in the home directory (otherwise we
+ # would have --nohome_rc). This is mainly about disabling interference from
+ # interactive builds in the workspace.
+ set(_bazel_startup_options "--nosystem_rc --noworkspace_rc '--bazelrc=${_bazelrc_file}' '--output_base=${_bazel_output_base}'")
+
+ # And emit scripts to delegate to bazel.
+ set(IREE_BAZEL_WRAPPER "${CMAKE_BINARY_DIR}/bazel")
+ configure_file(
+ "${CMAKE_CURRENT_SOURCE_DIR}/build_tools/cmake/bazel.sh.in"
+ "${IREE_BAZEL_WRAPPER}"
+ )
+ configure_file(
+ "${CMAKE_CURRENT_SOURCE_DIR}/build_tools/cmake/bazel.bat.in"
+ "${IREE_BAZEL_WRAPPER}.bat"
+ )
+ if(NOT WIN32)
+ execute_process(
+ COMMAND chmod a+x "${IREE_BAZEL_WRAPPER}"
+ )
+ endif()
+
+ # Now ready to start bazel and ask it things.
+ message(STATUS "Detecting bazel version...")
+ execute_process(
+ RESULT_VARIABLE RC
+ OUTPUT_VARIABLE BAZEL_RELEASE
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ COMMAND
+ "${IREE_BAZEL_WRAPPER}" info release
+ )
+ if(NOT RC EQUAL 0)
+ message(FATAL_ERROR "Failed to launch bazel using wrapper ${IREE_BAZEL_WRAPPER}. Inspect that script and ensure bazel is installed properly.")
+ endif()
+ execute_process(
+ RESULT_VARIABLE RC
+ OUTPUT_VARIABLE IREE_BAZEL_BIN
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ COMMAND
+ "${IREE_BAZEL_WRAPPER}" info bazel-bin
+ )
+ if(NOT RC EQUAL 0)
+ message(FATAL_ERROR "Failed to run 'info bazel-bin' via ${IREE_BAZEL_WRAPPER}. Inspect that script and ensure bazel is installed properly.")
+ endif()
+ message(STATUS "Found bazel ${BAZEL_RELEASE}, bin directory: ${IREE_BAZEL_BIN}")
+ message(STATUS "Bazel wrapper script generated at: ${IREE_BAZEL_WRAPPER}")
+
+ # Build automation will use the IREE_BAZEL_BIN variable, but also drop a
+ # convenience symlink, since that is what people expect.
+ # And since bazel isn't nice enough to create it...
+ if(NOT WIN32)
+ execute_process(
+ RESULT_VARIABLE RC
+ COMMAND
+ ln -sf "${IREE_BAZEL_BIN}" "${CMAKE_CURRENT_BINARY_DIR}/bazel-bin"
+ )
+ if(NOT RC EQUAL 0)
+ message(WARNING "Failed to create convenience bazel-bin symlink")
+ endif()
+ endif()
+
+ set(IREE_BAZEL_WRAPPER "${IREE_BAZEL_WRAPPER}" PARENT_SCOPE)
+ set(IREE_BAZEL_BIN "${IREE_BAZEL_BIN}" PARENT_SCOPE)
+endfunction()
+
+# iree_add_bazel_invocation
+#
+# Adds a target to perform a bazel invocation, building a list of targets
+# and exporting pseudo targets for some results of the build.
+#
+# Parameters:
+# INVOCATION_TARGET: The target name for the custom invocation target.
+# BAZEL_TARGETS: List of bazel targets to build.
+# EXECUTABLE_PATHS: Paths under bazel-bin for executables. An equivalent
+# CMake imported executable target will be created for each by replacing
+# the "/" with "_".
+function(iree_add_bazel_invocation)
+ cmake_parse_arguments(ARG
+ ""
+ "INVOCATION_TARGET"
+ "BAZEL_TARGETS;EXECUTABLE_PATHS"
+ ${ARGN}
+ )
+
+ add_custom_target(${ARG_INVOCATION_TARGET}
+ USES_TERMINAL
+ COMMAND ${CMAKE_COMMAND} -E echo
+ "Starting bazel build of targets ${ARG_BAZEL_TARGETS}"
+ COMMAND "${IREE_BAZEL_WRAPPER}" build ${ARG_BAZEL_TARGETS}
+ COMMAND ${CMAKE_COMMAND} -E echo "Bazel build complete."
+ )
+
+ # Create an imported executable target for each binary path.
+ # Since the bazel directory namespace lines up with the cmake namespace,
+ # generate a cmake target name for each.
+ foreach(_executable_path ${ARG_EXECUTABLE_PATHS})
+ string(REPLACE "/" "_" _executable_target "${_executable_path}")
+ message(STATUS "Add bazel executable target ${_executable_target}")
+ add_executable(${_executable_target} IMPORTED GLOBAL)
+ set_target_properties(${_executable_target}
+ PROPERTIES IMPORTED_LOCATION
+ "${IREE_BAZEL_BIN}/${_executable_path}${CMAKE_EXECUTABLE_SUFFIX}"
+ )
+ add_dependencies(${_executable_target} ${ARG_INVOCATION_TARGET})
+ endforeach()
+endfunction()
diff --git a/build_tools/cmake/iree_cross_compile.cmake b/build_tools/cmake/iree_cross_compile.cmake
index f749f90..4433eff 100644
--- a/build_tools/cmake/iree_cross_compile.cmake
+++ b/build_tools/cmake/iree_cross_compile.cmake
@@ -87,6 +87,7 @@
iree_to_bool(_CONFIG_BUILD_PYTHON_BINDINGS "${IREE_${CONFIG_NAME}_BUILD_PYTHON_BINDINGS}")
iree_to_bool(_CONFIG_BUILD_JAVA_BINDINGS "${IREE_${CONFIG_NAME}_BUILD_JAVA_BINDINGS}")
iree_to_bool(_CONFIG_BUILD_EXPERIMENTAL "${IREE_${CONFIG_NAME}_BUILD_EXPERIMENTAL}")
+ iree_to_bool(_CONFIG_BUILD_TENSORFLOW_COMPILER "${IREE_${CONFIG_NAME}_BUILD_TENSORFLOW_COMPILER")
# Escape semicolons in the targets list so that CMake doesn't expand them to
# spaces.
@@ -119,6 +120,7 @@
-DIREE_BUILD_PYTHON_BINDINGS=${_CONFIG_BUILD_PYTHON_BINDINGS}
-DIREE_BUILD_JAVA_BINDINGS=${_CONFIG_BUILD_JAVA_BINDINGS}
-DIREE_BUILD_EXPERIMENTAL=${_CONFIG_BUILD_EXPERIMENTAL}
+ -DIREE_BUILD_TENSORFLOW_COMPILER=${_CONFIG_BUILD_TENSORFLOW_COMPILER}
# LINT.ThenChange(
# https://github.com/google/iree/tree/main/CMakeLists.txt:iree_options,
# https://github.com/google/iree/tree/main/build_tools/cmake/iree_cross_compile.cmake:iree_cross_compile_options,
diff --git a/build_tools/cmake/iree_macros.cmake b/build_tools/cmake/iree_macros.cmake
index 04466b5..8f4e5d2 100644
--- a/build_tools/cmake/iree_macros.cmake
+++ b/build_tools/cmake/iree_macros.cmake
@@ -265,6 +265,49 @@
endfunction()
#-------------------------------------------------------------------------------
+# Tool symlinks
+#-------------------------------------------------------------------------------
+
+# iree_symlink_tool
+#
+# Adds a command to TARGET which symlinks a tool from elsewhere
+# (FROM_TOOL_TARGET_NAME) to a local file name (TO_EXE_NAME) in the current
+# binary directory.
+#
+# Parameters:
+# TARGET: Local target to which to add the symlink command (i.e. an
+# iree_py_library, etc).
+# FROM_TOOL_TARGET: Target of the tool executable that is the source of the
+# link.
+# TO_EXE_NAME: The executable name to output in the current binary dir.
+function(iree_symlink_tool)
+ cmake_parse_arguments(
+ ARG
+ ""
+ "TARGET;FROM_TOOL_TARGET;TO_EXE_NAME"
+ ""
+ ${ARGN}
+ )
+
+ # Transform TARGET
+ iree_package_ns(_PACKAGE_NS)
+ iree_package_name(_PACKAGE_NAME)
+ set(_TARGET "${_PACKAGE_NAME}_${ARG_TARGET}")
+ set(_FROM_TOOL_TARGET ${ARG_FROM_TOOL_TARGET})
+
+ add_custom_command(
+ TARGET "${_TARGET}"
+ BYPRODUCTS
+ "${CMAKE_CURRENT_BINARY_DIR}/${ARG_TO_EXE_NAME}${CMAKE_EXECUTABLE_SUFFIX}"
+ COMMAND
+ ${CMAKE_COMMAND} -E create_symlink
+ "$<TARGET_FILE:${_FROM_TOOL_TARGET}>"
+ "${CMAKE_CURRENT_BINARY_DIR}/${ARG_TO_EXE_NAME}${CMAKE_EXECUTABLE_SUFFIX}"
+ )
+endfunction()
+
+
+#-------------------------------------------------------------------------------
# Tests
#-------------------------------------------------------------------------------
diff --git a/build_tools/cmake/iree_multipy.cmake b/build_tools/cmake/iree_multipy.cmake
index 13510d4..3456fad 100644
--- a/build_tools/cmake/iree_multipy.cmake
+++ b/build_tools/cmake/iree_multipy.cmake
@@ -23,12 +23,20 @@
# Note that this is using the pybind11 configuration vars, which creates
# a fragile dependency. It would be better to derive these locally.
if(Python3_FOUND)
- set(IREE_MULTIPY_DEFAULT_EXECUTABLE "${PYTHON_EXECUTABLE}" CACHE INTERNAL "Python executable" )
- set(IREE_MULTIPY_DEFAULT_INCLUDE_DIRS "${PYTHON_INCLUDE_DIRS}" CACHE INTERNAL "Python include dirs" )
- set(IREE_MULTIPY_DEFAULT_LIBRARIES "${PYTHON_LIBRARIES}" CACHE INTERNAL "Python libraries")
- set(IREE_MULTIPY_DEFAULT_PREFIX "${PYTHON_MODULE_PREFIX}" CACHE INTERNAL "Python module prefix")
- set(IREE_MULTIPY_DEFAULT_SUFFIX "${PYTHON_MODULE_SUFFIX}" CACHE INTERNAL "Python module suffix")
- set(IREE_MULTIPY_DEFAULT_EXTENSION "${PYTHON_MODULE_EXTENSION}" CACHE INTERNAL "Python module extension")
+ set(IREE_MULTIPY_DEFAULT_EXECUTABLE "${Python3_EXECUTABLE}" CACHE INTERNAL "Python executable" )
+ set(IREE_MULTIPY_DEFAULT_INCLUDE_DIRS "${Python3_INCLUDE_DIRS}" CACHE INTERNAL "Python include dirs" )
+ set(IREE_MULTIPY_DEFAULT_LIBRARIES "${Python3_LIBRARIES}" CACHE INTERNAL "Python libraries")
+ set(IREE_MULTIPY_DEFAULT_PREFIX "${Python3_MODULE_PREFIX}" CACHE INTERNAL "Python module prefix")
+ set(IREE_MULTIPY_DEFAULT_SUFFIX "${Python3_MODULE_SUFFIX}" CACHE INTERNAL "Python module suffix")
+ # CMake 3.19 and there-abouts does define Python3_SOABI, but get it
+ # ourselves for compatibility.
+ execute_process(
+ OUTPUT_VARIABLE _FOUND_DEFAULT_EXTENSION
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ COMMAND
+ "${Python3_EXECUTABLE}" -c "import sysconfig;print(sysconfig.get_config_var('EXT_SUFFIX'))"
+ )
+ set(IREE_MULTIPY_DEFAULT_EXTENSION "${_FOUND_DEFAULT_EXTENSION}" CACHE INTERNAL "Python module extension")
endif()
if(IREE_MULTIPY_VERSIONS)
@@ -51,13 +59,13 @@
# Check for required settings.
if(NOT IREE_MULTIPY_${V}_INCLUDE_DIRS)
- message(FATAL " MULTIPY version ${V}: No IREE_MULTIPY_${VER}_EXECUTABLE var")
+ message(FATAL_ERROR " MULTIPY version ${V}: No IREE_MULTIPY_${VER}_EXECUTABLE var")
endif()
if(NOT IREE_MULTIPY_${V}_INCLUDE_DIRS)
- message(FATAL " MULTIPY version ${V}: No IREE_MULTIPY_${VER}_INCLUDE_DIRS var")
+ message(FATAL_ERROR " MULTIPY version ${V}: No IREE_MULTIPY_${VER}_INCLUDE_DIRS var")
endif()
if(NOT IREE_MULTIPY_${V}_EXTENSION)
- message(FATAL " MULTIPY version ${V}: No IREE_MULTIPY_${VER}_EXTENSION var")
+ message(FATAL_ERROR " MULTIPY version ${V}: No IREE_MULTIPY_${VER}_EXTENSION var")
endif()
endforeach()
endfunction()
diff --git a/configure_bazel.py b/configure_bazel.py
index f0bac93..18be4a4 100644
--- a/configure_bazel.py
+++ b/configure_bazel.py
@@ -49,7 +49,7 @@
user_site = subprocess.check_output(
[sys.executable, "-m", "site", "--user-site"]).decode("utf-8").strip()
print("Found user site directory:", user_site)
- except OSError:
+ except subprocess.CalledProcessError:
print("Could not resolve user site directory")
return
print("build --action_env PYTHONPATH=\"{}\"".format(
@@ -57,7 +57,10 @@
file=bazelrc)
-local_bazelrc = os.path.join(os.path.dirname(__file__), "configured.bazelrc")
+if len(sys.argv) > 1:
+ local_bazelrc = sys.argv[1]
+else:
+ local_bazelrc = os.path.join(os.path.dirname(__file__), "configured.bazelrc")
with open(local_bazelrc, "wt") as bazelrc:
write_platform(bazelrc)
write_python_bin(bazelrc)
diff --git a/integrations/tensorflow/CMakeLists.txt b/integrations/tensorflow/CMakeLists.txt
new file mode 100644
index 0000000..6194ee3
--- /dev/null
+++ b/integrations/tensorflow/CMakeLists.txt
@@ -0,0 +1,36 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# TensorFlow builds through bazel, and IREE maintains all of its TensorFlow
+# dependent code under this directory tree. The CMake support is limited to
+# compiler binaries and python bindings.
+#
+# Bazel is a beast that likes to be the center of the universe. There is some
+# fragility in delegating to it in this fashion.
+#
+# If this directory is included, then building TensorFlow is assumed (the
+# config option happens at the higher level).
+
+iree_add_bazel_invocation(
+ INVOCATION_TARGET
+ integrations_iree_tensorflow_importers
+ BAZEL_TARGETS
+ //integrations/tensorflow/compiler:iree-tf-import
+ EXECUTABLE_PATHS
+ integrations/tensorflow/compiler/iree-tf-import
+)
+
+if(${IREE_BUILD_PYTHON_BINDINGS})
+ add_subdirectory(bindings/python)
+endif()
diff --git a/integrations/tensorflow/bindings/python/CMakeLists.txt b/integrations/tensorflow/bindings/python/CMakeLists.txt
new file mode 100644
index 0000000..31b61a2
--- /dev/null
+++ b/integrations/tensorflow/bindings/python/CMakeLists.txt
@@ -0,0 +1,22 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Overlays a subdirectory into the main python bindings directory.
+function(_add_overlay_subdirectory dir)
+ # Overlay binary directories onto the main bindings directory.
+ set(_MAIN_PYTHON_DIR "${CMAKE_BINARY_DIR}/bindings/python")
+ add_subdirectory(${dir} "${_MAIN_PYTHON_DIR}/${dir}")
+endfunction()
+
+_add_overlay_subdirectory(pyiree/tools/tf)
diff --git a/integrations/tensorflow/bindings/python/pyiree/tools/tf/.skip_bazel_to_cmake b/integrations/tensorflow/bindings/python/pyiree/tools/tf/.skip_bazel_to_cmake
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/integrations/tensorflow/bindings/python/pyiree/tools/tf/.skip_bazel_to_cmake
diff --git a/integrations/tensorflow/bindings/python/pyiree/tools/tf/CMakeLists.txt b/integrations/tensorflow/bindings/python/pyiree/tools/tf/CMakeLists.txt
new file mode 100644
index 0000000..a10869b
--- /dev/null
+++ b/integrations/tensorflow/bindings/python/pyiree/tools/tf/CMakeLists.txt
@@ -0,0 +1,28 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+iree_py_library(
+ NAME
+ tf
+ SRCS
+ "__init__.py"
+ DEPS
+ integrations_iree_tensorflow_importers
+)
+
+iree_symlink_tool(
+ TARGET tf
+ FROM_TOOL_TARGET integrations_tensorflow_compiler_iree-tf-import
+ TO_EXE_NAME iree-tf-import
+)
diff --git a/bindings/python/pyiree/tools/tf/__init__.py b/integrations/tensorflow/bindings/python/pyiree/tools/tf/__init__.py
similarity index 100%
rename from bindings/python/pyiree/tools/tf/__init__.py
rename to integrations/tensorflow/bindings/python/pyiree/tools/tf/__init__.py
diff --git a/iree/tools/run_lit.sh b/iree/tools/run_lit.sh
index 704c7cc..78cbf66 100755
--- a/iree/tools/run_lit.sh
+++ b/iree/tools/run_lit.sh
@@ -17,9 +17,16 @@
set -o pipefail
if [ -z "${RUNFILES_DIR}" ]; then
- # Some versions of bazel do not set RUNFILES_DIR. Instead they just cd
- # into the directory.
- RUNFILES_DIR="$PWD"
+ if [ -f "CMakeCache.txt" ]; then
+ # If running under CMake/CTest in the build directory, just scope to the
+ # iree directory to avoid blowing up the search through things like
+ # bazel out directories and the like.
+ RUNFILES_DIR="$PWD/iree"
+ else
+ # Some versions of bazel do not set RUNFILES_DIR. Instead they just cd
+ # into the directory.
+ RUNFILES_DIR="$PWD"
+ fi
fi
# Detect whether cygwin/msys2 paths need to be translated.