Geoffrey Martin-Noble | 552d3f8 | 2021-05-25 17:56:09 -0700 | [diff] [blame] | 1 | # Copyright 2019 The IREE Authors |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 2 | # |
Geoffrey Martin-Noble | 552d3f8 | 2021-05-25 17:56:09 -0700 | [diff] [blame] | 3 | # Licensed under the Apache License v2.0 with LLVM Exceptions. |
| 4 | # See https://llvm.org/LICENSE.txt for license information. |
| 5 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 6 | |
Geoffrey Martin-Noble | 4fd7a1d | 2022-11-17 15:09:49 -0800 | [diff] [blame] | 7 | cmake_minimum_required(VERSION 3.21...3.24) |
Ben Vanik | 552c5f4 | 2021-06-21 17:39:14 -0700 | [diff] [blame] | 8 | |
| 9 | # LLVM requires CMP0116 for tblgen: https://reviews.llvm.org/D101083 |
| 10 | # CMP0116: Ninja generators transform `DEPFILE`s from `add_custom_command()` |
| 11 | # New in CMake 3.20. https://cmake.org/cmake/help/latest/policy/CMP0116.html |
| 12 | set(CMAKE_POLICY_DEFAULT_CMP0116 OLD) |
Ben Vanik | a49a5f5 | 2023-02-21 12:19:17 -0800 | [diff] [blame] | 13 | if(POLICY CMP0116) |
| 14 | cmake_policy(SET CMP0116 OLD) |
| 15 | endif() |
Ben Vanik | 552c5f4 | 2021-06-21 17:39:14 -0700 | [diff] [blame] | 16 | |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 17 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 18 | |
Stella Laurenzo | 688670f | 2021-09-24 18:16:25 -0700 | [diff] [blame] | 19 | project(IREE ASM C CXX) |
Lei Zhang | 6c5907b | 2020-06-02 09:06:08 -0700 | [diff] [blame] | 20 | set(CMAKE_C_STANDARD 11) |
Scott Todd | 07349fa | 2022-07-27 12:16:05 -0700 | [diff] [blame] | 21 | set(CMAKE_CXX_STANDARD 17) |
Stella Laurenzo | bc09f0e | 2022-07-27 16:22:39 -0700 | [diff] [blame] | 22 | # LLVM defines this as a CACHE property and uses a policy that causes the |
| 23 | # cache value to take precedence. This is causing us to mix 17/14 across |
| 24 | # the boundary. |
| 25 | # TODO: Remove this once the LLVM mechanism is updated. See: |
| 26 | # https://discourse.llvm.org/t/important-new-toolchain-requirements-to-build-llvm-will-most-likely-be-landing-within-a-week-prepare-your-buildbots/61447/9 |
| 27 | set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to" FORCE) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 28 | set(IREE_IDE_FOLDER IREE) |
| 29 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
| 30 | |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 31 | if(MSVC) |
Ben Vanik | 96fd277 | 2021-04-19 20:30:56 -0700 | [diff] [blame] | 32 | enable_language(ASM_MASM) |
| 33 | else() |
| 34 | enable_language(ASM) |
| 35 | endif() |
| 36 | |
Cindy Liu | b1bfb9c | 2022-06-27 10:46:13 -0700 | [diff] [blame] | 37 | # Set the default CMake build type so some of the build type dependent setting |
| 38 | # in the submodules and functions (IREE assertion) can be set properly. |
Cindy Liu | 23dafd0 | 2022-06-22 15:36:21 -0700 | [diff] [blame] | 39 | set(DEFAULT_CMAKE_BUILD_TYPE "Release") |
| 40 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) |
| 41 | message(STATUS "No build type selected, default to ${DEFAULT_CMAKE_BUILD_TYPE}") |
| 42 | set(CMAKE_BUILD_TYPE "${DEFAULT_CMAKE_BUILD_TYPE}" CACHE STRING "Build type (default ${DEFAULT_CMAKE_BUILD_TYPE})" FORCE) |
| 43 | endif() |
| 44 | |
Scott Todd | 99e9f5b | 2021-12-30 10:56:12 -0800 | [diff] [blame] | 45 | include(CMakeDependentOption) |
| 46 | |
Lei Zhang | 7e253da | 2020-06-10 07:51:19 -0700 | [diff] [blame] | 47 | #------------------------------------------------------------------------------- |
| 48 | # Project component configuration |
| 49 | #------------------------------------------------------------------------------- |
| 50 | |
Ben Vanik | 56d44bf | 2020-05-15 13:20:50 -0700 | [diff] [blame] | 51 | option(IREE_ENABLE_RUNTIME_TRACING "Enables instrumented runtime tracing." OFF) |
Scott Todd | 1cd9f0a | 2021-07-29 10:05:44 -0700 | [diff] [blame] | 52 | option(IREE_ENABLE_COMPILER_TRACING "Enables instrumented compiler tracing." OFF) |
Ben Vanik | 2d79c20 | 2022-10-24 15:08:57 -0700 | [diff] [blame] | 53 | option(IREE_ENABLE_RENDERDOC_PROFILING "Enables profiling HAL devices with the RenderDoc tool." OFF) |
Geoffrey Martin-Noble | fe74bd4 | 2021-10-27 22:17:13 -0700 | [diff] [blame] | 54 | option(IREE_ENABLE_THREADING "Builds IREE in with thread library support." ON) |
Rob Suderman | d42e002 | 2022-06-08 16:38:45 -0700 | [diff] [blame] | 55 | option(IREE_ENABLE_CLANG_TIDY "Builds IREE in with clang tidy enabled on IREE's libraries." OFF) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 56 | |
Ben Vanik | 4aae003 | 2022-04-19 15:49:26 -0700 | [diff] [blame] | 57 | # TODO(#8469): remove the dependency on cpuinfo entirely. |
| 58 | option(IREE_ENABLE_CPUINFO "Enables runtime use of cpuinfo for processor topology detection." ON) |
| 59 | |
Marius Brehler | edfc57f | 2019-12-18 11:19:38 -0800 | [diff] [blame] | 60 | option(IREE_BUILD_COMPILER "Builds the IREE compiler." ON) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 61 | option(IREE_BUILD_TESTS "Builds IREE unit tests." ON) |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 62 | option(IREE_BUILD_DOCS "Builds IREE docs." OFF) |
Ben Vanik | 6b112ef | 2019-10-03 10:45:14 -0700 | [diff] [blame] | 63 | option(IREE_BUILD_SAMPLES "Builds IREE sample projects." ON) |
Scott Todd | 382fc63 | 2022-06-06 10:57:24 -0700 | [diff] [blame] | 64 | option(IREE_BUILD_PYTHON_BINDINGS "Builds the IREE python bindings" OFF) |
Stella Laurenzo | d3770ff | 2021-10-18 22:54:18 -0700 | [diff] [blame] | 65 | option(IREE_BUILD_TRACY "Builds tracy server tools." OFF) |
Stella Laurenzo | 96d959e | 2023-02-19 11:58:14 -0800 | [diff] [blame] | 66 | option(IREE_BUILD_BUNDLED_LLVM "Builds the bundled llvm-project (vs using installed)" ON) |
Ben Vanik | cd1132f | 2021-01-29 15:58:17 -0800 | [diff] [blame] | 67 | |
Scott Todd | 352da3f | 2022-07-20 15:25:11 -0700 | [diff] [blame] | 68 | option(IREE_BYTECODE_MODULE_FORCE_LLVM_SYSTEM_LINKER "Use the system linker when generating IREE modules in tests/samples/benchmarks (useful for Tracy)." OFF) |
bjacob | 1af90ee | 2022-03-28 22:10:53 -0400 | [diff] [blame] | 69 | |
Stella Laurenzo | bb1de96 | 2021-01-05 08:18:33 -0800 | [diff] [blame] | 70 | # Properties controlling version and naming of release artifacts. |
Stella Laurenzo | f33f5b5 | 2022-01-08 17:49:52 +0000 | [diff] [blame] | 71 | set(IREE_RELEASE_PACKAGE_SUFFIX "" CACHE STRING "Suffix to append to distributed package names") |
Stella Laurenzo | bb1de96 | 2021-01-05 08:18:33 -0800 | [diff] [blame] | 72 | set(IREE_RELEASE_VERSION "0.1a1" CACHE STRING "Version to embed in distributed packages") |
| 73 | set(IREE_RELEASE_REVISION "HEAD" CACHE STRING "Version control revision information to embed in distributed packages") |
Jacques Pienaar | 27779b2 | 2022-12-22 15:37:56 -0800 | [diff] [blame] | 74 | option(IREE_EMBED_RELEASE_INFO "Embed the IREE version information in built artifacts." OFF) |
Stella Laurenzo | bb1de96 | 2021-01-05 08:18:33 -0800 | [diff] [blame] | 75 | |
Scott Todd | de426de | 2023-01-13 08:26:02 -0800 | [diff] [blame] | 76 | # Using already built host binaries, such as for cross-compilation. |
| 77 | set(IREE_HOST_BIN_DIR_DEFAULT "") |
| 78 | if(IREE_HOST_BINARY_ROOT) |
| 79 | message(WARNING "IREE_HOST_BINARY_ROOT is deprecated. Use IREE_HOST_BIN_DIR" |
| 80 | " pointing directly to the directory containing binaries" |
| 81 | " instead.") |
| 82 | set(IREE_HOST_BIN_DIR_DEFAULT "${IREE_HOST_BINARY_ROOT}/bin") |
| 83 | endif() |
| 84 | set(IREE_HOST_BIN_DIR "${IREE_HOST_BIN_DIR_DEFAULT}" CACHE STRING "Path to directory containing IREE binary tools to use instead of building them from source.") |
| 85 | |
Ben Vanik | cd1132f | 2021-01-29 15:58:17 -0800 | [diff] [blame] | 86 | option(IREE_BUILD_BINDINGS_TFLITE "Builds the IREE TFLite C API compatibility shim" ON) |
Kojo Acquah | 5bf3994 | 2021-04-22 16:01:28 -0700 | [diff] [blame] | 87 | option(IREE_BUILD_BINDINGS_TFLITE_JAVA "Builds the IREE TFLite Java bindings with the C API compatibility shim" ON) |
Ben Vanik | cd1132f | 2021-01-29 15:58:17 -0800 | [diff] [blame] | 88 | |
Jerry Wu | b6b1dee | 2022-06-01 13:45:16 +0000 | [diff] [blame] | 89 | option(IREE_BUILD_MICROBENCHMARKS "Builds IREE microbenchmark suites." OFF) |
| 90 | |
Jerry Wu | 5740497 | 2023-03-02 22:16:11 +0000 | [diff] [blame] | 91 | option(IREE_BUILD_E2E_TEST_ARTIFACTS "Builds IREE E2E test artifacts suite generated by the e2e test framework." "${IREE_BUILD_EXPERIMENTAL_E2E_TEST_ARTIFACTS}") |
| 92 | |
Stella Laurenzo | 289b9a1 | 2023-02-24 13:06:32 -0800 | [diff] [blame] | 93 | # For development, builds LLVM (and in the future) the whole compiler as |
| 94 | # individual shared libraries similar to if passing -DBUILD_SHARED_LIBS=ON |
| 95 | # to a standalone LLVM build. This can dramatically reduce linking time and |
| 96 | # makes the management of some dependencies more strict. |
| 97 | # This option is considered experimental and should not be relied on until |
| 98 | # CI coverage is established. |
| 99 | option(IREE_COMPILER_BUILD_SHARED_LIBS "Enables BUILD_SHARED_LIBS CMake mode for LLVM and the compiler (this is only suitable for development)" OFF) |
| 100 | |
| 101 | # Must be defined as an option (CMake does not do it automatically), even though |
| 102 | # we override it for different parts of the tree. |
| 103 | # This option is considered experimental and should not be relied on until |
| 104 | # CI coverage is established. |
| 105 | option(BUILD_SHARED_LIBS "Instructs CMake to build libraries as shared if possible" OFF) |
| 106 | |
Stella Laurenzo | 0f005e5 | 2020-12-27 11:54:33 -0800 | [diff] [blame] | 107 | #------------------------------------------------------------------------------- |
Ben Vanik | 5363ea3 | 2023-05-02 15:47:58 -0700 | [diff] [blame] | 108 | # IREE command-line tooling configuration |
| 109 | #------------------------------------------------------------------------------- |
| 110 | |
| 111 | # External user modules linked into IREE tooling (iree-run-module/etc). |
| 112 | # These are only available in the internal IREE tools and here for testing |
| 113 | # custom modules in standard workflows. This is not a deployment mechanism and |
| 114 | # users integrating IREE into their libraries or applications will need to |
| 115 | # manage the building and registering/resolving the modules themselves. |
| 116 | # |
| 117 | # See runtime/src/iree/tooling/modules/CMakeLists.txt for more information on |
| 118 | # how to declare external modules. |
| 119 | set(IREE_EXTERNAL_TOOLING_MODULES "" CACHE STRING "") |
| 120 | |
| 121 | #------------------------------------------------------------------------------- |
Stella Laurenzo | c6092c4 | 2023-03-25 19:55:37 -0700 | [diff] [blame] | 122 | # Compiler plugins |
| 123 | # IREE compiler plugins can be statically built into the compiler by adding |
| 124 | # directories to IREE_COMPILER_PLUGIN_PATHS. If directories are relative, they |
| 125 | # are interpreted against the IREE source directory. |
| 126 | # |
| 127 | # In addition, certain in-tree plugin directories are included regardless of |
| 128 | # this variable (possibly based on other flags). |
| 129 | # |
| 130 | # A plugin directory must contain an iree_compiler_plugin_group.cmake file that |
| 131 | # is loaded and must specify: |
| 132 | # - any needed add_subdirectory() calls to populate targets. |
| 133 | # - iree_compiler_register_plugin() targets (either directly or transitively) |
| 134 | # which associates a plugin id with a registration target. |
| 135 | # |
| 136 | # All iree_compiler_plugin_group.cmake files are included from the binary |
| 137 | # directory ${IREE_BINARY_DIR}/compiler/plugins and must create a sub binary |
| 138 | # directory that is globally unique. It is recommended to prefix with org |
| 139 | # name or project. The following names are reserved: |
| 140 | # - builtin |
| 141 | # - samples |
| 142 | # |
| 143 | # Example: |
| 144 | # add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/example samples/example) |
| 145 | #------------------------------------------------------------------------------- |
| 146 | |
| 147 | set(IREE_COMPILER_PLUGIN_PATHS "" CACHE STRING "Paths to external compiler plugins") |
| 148 | set(IREE_COMPILER_BUILTIN_PLUGIN_PATHS "compiler/plugins") |
| 149 | if(IREE_BUILD_SAMPLES) |
| 150 | list(APPEND IREE_COMPILER_BUILTIN_PLUGIN_PATHS "samples/compiler_plugins") |
| 151 | endif() |
| 152 | |
| 153 | #------------------------------------------------------------------------------- |
Stella Laurenzo | 0f005e5 | 2020-12-27 11:54:33 -0800 | [diff] [blame] | 154 | # Experimental project flags |
| 155 | #------------------------------------------------------------------------------- |
| 156 | |
bjacob | 3dc368e | 2023-05-09 12:50:18 -0400 | [diff] [blame] | 157 | option(IREE_BUILD_EXPERIMENTAL_CPU_UKERNEL_PLUGINS "Build experimental plugins making builtin ukernels available to llvm-cpu modules compiled with --iree-llvmcpu-enable-microkernels" OFF) |
Scott Todd | f237b5e | 2022-01-28 11:02:25 -0800 | [diff] [blame] | 158 | option(IREE_BUILD_EXPERIMENTAL_WEB_SAMPLES "Builds experimental web samples." OFF) |
Stella Laurenzo | 0f005e5 | 2020-12-27 11:54:33 -0800 | [diff] [blame] | 159 | |
| 160 | #------------------------------------------------------------------------------- |
Scott Todd | 18a5485 | 2023-01-27 08:52:12 -0800 | [diff] [blame] | 161 | # CUDA Toolkit. |
| 162 | # |
| 163 | # Using the (optional) CUDA support in the compiler and runtime requires the |
| 164 | # NVIDIA CUDA Toolkit. The toolkit can either be installed ahead of time or |
| 165 | # it can be automatically downloaded on certain host architectures. |
Scott Todd | 9fa5de7 | 2023-01-23 14:40:18 -0800 | [diff] [blame] | 166 | #------------------------------------------------------------------------------- |
| 167 | |
Scott Todd | 18a5485 | 2023-01-27 08:52:12 -0800 | [diff] [blame] | 168 | set(IREE_CUDA_AVAILABLE OFF) |
| 169 | find_package(CUDAToolkit) |
| 170 | if(CUDAToolkit_FOUND) |
| 171 | set(IREE_CUDA_AVAILABLE ON) |
| 172 | else() |
| 173 | # We can download the SDK in build_tools/third_party/cuda/CMakeLists.txt, if |
| 174 | # on a supported platform/arch. |
| 175 | if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR WIN32) |
| 176 | if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "(x86_64)|(AMD64|amd64)") |
| 177 | set(IREE_CUDA_AVAILABLE ON) |
| 178 | endif() |
Scott Todd | 9fa5de7 | 2023-01-23 14:40:18 -0800 | [diff] [blame] | 179 | endif() |
| 180 | endif() |
| 181 | |
| 182 | #------------------------------------------------------------------------------- |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 183 | # Runtime HAL Driver Options |
| 184 | # By default, all runtime drivers supported by the current platform which do |
| 185 | # not require external deps are enabled by default. This can be changed with: |
| 186 | # -DIREE_HAL_DRIVER_DEFAULTS=OFF |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 187 | #------------------------------------------------------------------------------- |
| 188 | |
Ben Vanik | 4e6af05 | 2022-06-07 17:10:20 -0700 | [diff] [blame] | 189 | # External HAL drivers; see runtime/src/iree/hal/drivers/CMakeLists.txt for more |
| 190 | # information on how to declare external drivers. |
| 191 | set(IREE_EXTERNAL_HAL_DRIVERS "" CACHE STRING "") |
| 192 | |
Ben Vanik | 8916027 | 2022-09-26 16:44:11 -0700 | [diff] [blame] | 193 | # Additional executable loader deps to add dependent libraries to any target |
| 194 | # using the default executable loader registration utilities. |
| 195 | # TODO(benvanik): extend the deps to encompass the built-in loaders too so that |
| 196 | # we have one flag. We could also support a list of deps and automatically |
| 197 | # generate the registration from that via a configure file. |
| 198 | set(IREE_HAL_EXECUTABLE_LOADER_EXTRA_DEPS "" CACHE STRING "") |
| 199 | |
Ben Vanik | e19fc8e | 2023-04-14 16:08:01 -0700 | [diff] [blame] | 200 | # Additional executable import provider deps to add dependent libraries to any |
| 201 | # target using the default executable import registration utilities. |
| 202 | # TODO(benvanik): extend the deps to encompass the built-in imports too so that |
| 203 | # we have one flag. We could also support a list of deps and automatically |
| 204 | # generate the registration from that via a configure file. |
| 205 | set(IREE_HAL_EXECUTABLE_PLUGIN_EXTRA_DEPS "" CACHE STRING "") |
| 206 | |
Scott Todd | d1620f0 | 2021-12-22 14:55:38 -0800 | [diff] [blame] | 207 | option(IREE_HAL_DRIVER_DEFAULTS "Sets the default value for all runtime HAL drivers" ON) |
Ben Vanik | a9aaebe | 2022-12-16 09:14:53 -0800 | [diff] [blame] | 208 | |
Scott Todd | 9fa5de7 | 2023-01-23 14:40:18 -0800 | [diff] [blame] | 209 | # CUDA support is enabled by default if the platform supports the CUDA SDK and |
| 210 | # not cross compiling. Note: a CUDA-compatible GPU with drivers is still |
| 211 | # required to actually run CUDA workloads. |
| 212 | set(IREE_HAL_DRIVER_CUDA_DEFAULT ${IREE_HAL_DRIVER_DEFAULTS}) |
Scott Todd | 18a5485 | 2023-01-27 08:52:12 -0800 | [diff] [blame] | 213 | if(NOT IREE_CUDA_AVAILABLE OR CMAKE_CROSSCOMPILING) |
Scott Todd | 9fa5de7 | 2023-01-23 14:40:18 -0800 | [diff] [blame] | 214 | set(IREE_HAL_DRIVER_CUDA_DEFAULT OFF) |
| 215 | endif() |
| 216 | |
| 217 | # Vulkan support is enabled by default if the platform might support Vulkan. |
| 218 | # Apple platforms support Metal instead of Vulkan, though MoltenVK may work. |
| 219 | set(IREE_HAL_DRIVER_VULKAN_DEFAULT ${IREE_HAL_DRIVER_DEFAULTS}) |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 220 | if(APPLE) |
Scott Todd | d1620f0 | 2021-12-22 14:55:38 -0800 | [diff] [blame] | 221 | set(IREE_HAL_DRIVER_VULKAN_DEFAULT OFF) |
Scott Todd | d1620f0 | 2021-12-22 14:55:38 -0800 | [diff] [blame] | 222 | endif() |
Marius Brehler | 0a4b67f | 2020-05-08 13:19:16 -0700 | [diff] [blame] | 223 | |
Scott Todd | d1620f0 | 2021-12-22 14:55:38 -0800 | [diff] [blame] | 224 | option(IREE_HAL_DRIVER_CUDA "Enables the 'cuda' runtime HAL driver" ${IREE_HAL_DRIVER_CUDA_DEFAULT}) |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 225 | option(IREE_HAL_DRIVER_LOCAL_SYNC "Enables the 'local-sync' runtime HAL driver" ${IREE_HAL_DRIVER_DEFAULTS}) |
| 226 | option(IREE_HAL_DRIVER_LOCAL_TASK "Enables the 'local-task' runtime HAL driver" ${IREE_HAL_DRIVER_DEFAULTS}) |
| 227 | option(IREE_HAL_DRIVER_VULKAN "Enables the 'vulkan' runtime HAL driver" ${IREE_HAL_DRIVER_VULKAN_DEFAULT}) |
| 228 | |
Ben Vanik | 6e64b6e | 2022-06-07 09:14:53 -0700 | [diff] [blame] | 229 | option(IREE_HAL_EXECUTABLE_LOADER_DEFAULTS "Sets the default value for all runtime HAL executable loaders" ON) |
| 230 | set(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF_DEFAULT ${IREE_HAL_EXECUTABLE_LOADER_DEFAULTS}) |
| 231 | set(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY_DEFAULT ${IREE_HAL_EXECUTABLE_LOADER_DEFAULTS}) |
| 232 | set(IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE_DEFAULT ${IREE_HAL_EXECUTABLE_LOADER_DEFAULTS}) |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 233 | |
Ben Vanik | e19fc8e | 2023-04-14 16:08:01 -0700 | [diff] [blame] | 234 | option(IREE_HAL_EXECUTABLE_PLUGIN_DEFAULTS "Sets the default value for all runtime HAL executable plugin mechanisms" ON) |
| 235 | set(IREE_HAL_EXECUTABLE_PLUGIN_EMBEDDED_ELF_DEFAULT ${IREE_HAL_EXECUTABLE_PLUGIN_DEFAULTS}) |
| 236 | set(IREE_HAL_EXECUTABLE_PLUGIN_SYSTEM_LIBRARY_DEFAULT ${IREE_HAL_EXECUTABLE_PLUGIN_DEFAULTS}) |
| 237 | |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 238 | # Emscripten builds don't support embedded ELF libraries. |
| 239 | if(EMSCRIPTEN) |
Ben Vanik | 2e8540e | 2022-06-06 20:39:34 -0700 | [diff] [blame] | 240 | set(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF_DEFAULT OFF) |
Ben Vanik | e19fc8e | 2023-04-14 16:08:01 -0700 | [diff] [blame] | 241 | set(IREE_HAL_EXECUTABLE_PLUGIN_EMBEDDED_ELF_DEFAULT OFF) |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 242 | endif() |
| 243 | |
| 244 | # If forcing system libraries (for TSAN/debugging tools/etc) then ensure the |
| 245 | # system library loader is linked in. |
Scott Todd | 352da3f | 2022-07-20 15:25:11 -0700 | [diff] [blame] | 246 | if(IREE_BYTECODE_MODULE_FORCE_LLVM_SYSTEM_LINKER) |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 247 | set(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY_DEFAULT ON) |
Ben Vanik | e19fc8e | 2023-04-14 16:08:01 -0700 | [diff] [blame] | 248 | set(IREE_HAL_EXECUTABLE_PLUGIN_SYSTEM_LIBRARY_DEFAULT ON) |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 249 | endif() |
| 250 | |
Ben Vanik | e19fc8e | 2023-04-14 16:08:01 -0700 | [diff] [blame] | 251 | # If no local driver is enabled then we force all the loaders/imports off; this |
| 252 | # allows for simpler checks that don't need to see if both the driver and |
| 253 | # feature is available. |
Ben Vanik | 6e64b6e | 2022-06-07 09:14:53 -0700 | [diff] [blame] | 254 | if(NOT IREE_HAL_DRIVER_LOCAL_SYNC AND NOT IREE_HAL_DRIVER_LOCAL_TASK) |
| 255 | set(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF_DEFAULT OFF) |
| 256 | set(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY_DEFAULT OFF) |
| 257 | set(IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE_DEFAULT OFF) |
Ben Vanik | e19fc8e | 2023-04-14 16:08:01 -0700 | [diff] [blame] | 258 | set(IREE_HAL_EXECUTABLE_PLUGIN_EMBEDDED_ELF_DEFAULT OFF) |
| 259 | set(IREE_HAL_EXECUTABLE_PLUGIN_SYSTEM_LIBRARY_DEFAULT OFF) |
Ben Vanik | 6e64b6e | 2022-06-07 09:14:53 -0700 | [diff] [blame] | 260 | endif() |
| 261 | |
Ben Vanik | 2e8540e | 2022-06-06 20:39:34 -0700 | [diff] [blame] | 262 | option(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF "Enables the embedded dynamic library loader for local HAL drivers" ${IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF_DEFAULT}) |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 263 | option(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY "Enables the system dynamic library loader for local HAL drivers" ${IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY_DEFAULT}) |
| 264 | option(IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE "Enables the VMVX module loader for local HAL drivers" ${IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE_DEFAULT}) |
| 265 | |
Ben Vanik | e19fc8e | 2023-04-14 16:08:01 -0700 | [diff] [blame] | 266 | option(IREE_HAL_EXECUTABLE_PLUGIN_EMBEDDED_ELF "Enables the embedded dynamic library plugin mechanism for local HAL drivers" ${IREE_HAL_EXECUTABLE_PLUGIN_EMBEDDED_ELF_DEFAULT}) |
| 267 | option(IREE_HAL_EXECUTABLE_PLUGIN_SYSTEM_LIBRARY "Enables the system dynamic library plugin mechanism for local HAL drivers" ${IREE_HAL_EXECUTABLE_PLUGIN_SYSTEM_LIBRARY_DEFAULT}) |
| 268 | |
Scott Todd | 0f1f8eb | 2022-06-10 15:53:30 -0700 | [diff] [blame] | 269 | if(IREE_BUILD_COMPILER) |
| 270 | # The compiler requires the local task driver with the VMVX loader. |
| 271 | set(IREE_HAL_DRIVER_LOCAL_TASK ON) |
| 272 | set(IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE ON) |
| 273 | endif() |
| 274 | |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 275 | message(STATUS "IREE HAL drivers:") |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 276 | if(IREE_HAL_DRIVER_CUDA) |
| 277 | message(STATUS " - cuda") |
| 278 | endif() |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 279 | if(IREE_HAL_DRIVER_LOCAL_SYNC) |
| 280 | message(STATUS " - local-sync") |
| 281 | endif() |
| 282 | if(IREE_HAL_DRIVER_LOCAL_TASK) |
| 283 | message(STATUS " - local-task") |
| 284 | endif() |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 285 | if(IREE_HAL_DRIVER_VULKAN) |
| 286 | message(STATUS " - vulkan") |
| 287 | endif() |
Ben Vanik | 4e6af05 | 2022-06-07 17:10:20 -0700 | [diff] [blame] | 288 | if(IREE_EXTERNAL_HAL_DRIVERS) |
| 289 | message(STATUS " + external: ${IREE_EXTERNAL_HAL_DRIVERS}") |
| 290 | endif() |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 291 | |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 292 | message(STATUS "IREE HAL local executable library loaders:") |
Ben Vanik | 2e8540e | 2022-06-06 20:39:34 -0700 | [diff] [blame] | 293 | if(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF) |
| 294 | message(STATUS " - embedded-elf") |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 295 | endif() |
| 296 | if(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY) |
| 297 | message(STATUS " - system-library") |
| 298 | endif() |
| 299 | if(IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE) |
| 300 | message(STATUS " - vmvx-module") |
| 301 | endif() |
| 302 | |
Ben Vanik | e19fc8e | 2023-04-14 16:08:01 -0700 | [diff] [blame] | 303 | message(STATUS "IREE HAL local executable plugin mechanisms:") |
| 304 | if(IREE_HAL_EXECUTABLE_PLUGIN_EMBEDDED_ELF) |
| 305 | message(STATUS " - embedded-elf") |
| 306 | endif() |
| 307 | if(IREE_HAL_EXECUTABLE_PLUGIN_SYSTEM_LIBRARY) |
| 308 | message(STATUS " - system-library") |
| 309 | endif() |
| 310 | |
Lei Zhang | 0d281b7 | 2020-06-01 20:00:23 -0400 | [diff] [blame] | 311 | #------------------------------------------------------------------------------- |
Ben Vanik | 4e6af05 | 2022-06-07 17:10:20 -0700 | [diff] [blame] | 312 | # Experimental ROCM HAL driver |
| 313 | #------------------------------------------------------------------------------- |
| 314 | |
| 315 | set(IREE_EXTERNAL_ROCM_HAL_DRIVER_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/experimental/rocm") |
| 316 | set(IREE_EXTERNAL_ROCM_HAL_DRIVER_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/experimental/rocm") |
| 317 | set(IREE_EXTERNAL_ROCM_HAL_DRIVER_TARGET "iree::experimental::rocm::registration") |
| 318 | set(IREE_EXTERNAL_ROCM_HAL_DRIVER_REGISTER "iree_hal_rocm_driver_module_register") |
| 319 | |
| 320 | #------------------------------------------------------------------------------- |
Scott Todd | 382fc63 | 2022-06-06 10:57:24 -0700 | [diff] [blame] | 321 | # Compiler Target Options |
Scott Todd | 9fa5de7 | 2023-01-23 14:40:18 -0800 | [diff] [blame] | 322 | # By default, all compiler targets supported by the current platform are |
| 323 | # enabled. Some compiler targets like CUDA will install external deps as |
| 324 | # needed at configure time. This can be changed with: |
Scott Todd | 382fc63 | 2022-06-06 10:57:24 -0700 | [diff] [blame] | 325 | # -DIREE_TARGET_BACKEND_DEFAULTS=OFF |
| 326 | #------------------------------------------------------------------------------- |
| 327 | |
| 328 | option(IREE_TARGET_BACKEND_DEFAULTS "Sets the default value for all compiler target backends" ON) |
| 329 | |
| 330 | # The VMVX backend is always enabled. |
| 331 | cmake_dependent_option(IREE_TARGET_BACKEND_VMVX "Enables the 'vmvx' compiler target backend" ON ${IREE_BUILD_COMPILER} OFF) |
| 332 | |
| 333 | # Supported default target backends. |
Scott Todd | 352da3f | 2022-07-20 15:25:11 -0700 | [diff] [blame] | 334 | cmake_dependent_option(IREE_TARGET_BACKEND_LLVM_CPU "Enables the 'llvm-cpu' compiler target backend" ${IREE_TARGET_BACKEND_DEFAULTS} ${IREE_BUILD_COMPILER} OFF) |
| 335 | cmake_dependent_option(IREE_TARGET_BACKEND_LLVM_CPU_WASM "Enables WebAssembly in the 'llvm-cpu' compiler target backend" ${IREE_TARGET_BACKEND_DEFAULTS} ${IREE_TARGET_BACKEND_LLVM_CPU} OFF) |
Scott Todd | 382fc63 | 2022-06-06 10:57:24 -0700 | [diff] [blame] | 336 | cmake_dependent_option(IREE_TARGET_BACKEND_METAL_SPIRV "Enables the 'metal-spirv' compiler target backend" ${IREE_TARGET_BACKEND_DEFAULTS} ${IREE_BUILD_COMPILER} OFF) |
Scott Todd | 382fc63 | 2022-06-06 10:57:24 -0700 | [diff] [blame] | 337 | cmake_dependent_option(IREE_TARGET_BACKEND_VULKAN_SPIRV "Enables the 'vulkan-spirv' compiler target backend" ${IREE_TARGET_BACKEND_DEFAULTS} ${IREE_BUILD_COMPILER} OFF) |
| 338 | |
Scott Todd | 9fa5de7 | 2023-01-23 14:40:18 -0800 | [diff] [blame] | 339 | # Supported default target backends that are only available on certain |
| 340 | # platforms. |
| 341 | set(IREE_TARGET_BACKEND_CUDA_DEFAULT ${IREE_TARGET_BACKEND_DEFAULTS}) |
Scott Todd | 18a5485 | 2023-01-27 08:52:12 -0800 | [diff] [blame] | 342 | if(NOT IREE_CUDA_AVAILABLE) |
Scott Todd | 9fa5de7 | 2023-01-23 14:40:18 -0800 | [diff] [blame] | 343 | set(IREE_TARGET_BACKEND_CUDA_DEFAULT OFF) |
| 344 | endif() |
| 345 | cmake_dependent_option(IREE_TARGET_BACKEND_CUDA "Enables the 'cuda' compiler target backend" ${IREE_TARGET_BACKEND_CUDA_DEFAULT} ${IREE_BUILD_COMPILER} OFF) |
| 346 | |
Scott Todd | 382fc63 | 2022-06-06 10:57:24 -0700 | [diff] [blame] | 347 | # Non-default target backends either have additional dependencies or are |
| 348 | # experimental/niche in some fashion. |
Scott Todd | 382fc63 | 2022-06-06 10:57:24 -0700 | [diff] [blame] | 349 | cmake_dependent_option(IREE_TARGET_BACKEND_ROCM "Enables the 'rocm' compiler target backend" OFF ${IREE_BUILD_COMPILER} OFF) |
| 350 | # Disable WebGPU by default - it has complex deps and is under development. |
| 351 | cmake_dependent_option(IREE_TARGET_BACKEND_WEBGPU "Enables the 'webgpu' compiler target backend" OFF ${IREE_BUILD_COMPILER} OFF) |
| 352 | |
| 353 | #------------------------------------------------------------------------------- |
Scott Todd | e23d4a7 | 2022-07-27 14:16:39 -0700 | [diff] [blame] | 354 | # Compiler Input Dialects |
| 355 | #------------------------------------------------------------------------------- |
| 356 | |
| 357 | cmake_dependent_option(IREE_INPUT_MHLO "Builds support for compiling MHLO programs" ON ${IREE_BUILD_COMPILER} OFF) |
| 358 | cmake_dependent_option(IREE_INPUT_TORCH "Builds support for compiling Torch MLIR programs" ON ${IREE_BUILD_COMPILER} OFF) |
| 359 | cmake_dependent_option(IREE_INPUT_TOSA "Builds support for compiling TOSA programs" ON ${IREE_BUILD_COMPILER} OFF) |
| 360 | |
Marius Brehler | 36f2451 | 2022-08-04 17:39:03 +0200 | [diff] [blame] | 361 | if(IREE_BUILD_COMPILER) |
| 362 | message(STATUS "IREE compiler input dialects:") |
| 363 | if(IREE_INPUT_MHLO) |
| 364 | message(STATUS " - MHLO") |
| 365 | endif() |
| 366 | if(IREE_INPUT_TORCH) |
| 367 | message(STATUS " - Torch MLIR") |
| 368 | endif() |
| 369 | if(IREE_INPUT_TOSA) |
| 370 | message(STATUS " - TOSA") |
| 371 | endif() |
Scott Todd | e23d4a7 | 2022-07-27 14:16:39 -0700 | [diff] [blame] | 372 | endif() |
| 373 | |
| 374 | #------------------------------------------------------------------------------- |
Scott Todd | 2a1925c | 2022-06-13 10:03:52 -0700 | [diff] [blame] | 375 | # Compiler Output Formats |
| 376 | #------------------------------------------------------------------------------- |
| 377 | |
Scott Todd | 2a1925c | 2022-06-13 10:03:52 -0700 | [diff] [blame] | 378 | cmake_dependent_option(IREE_OUTPUT_FORMAT_C "Enables the 'vm-c' output format, using MLIR EmitC" ON ${IREE_BUILD_COMPILER} OFF) |
| 379 | |
Marius Brehler | 36f2451 | 2022-08-04 17:39:03 +0200 | [diff] [blame] | 380 | if(IREE_BUILD_COMPILER) |
| 381 | message(STATUS "IREE compiler output formats:") |
| 382 | if(IREE_OUTPUT_FORMAT_C) |
Ben Vanik | 09630d6 | 2023-04-13 14:21:40 -0700 | [diff] [blame] | 383 | message(STATUS " - 'vm-c': textual C source module") |
Marius Brehler | 36f2451 | 2022-08-04 17:39:03 +0200 | [diff] [blame] | 384 | endif() |
| 385 | # The 'vm-bytecode' and 'vm-asm' formats are always enabled. |
Ben Vanik | 09630d6 | 2023-04-13 14:21:40 -0700 | [diff] [blame] | 386 | message(STATUS " - 'vm-bytecode': VM bytecode") |
| 387 | message(STATUS " - 'vm-asm': VM MLIR assembly") |
Scott Todd | e23d4a7 | 2022-07-27 14:16:39 -0700 | [diff] [blame] | 388 | endif() |
Scott Todd | e23d4a7 | 2022-07-27 14:16:39 -0700 | [diff] [blame] | 389 | |
Scott Todd | 2a1925c | 2022-06-13 10:03:52 -0700 | [diff] [blame] | 390 | #------------------------------------------------------------------------------- |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 391 | # IREE compilation toolchain configuration |
| 392 | #------------------------------------------------------------------------------- |
| 393 | |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 394 | option(IREE_ENABLE_ASAN "Enable address sanitizer" OFF) |
| 395 | option(IREE_ENABLE_MSAN "Enable memory sanitizer" OFF) |
| 396 | option(IREE_ENABLE_TSAN "Enable thread sanitizer" OFF) |
bjacob | 7cf5b84 | 2022-04-04 16:48:04 -0400 | [diff] [blame] | 397 | option(IREE_BYTECODE_MODULE_ENABLE_TSAN "Enable thread sanitizer in IREE modules in tests" OFF) |
Jakub Kuderski | 068b172 | 2022-07-27 18:14:59 -0400 | [diff] [blame] | 398 | option(IREE_ENABLE_UBSAN "Enable undefined behavior sanitizer" OFF) |
Stella Laurenzo | deb4805 | 2022-11-25 10:41:46 -0800 | [diff] [blame] | 399 | option(IREE_ENABLE_SPLIT_DWARF "Enable gsplit-dwarf for debug information if the platform supports it" OFF) |
| 400 | option(IREE_ENABLE_THIN_ARCHIVES "Enables thin ar archives (elf systems only). Disable for released static archives" OFF) |
Ben Vanik | adadd03 | 2022-11-28 23:18:16 -0800 | [diff] [blame] | 401 | option(IREE_LINK_COMPILER_SHARED_LIBRARY "Links IREE tools using the compiler compiled into a shared library" ON) |
bjacob | 7cf5b84 | 2022-04-04 16:48:04 -0400 | [diff] [blame] | 402 | |
| 403 | # STREQUAL feels wrong here - we don't care about the exact true-value used, |
| 404 | # ON or TRUE or something else. But we haven't been able to think of a less bad |
Scott Todd | c7b2912 | 2023-02-21 17:33:35 -0800 | [diff] [blame] | 405 | # alternative. https://github.com/openxla/iree/pull/8474#discussion_r840790062 |
bjacob | 7cf5b84 | 2022-04-04 16:48:04 -0400 | [diff] [blame] | 406 | if(NOT IREE_ENABLE_TSAN STREQUAL IREE_BYTECODE_MODULE_ENABLE_TSAN) |
| 407 | message(SEND_ERROR |
| 408 | "IREE_ENABLE_TSAN and IREE_BYTECODE_MODULE_ENABLE_TSAN must be " |
| 409 | "simultaneously ON or OFF. " |
| 410 | "A discrepancy between the two would cause tests to crash as IREE " |
| 411 | "runtime code (controlled by IREE_ENABLE_TSAN) calls into test IREE " |
| 412 | "modules (controlled by IREE_BYTECODE_MODULE_ENABLE_TSAN)") |
| 413 | endif() |
| 414 | |
| 415 | if(IREE_BYTECODE_MODULE_ENABLE_TSAN) |
Scott Todd | 352da3f | 2022-07-20 15:25:11 -0700 | [diff] [blame] | 416 | if(NOT IREE_BYTECODE_MODULE_FORCE_LLVM_SYSTEM_LINKER) |
bjacob | 7cf5b84 | 2022-04-04 16:48:04 -0400 | [diff] [blame] | 417 | message(SEND_ERROR |
| 418 | "When IREE_BYTECODE_MODULE_ENABLE_TSAN is ON, " |
Scott Todd | 352da3f | 2022-07-20 15:25:11 -0700 | [diff] [blame] | 419 | "IREE_BYTECODE_MODULE_FORCE_LLVM_SYSTEM_LINKER must also be ON. " |
bjacob | 7cf5b84 | 2022-04-04 16:48:04 -0400 | [diff] [blame] | 420 | "TSAN instrumentation is not currently supported in embedded modules.") |
| 421 | endif() |
| 422 | endif() |
| 423 | |
Scott Todd | 8678138 | 2023-02-07 14:11:52 -0800 | [diff] [blame] | 424 | if(IREE_LINK_COMPILER_SHARED_LIBRARY AND IREE_ENABLE_COMPILER_TRACING) |
| 425 | message(SEND_ERROR |
| 426 | "IREE_ENABLE_COMPILER_TRACING requires " |
| 427 | "-DIREE_LINK_COMPILER_SHARED_LIBRARY=OFF (the compiler library must not " |
| 428 | "be unloaded before Tracy finishes, static linking is one workaround)") |
| 429 | endif() |
| 430 | |
Geoffrey Martin-Noble | 61ea1ed | 2022-11-23 16:25:57 -0800 | [diff] [blame] | 431 | option(IREE_ENABLE_CCACHE |
| 432 | "[DEPRECATED: Use CMAKE_<LANG>_COMPILER_LAUNCHER configure options or environment variables instead.] Use ccache if installed." |
| 433 | OFF) |
bjacob | e694d95 | 2020-11-03 12:05:35 -0500 | [diff] [blame] | 434 | |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 435 | if(IREE_ENABLE_CCACHE) |
Geoffrey Martin-Noble | 61ea1ed | 2022-11-23 16:25:57 -0800 | [diff] [blame] | 436 | message(WARNING |
| 437 | "IREE_ENABLE_CCACHE is deprecated. Use CMAKE_<LANG>_COMPILER_LAUNCHER" |
| 438 | " configure options or environment variables instead.") |
bjacob | e694d95 | 2020-11-03 12:05:35 -0500 | [diff] [blame] | 439 | find_program(CCACHE_PROGRAM ccache) |
| 440 | if(CCACHE_PROGRAM) |
| 441 | set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}") |
Geoffrey Martin-Noble | 61ea1ed | 2022-11-23 16:25:57 -0800 | [diff] [blame] | 442 | else() |
| 443 | message(SEND_ERROR |
| 444 | "IREE_ENABLE_CCACHE was set, but executable `ccache` was not found.") |
bjacob | e694d95 | 2020-11-03 12:05:35 -0500 | [diff] [blame] | 445 | endif() |
| 446 | endif() |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 447 | |
Geoffrey Martin-Noble | 3fa4f8d | 2021-09-10 09:25:27 -0700 | [diff] [blame] | 448 | option(IREE_DEV_MODE "Configure settings to optimize for IREE development (as opposed to CI or release)" OFF) |
Stella Laurenzo | 5b63912 | 2021-06-18 14:44:10 -0700 | [diff] [blame] | 449 | |
| 450 | #------------------------------------------------------------------------------- |
| 451 | # IREE assertions |
| 452 | # We don't love the way this is done, but we have to line it up with how LLVM |
| 453 | # does it and not diverge, since all implementations and all header users must |
| 454 | # have the same definition of NDEBUG. |
| 455 | # |
| 456 | # LLVM defaults LLVM_ENABLE_ASSERTIONS to ON for Debug builds only but then |
| 457 | # conditions itself to only update flags if not building Debug. We just let |
| 458 | # IREE_ENABLE_ASSERTIONS be not conditioned on anything and only update the |
| 459 | # flags in appropriate build types. |
| 460 | # |
| 461 | # If IREE_ENABLE_ASSERTIONS is set ON manually, then |
| 462 | # - NDEBUG must be undefined |
| 463 | # - LLVM_ENABLE_ASSERTIONS is forced off in order to keep multiple parties |
| 464 | # from mucking with globals. |
| 465 | # |
| 466 | # Since CMake forces NDEBUG for !Debug builds, some surgery needs to be done |
| 467 | # at the top level to avoid divergence. |
| 468 | #------------------------------------------------------------------------------- |
| 469 | |
| 470 | option(IREE_ENABLE_ASSERTIONS "Force unset of NDEBUG compile option" OFF) |
| 471 | |
| 472 | # Filter -DNDEBUG from CMAKE_CXX_FLAGS_* and CMAKE_C_FLAGS_* (if |
| 473 | # CMAKE_BUILD_TYPE is not Debug). |
| 474 | function(iree_fix_ndebug) |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 475 | string(TOUPPER "${CMAKE_BUILD_TYPE}" _UPPERCASE_CMAKE_BUILD_TYPE) |
| 476 | if(IREE_ENABLE_ASSERTIONS AND NOT "${_UPPERCASE_CMAKE_BUILD_TYPE}" STREQUAL "DEBUG") |
Stella Laurenzo | 5b63912 | 2021-06-18 14:44:10 -0700 | [diff] [blame] | 477 | # Also remove /D NDEBUG to avoid MSVC warnings about conflicting defines. |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 478 | foreach(_FLAGS_VAR_TO_SCRUB |
| 479 | CMAKE_CXX_FLAGS_${_UPPERCASE_CMAKE_BUILD_TYPE} |
| 480 | CMAKE_C_FLAGS_${_UPPERCASE_CMAKE_BUILD_TYPE}) |
| 481 | set(_ORIGINAL_FLAGS "${${_FLAGS_VAR_TO_SCRUB}}") |
| 482 | string(REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" " " _ALTERED_FLAGS "${_ORIGINAL_FLAGS}") |
| 483 | if(NOT "${_ORIGINAL_FLAGS}" STREQUAL "${_ALTERED_FLAGS}") |
Stella Laurenzo | 5b63912 | 2021-06-18 14:44:10 -0700 | [diff] [blame] | 484 | message(STATUS |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 485 | "IREE_ENABLE_ASSERTIONS force disabled NDEBUG for ${_FLAGS_VAR_TO_SCRUB}: '${_ORIGINAL_FLAGS}' -> '${_ALTERED_FLAGS}'") |
| 486 | set(${_FLAGS_VAR_TO_SCRUB} "${_ALTERED_FLAGS}" PARENT_SCOPE) |
Stella Laurenzo | 5b63912 | 2021-06-18 14:44:10 -0700 | [diff] [blame] | 487 | endif() |
| 488 | endforeach() |
| 489 | |
| 490 | # Make sure that LLVM doesn't add its own logic for assertion disabling. |
| 491 | # We'd like to make sure that we are not dueling over globals. |
| 492 | set(LLVM_ENABLE_ASSERTIONS OFF PARENT_SCOPE) |
| 493 | endif() |
| 494 | endfunction() |
| 495 | iree_fix_ndebug() |
| 496 | |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 497 | #------------------------------------------------------------------------------- |
Lei Zhang | 7e253da | 2020-06-10 07:51:19 -0700 | [diff] [blame] | 498 | # IREE utility definitions |
Lei Zhang | 0d281b7 | 2020-06-01 20:00:23 -0400 | [diff] [blame] | 499 | #------------------------------------------------------------------------------- |
| 500 | |
Scott Todd | d1620f0 | 2021-12-22 14:55:38 -0800 | [diff] [blame] | 501 | list(APPEND CMAKE_MODULE_PATH |
| 502 | ${CMAKE_CURRENT_LIST_DIR}/build_tools/cmake/ |
Scott Todd | d1620f0 | 2021-12-22 14:55:38 -0800 | [diff] [blame] | 503 | ) |
| 504 | |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 505 | include(iree_macros) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 506 | include(iree_copts) |
Ben Vanik | 6b112ef | 2019-10-03 10:45:14 -0700 | [diff] [blame] | 507 | include(iree_cc_binary) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 508 | include(iree_cc_library) |
| 509 | include(iree_cc_test) |
Stella Laurenzo | 17b3e5f | 2023-03-21 16:00:57 -0700 | [diff] [blame] | 510 | include(iree_compiler_plugin) |
Scott Todd | 20d746a | 2023-01-12 09:11:59 -0800 | [diff] [blame] | 511 | include(iree_import_binary) |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 512 | include(iree_external_cmake_options) |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 513 | include(iree_tablegen_library) |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 514 | include(iree_tablegen_doc) |
CindyLiu | 40ed02d | 2021-04-22 16:16:28 +0000 | [diff] [blame] | 515 | include(iree_c_embed_data) |
Ben Vanik | 7f6c57c | 2023-02-07 18:04:32 -0800 | [diff] [blame] | 516 | include(iree_bitcode_library) |
Scott Todd | 11adcab | 2019-12-18 14:10:44 -0800 | [diff] [blame] | 517 | include(iree_bytecode_module) |
Marius Brehler | 46e8331 | 2021-03-25 00:11:39 +0100 | [diff] [blame] | 518 | include(iree_c_module) |
Stella Laurenzo | 94363e2 | 2020-12-15 13:46:14 -0800 | [diff] [blame] | 519 | include(iree_python) |
Geoffrey Martin-Noble | f0eaf37 | 2020-01-28 10:03:14 -0800 | [diff] [blame] | 520 | include(iree_lit_test) |
Stella Laurenzo | 96d959e | 2023-02-19 11:58:14 -0800 | [diff] [blame] | 521 | include(iree_llvm) |
Geoffrey Martin-Noble | 4526dcc | 2020-03-09 11:59:52 -0700 | [diff] [blame] | 522 | include(iree_add_all_subdirs) |
Geoffrey Martin-Noble | e5fd5b5 | 2020-03-31 11:31:30 -0700 | [diff] [blame] | 523 | include(iree_check_test) |
bjacob | 5feef48 | 2021-10-21 16:53:58 -0400 | [diff] [blame] | 524 | include(iree_trace_runner_test) |
Geoffrey Martin-Noble | 435c270 | 2022-01-24 15:56:56 -0800 | [diff] [blame] | 525 | include(iree_native_test) |
Geoffrey Martin-Noble | 2811e50 | 2022-01-25 09:44:40 -0800 | [diff] [blame] | 526 | include(iree_cc_binary_benchmark) |
Geoffrey Martin-Noble | 66d4889 | 2021-10-29 12:24:58 -0700 | [diff] [blame] | 527 | include(iree_benchmark_suite) |
Han-Chung Wang | a6fbb76 | 2022-04-15 14:25:04 -0700 | [diff] [blame] | 528 | include(iree_microbenchmark_suite) |
Scott Todd | 434ff0e | 2021-12-21 10:38:36 -0800 | [diff] [blame] | 529 | include(iree_hal_cts_test_suite) |
CindyLiu | ae72b95 | 2022-08-23 15:26:08 -0700 | [diff] [blame] | 530 | include(iree_static_linker_test) |
Jerry Wu | 116db87 | 2022-09-22 19:33:13 +0000 | [diff] [blame] | 531 | include(iree_fetch_artifact) |
CindyLiu | 080198f | 2022-10-06 07:21:17 -0700 | [diff] [blame] | 532 | include(iree_run_module_test) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 533 | |
Stella Laurenzo | be0f1e1 | 2023-04-03 13:34:38 -0700 | [diff] [blame] | 534 | # Default any sub-tree which doesn't provide its own package namespacing |
| 535 | # to derive it relative to this directory and prefixed with iree/. |
| 536 | set(IREE_PACKAGE_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}") |
Lei Zhang | 923535d | 2023-04-06 18:07:43 -0400 | [diff] [blame] | 537 | set(IREE_PACKAGE_ROOT_PREFIX "iree") |
Stella Laurenzo | be0f1e1 | 2023-04-03 13:34:38 -0700 | [diff] [blame] | 538 | |
Marius Brehler | 06ac36e | 2020-01-10 14:44:11 -0800 | [diff] [blame] | 539 | set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) |
| 540 | |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 541 | #------------------------------------------------------------------------------- |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 542 | # IREE compilation flags |
Scott Todd | 29d654e | 2020-06-11 15:24:17 -0700 | [diff] [blame] | 543 | #------------------------------------------------------------------------------- |
| 544 | |
Lei Zhang | dd21f32 | 2020-09-10 10:47:33 -0400 | [diff] [blame] | 545 | iree_append_list_to_string(CMAKE_C_FLAGS_DEBUG ${IREE_C_FLAGS_DEBUG_LIST}) |
| 546 | iree_append_list_to_string(CMAKE_CXX_FLAGS_DEBUG ${IREE_CXX_FLAGS_DEBUG_LIST}) |
Scott Todd | 29d654e | 2020-06-11 15:24:17 -0700 | [diff] [blame] | 547 | |
| 548 | set(CMAKE_CXX_FLAGS_FASTBUILD "-gmlt" CACHE STRING "Flags used by the C++ compiler during fast builds." FORCE) |
| 549 | set(CMAKE_C_FLAGS_FASTBUILD "-gmlt" CACHE STRING "Flags used by the C compiler during fast builds." FORCE) |
| 550 | set(CMAKE_EXE_LINKER_FLAGS_FASTBUILD "-Wl,-S" CACHE STRING "Flags used for linking binaries during fast builds." FORCE) |
| 551 | set(CMAKE_SHARED_LINKER_FLAGS_FASTBUILD "-Wl,-S" CACHE STRING "Flags used by the shared libraries linker binaries during fast builds." FORCE) |
| 552 | mark_as_advanced( |
| 553 | CMAKE_CXX_FLAGS_FASTBUILD |
| 554 | CMAKE_C_FLAGS_FASTBUILD |
| 555 | CMAKE_EXE_LINKER_FLAGS_FASTBUILD |
| 556 | CMAKE_SHARED_LINKER_FLAGS_FASTBUILD |
| 557 | ) |
| 558 | |
Scott Todd | 7649dee | 2022-07-18 11:31:46 -0700 | [diff] [blame] | 559 | # Override the system's default linker. |
| 560 | # See also: https://llvm.org/docs/CMake.html#llvm-use-linker. |
| 561 | set(IREE_USE_LINKER "" CACHE STRING "") |
| 562 | # Equivalent to setting -DIREE_USE_LINKER=lld. |
| 563 | # Note that unlike LLVM's LLVM_ENABLE_LLD, this does _not_ build lld. You will |
| 564 | # need to either install a recent version of lld or build it from source prior |
| 565 | # to setting this option. See also: https://lld.llvm.org/#using-lld. |
| 566 | # This option is disabled on Apple platforms, where lld is not supported. |
| 567 | cmake_dependent_option(IREE_ENABLE_LLD "Override the system's default linker to lld" OFF "NOT APPLE" OFF) |
| 568 | |
Scott Todd | 29d654e | 2020-06-11 15:24:17 -0700 | [diff] [blame] | 569 | include(iree_setup_toolchain) |
| 570 | |
| 571 | #------------------------------------------------------------------------------- |
Stella Laurenzo | 29032b8 | 2021-10-14 15:21:44 -0700 | [diff] [blame] | 572 | # Python |
| 573 | # If building features that require Python development, find them early in |
| 574 | # one invocation (some CMake versions are sensitive to resolving out of order). |
| 575 | # Otherwise, for features that just require the interpreter, find that alone. |
Stella Laurenzo | a3e97f1 | 2020-12-05 23:29:13 -0800 | [diff] [blame] | 576 | #------------------------------------------------------------------------------- |
| 577 | |
Stella Laurenzo | 29032b8 | 2021-10-14 15:21:44 -0700 | [diff] [blame] | 578 | if(IREE_BUILD_PYTHON_BINDINGS) |
| 579 | # After CMake 3.18, we are able to limit the scope of the search to just |
| 580 | # Development.Module. Searching for Development will fail in situations where |
| 581 | # the Python libraries are not available. When possible, limit to just |
| 582 | # Development.Module. |
| 583 | # See https://pybind11.readthedocs.io/en/stable/compiling.html#findpython-mode |
Scott Todd | a24c8c5 | 2022-05-17 09:22:47 -0700 | [diff] [blame] | 584 | # |
| 585 | # Configuring the Development.Module is flaky in multi-project setups. |
| 586 | # "Bootstrapping" by first looking for the optional Development component |
| 587 | # seems to be robust generally. |
| 588 | # See: https://reviews.llvm.org/D118148 |
| 589 | find_package(Python3 COMPONENTS Interpreter Development) |
| 590 | find_package(Python3 COMPONENTS Interpreter Development.Module REQUIRED) |
Stella Laurenzo | 3149b6d | 2021-10-24 18:45:17 -0700 | [diff] [blame] | 591 | elseif(IREE_BUILD_COMPILER OR IREE_BUILD_TESTS) |
Stella Laurenzo | a3e97f1 | 2020-12-05 23:29:13 -0800 | [diff] [blame] | 592 | find_package(Python3 COMPONENTS Interpreter REQUIRED) |
| 593 | endif() |
| 594 | |
Stella Laurenzo | 3149b6d | 2021-10-24 18:45:17 -0700 | [diff] [blame] | 595 | # Extended Python environment checks. |
| 596 | if(Python3_FOUND) |
| 597 | iree_detect_pyyaml() |
| 598 | endif() |
| 599 | |
| 600 | if(IREE_BUILD_TESTS AND NOT IREE_PYYAML_FOUND) |
| 601 | message(WARNING "IREE's regression test suite requires PyYAML to run all tests. It is not installed, so some tests will be disabled.") |
| 602 | endif() |
| 603 | |
Stella Laurenzo | a3e97f1 | 2020-12-05 23:29:13 -0800 | [diff] [blame] | 604 | #------------------------------------------------------------------------------- |
Niloy Sikdar | 47238df | 2021-07-28 23:37:33 +0530 | [diff] [blame] | 605 | # Check if git submodules have been initialized. |
| 606 | # This will only run if python3 is available. |
| 607 | #------------------------------------------------------------------------------- |
| 608 | |
Marius Brehler | 776d7e6 | 2021-12-21 22:50:52 +0100 | [diff] [blame] | 609 | option(IREE_ERROR_ON_MISSING_SUBMODULES "Error if submodules have not been initialized." ON) |
| 610 | |
Niloy Sikdar | 47238df | 2021-07-28 23:37:33 +0530 | [diff] [blame] | 611 | find_package(Python3 COMPONENTS Interpreter QUIET) |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 612 | find_package(Git) |
Marius Brehler | 776d7e6 | 2021-12-21 22:50:52 +0100 | [diff] [blame] | 613 | if(IREE_ERROR_ON_MISSING_SUBMODULES AND Python3_FOUND AND Git_FOUND) |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 614 | # Only check submodule status when the git commit changes. |
Niloy Sikdar | 47238df | 2021-07-28 23:37:33 +0530 | [diff] [blame] | 615 | execute_process( |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 616 | COMMAND git rev-parse --short HEAD |
Niloy Sikdar | 47238df | 2021-07-28 23:37:33 +0530 | [diff] [blame] | 617 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 618 | RESULT_VARIABLE SHORT_HASH_RESULT |
| 619 | OUTPUT_VARIABLE SHORT_HASH) |
| 620 | string(REGEX REPLACE "\n$" "" SHORT_HASH "${SHORT_HASH}") |
Scott Todd | 2a8cd3b | 2021-12-13 11:58:44 -0800 | [diff] [blame] | 621 | if(SHORT_HASH_RESULT EQUAL "0" AND NOT "${IREE_GIT_SHORT_HASH}" STREQUAL "${SHORT_HASH}") |
CindyLiu | 0e8fdc6 | 2022-10-14 09:35:44 -0700 | [diff] [blame] | 622 | if(NOT IREE_BUILD_COMPILER) |
| 623 | set(CHECK_SUBMODULE_ARGS "--runtime_only") |
| 624 | endif() |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 625 | execute_process( |
CindyLiu | 0e8fdc6 | 2022-10-14 09:35:44 -0700 | [diff] [blame] | 626 | COMMAND ${Python3_EXECUTABLE} build_tools/scripts/git/check_submodule_init.py ${CHECK_SUBMODULE_ARGS} |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 627 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 628 | RESULT_VARIABLE SUBMODULE_INIT_RESULT |
| 629 | ) |
| 630 | if(NOT SUBMODULE_INIT_RESULT EQUAL "0") |
| 631 | message(FATAL_ERROR "check_submodule_init.py failed, see the logs above") |
| 632 | else() |
| 633 | set(IREE_GIT_SHORT_HASH "${SHORT_HASH}" CACHE STRING "" FORCE) |
| 634 | endif() |
Niloy Sikdar | 47238df | 2021-07-28 23:37:33 +0530 | [diff] [blame] | 635 | endif() |
| 636 | endif() |
| 637 | |
| 638 | #------------------------------------------------------------------------------- |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 639 | # IREE top-level targets |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 640 | # We define these here because various things in the build tree adds |
| 641 | # dependencies to them. |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 642 | #------------------------------------------------------------------------------- |
| 643 | |
Jerry Wu | 5740497 | 2023-03-02 22:16:11 +0000 | [diff] [blame] | 644 | if(IREE_BUILD_E2E_TEST_ARTIFACTS) |
Jerry Wu | 43305f7 | 2023-05-23 17:17:20 +0000 | [diff] [blame] | 645 | # iree-benchmark-import-models imports benchmark models from their source |
| 646 | # formats, such as .tflite flatbuffers, to IREE-compatible .mlir files. |
| 647 | add_custom_target(iree-benchmark-import-models) |
| 648 | |
| 649 | # iree-benchmark-suites* fully prepares benchmark models for benchmarking: |
| 650 | # * importing from source formats to IREE-compatible .mlir files |
| 651 | # * compiling from .mlir files to benchmark-ready .vmfb files |
| 652 | # Build default benchmark suites. |
| 653 | add_custom_target(iree-benchmark-suites) |
| 654 | # Build long-running benchmark suites. |
| 655 | add_custom_target(iree-benchmark-suites-long) |
| 656 | |
| 657 | # iree-e2e-compile-stats-suites* compiles the benchmark models with specific |
Jerry Wu | fb87ad1 | 2022-12-21 05:59:02 +0000 | [diff] [blame] | 658 | # flags to collect the compilation statistics. |
Jerry Wu | 43305f7 | 2023-05-23 17:17:20 +0000 | [diff] [blame] | 659 | # Build for default benchmark suites. |
Jerry Wu | fb87ad1 | 2022-12-21 05:59:02 +0000 | [diff] [blame] | 660 | add_custom_target(iree-e2e-compile-stats-suites) |
Jerry Wu | 43305f7 | 2023-05-23 17:17:20 +0000 | [diff] [blame] | 661 | # Build for long-running benchmark suites. |
| 662 | add_custom_target(iree-e2e-compile-stats-suites-long) |
Jerry Wu | fb87ad1 | 2022-12-21 05:59:02 +0000 | [diff] [blame] | 663 | |
Jerry Wu | d41d073 | 2022-11-23 01:43:55 +0000 | [diff] [blame] | 664 | # iree-e2e-test-artifacts builds all e2e test artifacts, including benchmarks |
| 665 | # and model tests. |
| 666 | add_custom_target(iree-e2e-test-artifacts) |
Jerry Wu | d41d073 | 2022-11-23 01:43:55 +0000 | [diff] [blame] | 667 | add_dependencies(iree-e2e-test-artifacts |
| 668 | iree-benchmark-import-models |
| 669 | iree-benchmark-suites |
Jerry Wu | 43305f7 | 2023-05-23 17:17:20 +0000 | [diff] [blame] | 670 | iree-benchmark-suites-long |
Jerry Wu | fb87ad1 | 2022-12-21 05:59:02 +0000 | [diff] [blame] | 671 | iree-e2e-compile-stats-suites |
Jerry Wu | 43305f7 | 2023-05-23 17:17:20 +0000 | [diff] [blame] | 672 | iree-e2e-compile-stats-suites-long |
Jerry Wu | d41d073 | 2022-11-23 01:43:55 +0000 | [diff] [blame] | 673 | ) |
| 674 | endif() |
| 675 | |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 676 | if(IREE_BUILD_MICROBENCHMARKS) |
Han-Chung Wang | a6fbb76 | 2022-04-15 14:25:04 -0700 | [diff] [blame] | 677 | # Add top-level custom targets to drive generating microbenchmark suites. |
| 678 | add_custom_target(iree-microbenchmark-suites) |
| 679 | endif() |
| 680 | |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 681 | if(IREE_BUILD_DOCS) |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 682 | # Add a top-level custom target to drive generating all documentation. |
| 683 | # Register it to the default target given that IREE_BUILD_DOCS is explicitly |
| 684 | # requested. |
| 685 | add_custom_target(iree-doc ALL) |
| 686 | endif() |
| 687 | |
Jakub Kuderski | 3f76468 | 2023-02-07 17:14:23 -0500 | [diff] [blame] | 688 | # Samples may require additional files to be built/configured and will add |
| 689 | # dependencies to this target. |
| 690 | # Note: These will be automatically built with test dependencies |
| 691 | # (`iree-test-deps`). |
| 692 | add_custom_target(iree-sample-deps |
| 693 | COMMENT |
| 694 | "Building IREE sample data targets" |
| 695 | ) |
| 696 | |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 697 | # Testing rules that require generation will add dependencies to this target. |
| 698 | # This allows them to be EXCLUDE_FROM_ALL but still invokable. |
Jakub Kuderski | 3f76468 | 2023-02-07 17:14:23 -0500 | [diff] [blame] | 699 | add_custom_target(iree-test-deps |
| 700 | COMMENT |
| 701 | "Building IREE test deps" |
| 702 | DEPENDS |
| 703 | iree-sample-deps |
| 704 | ) |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 705 | |
CindyLiu | 99373e0 | 2022-10-12 09:22:24 -0700 | [diff] [blame] | 706 | # Testing rules that generate test scripts for iree-run-module-test will add |
| 707 | # dependencies to this target. It is a subset of `iree-test-deps`. |
| 708 | add_custom_target(iree-run-module-test-deps |
| 709 | COMMENT |
| 710 | "Building IREE run module test targets" |
| 711 | ) |
| 712 | |
Stella Laurenzo | e2dfc65 | 2023-02-15 18:12:03 -0800 | [diff] [blame] | 713 | # Convenience target for running IREE tests. |
| 714 | add_custom_target(iree-run-tests |
| 715 | COMMENT |
| 716 | "Run IREE unit tests" |
| 717 | WORKING_DIRECTORY |
| 718 | "${CMAKE_CURRENT_BINARY_DIR}" |
| 719 | USES_TERMINAL |
| 720 | COMMAND |
| 721 | "${CMAKE_COMMAND}" -E echo |
| 722 | "The 'iree-run-tests' target is a helper for running ctest. For advanced" |
| 723 | "options, build dependencies and invoke ctest independently as in:" |
| 724 | COMMAND |
| 725 | "${CMAKE_COMMAND}" -E echo |
| 726 | " \\(cd ${CMAKE_CURRENT_BINARY_DIR} \\&\\& cmake --build . --target iree-test-deps \\&\\& ctest --output-on-failure\\)" |
| 727 | COMMAND |
| 728 | "${CMAKE_COMMAND}" -E echo |
| 729 | "Run tests in parallel by setting a variable like CTEST_PARALLEL_LEVEL=25." |
| 730 | COMMAND |
| 731 | "${CMAKE_CTEST_COMMAND}" |
| 732 | --output-on-failure |
| 733 | ) |
| 734 | add_dependencies(iree-run-tests iree-test-deps) |
| 735 | |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 736 | #------------------------------------------------------------------------------- |
| 737 | # CUDA configuration for both the compiler and runtime. |
| 738 | # We do this at the top level so that we can fail fast and make global |
| 739 | # decisions that effect both compiler and runtime. It also helps with error |
| 740 | # messaging to do this all in one place, since we can provide very targeted |
| 741 | # advice. |
| 742 | #------------------------------------------------------------------------------- |
| 743 | |
| 744 | set(IREE_CUDA_LIBDEVICE_PATH "" CACHE FILEPATH "Absolute path to an appropriate libdevice.*.bc (needed to build the IREE cuda compiler target)") |
| 745 | |
| 746 | # If any CUDA features are being built, try to locate a CUDA SDK. We will fall |
| 747 | # back to this as needed for specific features. |
| 748 | if(IREE_TARGET_BACKEND_CUDA OR IREE_HAL_DRIVER_CUDA) |
| 749 | add_subdirectory(build_tools/third_party/cuda EXCLUDE_FROM_ALL) |
| 750 | endif() |
| 751 | |
| 752 | #------------------------------------------------------------------------------- |
| 753 | # MLIR/LLVM Dependency |
| 754 | #------------------------------------------------------------------------------- |
| 755 | |
| 756 | if(NOT IREE_BUILD_COMPILER) |
| 757 | message(STATUS "Not adding LLVM/MLIR because the configuration does not require it") |
| 758 | else() |
Stella Laurenzo | 289b9a1 | 2023-02-24 13:06:32 -0800 | [diff] [blame] | 759 | # Force enable BUILD_SHARED_LIBS for the compiler if instructed. |
| 760 | set(_IREE_ORIG_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) |
| 761 | if(IREE_COMPILER_BUILD_SHARED_LIBS) |
| 762 | set(BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE) |
| 763 | endif() |
| 764 | |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 765 | # Get the main LLVM deps. |
| 766 | if(IREE_BUILD_BUNDLED_LLVM) |
| 767 | iree_llvm_configure_bundled() |
| 768 | else() |
| 769 | iree_llvm_configure_installed() |
| 770 | endif() |
| 771 | |
| 772 | # Also add a library that can be depended on to get LLVM includes setup |
| 773 | # properly. bazel_to_cmake targets this for some header only pseudo deps. |
| 774 | add_library(IREELLVMIncludeSetup INTERFACE) |
| 775 | target_include_directories(IREELLVMIncludeSetup INTERFACE |
| 776 | ${LLVM_INCLUDE_DIRS} |
| 777 | ${MLIR_INCLUDE_DIRS} |
| 778 | ${LLD_INCLUDE_DIRS} |
| 779 | ) |
| 780 | |
| 781 | # Splice the includes setup into base LLVM libraries so that using them |
| 782 | # gets everything nice and tidy. It would be super if some day, LLVM |
| 783 | # libraries set their right usage requirements for includes. In the meantime |
| 784 | # we add usage requirements to libraries at the root of all things LLVM. |
| 785 | iree_llvm_add_usage_requirements(LLVMSupport IREELLVMIncludeSetup) |
| 786 | iree_llvm_add_usage_requirements(MLIRSupport IREELLVMIncludeSetup) |
| 787 | |
| 788 | # Add default external projects. |
| 789 | iree_llvm_add_external_project(mlir-iree-dialects ${CMAKE_CURRENT_SOURCE_DIR}/llvm-external-projects/iree-dialects) |
| 790 | iree_llvm_add_external_project(mlir-hlo ${CMAKE_CURRENT_SOURCE_DIR}/third_party/mlir-hlo) |
| 791 | if(IREE_INPUT_TORCH) |
| 792 | iree_llvm_add_external_project(torch-mlir-dialects ${CMAKE_CURRENT_SOURCE_DIR}/third_party/torch-mlir-dialects) |
| 793 | endif() |
| 794 | |
| 795 | # Ensure that LLVM-based dependencies needed for testing are included. |
| 796 | add_dependencies(iree-test-deps FileCheck) |
| 797 | if(IREE_LLD_TARGET) |
| 798 | add_dependencies(iree-test-deps ${IREE_LLD_TARGET}) |
| 799 | endif() |
| 800 | if(IREE_CLANG_TARGET) |
| 801 | add_dependencies(iree-test-deps ${IREE_CLANG_TARGET}) |
| 802 | endif() |
Stella Laurenzo | 289b9a1 | 2023-02-24 13:06:32 -0800 | [diff] [blame] | 803 | |
| 804 | set(BUILD_SHARED_LIBS ${_IREE_ORIG_BUILD_SHARED_LIBS} CACHE BOOL "" FORCE) |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 805 | endif() |
| 806 | |
| 807 | #------------------------------------------------------------------------------- |
| 808 | # Other dependencies |
| 809 | #------------------------------------------------------------------------------- |
| 810 | |
| 811 | include(external_cc_library) |
| 812 | include(flatbuffer_c_library) |
| 813 | |
| 814 | add_subdirectory(build_tools/third_party/libyaml EXCLUDE_FROM_ALL) |
| 815 | add_subdirectory(build_tools/third_party/llvm-project EXCLUDE_FROM_ALL) |
| 816 | add_subdirectory(build_tools/third_party/tracy_client EXCLUDE_FROM_ALL) |
| 817 | add_subdirectory(build_tools/third_party/vulkan_memory_allocator EXCLUDE_FROM_ALL) |
| 818 | |
| 819 | iree_set_googletest_cmake_options() |
| 820 | add_subdirectory(third_party/googletest EXCLUDE_FROM_ALL) |
| 821 | |
| 822 | if(IREE_ENABLE_THREADING) |
| 823 | iree_set_benchmark_cmake_options() |
| 824 | add_subdirectory(third_party/benchmark EXCLUDE_FROM_ALL) |
| 825 | if(IREE_ENABLE_CPUINFO) |
| 826 | iree_set_cpuinfo_cmake_options() |
| 827 | add_subdirectory(third_party/cpuinfo EXCLUDE_FROM_ALL) |
| 828 | endif() |
| 829 | endif() |
| 830 | |
| 831 | # This defines the iree-flatcc-cli target, so we don't use EXCLUDE_FROM_ALL. |
| 832 | add_subdirectory(build_tools/third_party/flatcc) |
| 833 | |
| 834 | if(IREE_HAL_DRIVER_CUDA) |
| 835 | add_subdirectory(build_tools/third_party/nccl EXCLUDE_FROM_ALL) |
| 836 | endif() |
| 837 | |
| 838 | if(IREE_HAL_DRIVER_VULKAN) |
| 839 | add_subdirectory(third_party/vulkan_headers EXCLUDE_FROM_ALL) |
| 840 | endif() |
| 841 | |
| 842 | if(IREE_BUILD_COMPILER) |
| 843 | add_subdirectory(build_tools/third_party/mlir-hlo EXCLUDE_FROM_ALL) |
| 844 | endif() |
| 845 | |
| 846 | if(IREE_BUILD_TESTS) |
| 847 | include(iree_configure_testing) |
| 848 | endif() |
| 849 | |
| 850 | if(IREE_BUILD_PYTHON_BINDINGS) |
| 851 | if(NOT TARGET pybind11::module) |
| 852 | message(STATUS "Using bundled pybind11") |
| 853 | add_subdirectory(third_party/pybind11 EXCLUDE_FROM_ALL) |
| 854 | else() |
| 855 | message(STATUS "Not including bundled pybind11 (already configured)") |
| 856 | endif() |
| 857 | endif() |
| 858 | |
| 859 | if(IREE_TARGET_BACKEND_METAL_SPIRV) |
| 860 | iree_set_spirv_cross_cmake_options() |
| 861 | # SPIRV-Cross is needed to cross compile SPIR-V into MSL source code. |
| 862 | add_subdirectory(third_party/spirv_cross EXCLUDE_FROM_ALL) |
| 863 | endif() |
| 864 | |
| 865 | if(IREE_TARGET_BACKEND_WEBGPU) |
| 866 | # Tint is needed to compile SPIR-V into WGSL source code. |
| 867 | # Tint also requires SPIRV-Tools, which requires SPIRV-Headers. |
| 868 | iree_set_spirv_headers_cmake_options() |
| 869 | add_subdirectory(third_party/spirv_headers EXCLUDE_FROM_ALL) |
| 870 | add_subdirectory(build_tools/third_party/spirv-tools EXCLUDE_FROM_ALL) |
| 871 | add_subdirectory(build_tools/third_party/tint EXCLUDE_FROM_ALL) |
| 872 | endif() |
Stella Laurenzo | e2dfc65 | 2023-02-15 18:12:03 -0800 | [diff] [blame] | 873 | |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 874 | #------------------------------------------------------------------------------- |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 875 | # IREE top-level libraries |
| 876 | #------------------------------------------------------------------------------- |
| 877 | |
Rob Suderman | d42e002 | 2022-06-08 16:38:45 -0700 | [diff] [blame] | 878 | if(IREE_ENABLE_CLANG_TIDY) |
| 879 | set(CMAKE_CXX_CLANG_TIDY clang-tidy -warnings-as-errors=*) |
| 880 | endif() |
| 881 | |
Marius Brehler | f5022e8 | 2019-12-13 15:20:25 -0800 | [diff] [blame] | 882 | add_subdirectory(build_tools/embed_data/) |
| 883 | |
Jerry Wu | 36641f9 | 2023-05-24 19:30:38 +0000 | [diff] [blame] | 884 | if(IREE_BUILD_E2E_TEST_ARTIFACTS) |
Stella Laurenzo | a6bf65c | 2022-01-11 20:47:51 -0800 | [diff] [blame] | 885 | find_program(IREE_IMPORT_TFLITE_PATH iree-import-tflite) |
| 886 | if(IREE_IMPORT_TFLITE_PATH) |
| 887 | message(STATUS "Found ${IREE_IMPORT_TFLITE_PATH} to generate benchmark artifacts") |
| 888 | else() |
| 889 | message(STATUS "iree-import-tflite not found. Some benchmarks may not configure") |
| 890 | endif() |
Jerry Wu | 60798ca | 2022-06-21 23:36:40 +0000 | [diff] [blame] | 891 | find_program(IREE_IMPORT_TF_PATH iree-import-tf) |
| 892 | if(IREE_IMPORT_TF_PATH) |
| 893 | message(STATUS "Found ${IREE_IMPORT_TF_PATH} to generate benchmark artifacts") |
| 894 | else() |
| 895 | message(STATUS "iree-import-tf not found. Some benchmarks may not configure") |
| 896 | endif() |
Jerry Wu | 16e2d9c | 2022-11-22 06:19:46 +0000 | [diff] [blame] | 897 | endif() |
| 898 | |
| 899 | # Note: Test deps are not built as part of all (use the iree-test-deps target). |
| 900 | add_subdirectory(tests EXCLUDE_FROM_ALL) |
| 901 | |
Jacques Pienaar | 702929a | 2022-12-30 14:46:22 -0800 | [diff] [blame] | 902 | # tools/ can depend on compiler/ and runtime/. |
| 903 | # Note: tools sub directory is added before compiler/ so that phony targets for |
| 904 | # files with the same names from different rules are disambiguated towards |
| 905 | # those in tools/. |
| 906 | add_subdirectory(tools) |
Stella Laurenzo | 309dc5b | 2023-02-22 23:07:43 -0800 | [diff] [blame] | 907 | add_subdirectory(compiler) |
Scott Todd | 4f16b99 | 2022-05-17 10:33:53 -0700 | [diff] [blame] | 908 | add_subdirectory(runtime) |
| 909 | |
Rob Suderman | d42e002 | 2022-06-08 16:38:45 -0700 | [diff] [blame] | 910 | if(IREE_ENABLE_CLANG_TIDY) |
| 911 | set(CMAKE_CXX_CLANG_TIDY "") |
| 912 | endif() |
| 913 | |
Stella Laurenzo | d3770ff | 2021-10-18 22:54:18 -0700 | [diff] [blame] | 914 | if(IREE_BUILD_TRACY) |
Stella Laurenzo | 3149b6d | 2021-10-24 18:45:17 -0700 | [diff] [blame] | 915 | if(NOT CMAKE_SYSTEM_NAME MATCHES "Linux") |
Stella Laurenzo | d3770ff | 2021-10-18 22:54:18 -0700 | [diff] [blame] | 916 | message(WARNING "Building Tracy (IREE_BUILD_TRACY) on non-Linux is unsupported and may fail below.") |
| 917 | endif() |
| 918 | add_subdirectory(build_tools/third_party/tracy ${CMAKE_CURRENT_BINARY_DIR}/tracy) |
| 919 | if(NOT TARGET IREETracyCaptureServer) |
| 920 | message(SEND_ERROR "Could not build Tracy. Either unset IREE_BUILD_TRACY or look for missing dependencies above and install them.") |
| 921 | endif() |
| 922 | endif() |
| 923 | |
Scott Todd | f57ab75 | 2022-05-23 10:36:44 -0700 | [diff] [blame] | 924 | # Order constraint: The python bindings install tools targets from tools/ |
Stella Laurenzo | d3770ff | 2021-10-18 22:54:18 -0700 | [diff] [blame] | 925 | # and tracy, and must come after it. |
Stella Laurenzo | 3b44a0a | 2022-04-18 19:57:57 -0700 | [diff] [blame] | 926 | if(IREE_BUILD_PYTHON_BINDINGS) |
Stella Laurenzo | 6012859 | 2022-04-17 21:52:09 -0700 | [diff] [blame] | 927 | # Write out a .env file to make IDEs and developers happy. |
| 928 | # Yes, we are writing this to the source dir. It is only for IDEs and if |
Scott Todd | fe9cb17 | 2022-12-08 09:17:52 -0800 | [diff] [blame] | 929 | # it gets clobbered, it is fine (it is also ignored in .gitignore). |
Stella Laurenzo | 41a2ceb | 2022-04-29 12:49:36 -0700 | [diff] [blame] | 930 | set(_PYTHONPATH_ENV "PYTHONPATH=$<SHELL_PATH:${CMAKE_CURRENT_BINARY_DIR}/compiler/bindings/python;${CMAKE_CURRENT_BINARY_DIR}/runtime/bindings/python>\n") |
Scott Todd | fe9cb17 | 2022-12-08 09:17:52 -0800 | [diff] [blame] | 931 | file(GENERATE OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/.env" CONTENT "${_PYTHONPATH_ENV}") |
| 932 | file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/.env" CONTENT "${_PYTHONPATH_ENV}") |
| 933 | # Similarly, write out .env.bat for Windows. |
| 934 | set(_PYTHONPATH_ENV_BAT "set PYTHONPATH=$<SHELL_PATH:${CMAKE_CURRENT_BINARY_DIR}/compiler/bindings/python;${CMAKE_CURRENT_BINARY_DIR}/runtime/bindings/python>\n") |
| 935 | file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/.env.bat" CONTENT "${_PYTHONPATH_ENV_BAT}") |
Stella Laurenzo | 77a63cd | 2021-01-04 17:29:54 -0800 | [diff] [blame] | 936 | endif() |
| 937 | |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 938 | if(IREE_BUILD_BINDINGS_TFLITE) |
Scott Todd | ada25e6 | 2022-05-03 16:16:15 -0700 | [diff] [blame] | 939 | add_subdirectory(runtime/bindings/tflite) |
Ben Vanik | cd1132f | 2021-01-29 15:58:17 -0800 | [diff] [blame] | 940 | endif() |
| 941 | |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 942 | if(IREE_BUILD_EXPERIMENTAL_WEB_SAMPLES) |
Scott Todd | 15fce0a | 2022-02-14 12:43:23 -0800 | [diff] [blame] | 943 | add_subdirectory(experimental/web) |
Scott Todd | f237b5e | 2022-01-28 11:02:25 -0800 | [diff] [blame] | 944 | endif() |
| 945 | |
bjacob | 3dc368e | 2023-05-09 12:50:18 -0400 | [diff] [blame] | 946 | if(IREE_BUILD_EXPERIMENTAL_CPU_UKERNEL_PLUGINS) |
| 947 | add_subdirectory(experimental/cpu_ukernel) |
| 948 | endif() |
| 949 | |
Stella Laurenzo | 03e48db | 2020-06-11 18:35:13 -0700 | [diff] [blame] | 950 | set(IREE_PUBLIC_INCLUDE_DIRS "${IREE_COMMON_INCLUDE_DIRS}" |
| 951 | CACHE INTERNAL "IREE: Include Directories" FORCE) |
Stella Laurenzo | 688670f | 2021-09-24 18:16:25 -0700 | [diff] [blame] | 952 | |
Jerry Wu | 623d174 | 2022-03-31 18:16:02 +0000 | [diff] [blame] | 953 | #------------------------------------------------------------------------------- |
Jerry Wu | 161daa7 | 2023-05-22 22:08:49 +0000 | [diff] [blame] | 954 | # IREE build tools |
Jerry Wu | 623d174 | 2022-03-31 18:16:02 +0000 | [diff] [blame] | 955 | #------------------------------------------------------------------------------- |
| 956 | |
| 957 | add_subdirectory(build_tools/benchmarks) |
Jerry Wu | 161daa7 | 2023-05-22 22:08:49 +0000 | [diff] [blame] | 958 | add_subdirectory(build_tools/github_actions) |
Jerry Wu | 71562cc | 2022-09-20 18:56:41 -0700 | [diff] [blame] | 959 | add_subdirectory(build_tools/python) |
| 960 | |
| 961 | #------------------------------------------------------------------------------- |
Stella Laurenzo | c6092c4 | 2023-03-25 19:55:37 -0700 | [diff] [blame] | 962 | # Optional features |
Stella Laurenzo | 3b44a0a | 2022-04-18 19:57:57 -0700 | [diff] [blame] | 963 | #------------------------------------------------------------------------------- |
| 964 | |
Scott Todd | 4c022df | 2022-05-10 16:55:18 -0700 | [diff] [blame] | 965 | # samples/ can depend on anything, so we include it last |
Stella Laurenzo | 1e8d1fa | 2022-04-22 09:50:43 -0700 | [diff] [blame] | 966 | if(IREE_BUILD_SAMPLES) |
| 967 | add_subdirectory(samples) |
| 968 | endif() |
Geoffrey Martin-Noble | 10f1822 | 2022-06-09 16:00:13 -0700 | [diff] [blame] | 969 | |
| 970 | if(IREE_BUILD_TESTS) |
| 971 | iree_create_ctest_customization() |
| 972 | endif() |