Merge pull request #2258 from phoenix-meadowlark:e2e-coverage
PiperOrigin-RevId: 318460243
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 501cd0a..004bed5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -33,6 +33,7 @@
# Project component configuration
#-------------------------------------------------------------------------------
+# LINT.IfChange(iree_options)
option(IREE_ENABLE_RUNTIME_TRACING "Enables instrumented runtime tracing." OFF)
option(IREE_ENABLE_MLIR "Enables MLIR/LLVM dependencies." ON)
option(IREE_ENABLE_EMITC "Enables MLIR EmitC dependencies." OFF)
@@ -50,6 +51,10 @@
CACHE STRING "Semicolon-separated list of HAL drivers to build, or \"all\"." FORCE)
set(IREE_TARGET_BACKENDS_TO_BUILD "all"
CACHE STRING "Semicolon-separated list of target backends to build, or \"all\"." FORCE)
+# LINT.ThenChange(
+# https://github.com/google/iree/tree/master/build_tools/cmake/iree_cross_compile.cmake:iree_cross_compile_options,
+# https://github.com/google/iree/tree/master/build_tools/cmake/iree_cross_compile.cmake:iree_cross_compile_invoke
+# )
if(${IREE_BUILD_SAMPLES} OR ${IREE_BUILD_EXPERIMENTAL})
set(IREE_BUILD_COMPILER ON CACHE BOOL "Build the IREE compiler for sample projects." FORCE)
@@ -136,6 +141,44 @@
)
#-------------------------------------------------------------------------------
+# Cross compiling configuration
+#-------------------------------------------------------------------------------
+
+if(CMAKE_CROSSCOMPILING)
+ if(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
+ message(FATAL_ERROR "Cross compilation with Windows host system is not supported yet")
+ endif()
+
+ message(STATUS "Detected cross compilation mode; configuring IREE on host...")
+
+ # C/C++ compilers for host compilation.
+ # Note: we need to explicitly set this because IREE does not work well with
+ # GCC at the moment: https://github.com/google/iree/issues/1269
+ set(IREE_HOST_C_COMPILER "$ENV{IREE_HOST_C_COMPILER}" CACHE FILEPATH "C compiler for host compilation")
+ set(IREE_HOST_CXX_COMPILER "$ENV{IREE_HOST_CXX_COMPILER}" CACHE FILEPATH "C++ compiler for host compilation")
+
+ # Master configuration for the binary directory containing all artifacts
+ # compiled for host.
+ if(NOT IREE_HOST_BINARY_ROOT)
+ set(IREE_HOST_BINARY_ROOT "${CMAKE_CURRENT_BINARY_DIR}/host" CACHE FILEPATH "directory containing host artifacts")
+ endif()
+
+ set(IREE_HOST_BUILD_COMPILER ON) # For iree-translate
+ set(IREE_HOST_ENABLE_LLVM ON) # For iree-tblgen
+
+ # Set the host build directory for LLVM to our directory. Otherwise it will
+ # follow its own convention.
+ set(LLVM_NATIVE_BUILD "${IREE_HOST_BINARY_ROOT}/third_party/llvm-project/llvm")
+
+ include(iree_cross_compile)
+
+ # Use another CMake invocation to configure a build for host.
+ iree_create_configuration(HOST)
+
+ message(STATUS "Done configuring IREE on host in ${IREE_HOST_BINARY_ROOT}")
+endif()
+
+#-------------------------------------------------------------------------------
# IREE utility definitions
#-------------------------------------------------------------------------------
@@ -291,6 +334,24 @@
add_subdirectory(build_tools/third_party/renderdoc_api EXCLUDE_FROM_ALL)
add_subdirectory(build_tools/third_party/vulkan_extensionlayer EXCLUDE_FROM_ALL)
+if(CMAKE_CROSSCOMPILING)
+ # We need flatc to generate some source code. When cross-compiling, we need
+ # to make sure the flatc binary is configured under host environment.
+ iree_declare_host_excutable(flatc BUILDONLY)
+
+ # Set the FLATBUFFERS_FLATC_EXECUTABLE. It controls where to find the flatc
+ # binary in BuildFlatBuffers().
+ iree_get_executable_path(FLATBUFFERS_FLATC_EXECUTABLE flatc)
+
+ # Add a custom target to copy the flatc to the binary directory.
+ add_custom_target(iree_host_flatc
+ COMMAND "${CMAKE_COMMAND}" -E copy_if_different
+ "${IREE_HOST_BINARY_ROOT}/third_party/flatbuffers/flatc" "${IREE_HOST_BINARY_ROOT}/bin"
+ DEPENDS iree_host_build_flatc
+ COMMENT "Installing host flatc..."
+ )
+endif()
+
if(${IREE_BUILD_COMPILER})
add_subdirectory(build_tools/third_party/tensorflow/tensorflow/compiler/mlir/xla EXCLUDE_FROM_ALL)
endif()
diff --git a/SUBMODULE_VERSIONS b/SUBMODULE_VERSIONS
index fcc70e7..5060a5b 100644
--- a/SUBMODULE_VERSIONS
+++ b/SUBMODULE_VERSIONS
@@ -3,7 +3,7 @@
4c13807b7d43ff0946b7ffea0ae3aee9e611d778 third_party/dear_imgui
a5d9d0f7d368054fd1691aedf1db4116efcc233e third_party/flatbuffers
f2fb48c3b3d79a75a88a99fba6576b25d42ec528 third_party/googletest
-1c0bbe4341ac0ffbaf2e1f482239b45166607f2d third_party/llvm-project
+d45cf9105b5a88ed03382ffbbfcd54b461f1bb23 third_party/llvm-project
17b12a4481daa150e2d1ea3ada086b551b856707 third_party/marl
67f3ccebee84f3488b46a8d3ac005178c52ff264 third_party/mlir-emitc
80d452484c5409444b0ec19383faa84bb7a4d351 third_party/pybind11
@@ -11,7 +11,7 @@
b73f111094da3e380a1774b56b15f16c90ae8e23 third_party/sdl2
f8bf11a0253a32375c32cad92c841237b96696c0 third_party/spirv_headers
57eb48aed36160c4876bc8310d9ca84d42ee9e2a third_party/swiftshader
-2c4a0140f62e021bb596c11a3b306eb94e481d85 third_party/tensorflow
+f74654ac7b314a212b1df6687c2f99800084e97f third_party/tensorflow
864d86e8b6d21449474db5e9313dbff90aa9c24f third_party/tracy
8a457f8552d8d47ce3a96ed80a714ff6396f8ad8 third_party/vulkan_extensionlayer
9bd3f561bcee3f01d22912de10bb07ce4e23d378 third_party/vulkan_headers
diff --git a/build_tools/cmake/flatbuffer_cc_library.cmake b/build_tools/cmake/flatbuffer_cc_library.cmake
index 6ad2995..febf234 100644
--- a/build_tools/cmake/flatbuffer_cc_library.cmake
+++ b/build_tools/cmake/flatbuffer_cc_library.cmake
@@ -95,18 +95,24 @@
set(FLATBUFFERS_FLATC_SCHEMA_EXTRA_ARGS ${_RULE_FLATC_ARGS})
endif()
+ set(_GEN_TARGET "${_NAME}_gen")
+
build_flatbuffers(
"${_RULE_SRCS}"
"${IREE_ROOT_DIR}"
- "${_NAME}_gen" # custom_target_name
- "${_RULE_DEPS}" # additional_dependencies
+ "${_GEN_TARGET}" # custom_target_name
+ "${_RULE_DEPS}" # additional_dependencies
"${CMAKE_CURRENT_BINARY_DIR}" # generated_include_dir
"${CMAKE_CURRENT_BINARY_DIR}" # binary_schemas_dir
"" # copy_text_schemas_dir
)
+ # Add dependency on flatc explicitly. This is needed for cross-compiling
+ # where flatc comes from another CMake invocation for host.
+ iree_add_executable_dependencies(${_GEN_TARGET} flatc)
+
add_library(${_NAME} INTERFACE)
- add_dependencies(${_NAME} ${_NAME}_gen)
+ add_dependencies(${_NAME} ${_GEN_TARGET})
target_include_directories(${_NAME}
INTERFACE
"$<BUILD_INTERFACE:${IREE_COMMON_INCLUDE_DIRS}>"
diff --git a/build_tools/cmake/iree_bytecode_module.cmake b/build_tools/cmake/iree_bytecode_module.cmake
index f8002ec..64f8fd0 100644
--- a/build_tools/cmake/iree_bytecode_module.cmake
+++ b/build_tools/cmake/iree_bytecode_module.cmake
@@ -56,23 +56,24 @@
if(DEFINED _RULE_TRANSLATE_TOOL)
set(_TRANSLATE_TOOL ${_RULE_TRANSLATE_TOOL})
else()
- set(_TRANSLATE_TOOL "iree_tools_iree-translate")
+ set(_TRANSLATE_TOOL "iree-translate")
endif()
- # Resolve the executable binary path from the target name.
- set(_TRANSLATE_TOOL_EXECUTABLE $<TARGET_FILE:${_TRANSLATE_TOOL}>)
+ iree_get_executable_path(_TRANSLATE_TOOL_EXECUTABLE ${_TRANSLATE_TOOL})
set(_ARGS "${_FLAGS}")
list(APPEND _ARGS "${CMAKE_CURRENT_SOURCE_DIR}/${_RULE_SRC}")
list(APPEND _ARGS "-o")
list(APPEND _ARGS "${_RULE_NAME}.module")
+ # Depending on the binary instead of the target here given we might not have
+ # a target in this CMake invocation when cross-compiling.
add_custom_command(
OUTPUT "${_RULE_NAME}.module"
COMMAND ${_TRANSLATE_TOOL_EXECUTABLE} ${_ARGS}
# Changes to either the translation tool or the input source should
# trigger rebuilding.
- DEPENDS ${_TRANSLATE_TOOL} ${_RULE_SRC}
+ DEPENDS ${_TRANSLATE_TOOL_EXECUTABLE} ${_RULE_SRC}
)
if(_RULE_TESTONLY)
diff --git a/build_tools/cmake/iree_cc_binary.cmake b/build_tools/cmake/iree_cc_binary.cmake
index b4d6eff..6b3653a 100644
--- a/build_tools/cmake/iree_cc_binary.cmake
+++ b/build_tools/cmake/iree_cc_binary.cmake
@@ -30,6 +30,8 @@
# COPTS: List of private compile options
# DEFINES: List of public defines
# LINKOPTS: List of link options
+# TESTONLY: for testing; won't compile when tests are disabled
+# HOSTONLY: host only; compile using host toolchain when cross-compiling
#
# Note:
# By default, iree_cc_binary will always create a binary named iree_${NAME}.
@@ -58,7 +60,7 @@
function(iree_cc_binary)
cmake_parse_arguments(
_RULE
- "TESTONLY"
+ "HOSTONLY;TESTONLY"
"NAME;OUT"
"SRCS;COPTS;DEFINES;LINKOPTS;DATA;DEPS"
${ARGN}
@@ -68,6 +70,14 @@
return()
endif()
+ if(_RULE_HOSTONLY AND CMAKE_CROSSCOMPILING)
+ # The binary is marked as host only. We need to declare the rules for
+ # generating them under host configuration so cross-compiling towards
+ # target we can still have this binary.
+ iree_declare_host_excutable(${_RULE_NAME})
+ return()
+ endif()
+
# Prefix the library with the package name, so we get: iree_package_name
iree_package_name(_PACKAGE_NAME)
set(_NAME "${_PACKAGE_NAME}_${_RULE_NAME}")
@@ -126,6 +136,11 @@
# Track target and deps, use in iree_complete_binary_link_options() later.
set_property(GLOBAL APPEND PROPERTY _IREE_CC_BINARY_NAMES "${_NAME}")
set_property(TARGET ${_NAME} PROPERTY DIRECT_DEPS ${_RULE_DEPS})
+
+ install(TARGETS ${_NAME}
+ RENAME ${_RULE_NAME}
+ COMPONENT ${_RULE_NAME}
+ RUNTIME DESTINATION bin)
endfunction()
# Lists all transitive dependencies of DIRECT_DEPS in TRANSITIVE_DEPS.
diff --git a/build_tools/cmake/iree_cc_embed_data.cmake b/build_tools/cmake/iree_cc_embed_data.cmake
index d3644ed..7eeac23 100644
--- a/build_tools/cmake/iree_cc_embed_data.cmake
+++ b/build_tools/cmake/iree_cc_embed_data.cmake
@@ -79,10 +79,12 @@
list(APPEND _ARGS "${SRC}")
endforeach(SRC)
+ iree_get_executable_path(_EXE_PATH generate_cc_embed_data)
+
add_custom_command(
OUTPUT "${_RULE_H_FILE_OUTPUT}" "${_RULE_CC_FILE_OUTPUT}"
- COMMAND generate_cc_embed_data ${_ARGS}
- DEPENDS generate_cc_embed_data ${_RULE_SRCS} ${_RULE_GENERATED_SRCS}
+ COMMAND ${_EXE_PATH} ${_ARGS}
+ DEPENDS ${_EXE_PATH} ${_RULE_SRCS} ${_RULE_GENERATED_SRCS}
)
if(_RULE_TESTONLY)
diff --git a/build_tools/cmake/iree_copts.cmake b/build_tools/cmake/iree_copts.cmake
index 1bd8584..542536b 100644
--- a/build_tools/cmake/iree_copts.cmake
+++ b/build_tools/cmake/iree_copts.cmake
@@ -12,8 +12,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+#-------------------------------------------------------------------------------
+# Abseil configuration
+#-------------------------------------------------------------------------------
+
include(AbseilConfigureCopts)
+# By default Abseil strips string literals on mobile platforms, which means
+# we cannot run IREE binaries via command-line with proper options. Turn off
+# the stripping.
+# TODO: we might still want to strip when compiling IREE into Android Java apps.
+if(CMAKE_CROSSCOMPILING AND "${CMAKE_SYSTEM_NAME}" MATCHES "Android")
+ add_definitions(-DABSL_FLAGS_STRIP_NAMES=0)
+endif()
+
#-------------------------------------------------------------------------------
# C++ used within IREE
#-------------------------------------------------------------------------------
@@ -92,13 +104,19 @@
#-------------------------------------------------------------------------------
set(FLATBUFFERS_BUILD_TESTS OFF CACHE BOOL "" FORCE)
-set(FLATBUFFERS_INSTALL OFF CACHE BOOL "" FORCE)
-set(FLATBUFFERS_BUILD_FLATC ON CACHE BOOL "" FORCE)
set(FLATBUFFERS_BUILD_FLATHASH OFF CACHE BOOL "" FORCE)
set(FLATBUFFERS_BUILD_GRPCTEST OFF CACHE BOOL "" FORCE)
+set(FLATBUFFERS_INSTALL OFF CACHE BOOL "" FORCE)
set(FLATBUFFERS_INCLUDE_DIRS
"${PROJECT_SOURCE_DIR}/third_party/flatbuffers/include/"
)
+
+if(CMAKE_CROSSCOMPILING)
+ set(FLATBUFFERS_BUILD_FLATC OFF CACHE BOOL "" FORCE)
+else()
+ set(FLATBUFFERS_BUILD_FLATC ON CACHE BOOL "" FORCE)
+endif()
+
iree_select_compiler_opts(FLATBUFFERS_COPTS
CLANG
# Flatbuffers has a bunch of incorrect documentation annotations.
@@ -151,7 +169,9 @@
endif()
set(MLIR_TABLEGEN_EXE mlir-tblgen)
-set(IREE_TABLEGEN_EXE iree-tblgen)
+# iree-tblgen is not defined using the add_tablegen mechanism as other TableGen
+# tools in LLVM.
+iree_get_executable_path(IREE_TABLEGEN_EXE iree-tblgen)
#-------------------------------------------------------------------------------
# Third party: tensorflow
diff --git a/build_tools/cmake/iree_cross_compile.cmake b/build_tools/cmake/iree_cross_compile.cmake
new file mode 100644
index 0000000..2568abd
--- /dev/null
+++ b/build_tools/cmake/iree_cross_compile.cmake
@@ -0,0 +1,234 @@
+# 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.
+
+include(iree_macros)
+
+# iree_create_configuration
+#
+# Creates custom commands and targets for an IREE configuration. An IREE
+# configuration means a new IREE CMake invocation with its own set of
+# parameters.
+#
+# This function defines a custom target, `iree_configure_${CONFIG_NAME}`,
+# to drive the generation of a new IREE configuration's `CMakeCache.txt`
+# file. Callers can then depend on either the `CMakeCache.txt` file or the
+# `iree_configure_${CONFIG_NAME}` target to make sure the configuration
+# is invoked as a dependency.
+#
+# This function is typically useful when cross-compiling towards another
+# architecture. For example, when cross-compiling towards Android, we need
+# to have certain tools first compiled on the host so that we can use them
+# to programmatically generate some source code to be compiled together
+# with other checked-in source code. Those host tools will be generated
+# by another CMake invocation configured by this function.
+#
+# Supported CMake options:
+# - IREE_<CONFIG_NAME>_BINARY_ROOT: the root directory for containing IREE build
+# artifacts for the given `CONFIG_NAME`. If not specified in caller, this is
+# set to a directory named as `CONFIG_NAME` under the current CMake binary
+# directory.
+# - IREE_<CONFIG_NAME>_C_COMPILER: C compiler for the given `CONFIG_NAME`.
+# This must be defined by the caller.
+# - IREE_<CONFIG_NAME>_CXX_COMPILER: C++ compiler for the given `CONFIG_NAME`.
+# This must be defined by the caller.
+# - IREE_<CONFIG_NAME>_<option>: switch for the given `option` specifically for
+# `CONFIG_NAME`. If missing, default to OFF for bool options; default to
+# IREE_<option> for non-bool variables.
+function(iree_create_configuration CONFIG_NAME)
+ # Set IREE_${CONFIG_NAME}_BINARY_ROOT if missing.
+ if(NOT DEFINED IREE_${CONFIG_NAME}_BINARY_ROOT)
+ set(IREE_${CONFIG_NAME}_BINARY_ROOT "${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}")
+ set(IREE_${CONFIG_NAME}_BINARY_ROOT ${IREE_${CONFIG_NAME}_BINARY_ROOT} PARENT_SCOPE)
+ message(STATUS "Setting ${CONFIG_NAME} build directory to ${IREE_${CONFIG_NAME}_BINARY_ROOT}")
+ endif()
+
+ set(_CONFIG_BINARY_ROOT ${IREE_${CONFIG_NAME}_BINARY_ROOT})
+
+ set(_CONFIG_C_COMPILER ${IREE_${CONFIG_NAME}_C_COMPILER})
+ set(_CONFIG_CXX_COMPILER ${IREE_${CONFIG_NAME}_CXX_COMPILER})
+
+ # Check the compilers are specified in the caller.
+ if("${_CONFIG_C_COMPILER}" STREQUAL "")
+ message(FATAL_ERROR "Must define IREE_${CONFIG_NAME}_C_COMPILER for \"${CONFIG_NAME}\" configuration build")
+ endif()
+ if("${_CONFIG_CXX_COMPILER}" STREQUAL "")
+ message(FATAL_ERROR "Must define IREE_${CONFIG_NAME}_CXX_COMPILER for \"${CONFIG_NAME}\" configuration build")
+ endif()
+
+ add_custom_command(OUTPUT ${_CONFIG_BINARY_ROOT}
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${_CONFIG_BINARY_ROOT}
+ COMMENT "Creating ${_CONFIG_BINARY_ROOT}...")
+
+ # Give it a custom target so we can drive the generation manually
+ # when useful.
+ add_custom_target(iree_prepare_${CONFIG_NAME}_dir DEPENDS ${_CONFIG_BINARY_ROOT})
+
+ # LINT.IfChange(iree_cross_compile_options)
+ iree_to_bool(_CONFIG_ENABLE_RUNTIME_TRACING "${IREE_${CONFIG_NAME}_ENABLE_RUNTIME_TRACING}")
+ iree_to_bool(_CONFIG_ENABLE_MLIR "${IREE_${CONFIG_NAME}_ENABLE_MLIR}")
+ iree_to_bool(_CONFIG_ENABLE_EMITC "${IREE_${CONFIG_NAME}_ENABLE_EMITC}")
+
+ iree_to_bool(_CONFIG_BUILD_COMPILER "${IREE_${CONFIG_NAME}_BUILD_COMPILER}")
+ iree_to_bool(_CONFIG_BUILD_TESTS "${IREE_${CONFIG_NAME}_BUILD_TESTS}")
+ iree_to_bool(_CONFIG_BUILD_DOCS "${IREE_${CONFIG_NAME}_BUILD_DOCS}")
+ iree_to_bool(_CONFIG_BUILD_SAMPLES "${IREE_${CONFIG_NAME}_BUILD_SAMPLES}")
+ iree_to_bool(_CONFIG_BUILD_DEBUGGER "${IREE_${CONFIG_NAME}_BUILD_DEBUGGER}")
+ iree_to_bool(_CONFIG_BUILD_PYTHON_BINDINGS "${IREE_${CONFIG_NAME}_BUILD_PYTHON_BINDINGS}")
+ iree_to_bool(_CONFIG_BUILD_EXPERIMENTAL "${IREE_${CONFIG_NAME}_BUILD_EXPERIMENTAL}")
+
+ # Escape semicolons in the targets list so that CMake doesn't expand them to
+ # spaces.
+ string(REPLACE ";" "$<SEMICOLON>" _CONFIG_HAL_DRIVERS_TO_BUILD "${IREE_HAL_DRIVERS_TO_BUILD}")
+ string(REPLACE ";" "$<SEMICOLON>" _CONFIG_TARGET_BACKENDS_TO_BUILD "${IREE_TARGET_BACKENDS_TO_BUILD}")
+ # LINT.ThenChange(
+ # https://github.com/google/iree/tree/master/CMakeLists.txt:iree_options,
+ # https://github.com/google/iree/tree/master/build_tools/cmake/iree_cross_compile.cmake:iree_cross_compile_invoke
+ # )
+
+ message(STATUS "C compiler for ${CONFIG_NAME} build: ${_CONFIG_C_COMPILER}")
+ message(STATUS "C++ compiler for ${CONFIG_NAME} build: ${_CONFIG_CXX_COMPILER}")
+
+ add_custom_command(OUTPUT ${IREE_${CONFIG_NAME}_BINARY_ROOT}/CMakeCache.txt
+ COMMAND "${CMAKE_COMMAND}" "${PROJECT_SOURCE_DIR}" -G "${CMAKE_GENERATOR}"
+ -DCMAKE_MAKE_PROGRAM="${CMAKE_MAKE_PROGRAM}"
+ -DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}"
+ -DCMAKE_C_COMPILER="${_CONFIG_C_COMPILER}"
+ -DCMAKE_CXX_COMPILER="${_CONFIG_CXX_COMPILER}"
+ # LINT.IfChange(iree_cross_compile_invoke)
+ -DIREE_ENABLE_RUNTIME_TRACING=${_CONFIG_ENABLE_RUNTIME_TRACING}
+ -DIREE_ENABLE_MLIR=${_CONFIG_ENABLE_MLIR}
+ -DIREE_ENABLE_EMITC=${_CONFIG_ENABLE_EMITC}
+ -DIREE_BUILD_COMPILER=${_CONFIG_BUILD_COMPILER}
+ -DIREE_BUILD_TESTS=${_CONFIG_BUILD_TESTS}
+ -DIREE_BUILD_DOCS=${_CONFIG_BUILD_DOCS}
+ -DIREE_BUILD_SAMPLES=${_CONFIG_BUILD_SAMPLES}
+ -DIREE_BUILD_DEBUGGER=${_CONFIG_BUILD_DEBUGGER}
+ -DIREE_BUILD_PYTHON_BINDINGS=${_CONFIG_BUILD_PYTHON_BINDINGS}
+ -DIREE_BUILD_EXPERIMENTAL=${_CONFIG_BUILD_EXPERIMENTAL}
+ # LINT.ThenChange(
+ # https://github.com/google/iree/tree/master/CMakeLists.txt:iree_options,
+ # https://github.com/google/iree/tree/master/build_tools/cmake/iree_cross_compile.cmake:iree_cross_compile_options,
+ # )
+ -DIREE_HAL_DRIVERS_TO_BUILD="${_CONFIG_HAL_DRIVERS_TO_BUILD}"
+ -DIREE_TARGET_BACKENDS_TO_BUILD="${_CONFIG_TARGET_BACKENDS_TO_BUILD}"
+ WORKING_DIRECTORY ${_CONFIG_BINARY_ROOT}
+ DEPENDS iree_prepare_${CONFIG_NAME}_dir
+ COMMENT "Configuring IREE for ${CONFIG_NAME} build...")
+
+ add_custom_target(iree_configure_${CONFIG_NAME} DEPENDS ${_CONFIG_BINARY_ROOT}/CMakeCache.txt)
+endfunction()
+
+# iree_get_build_command
+#
+# Gets the CMake build command for the given `TARGET`.
+#
+# Parameters:
+# TARGET: the target to build.
+# BINDIR: root binary directory containing CMakeCache.txt.
+# CMDVAR: variable name for receiving the build command.
+function(iree_get_build_command TARGET)
+ cmake_parse_arguments(_RULE "" "BINDIR;CMDVAR;CONFIG" "" ${ARGN})
+ if(NOT _RULE_CONFIG)
+ set(_RULE_CONFIG "$<CONFIG>")
+ endif()
+ if (CMAKE_GENERATOR MATCHES "Make")
+ # Use special command for Makefiles to support parallelism.
+ set(${_RULE_CMDVAR}
+ "$(MAKE)" "-C" "${_RULE_BINDIR}" "${TARGET}" PARENT_SCOPE)
+ else()
+ set(${_RULE_CMDVAR}
+ "${CMAKE_COMMAND}" --build ${_RULE_BINDIR}
+ --target ${TARGET}
+ --config ${_RULE_CONFIG} PARENT_SCOPE)
+ endif()
+endfunction()
+
+# iree_host_install
+#
+# Defines custom commands and targets for installing the given `target` under
+# host configuration. The custom target for install will be named as
+# `iree_host_install_${TARGET}`.
+#
+# Precondition:
+# iree_create_configuration(HOST) is invoked previously.
+#
+# Parameters:
+# COMPONENT: installation component; used for filtering installation targets.
+# PREFIX: the root installation path prefix.
+# DEPENDS: addtional dependencies for the installation.
+function(iree_host_install TARGET)
+ cmake_parse_arguments(_RULE "" "TARGET;COMPONENT;PREFIX" "DEPENDS" ${ARGN})
+ if(_RULE_COMPONENT)
+ set(_COMPONENT_OPTION -DCMAKE_INSTALL_COMPONENT="${_RULE_COMPONENT}")
+ endif()
+ if(_RULE_PREFIX)
+ set(_PREFIX_OPTION -DCMAKE_INSTALL_PREFIX="${_RULE_PREFIX}")
+ endif()
+
+ iree_get_executable_path(_OUTPUT_PATH ${TARGET})
+
+ add_custom_command(
+ OUTPUT ${_OUTPUT_PATH}
+ DEPENDS ${_RULE_DEPENDS}
+ COMMAND "${CMAKE_COMMAND}" ${_COMPONENT_OPTION} ${_PREFIX_OPTION}
+ -P "${IREE_HOST_BINARY_ROOT}/cmake_install.cmake"
+ USES_TERMINAL)
+
+ # Give it a custom target so we can drive the generation manually
+ # when useful.
+ add_custom_target(iree_host_install_${TARGET} DEPENDS ${_OUTPUT_PATH})
+endfunction()
+
+# iree_declare_host_excutable
+#
+# Generates custom commands and targets for building and installing a tool on
+# host for cross-compilation.
+#
+# Precondition:
+# iree_create_configuration(HOST) is invoked previously.
+#
+# Parameters:
+# TARGET: the target to build on host.
+# BUILDONLY: only generates commands for building the target.
+# DEPENDS: any additional dependencies for the target.
+function(iree_declare_host_excutable TARGET)
+ cmake_parse_arguments(_RULE "BUILDONLY" "" "DEPENDS" ${ARGN})
+
+ iree_get_executable_path(_OUTPUT_PATH ${TARGET})
+
+ iree_get_build_command(${TARGET}
+ BINDIR ${IREE_HOST_BINARY_ROOT}
+ CMDVAR build_cmd)
+
+ add_custom_target(iree_host_build_${TARGET}
+ COMMAND ${build_cmd}
+ DEPENDS iree_configure_HOST ${_RULE_DEPENDS}
+ WORKING_DIRECTORY "${IREE_HOST_BINARY_ROOT}"
+ COMMENT "Building host ${TARGET}..."
+ USES_TERMINAL)
+
+ if(_RULE_BUILDONLY)
+ return()
+ endif()
+
+ iree_host_install(${TARGET}
+ COMPONENT ${TARGET}
+ PREFIX ${IREE_HOST_BINARY_ROOT}
+ DEPENDS iree_host_build_${TARGET})
+
+ # Note that this is not enabled when BUILDONLY so we can define
+ # iree_host_${TARGET} to point to another installation path to
+ # allow flexibility.
+ add_custom_target(iree_host_${TARGET} DEPENDS "${_OUTPUT_PATH}")
+endfunction()
diff --git a/build_tools/cmake/iree_macros.cmake b/build_tools/cmake/iree_macros.cmake
index 4929146..7b27392 100644
--- a/build_tools/cmake/iree_macros.cmake
+++ b/build_tools/cmake/iree_macros.cmake
@@ -25,6 +25,22 @@
endif()
#-------------------------------------------------------------------------------
+# General utilities
+#-------------------------------------------------------------------------------
+
+# iree_to_bool
+#
+# Sets `variable` to `ON` if `value` is true and `OFF` otherwise.
+function(iree_to_bool VARIABLE VALUE)
+ if(VALUE)
+ set(${VARIABLE} "ON" PARENT_SCOPE)
+ else()
+ set(${VARIABLE} "OFF" PARENT_SCOPE)
+ endif()
+endfunction()
+
+
+#-------------------------------------------------------------------------------
# Packages and Paths
#-------------------------------------------------------------------------------
@@ -72,6 +88,28 @@
set(${PACKAGE_DIR} ${_PACKAGE_DIR} PARENT_SCOPE)
endfunction()
+# iree_get_executable_path
+#
+# Gets the path to an executable in a cross-compilation-aware way. This
+# should be used when accessing binaries that are used as part of the build,
+# such as for generating files used for later build steps.
+#
+# Paramters:
+# - OUTPUT_PATH_VAR: variable name for receiving the path to the built target.
+# - TARGET: the target to build on host.
+function(iree_get_executable_path OUTPUT_PATH_VAR TARGET)
+ if(CMAKE_CROSSCOMPILING)
+ # The target is defined in the CMake invocation for host. We don't have
+ # access to the target; relying on the path here.
+ set(_OUTPUT_PATH "${IREE_HOST_BINARY_ROOT}/bin/${TARGET}")
+ set(${OUTPUT_PATH_VAR} "${_OUTPUT_PATH}" PARENT_SCOPE)
+ else()
+ # The target is defined in this CMake invocation. We can query the location
+ # directly from CMake.
+ set(${OUTPUT_PATH_VAR} "$<TARGET_FILE:${TARGET}>" PARENT_SCOPE)
+ endif()
+endfunction()
+
#-------------------------------------------------------------------------------
# select()-like Evaluation
#-------------------------------------------------------------------------------
@@ -169,3 +207,20 @@
endif()
endforeach()
endfunction()
+
+# iree_add_executable_dependencies
+#
+# Adds dependency on a target in a cross-compilation-aware way. This should
+# be used for depending on targets that are used as part of the build, such
+# as for generating files used for later build steps.
+#
+# Parameters:
+# TARGET: the target to take on dependencies
+# DEPENDENCY: additional dependencies to append to target
+function(iree_add_executable_dependencies TARGET DEPENDENCY)
+ if(CMAKE_CROSSCOMPILING)
+ add_dependencies(${TARGET} iree_host_${DEPENDENCY})
+ else()
+ add_dependencies(${TARGET} ${DEPENDENCY})
+ endif()
+endfunction()
diff --git a/build_tools/embed_data/CMakeLists.txt b/build_tools/embed_data/CMakeLists.txt
index ec07934..4efad40 100644
--- a/build_tools/embed_data/CMakeLists.txt
+++ b/build_tools/embed_data/CMakeLists.txt
@@ -12,13 +12,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-add_executable(generate_cc_embed_data)
-target_sources(generate_cc_embed_data PRIVATE generate_cc_embed_data.cc)
-set_target_properties(generate_cc_embed_data PROPERTIES OUTPUT_NAME generate_cc_embed_data)
+if(CMAKE_CROSSCOMPILING)
+ iree_declare_host_excutable(generate_cc_embed_data)
+else()
+ add_executable(generate_cc_embed_data)
+ target_sources(generate_cc_embed_data PRIVATE generate_cc_embed_data.cc)
+ set_target_properties(generate_cc_embed_data PROPERTIES OUTPUT_NAME generate_cc_embed_data)
-target_link_libraries(generate_cc_embed_data
- absl::flags
- absl::flags_parse
- absl::strings
- absl::time
-)
+ target_link_libraries(generate_cc_embed_data
+ absl::flags
+ absl::flags_parse
+ absl::strings
+ absl::time
+ )
+ install(TARGETS generate_cc_embed_data
+ COMPONENT generate_cc_embed_data
+ RUNTIME DESTINATION bin)
+endif()
diff --git a/docs/developer_overview.md b/docs/developer_overview.md
index 5898490..7ab969b 100644
--- a/docs/developer_overview.md
+++ b/docs/developer_overview.md
@@ -68,24 +68,35 @@
[mlir-opt](https://github.com/llvm/llvm-project/tree/master/mlir/tools/mlir-opt)
and runs sets of IREE's compiler passes on `.mlir` input files. See "conversion"
in [MLIR's Glossary](https://mlir.llvm.org/getting_started/Glossary/#conversion)
-for more information.
+for more information. Transformations performed by `iree-opt` can range from
+individual passes performing isolated manipulations to broad pipelines that
+encompass a sequence of steps.
Test `.mlir` files that are checked in typically include a `RUN` block at the
top of the file that specifies which passes should be performed and if
`FileCheck` should be used to test the generated output.
-For example, to run some passes on the
-[reshape.mlir](https://github.com/google/iree/blob/master/iree/compiler/Translation/SPIRV/XLAToSPIRV/test/reshape.mlir)
-test file:
+Here's an example of a small compiler pass running on a
+[test file](https://github.com/google/iree/blob/master/iree/compiler/Dialect/IREE/Transforms/test/drop_compiler_hints.mlir):
```shell
$ bazel run iree/tools:iree-opt -- \
-split-input-file \
- -iree-index-computation \
- -simplify-spirv-affine-exprs=false \
- -convert-iree-to-spirv \
- -verify-diagnostics \
- $PWD/iree/compiler/Translation/SPIRV/XLAToSPIRV/test/reshape.mlir
+ -print-ir-before-all \
+ -iree-drop-compiler-hints \
+ $PWD/iree/compiler/Dialect/IREE/Transforms/test/drop_compiler_hints.mlir
+```
+
+For a more complex example, here's how to run IREE's complete transformation
+pipeline targeting the VMLA backend on the
+[fullyconnected.mlir](https://github.com/google/iree/blob/master/iree/test/e2e/models/fullyconnected.mlir)
+model file:
+
+```shell
+$ bazel run iree/tools:iree-opt -- \
+ -iree-transformation-pipeline \
+ -iree-hal-target-backends=vmla \
+ $PWD/iree/test/e2e/models/fullyconnected.mlir
```
Custom passes may also be layered on top of `iree-opt`, see
diff --git a/integrations/tensorflow/bindings/python/pyiree/tf/compiler/BUILD b/integrations/tensorflow/bindings/python/pyiree/tf/compiler/BUILD
index d23a095..1f980ae 100644
--- a/integrations/tensorflow/bindings/python/pyiree/tf/compiler/BUILD
+++ b/integrations/tensorflow/bindings/python/pyiree/tf/compiler/BUILD
@@ -108,6 +108,7 @@
"@llvm-project//mlir:IR",
"@org_tensorflow//tensorflow/cc/saved_model:loader_lite",
"@org_tensorflow//tensorflow/compiler/mlir/tensorflow:convert_graphdef",
+ "@org_tensorflow//tensorflow/compiler/mlir/tensorflow:tf_saved_model_passes",
"@org_tensorflow//tensorflow/core:core_cpu",
],
)
diff --git a/iree/compiler/Dialect/Flow/Transforms/DispatchConfig.cpp b/iree/compiler/Dialect/Flow/Transforms/DispatchConfig.cpp
index 1df92f2..3af7f8c 100644
--- a/iree/compiler/Dialect/Flow/Transforms/DispatchConfig.cpp
+++ b/iree/compiler/Dialect/Flow/Transforms/DispatchConfig.cpp
@@ -34,7 +34,9 @@
bool isUnsupportedFusionOp(Operation *op) {
return isa<xla_hlo::DotOp>(op) || isa<xla_hlo::ConvOp>(op) ||
isa<xla_hlo::ReduceOp>(op) || isa<xla_hlo::PadOp>(op) ||
- isa<xla_hlo::ReduceWindowOp>(op);
+ isa<xla_hlo::ReduceWindowOp>(op) ||
+ isa<xla_hlo::TorchIndexSelectOp>(op) || isa<xla_hlo::SliceOp>(op) ||
+ isa<xla_hlo::ConcatenateOp>(op);
}
// Allowlist of ops that materialize to a an index-permuted copy of some kind
diff --git a/iree/compiler/Dialect/Flow/Transforms/FoldCompatibleDispatchRegions.cpp b/iree/compiler/Dialect/Flow/Transforms/FoldCompatibleDispatchRegions.cpp
index c83cb09..53878d6 100644
--- a/iree/compiler/Dialect/Flow/Transforms/FoldCompatibleDispatchRegions.cpp
+++ b/iree/compiler/Dialect/Flow/Transforms/FoldCompatibleDispatchRegions.cpp
@@ -199,7 +199,8 @@
// TODO(b/144530470): replace with tablegen attributes/interfaces.
if (isa<xla_hlo::ReduceOp>(op) || isa<xla_hlo::DotOp>(op) ||
isa<xla_hlo::ConvOp>(op) || isa<xla_hlo::ReduceWindowOp>(op) ||
- isa<xla_hlo::PadOp>(op)) {
+ isa<xla_hlo::PadOp>(op) || isa<xla_hlo::TorchIndexSelectOp>(op) ||
+ isa<xla_hlo::SliceOp>(op) || isa<xla_hlo::ConcatenateOp>(op)) {
return false;
}
}
diff --git a/iree/compiler/Dialect/IREE/Transforms/test/drop_compiler_hints.mlir b/iree/compiler/Dialect/IREE/Transforms/test/drop_compiler_hints.mlir
index ef76d07..9486f96 100644
--- a/iree/compiler/Dialect/IREE/Transforms/test/drop_compiler_hints.mlir
+++ b/iree/compiler/Dialect/IREE/Transforms/test/drop_compiler_hints.mlir
@@ -1,5 +1,8 @@
// RUN: iree-opt -split-input-file -iree-drop-compiler-hints %s | IreeFileCheck --implicit-check-not="iree.do_not_optimize" %s
+// This file is used as an example in docs/developer_overview.md.
+// If you move or delete it, please update the documentation accordingly.
+
// CHECK-LABEL: @constant
func @constant() -> i32 {
// CHECK-NEXT: %[[C1:.+]] = constant 1
diff --git a/iree/hal/vmla/op_kernels.h b/iree/hal/vmla/op_kernels.h
index 093d52d..b7cb8b7 100644
--- a/iree/hal/vmla/op_kernels.h
+++ b/iree/hal/vmla/op_kernels.h
@@ -442,6 +442,6 @@
} // namespace iree
#include "iree/hal/vmla/op_kernels_generic.h" // IWYU pragma: export
-#include "iree/hal/vmla/op_kernels_ruy.h" // IWYU pragma: export
+#include "iree/hal/vmla/op_kernels_ruy.h" // IWYU pragma: export
#endif // IREE_HAL_VMLA_OP_KERNELS_H_
diff --git a/iree/hal/vulkan/CMakeLists.txt b/iree/hal/vulkan/CMakeLists.txt
index e534073..663437d 100644
--- a/iree/hal/vulkan/CMakeLists.txt
+++ b/iree/hal/vulkan/CMakeLists.txt
@@ -18,6 +18,11 @@
option(IREE_HAL_VULKAN_EMULATE_TIMELINE_SEMAPHORE
"Emulates timeline semaphore with binary semaphores and fences" OFF)
+# Unconditionally turn on emulated timleine semaphore for Android.
+if(CMAKE_CROSSCOMPILING AND "${CMAKE_SYSTEM_NAME}" MATCHES "Android")
+ set(IREE_HAL_VULKAN_EMULATE_TIMELINE_SEMAPHORE ON CACHE BOOL "" FORCE)
+endif()
+# Unless we are not compiling Vulkan HAL backend in.
if(NOT IREE_HAL_DRIVER_VULKAN)
set(IREE_HAL_VULKAN_EMULATE_TIMELINE_SEMAPHORE OFF CACHE BOOL "" FORCE)
endif()
diff --git a/iree/tools/CMakeLists.txt b/iree/tools/CMakeLists.txt
index fce935b..5267dec 100644
--- a/iree/tools/CMakeLists.txt
+++ b/iree/tools/CMakeLists.txt
@@ -101,6 +101,7 @@
iree::compiler::Dialect::VM::Tools
LINKOPTS
"-lpthread"
+ HOSTONLY
)
endif()
@@ -253,6 +254,31 @@
PUBLIC
)
+ iree_cc_library(
+ NAME
+ iree_translate_main
+ SRCS
+ "translate_main.cc"
+ DEPS
+ ::init_compiler_modules
+ ::init_iree_passes_and_dialects
+ ::init_mlir_passes_and_dialects
+ ::init_targets
+ ::init_translations
+ ::init_xla_dialects
+ LLVMSupport
+ MLIRIR
+ MLIRSCFTransforms
+ MLIRPass
+ MLIRSupport
+ MLIRTranslation
+ iree::compiler::Conversion::init_conversions
+ iree::compiler::Dialect::VM::Target::Bytecode
+ iree::compiler::Dialect::VM::Target::init_targets
+ iree::compiler::Translation::IREEVM
+ PUBLIC
+ )
+
iree_cc_binary(
NAME
iree-opt
@@ -260,6 +286,7 @@
iree-opt
DEPS
::iree_opt_main
+ HOSTONLY
)
iree_cc_binary(
@@ -303,33 +330,14 @@
iree::vm::bytecode_module
iree::vm::value
${IREE_HAL_DRIVER_MODULES}
+ HOSTONLY
)
+endif(${IREE_BUILD_COMPILER})
- iree_cc_library(
- NAME
- iree_translate_main
- SRCS
- "translate_main.cc"
- DEPS
- ::init_compiler_modules
- ::init_iree_passes_and_dialects
- ::init_mlir_passes_and_dialects
- ::init_targets
- ::init_translations
- ::init_xla_dialects
- LLVMSupport
- MLIRIR
- MLIRSCFTransforms
- MLIRPass
- MLIRSupport
- MLIRTranslation
- iree::compiler::Conversion::init_conversions
- iree::compiler::Dialect::VM::Target::Bytecode
- iree::compiler::Dialect::VM::Target::init_targets
- iree::compiler::Translation::IREEVM
- PUBLIC
- )
-
+# If cross-compiling, we need to declare iree-translate under host configuration
+# unconditionally because we need to run it on host to generate VM modules
+# for tests.
+if(${IREE_BUILD_COMPILER} OR CMAKE_CROSSCOMPILING)
iree_cc_binary(
NAME
iree-translate
@@ -337,6 +345,7 @@
iree-translate
DEPS
::iree_translate_main
+ HOSTONLY
)
endif()
diff --git a/iree/vm/test/BUILD b/iree/vm/test/BUILD
index 28312bc..fb9848d 100644
--- a/iree/vm/test/BUILD
+++ b/iree/vm/test/BUILD
@@ -35,13 +35,11 @@
iree_bytecode_module(
name = "arithmetic_ops",
src = "arithmetic_ops.mlir",
- cc_namespace = "iree::vm::test",
flags = ["-iree-vm-ir-to-bytecode-module"],
)
iree_bytecode_module(
name = "control_flow_ops",
src = "control_flow_ops.mlir",
- cc_namespace = "iree::vm::test",
flags = ["-iree-vm-ir-to-bytecode-module"],
)
diff --git a/iree/vm/test/CMakeLists.txt b/iree/vm/test/CMakeLists.txt
index 7f9a4ae..6c189b6 100644
--- a/iree/vm/test/CMakeLists.txt
+++ b/iree/vm/test/CMakeLists.txt
@@ -35,8 +35,6 @@
arithmetic_ops
SRC
"arithmetic_ops.mlir"
- CC_NAMESPACE
- "iree::vm::test"
FLAGS
"-iree-vm-ir-to-bytecode-module"
PUBLIC
@@ -47,8 +45,6 @@
control_flow_ops
SRC
"control_flow_ops.mlir"
- CC_NAMESPACE
- "iree::vm::test"
FLAGS
"-iree-vm-ir-to-bytecode-module"
PUBLIC
diff --git a/scripts/prepare_doc_publication.py b/scripts/prepare_doc_publication.py
index f36de29..ee1a5dd 100755
--- a/scripts/prepare_doc_publication.py
+++ b/scripts/prepare_doc_publication.py
@@ -140,8 +140,8 @@
# A dictionary containing the supporting JavaScript files for each doc.
JS_FILES_DICT = {
- 'op_coverage.md': ['js/add_classes.js'],
- 'e2e_coverage.md': ['js/add_classes.js'],
+ 'op_coverage.md': ['js/add_classes.js'],
+ 'e2e_coverage.md': ['js/add_classes.js'],
}
diff --git a/scripts/update_e2e_coverage.py b/scripts/update_e2e_coverage.py
index 4e5f09a..32a3177 100755
--- a/scripts/update_e2e_coverage.py
+++ b/scripts/update_e2e_coverage.py
@@ -23,7 +23,6 @@
import os
import subprocess
-
REFERENCE_BACKEND = 'tf'
# Assumes that tests are expanded for the tf_also, iree_vmla, iree_llvmjit and
# iree_vulkan backends.
diff --git a/third_party/llvm-project b/third_party/llvm-project
index 1c0bbe4..d45cf91 160000
--- a/third_party/llvm-project
+++ b/third_party/llvm-project
@@ -1 +1 @@
-Subproject commit 1c0bbe4341ac0ffbaf2e1f482239b45166607f2d
+Subproject commit d45cf9105b5a88ed03382ffbbfcd54b461f1bb23
diff --git a/third_party/tensorflow b/third_party/tensorflow
index 2c4a014..f74654a 160000
--- a/third_party/tensorflow
+++ b/third_party/tensorflow
@@ -1 +1 @@
-Subproject commit 2c4a0140f62e021bb596c11a3b306eb94e481d85
+Subproject commit f74654ac7b314a212b1df6687c2f99800084e97f