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 | # Properties building and controlling benchmark suites. |
| 90 | option(IREE_BUILD_BENCHMARKS "Builds IREE benchmark suites." OFF) |
| 91 | # TODO(pzread): Currently IREE_ENABLE_COMPILATION_BENCHMARKS needs |
| 92 | # IREE_BUILD_BENCHMARKS. Eventually we will decouple them. |
| 93 | cmake_dependent_option(IREE_ENABLE_COMPILATION_BENCHMARKS "Builds IREE benchmark suites for compilation statistics." OFF ${IREE_BUILD_BENCHMARKS} OFF) |
| 94 | |
| 95 | option(IREE_BUILD_MICROBENCHMARKS "Builds IREE microbenchmark suites." OFF) |
| 96 | |
Stella Laurenzo | 0f005e5 | 2020-12-27 11:54:33 -0800 | [diff] [blame] | 97 | #------------------------------------------------------------------------------- |
| 98 | # Experimental project flags |
| 99 | #------------------------------------------------------------------------------- |
| 100 | |
Ben Vanik | a372ab5 | 2022-07-25 18:40:22 -0700 | [diff] [blame] | 101 | option(IREE_BUILD_EXPERIMENTAL_VMVX_MMT4D "Enables MMT4D methods in the VMVX module." OFF) |
Scott Todd | f237b5e | 2022-01-28 11:02:25 -0800 | [diff] [blame] | 102 | option(IREE_BUILD_EXPERIMENTAL_WEB_SAMPLES "Builds experimental web samples." OFF) |
Jerry Wu | 16e2d9c | 2022-11-22 06:19:46 +0000 | [diff] [blame] | 103 | option(IREE_BUILD_EXPERIMENTAL_E2E_TEST_ARTIFACTS "Builds IREE E2E test artifacts suite generated by the e2e test framework." OFF) |
Stella Laurenzo | 0f005e5 | 2020-12-27 11:54:33 -0800 | [diff] [blame] | 104 | |
| 105 | #------------------------------------------------------------------------------- |
Scott Todd | 18a5485 | 2023-01-27 08:52:12 -0800 | [diff] [blame] | 106 | # CUDA Toolkit. |
| 107 | # |
| 108 | # Using the (optional) CUDA support in the compiler and runtime requires the |
| 109 | # NVIDIA CUDA Toolkit. The toolkit can either be installed ahead of time or |
| 110 | # it can be automatically downloaded on certain host architectures. |
Scott Todd | 9fa5de7 | 2023-01-23 14:40:18 -0800 | [diff] [blame] | 111 | #------------------------------------------------------------------------------- |
| 112 | |
Scott Todd | 18a5485 | 2023-01-27 08:52:12 -0800 | [diff] [blame] | 113 | set(IREE_CUDA_AVAILABLE OFF) |
| 114 | find_package(CUDAToolkit) |
| 115 | if(CUDAToolkit_FOUND) |
| 116 | set(IREE_CUDA_AVAILABLE ON) |
| 117 | else() |
| 118 | # We can download the SDK in build_tools/third_party/cuda/CMakeLists.txt, if |
| 119 | # on a supported platform/arch. |
| 120 | if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR WIN32) |
| 121 | if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "(x86_64)|(AMD64|amd64)") |
| 122 | set(IREE_CUDA_AVAILABLE ON) |
| 123 | endif() |
Scott Todd | 9fa5de7 | 2023-01-23 14:40:18 -0800 | [diff] [blame] | 124 | endif() |
| 125 | endif() |
| 126 | |
| 127 | #------------------------------------------------------------------------------- |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 128 | # Runtime HAL Driver Options |
| 129 | # By default, all runtime drivers supported by the current platform which do |
| 130 | # not require external deps are enabled by default. This can be changed with: |
| 131 | # -DIREE_HAL_DRIVER_DEFAULTS=OFF |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 132 | #------------------------------------------------------------------------------- |
| 133 | |
Ben Vanik | 4e6af05 | 2022-06-07 17:10:20 -0700 | [diff] [blame] | 134 | # External HAL drivers; see runtime/src/iree/hal/drivers/CMakeLists.txt for more |
| 135 | # information on how to declare external drivers. |
| 136 | set(IREE_EXTERNAL_HAL_DRIVERS "" CACHE STRING "") |
| 137 | |
Ben Vanik | 8916027 | 2022-09-26 16:44:11 -0700 | [diff] [blame] | 138 | # Additional executable loader deps to add dependent libraries to any target |
| 139 | # using the default executable loader registration utilities. |
| 140 | # TODO(benvanik): extend the deps to encompass the built-in loaders too so that |
| 141 | # we have one flag. We could also support a list of deps and automatically |
| 142 | # generate the registration from that via a configure file. |
| 143 | set(IREE_HAL_EXECUTABLE_LOADER_EXTRA_DEPS "" CACHE STRING "") |
| 144 | |
Scott Todd | d1620f0 | 2021-12-22 14:55:38 -0800 | [diff] [blame] | 145 | 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] | 146 | |
Scott Todd | 9fa5de7 | 2023-01-23 14:40:18 -0800 | [diff] [blame] | 147 | # CUDA support is enabled by default if the platform supports the CUDA SDK and |
| 148 | # not cross compiling. Note: a CUDA-compatible GPU with drivers is still |
| 149 | # required to actually run CUDA workloads. |
| 150 | set(IREE_HAL_DRIVER_CUDA_DEFAULT ${IREE_HAL_DRIVER_DEFAULTS}) |
Scott Todd | 18a5485 | 2023-01-27 08:52:12 -0800 | [diff] [blame] | 151 | if(NOT IREE_CUDA_AVAILABLE OR CMAKE_CROSSCOMPILING) |
Scott Todd | 9fa5de7 | 2023-01-23 14:40:18 -0800 | [diff] [blame] | 152 | set(IREE_HAL_DRIVER_CUDA_DEFAULT OFF) |
| 153 | endif() |
| 154 | |
| 155 | # Vulkan support is enabled by default if the platform might support Vulkan. |
| 156 | # Apple platforms support Metal instead of Vulkan, though MoltenVK may work. |
| 157 | set(IREE_HAL_DRIVER_VULKAN_DEFAULT ${IREE_HAL_DRIVER_DEFAULTS}) |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 158 | if(APPLE) |
Scott Todd | d1620f0 | 2021-12-22 14:55:38 -0800 | [diff] [blame] | 159 | set(IREE_HAL_DRIVER_VULKAN_DEFAULT OFF) |
Scott Todd | d1620f0 | 2021-12-22 14:55:38 -0800 | [diff] [blame] | 160 | endif() |
Marius Brehler | 0a4b67f | 2020-05-08 13:19:16 -0700 | [diff] [blame] | 161 | |
Scott Todd | d1620f0 | 2021-12-22 14:55:38 -0800 | [diff] [blame] | 162 | 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] | 163 | option(IREE_HAL_DRIVER_LOCAL_SYNC "Enables the 'local-sync' runtime HAL driver" ${IREE_HAL_DRIVER_DEFAULTS}) |
| 164 | option(IREE_HAL_DRIVER_LOCAL_TASK "Enables the 'local-task' runtime HAL driver" ${IREE_HAL_DRIVER_DEFAULTS}) |
| 165 | option(IREE_HAL_DRIVER_VULKAN "Enables the 'vulkan' runtime HAL driver" ${IREE_HAL_DRIVER_VULKAN_DEFAULT}) |
| 166 | |
Ben Vanik | 6e64b6e | 2022-06-07 09:14:53 -0700 | [diff] [blame] | 167 | option(IREE_HAL_EXECUTABLE_LOADER_DEFAULTS "Sets the default value for all runtime HAL executable loaders" ON) |
| 168 | set(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF_DEFAULT ${IREE_HAL_EXECUTABLE_LOADER_DEFAULTS}) |
| 169 | set(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY_DEFAULT ${IREE_HAL_EXECUTABLE_LOADER_DEFAULTS}) |
| 170 | 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] | 171 | |
| 172 | # Emscripten builds don't support embedded ELF libraries. |
| 173 | if(EMSCRIPTEN) |
Ben Vanik | 2e8540e | 2022-06-06 20:39:34 -0700 | [diff] [blame] | 174 | set(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF_DEFAULT OFF) |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 175 | endif() |
| 176 | |
| 177 | # If forcing system libraries (for TSAN/debugging tools/etc) then ensure the |
| 178 | # system library loader is linked in. |
Scott Todd | 352da3f | 2022-07-20 15:25:11 -0700 | [diff] [blame] | 179 | if(IREE_BYTECODE_MODULE_FORCE_LLVM_SYSTEM_LINKER) |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 180 | set(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY_DEFAULT ON) |
| 181 | endif() |
| 182 | |
Ben Vanik | 6e64b6e | 2022-06-07 09:14:53 -0700 | [diff] [blame] | 183 | # If no local driver is enabled then we force all the loaders off; this allows |
| 184 | # for simpler checks that don't need to see if both the driver and loader is |
| 185 | # available. |
| 186 | if(NOT IREE_HAL_DRIVER_LOCAL_SYNC AND NOT IREE_HAL_DRIVER_LOCAL_TASK) |
| 187 | set(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF_DEFAULT OFF) |
| 188 | set(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY_DEFAULT OFF) |
| 189 | set(IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE_DEFAULT OFF) |
| 190 | endif() |
| 191 | |
Ben Vanik | 2e8540e | 2022-06-06 20:39:34 -0700 | [diff] [blame] | 192 | 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] | 193 | option(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY "Enables the system dynamic library loader for local HAL drivers" ${IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY_DEFAULT}) |
| 194 | option(IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE "Enables the VMVX module loader for local HAL drivers" ${IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE_DEFAULT}) |
| 195 | |
Scott Todd | 0f1f8eb | 2022-06-10 15:53:30 -0700 | [diff] [blame] | 196 | if(IREE_BUILD_COMPILER) |
| 197 | # The compiler requires the local task driver with the VMVX loader. |
| 198 | set(IREE_HAL_DRIVER_LOCAL_TASK ON) |
| 199 | set(IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE ON) |
| 200 | endif() |
| 201 | |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 202 | message(STATUS "IREE HAL drivers:") |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 203 | if(IREE_HAL_DRIVER_CUDA) |
| 204 | message(STATUS " - cuda") |
| 205 | endif() |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 206 | if(IREE_HAL_DRIVER_LOCAL_SYNC) |
| 207 | message(STATUS " - local-sync") |
| 208 | endif() |
| 209 | if(IREE_HAL_DRIVER_LOCAL_TASK) |
| 210 | message(STATUS " - local-task") |
| 211 | endif() |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 212 | if(IREE_HAL_DRIVER_VULKAN) |
| 213 | message(STATUS " - vulkan") |
| 214 | endif() |
Ben Vanik | 4e6af05 | 2022-06-07 17:10:20 -0700 | [diff] [blame] | 215 | if(IREE_EXTERNAL_HAL_DRIVERS) |
| 216 | message(STATUS " + external: ${IREE_EXTERNAL_HAL_DRIVERS}") |
| 217 | endif() |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 218 | |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 219 | message(STATUS "IREE HAL local executable library loaders:") |
Ben Vanik | 2e8540e | 2022-06-06 20:39:34 -0700 | [diff] [blame] | 220 | if(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF) |
| 221 | message(STATUS " - embedded-elf") |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 222 | endif() |
| 223 | if(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY) |
| 224 | message(STATUS " - system-library") |
| 225 | endif() |
| 226 | if(IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE) |
| 227 | message(STATUS " - vmvx-module") |
| 228 | endif() |
| 229 | |
Lei Zhang | 0d281b7 | 2020-06-01 20:00:23 -0400 | [diff] [blame] | 230 | #------------------------------------------------------------------------------- |
Ben Vanik | 4e6af05 | 2022-06-07 17:10:20 -0700 | [diff] [blame] | 231 | # Experimental ROCM HAL driver |
| 232 | #------------------------------------------------------------------------------- |
| 233 | |
| 234 | set(IREE_EXTERNAL_ROCM_HAL_DRIVER_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/experimental/rocm") |
| 235 | set(IREE_EXTERNAL_ROCM_HAL_DRIVER_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/experimental/rocm") |
| 236 | set(IREE_EXTERNAL_ROCM_HAL_DRIVER_TARGET "iree::experimental::rocm::registration") |
| 237 | set(IREE_EXTERNAL_ROCM_HAL_DRIVER_REGISTER "iree_hal_rocm_driver_module_register") |
| 238 | |
| 239 | #------------------------------------------------------------------------------- |
Scott Todd | 382fc63 | 2022-06-06 10:57:24 -0700 | [diff] [blame] | 240 | # Compiler Target Options |
Scott Todd | 9fa5de7 | 2023-01-23 14:40:18 -0800 | [diff] [blame] | 241 | # By default, all compiler targets supported by the current platform are |
| 242 | # enabled. Some compiler targets like CUDA will install external deps as |
| 243 | # needed at configure time. This can be changed with: |
Scott Todd | 382fc63 | 2022-06-06 10:57:24 -0700 | [diff] [blame] | 244 | # -DIREE_TARGET_BACKEND_DEFAULTS=OFF |
| 245 | #------------------------------------------------------------------------------- |
| 246 | |
| 247 | option(IREE_TARGET_BACKEND_DEFAULTS "Sets the default value for all compiler target backends" ON) |
| 248 | |
| 249 | # The VMVX backend is always enabled. |
| 250 | cmake_dependent_option(IREE_TARGET_BACKEND_VMVX "Enables the 'vmvx' compiler target backend" ON ${IREE_BUILD_COMPILER} OFF) |
| 251 | |
| 252 | # Supported default target backends. |
Scott Todd | 352da3f | 2022-07-20 15:25:11 -0700 | [diff] [blame] | 253 | cmake_dependent_option(IREE_TARGET_BACKEND_LLVM_CPU "Enables the 'llvm-cpu' compiler target backend" ${IREE_TARGET_BACKEND_DEFAULTS} ${IREE_BUILD_COMPILER} OFF) |
| 254 | 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] | 255 | 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] | 256 | cmake_dependent_option(IREE_TARGET_BACKEND_VULKAN_SPIRV "Enables the 'vulkan-spirv' compiler target backend" ${IREE_TARGET_BACKEND_DEFAULTS} ${IREE_BUILD_COMPILER} OFF) |
| 257 | |
Scott Todd | 9fa5de7 | 2023-01-23 14:40:18 -0800 | [diff] [blame] | 258 | # Supported default target backends that are only available on certain |
| 259 | # platforms. |
| 260 | set(IREE_TARGET_BACKEND_CUDA_DEFAULT ${IREE_TARGET_BACKEND_DEFAULTS}) |
Scott Todd | 18a5485 | 2023-01-27 08:52:12 -0800 | [diff] [blame] | 261 | if(NOT IREE_CUDA_AVAILABLE) |
Scott Todd | 9fa5de7 | 2023-01-23 14:40:18 -0800 | [diff] [blame] | 262 | set(IREE_TARGET_BACKEND_CUDA_DEFAULT OFF) |
| 263 | endif() |
| 264 | cmake_dependent_option(IREE_TARGET_BACKEND_CUDA "Enables the 'cuda' compiler target backend" ${IREE_TARGET_BACKEND_CUDA_DEFAULT} ${IREE_BUILD_COMPILER} OFF) |
| 265 | |
Scott Todd | 382fc63 | 2022-06-06 10:57:24 -0700 | [diff] [blame] | 266 | # Non-default target backends either have additional dependencies or are |
| 267 | # experimental/niche in some fashion. |
Scott Todd | 382fc63 | 2022-06-06 10:57:24 -0700 | [diff] [blame] | 268 | cmake_dependent_option(IREE_TARGET_BACKEND_ROCM "Enables the 'rocm' compiler target backend" OFF ${IREE_BUILD_COMPILER} OFF) |
| 269 | # Disable WebGPU by default - it has complex deps and is under development. |
| 270 | cmake_dependent_option(IREE_TARGET_BACKEND_WEBGPU "Enables the 'webgpu' compiler target backend" OFF ${IREE_BUILD_COMPILER} OFF) |
| 271 | |
| 272 | #------------------------------------------------------------------------------- |
Scott Todd | e23d4a7 | 2022-07-27 14:16:39 -0700 | [diff] [blame] | 273 | # Compiler Input Dialects |
| 274 | #------------------------------------------------------------------------------- |
| 275 | |
| 276 | cmake_dependent_option(IREE_INPUT_MHLO "Builds support for compiling MHLO programs" ON ${IREE_BUILD_COMPILER} OFF) |
| 277 | cmake_dependent_option(IREE_INPUT_TORCH "Builds support for compiling Torch MLIR programs" ON ${IREE_BUILD_COMPILER} OFF) |
| 278 | cmake_dependent_option(IREE_INPUT_TOSA "Builds support for compiling TOSA programs" ON ${IREE_BUILD_COMPILER} OFF) |
| 279 | |
Marius Brehler | 36f2451 | 2022-08-04 17:39:03 +0200 | [diff] [blame] | 280 | if(IREE_BUILD_COMPILER) |
| 281 | message(STATUS "IREE compiler input dialects:") |
| 282 | if(IREE_INPUT_MHLO) |
| 283 | message(STATUS " - MHLO") |
| 284 | endif() |
| 285 | if(IREE_INPUT_TORCH) |
| 286 | message(STATUS " - Torch MLIR") |
| 287 | endif() |
| 288 | if(IREE_INPUT_TOSA) |
| 289 | message(STATUS " - TOSA") |
| 290 | endif() |
Scott Todd | e23d4a7 | 2022-07-27 14:16:39 -0700 | [diff] [blame] | 291 | endif() |
| 292 | |
| 293 | #------------------------------------------------------------------------------- |
Scott Todd | 2a1925c | 2022-06-13 10:03:52 -0700 | [diff] [blame] | 294 | # Compiler Output Formats |
| 295 | #------------------------------------------------------------------------------- |
| 296 | |
Scott Todd | 2a1925c | 2022-06-13 10:03:52 -0700 | [diff] [blame] | 297 | cmake_dependent_option(IREE_OUTPUT_FORMAT_C "Enables the 'vm-c' output format, using MLIR EmitC" ON ${IREE_BUILD_COMPILER} OFF) |
| 298 | |
Marius Brehler | 36f2451 | 2022-08-04 17:39:03 +0200 | [diff] [blame] | 299 | if(IREE_BUILD_COMPILER) |
| 300 | message(STATUS "IREE compiler output formats:") |
| 301 | if(IREE_OUTPUT_FORMAT_C) |
| 302 | message(STATUS " - C source module") |
| 303 | endif() |
| 304 | # The 'vm-bytecode' and 'vm-asm' formats are always enabled. |
| 305 | message(STATUS " - VM Bytecode") |
| 306 | message(STATUS " - VM MLIR Assembly") |
Scott Todd | e23d4a7 | 2022-07-27 14:16:39 -0700 | [diff] [blame] | 307 | endif() |
Scott Todd | e23d4a7 | 2022-07-27 14:16:39 -0700 | [diff] [blame] | 308 | |
Scott Todd | 2a1925c | 2022-06-13 10:03:52 -0700 | [diff] [blame] | 309 | #------------------------------------------------------------------------------- |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 310 | # IREE compilation toolchain configuration |
| 311 | #------------------------------------------------------------------------------- |
| 312 | |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 313 | option(IREE_ENABLE_ASAN "Enable address sanitizer" OFF) |
| 314 | option(IREE_ENABLE_MSAN "Enable memory sanitizer" OFF) |
| 315 | option(IREE_ENABLE_TSAN "Enable thread sanitizer" OFF) |
bjacob | 7cf5b84 | 2022-04-04 16:48:04 -0400 | [diff] [blame] | 316 | 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] | 317 | option(IREE_ENABLE_UBSAN "Enable undefined behavior sanitizer" OFF) |
Stella Laurenzo | deb4805 | 2022-11-25 10:41:46 -0800 | [diff] [blame] | 318 | option(IREE_ENABLE_SPLIT_DWARF "Enable gsplit-dwarf for debug information if the platform supports it" OFF) |
| 319 | 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] | 320 | 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] | 321 | |
| 322 | # STREQUAL feels wrong here - we don't care about the exact true-value used, |
| 323 | # ON or TRUE or something else. But we haven't been able to think of a less bad |
Scott Todd | 7df3973 | 2022-06-28 09:21:35 -0700 | [diff] [blame] | 324 | # alternative. https://github.com/iree-org/iree/pull/8474#discussion_r840790062 |
bjacob | 7cf5b84 | 2022-04-04 16:48:04 -0400 | [diff] [blame] | 325 | if(NOT IREE_ENABLE_TSAN STREQUAL IREE_BYTECODE_MODULE_ENABLE_TSAN) |
| 326 | message(SEND_ERROR |
| 327 | "IREE_ENABLE_TSAN and IREE_BYTECODE_MODULE_ENABLE_TSAN must be " |
| 328 | "simultaneously ON or OFF. " |
| 329 | "A discrepancy between the two would cause tests to crash as IREE " |
| 330 | "runtime code (controlled by IREE_ENABLE_TSAN) calls into test IREE " |
| 331 | "modules (controlled by IREE_BYTECODE_MODULE_ENABLE_TSAN)") |
| 332 | endif() |
| 333 | |
| 334 | if(IREE_BYTECODE_MODULE_ENABLE_TSAN) |
Scott Todd | 352da3f | 2022-07-20 15:25:11 -0700 | [diff] [blame] | 335 | if(NOT IREE_BYTECODE_MODULE_FORCE_LLVM_SYSTEM_LINKER) |
bjacob | 7cf5b84 | 2022-04-04 16:48:04 -0400 | [diff] [blame] | 336 | message(SEND_ERROR |
| 337 | "When IREE_BYTECODE_MODULE_ENABLE_TSAN is ON, " |
Scott Todd | 352da3f | 2022-07-20 15:25:11 -0700 | [diff] [blame] | 338 | "IREE_BYTECODE_MODULE_FORCE_LLVM_SYSTEM_LINKER must also be ON. " |
bjacob | 7cf5b84 | 2022-04-04 16:48:04 -0400 | [diff] [blame] | 339 | "TSAN instrumentation is not currently supported in embedded modules.") |
| 340 | endif() |
| 341 | endif() |
| 342 | |
Scott Todd | 8678138 | 2023-02-07 14:11:52 -0800 | [diff] [blame] | 343 | if(IREE_LINK_COMPILER_SHARED_LIBRARY AND IREE_ENABLE_COMPILER_TRACING) |
| 344 | message(SEND_ERROR |
| 345 | "IREE_ENABLE_COMPILER_TRACING requires " |
| 346 | "-DIREE_LINK_COMPILER_SHARED_LIBRARY=OFF (the compiler library must not " |
| 347 | "be unloaded before Tracy finishes, static linking is one workaround)") |
| 348 | endif() |
| 349 | |
Geoffrey Martin-Noble | 61ea1ed | 2022-11-23 16:25:57 -0800 | [diff] [blame] | 350 | option(IREE_ENABLE_CCACHE |
| 351 | "[DEPRECATED: Use CMAKE_<LANG>_COMPILER_LAUNCHER configure options or environment variables instead.] Use ccache if installed." |
| 352 | OFF) |
bjacob | e694d95 | 2020-11-03 12:05:35 -0500 | [diff] [blame] | 353 | |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 354 | if(IREE_ENABLE_CCACHE) |
Geoffrey Martin-Noble | 61ea1ed | 2022-11-23 16:25:57 -0800 | [diff] [blame] | 355 | message(WARNING |
| 356 | "IREE_ENABLE_CCACHE is deprecated. Use CMAKE_<LANG>_COMPILER_LAUNCHER" |
| 357 | " configure options or environment variables instead.") |
bjacob | e694d95 | 2020-11-03 12:05:35 -0500 | [diff] [blame] | 358 | find_program(CCACHE_PROGRAM ccache) |
| 359 | if(CCACHE_PROGRAM) |
| 360 | set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}") |
Geoffrey Martin-Noble | 61ea1ed | 2022-11-23 16:25:57 -0800 | [diff] [blame] | 361 | else() |
| 362 | message(SEND_ERROR |
| 363 | "IREE_ENABLE_CCACHE was set, but executable `ccache` was not found.") |
bjacob | e694d95 | 2020-11-03 12:05:35 -0500 | [diff] [blame] | 364 | endif() |
| 365 | endif() |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 366 | |
Geoffrey Martin-Noble | 3fa4f8d | 2021-09-10 09:25:27 -0700 | [diff] [blame] | 367 | 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] | 368 | |
| 369 | #------------------------------------------------------------------------------- |
| 370 | # IREE assertions |
| 371 | # We don't love the way this is done, but we have to line it up with how LLVM |
| 372 | # does it and not diverge, since all implementations and all header users must |
| 373 | # have the same definition of NDEBUG. |
| 374 | # |
| 375 | # LLVM defaults LLVM_ENABLE_ASSERTIONS to ON for Debug builds only but then |
| 376 | # conditions itself to only update flags if not building Debug. We just let |
| 377 | # IREE_ENABLE_ASSERTIONS be not conditioned on anything and only update the |
| 378 | # flags in appropriate build types. |
| 379 | # |
| 380 | # If IREE_ENABLE_ASSERTIONS is set ON manually, then |
| 381 | # - NDEBUG must be undefined |
| 382 | # - LLVM_ENABLE_ASSERTIONS is forced off in order to keep multiple parties |
| 383 | # from mucking with globals. |
| 384 | # |
| 385 | # Since CMake forces NDEBUG for !Debug builds, some surgery needs to be done |
| 386 | # at the top level to avoid divergence. |
| 387 | #------------------------------------------------------------------------------- |
| 388 | |
| 389 | option(IREE_ENABLE_ASSERTIONS "Force unset of NDEBUG compile option" OFF) |
| 390 | |
| 391 | # Filter -DNDEBUG from CMAKE_CXX_FLAGS_* and CMAKE_C_FLAGS_* (if |
| 392 | # CMAKE_BUILD_TYPE is not Debug). |
| 393 | function(iree_fix_ndebug) |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 394 | string(TOUPPER "${CMAKE_BUILD_TYPE}" _UPPERCASE_CMAKE_BUILD_TYPE) |
| 395 | if(IREE_ENABLE_ASSERTIONS AND NOT "${_UPPERCASE_CMAKE_BUILD_TYPE}" STREQUAL "DEBUG") |
Stella Laurenzo | 5b63912 | 2021-06-18 14:44:10 -0700 | [diff] [blame] | 396 | # Also remove /D NDEBUG to avoid MSVC warnings about conflicting defines. |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 397 | foreach(_FLAGS_VAR_TO_SCRUB |
| 398 | CMAKE_CXX_FLAGS_${_UPPERCASE_CMAKE_BUILD_TYPE} |
| 399 | CMAKE_C_FLAGS_${_UPPERCASE_CMAKE_BUILD_TYPE}) |
| 400 | set(_ORIGINAL_FLAGS "${${_FLAGS_VAR_TO_SCRUB}}") |
| 401 | string(REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" " " _ALTERED_FLAGS "${_ORIGINAL_FLAGS}") |
| 402 | if(NOT "${_ORIGINAL_FLAGS}" STREQUAL "${_ALTERED_FLAGS}") |
Stella Laurenzo | 5b63912 | 2021-06-18 14:44:10 -0700 | [diff] [blame] | 403 | message(STATUS |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 404 | "IREE_ENABLE_ASSERTIONS force disabled NDEBUG for ${_FLAGS_VAR_TO_SCRUB}: '${_ORIGINAL_FLAGS}' -> '${_ALTERED_FLAGS}'") |
| 405 | set(${_FLAGS_VAR_TO_SCRUB} "${_ALTERED_FLAGS}" PARENT_SCOPE) |
Stella Laurenzo | 5b63912 | 2021-06-18 14:44:10 -0700 | [diff] [blame] | 406 | endif() |
| 407 | endforeach() |
| 408 | |
| 409 | # Make sure that LLVM doesn't add its own logic for assertion disabling. |
| 410 | # We'd like to make sure that we are not dueling over globals. |
| 411 | set(LLVM_ENABLE_ASSERTIONS OFF PARENT_SCOPE) |
| 412 | endif() |
| 413 | endfunction() |
| 414 | iree_fix_ndebug() |
| 415 | |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 416 | #------------------------------------------------------------------------------- |
Lei Zhang | 7e253da | 2020-06-10 07:51:19 -0700 | [diff] [blame] | 417 | # IREE utility definitions |
Lei Zhang | 0d281b7 | 2020-06-01 20:00:23 -0400 | [diff] [blame] | 418 | #------------------------------------------------------------------------------- |
| 419 | |
Scott Todd | d1620f0 | 2021-12-22 14:55:38 -0800 | [diff] [blame] | 420 | list(APPEND CMAKE_MODULE_PATH |
| 421 | ${CMAKE_CURRENT_LIST_DIR}/build_tools/cmake/ |
Scott Todd | d1620f0 | 2021-12-22 14:55:38 -0800 | [diff] [blame] | 422 | ) |
| 423 | |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 424 | include(iree_macros) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 425 | include(iree_copts) |
Ben Vanik | 6b112ef | 2019-10-03 10:45:14 -0700 | [diff] [blame] | 426 | include(iree_cc_binary) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 427 | include(iree_cc_library) |
| 428 | include(iree_cc_test) |
Scott Todd | 20d746a | 2023-01-12 09:11:59 -0800 | [diff] [blame] | 429 | include(iree_import_binary) |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 430 | include(iree_external_cmake_options) |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 431 | include(iree_tablegen_library) |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 432 | include(iree_tablegen_doc) |
CindyLiu | 40ed02d | 2021-04-22 16:16:28 +0000 | [diff] [blame] | 433 | include(iree_c_embed_data) |
Ben Vanik | 7f6c57c | 2023-02-07 18:04:32 -0800 | [diff] [blame^] | 434 | include(iree_bitcode_library) |
Scott Todd | 11adcab | 2019-12-18 14:10:44 -0800 | [diff] [blame] | 435 | include(iree_bytecode_module) |
Marius Brehler | 46e8331 | 2021-03-25 00:11:39 +0100 | [diff] [blame] | 436 | include(iree_c_module) |
Stella Laurenzo | 94363e2 | 2020-12-15 13:46:14 -0800 | [diff] [blame] | 437 | include(iree_python) |
Geoffrey Martin-Noble | f0eaf37 | 2020-01-28 10:03:14 -0800 | [diff] [blame] | 438 | include(iree_lit_test) |
Stella Laurenzo | 96d959e | 2023-02-19 11:58:14 -0800 | [diff] [blame] | 439 | include(iree_llvm) |
Geoffrey Martin-Noble | 4526dcc | 2020-03-09 11:59:52 -0700 | [diff] [blame] | 440 | include(iree_add_all_subdirs) |
Geoffrey Martin-Noble | e5fd5b5 | 2020-03-31 11:31:30 -0700 | [diff] [blame] | 441 | include(iree_check_test) |
bjacob | 5feef48 | 2021-10-21 16:53:58 -0400 | [diff] [blame] | 442 | include(iree_trace_runner_test) |
Geoffrey Martin-Noble | 435c270 | 2022-01-24 15:56:56 -0800 | [diff] [blame] | 443 | include(iree_native_test) |
Geoffrey Martin-Noble | 2811e50 | 2022-01-25 09:44:40 -0800 | [diff] [blame] | 444 | include(iree_cc_binary_benchmark) |
Geoffrey Martin-Noble | 66d4889 | 2021-10-29 12:24:58 -0700 | [diff] [blame] | 445 | include(iree_benchmark_suite) |
Han-Chung Wang | a6fbb76 | 2022-04-15 14:25:04 -0700 | [diff] [blame] | 446 | include(iree_microbenchmark_suite) |
Scott Todd | 434ff0e | 2021-12-21 10:38:36 -0800 | [diff] [blame] | 447 | include(iree_hal_cts_test_suite) |
CindyLiu | ae72b95 | 2022-08-23 15:26:08 -0700 | [diff] [blame] | 448 | include(iree_static_linker_test) |
Jerry Wu | 116db87 | 2022-09-22 19:33:13 +0000 | [diff] [blame] | 449 | include(iree_fetch_artifact) |
CindyLiu | 080198f | 2022-10-06 07:21:17 -0700 | [diff] [blame] | 450 | include(iree_run_module_test) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 451 | |
Marius Brehler | 06ac36e | 2020-01-10 14:44:11 -0800 | [diff] [blame] | 452 | set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) |
| 453 | |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 454 | #------------------------------------------------------------------------------- |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 455 | # IREE compilation flags |
Scott Todd | 29d654e | 2020-06-11 15:24:17 -0700 | [diff] [blame] | 456 | #------------------------------------------------------------------------------- |
| 457 | |
Lei Zhang | dd21f32 | 2020-09-10 10:47:33 -0400 | [diff] [blame] | 458 | iree_append_list_to_string(CMAKE_C_FLAGS_DEBUG ${IREE_C_FLAGS_DEBUG_LIST}) |
| 459 | 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] | 460 | |
| 461 | set(CMAKE_CXX_FLAGS_FASTBUILD "-gmlt" CACHE STRING "Flags used by the C++ compiler during fast builds." FORCE) |
| 462 | set(CMAKE_C_FLAGS_FASTBUILD "-gmlt" CACHE STRING "Flags used by the C compiler during fast builds." FORCE) |
| 463 | set(CMAKE_EXE_LINKER_FLAGS_FASTBUILD "-Wl,-S" CACHE STRING "Flags used for linking binaries during fast builds." FORCE) |
| 464 | set(CMAKE_SHARED_LINKER_FLAGS_FASTBUILD "-Wl,-S" CACHE STRING "Flags used by the shared libraries linker binaries during fast builds." FORCE) |
| 465 | mark_as_advanced( |
| 466 | CMAKE_CXX_FLAGS_FASTBUILD |
| 467 | CMAKE_C_FLAGS_FASTBUILD |
| 468 | CMAKE_EXE_LINKER_FLAGS_FASTBUILD |
| 469 | CMAKE_SHARED_LINKER_FLAGS_FASTBUILD |
| 470 | ) |
| 471 | |
Scott Todd | 7649dee | 2022-07-18 11:31:46 -0700 | [diff] [blame] | 472 | # Override the system's default linker. |
| 473 | # See also: https://llvm.org/docs/CMake.html#llvm-use-linker. |
| 474 | set(IREE_USE_LINKER "" CACHE STRING "") |
| 475 | # Equivalent to setting -DIREE_USE_LINKER=lld. |
| 476 | # Note that unlike LLVM's LLVM_ENABLE_LLD, this does _not_ build lld. You will |
| 477 | # need to either install a recent version of lld or build it from source prior |
| 478 | # to setting this option. See also: https://lld.llvm.org/#using-lld. |
| 479 | # This option is disabled on Apple platforms, where lld is not supported. |
| 480 | cmake_dependent_option(IREE_ENABLE_LLD "Override the system's default linker to lld" OFF "NOT APPLE" OFF) |
| 481 | |
Scott Todd | 29d654e | 2020-06-11 15:24:17 -0700 | [diff] [blame] | 482 | include(iree_setup_toolchain) |
| 483 | |
| 484 | #------------------------------------------------------------------------------- |
Stella Laurenzo | 29032b8 | 2021-10-14 15:21:44 -0700 | [diff] [blame] | 485 | # Python |
| 486 | # If building features that require Python development, find them early in |
| 487 | # one invocation (some CMake versions are sensitive to resolving out of order). |
| 488 | # Otherwise, for features that just require the interpreter, find that alone. |
Stella Laurenzo | a3e97f1 | 2020-12-05 23:29:13 -0800 | [diff] [blame] | 489 | #------------------------------------------------------------------------------- |
| 490 | |
Stella Laurenzo | 29032b8 | 2021-10-14 15:21:44 -0700 | [diff] [blame] | 491 | if(IREE_BUILD_PYTHON_BINDINGS) |
| 492 | # After CMake 3.18, we are able to limit the scope of the search to just |
| 493 | # Development.Module. Searching for Development will fail in situations where |
| 494 | # the Python libraries are not available. When possible, limit to just |
| 495 | # Development.Module. |
| 496 | # See https://pybind11.readthedocs.io/en/stable/compiling.html#findpython-mode |
Scott Todd | a24c8c5 | 2022-05-17 09:22:47 -0700 | [diff] [blame] | 497 | # |
| 498 | # Configuring the Development.Module is flaky in multi-project setups. |
| 499 | # "Bootstrapping" by first looking for the optional Development component |
| 500 | # seems to be robust generally. |
| 501 | # See: https://reviews.llvm.org/D118148 |
| 502 | find_package(Python3 COMPONENTS Interpreter Development) |
| 503 | find_package(Python3 COMPONENTS Interpreter Development.Module REQUIRED) |
Stella Laurenzo | 3149b6d | 2021-10-24 18:45:17 -0700 | [diff] [blame] | 504 | elseif(IREE_BUILD_COMPILER OR IREE_BUILD_TESTS) |
Stella Laurenzo | a3e97f1 | 2020-12-05 23:29:13 -0800 | [diff] [blame] | 505 | find_package(Python3 COMPONENTS Interpreter REQUIRED) |
| 506 | endif() |
| 507 | |
Stella Laurenzo | 3149b6d | 2021-10-24 18:45:17 -0700 | [diff] [blame] | 508 | # Extended Python environment checks. |
| 509 | if(Python3_FOUND) |
| 510 | iree_detect_pyyaml() |
| 511 | endif() |
| 512 | |
| 513 | if(IREE_BUILD_TESTS AND NOT IREE_PYYAML_FOUND) |
| 514 | message(WARNING "IREE's regression test suite requires PyYAML to run all tests. It is not installed, so some tests will be disabled.") |
| 515 | endif() |
| 516 | |
Stella Laurenzo | a3e97f1 | 2020-12-05 23:29:13 -0800 | [diff] [blame] | 517 | #------------------------------------------------------------------------------- |
Niloy Sikdar | 47238df | 2021-07-28 23:37:33 +0530 | [diff] [blame] | 518 | # Check if git submodules have been initialized. |
| 519 | # This will only run if python3 is available. |
| 520 | #------------------------------------------------------------------------------- |
| 521 | |
Marius Brehler | 776d7e6 | 2021-12-21 22:50:52 +0100 | [diff] [blame] | 522 | option(IREE_ERROR_ON_MISSING_SUBMODULES "Error if submodules have not been initialized." ON) |
| 523 | |
Niloy Sikdar | 47238df | 2021-07-28 23:37:33 +0530 | [diff] [blame] | 524 | find_package(Python3 COMPONENTS Interpreter QUIET) |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 525 | find_package(Git) |
Marius Brehler | 776d7e6 | 2021-12-21 22:50:52 +0100 | [diff] [blame] | 526 | if(IREE_ERROR_ON_MISSING_SUBMODULES AND Python3_FOUND AND Git_FOUND) |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 527 | # Only check submodule status when the git commit changes. |
Niloy Sikdar | 47238df | 2021-07-28 23:37:33 +0530 | [diff] [blame] | 528 | execute_process( |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 529 | COMMAND git rev-parse --short HEAD |
Niloy Sikdar | 47238df | 2021-07-28 23:37:33 +0530 | [diff] [blame] | 530 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 531 | RESULT_VARIABLE SHORT_HASH_RESULT |
| 532 | OUTPUT_VARIABLE SHORT_HASH) |
| 533 | string(REGEX REPLACE "\n$" "" SHORT_HASH "${SHORT_HASH}") |
Scott Todd | 2a8cd3b | 2021-12-13 11:58:44 -0800 | [diff] [blame] | 534 | 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] | 535 | if(NOT IREE_BUILD_COMPILER) |
| 536 | set(CHECK_SUBMODULE_ARGS "--runtime_only") |
| 537 | endif() |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 538 | execute_process( |
CindyLiu | 0e8fdc6 | 2022-10-14 09:35:44 -0700 | [diff] [blame] | 539 | 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] | 540 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 541 | RESULT_VARIABLE SUBMODULE_INIT_RESULT |
| 542 | ) |
| 543 | if(NOT SUBMODULE_INIT_RESULT EQUAL "0") |
| 544 | message(FATAL_ERROR "check_submodule_init.py failed, see the logs above") |
| 545 | else() |
| 546 | set(IREE_GIT_SHORT_HASH "${SHORT_HASH}" CACHE STRING "" FORCE) |
| 547 | endif() |
Niloy Sikdar | 47238df | 2021-07-28 23:37:33 +0530 | [diff] [blame] | 548 | endif() |
| 549 | endif() |
| 550 | |
| 551 | #------------------------------------------------------------------------------- |
Stella Laurenzo | 9838866 | 2022-02-03 15:37:30 -0800 | [diff] [blame] | 552 | # CUDA configuration for both the compiler and runtime. |
| 553 | # We do this at the top level so that we can fail fast and make global |
| 554 | # decisions that effect both compiler and runtime. It also helps with error |
| 555 | # messaging to do this all in one place, since we can provide very targeted |
| 556 | # advice. |
| 557 | #------------------------------------------------------------------------------- |
| 558 | |
Lei Zhang | 299fc93 | 2022-12-08 16:04:35 -0800 | [diff] [blame] | 559 | set(IREE_CUDA_LIBDEVICE_PATH "" CACHE FILEPATH "Absolute path to an appropriate libdevice.*.bc (needed to build the IREE cuda compiler target)") |
Stella Laurenzo | 9838866 | 2022-02-03 15:37:30 -0800 | [diff] [blame] | 560 | |
| 561 | # If any CUDA features are being built, try to locate a CUDA SDK. We will fall |
| 562 | # back to this as needed for specific features. |
| 563 | if(IREE_TARGET_BACKEND_CUDA OR IREE_HAL_DRIVER_CUDA) |
Stella Laurenzo | a9d23f6 | 2022-12-27 17:28:58 -0800 | [diff] [blame] | 564 | add_subdirectory(build_tools/third_party/cuda EXCLUDE_FROM_ALL) |
Stella Laurenzo | 9838866 | 2022-02-03 15:37:30 -0800 | [diff] [blame] | 565 | endif() |
| 566 | |
| 567 | #------------------------------------------------------------------------------- |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 568 | # MLIR/LLVM Dependency |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 569 | #------------------------------------------------------------------------------- |
| 570 | |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 571 | if(NOT IREE_BUILD_COMPILER) |
| 572 | message(STATUS "Not adding LLVM/MLIR because the configuration does not require it") |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 573 | else() |
Stella Laurenzo | 96d959e | 2023-02-19 11:58:14 -0800 | [diff] [blame] | 574 | # Get the main LLVM deps. |
| 575 | if(IREE_BUILD_BUNDLED_LLVM) |
| 576 | iree_llvm_configure_bundled() |
| 577 | else() |
| 578 | iree_llvm_configure_installed() |
Stella Laurenzo | 688670f | 2021-09-24 18:16:25 -0700 | [diff] [blame] | 579 | endif() |
| 580 | |
Stella Laurenzo | 96d959e | 2023-02-19 11:58:14 -0800 | [diff] [blame] | 581 | # Also add a library that can be depended on to get LLVM includes setup |
| 582 | # properly. bazel_to_cmake targets this for some header only pseudo deps. |
| 583 | add_library(IREELLVMIncludeSetup INTERFACE) |
| 584 | target_include_directories(IREELLVMIncludeSetup INTERFACE |
| 585 | ${LLVM_INCLUDE_DIRS} |
| 586 | ${MLIR_INCLUDE_DIRS} |
| 587 | ${LLD_INCLUDE_DIRS} |
| 588 | ) |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 589 | |
Stella Laurenzo | 96d959e | 2023-02-19 11:58:14 -0800 | [diff] [blame] | 590 | # Splice the includes setup into base LLVM libraries so that using them |
| 591 | # gets everything nice and tidy. It would be super if some day, LLVM |
| 592 | # libraries set their right usage requirements for includes. In the meantime |
| 593 | # we add usage requirements to libraries at the root of all things LLVM. |
| 594 | iree_llvm_add_usage_requirements(LLVMSupport IREELLVMIncludeSetup) |
| 595 | iree_llvm_add_usage_requirements(MLIRSupport IREELLVMIncludeSetup) |
Ben Vanik | 89a77fa | 2020-10-07 17:19:31 -0700 | [diff] [blame] | 596 | |
Stella Laurenzo | 62fbef0 | 2021-08-09 20:52:48 -0700 | [diff] [blame] | 597 | # Add default external projects. |
Stella Laurenzo | 96d959e | 2023-02-19 11:58:14 -0800 | [diff] [blame] | 598 | iree_llvm_add_external_project(mlir-iree-dialects ${CMAKE_CURRENT_SOURCE_DIR}/llvm-external-projects/iree-dialects) |
| 599 | iree_llvm_add_external_project(mlir-hlo ${CMAKE_CURRENT_SOURCE_DIR}/third_party/mlir-hlo) |
Scott Todd | e23d4a7 | 2022-07-27 14:16:39 -0700 | [diff] [blame] | 600 | if(IREE_INPUT_TORCH) |
Stella Laurenzo | 96d959e | 2023-02-19 11:58:14 -0800 | [diff] [blame] | 601 | iree_llvm_add_external_project(torch-mlir-dialects ${CMAKE_CURRENT_SOURCE_DIR}/third_party/torch-mlir-dialects) |
Yi Zhang | c35fee8 | 2022-04-06 14:35:28 -0400 | [diff] [blame] | 602 | endif() |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 603 | endif() |
| 604 | |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 605 | #------------------------------------------------------------------------------- |
Scott Todd | 8b0b0cd | 2021-12-16 15:13:57 -0800 | [diff] [blame] | 606 | # Other dependencies |
Stella Laurenzo | a3e97f1 | 2020-12-05 23:29:13 -0800 | [diff] [blame] | 607 | #------------------------------------------------------------------------------- |
| 608 | |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 609 | include(external_cc_library) |
Ben Vanik | 2d1808b | 2020-07-17 19:02:16 -0700 | [diff] [blame] | 610 | include(flatbuffer_c_library) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 611 | |
Ben Vanik | a903649 | 2021-06-25 09:39:53 -0700 | [diff] [blame] | 612 | add_subdirectory(build_tools/third_party/libyaml EXCLUDE_FROM_ALL) |
Jerry Wu | ae05f30 | 2022-05-17 13:58:13 +0000 | [diff] [blame] | 613 | add_subdirectory(build_tools/third_party/llvm-project EXCLUDE_FROM_ALL) |
Stella Laurenzo | 4cf4b5a | 2022-12-27 14:01:06 -0800 | [diff] [blame] | 614 | add_subdirectory(build_tools/third_party/tracy_client EXCLUDE_FROM_ALL) |
Ben Vanik | a903649 | 2021-06-25 09:39:53 -0700 | [diff] [blame] | 615 | add_subdirectory(build_tools/third_party/vulkan_memory_allocator EXCLUDE_FROM_ALL) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 616 | |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 617 | iree_set_googletest_cmake_options() |
Marius Brehler | f5022e8 | 2019-12-13 15:20:25 -0800 | [diff] [blame] | 618 | add_subdirectory(third_party/googletest EXCLUDE_FROM_ALL) |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 619 | |
| 620 | if(IREE_ENABLE_THREADING) |
| 621 | iree_set_benchmark_cmake_options() |
Cindy Liu | 331946c | 2021-06-01 12:20:30 -0700 | [diff] [blame] | 622 | add_subdirectory(third_party/benchmark EXCLUDE_FROM_ALL) |
Ben Vanik | 4aae003 | 2022-04-19 15:49:26 -0700 | [diff] [blame] | 623 | if(IREE_ENABLE_CPUINFO) |
| 624 | iree_set_cpuinfo_cmake_options() |
| 625 | add_subdirectory(third_party/cpuinfo EXCLUDE_FROM_ALL) |
| 626 | endif() |
Cindy Liu | 331946c | 2021-06-01 12:20:30 -0700 | [diff] [blame] | 627 | endif() |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 628 | |
Scott Todd | 20d746a | 2023-01-12 09:11:59 -0800 | [diff] [blame] | 629 | # This defines the iree-flatcc-cli target, so we don't use EXCLUDE_FROM_ALL. |
| 630 | add_subdirectory(build_tools/third_party/flatcc) |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 631 | |
Okwan Kwon | c31c8a0 | 2023-01-13 16:36:40 -0800 | [diff] [blame] | 632 | if(IREE_HAL_DRIVER_CUDA) |
| 633 | add_subdirectory(build_tools/third_party/nccl EXCLUDE_FROM_ALL) |
| 634 | endif() |
| 635 | |
Marius Brehler | 9b86ad5 | 2022-06-08 17:09:02 +0200 | [diff] [blame] | 636 | if(IREE_HAL_DRIVER_VULKAN) |
| 637 | add_subdirectory(third_party/vulkan_headers EXCLUDE_FROM_ALL) |
| 638 | endif() |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 639 | |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 640 | if(IREE_BUILD_COMPILER) |
Marius Brehler | 3eaf444 | 2021-01-13 18:22:08 +0100 | [diff] [blame] | 641 | add_subdirectory(build_tools/third_party/mlir-hlo EXCLUDE_FROM_ALL) |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 642 | endif() |
| 643 | |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 644 | if(IREE_BUILD_TESTS) |
Geoffrey Martin-Noble | 10f1822 | 2022-06-09 16:00:13 -0700 | [diff] [blame] | 645 | include(iree_configure_testing) |
Marius Brehler | 2967650 | 2019-12-27 17:07:10 -0800 | [diff] [blame] | 646 | endif() |
| 647 | |
MaheshRavishankar | 1547ac2 | 2021-09-23 15:22:46 -0700 | [diff] [blame] | 648 | if(IREE_BUILD_PYTHON_BINDINGS) |
Stella Laurenzo | 95ad84c | 2021-09-24 14:56:01 -0700 | [diff] [blame] | 649 | if(NOT TARGET pybind11::module) |
| 650 | message(STATUS "Using bundled pybind11") |
| 651 | add_subdirectory(third_party/pybind11 EXCLUDE_FROM_ALL) |
| 652 | else() |
| 653 | message(STATUS "Not including bundled pybind11 (already configured)") |
| 654 | endif() |
Marius Brehler | f3d73c9 | 2020-01-16 16:11:52 -0800 | [diff] [blame] | 655 | endif() |
| 656 | |
Scott Todd | d1620f0 | 2021-12-22 14:55:38 -0800 | [diff] [blame] | 657 | if(IREE_TARGET_BACKEND_METAL_SPIRV) |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 658 | iree_set_spirv_cross_cmake_options() |
Lei Zhang | 3cbb28e | 2020-09-22 15:30:27 -0400 | [diff] [blame] | 659 | # SPIRV-Cross is needed to cross compile SPIR-V into MSL source code. |
| 660 | add_subdirectory(third_party/spirv_cross EXCLUDE_FROM_ALL) |
| 661 | endif() |
| 662 | |
Scott Todd | f8519ca | 2021-12-16 16:01:49 -0800 | [diff] [blame] | 663 | if(IREE_TARGET_BACKEND_WEBGPU) |
| 664 | # Tint is needed to compile SPIR-V into WGSL source code. |
| 665 | # Tint also requires SPIRV-Tools, which requires SPIRV-Headers. |
| 666 | iree_set_spirv_headers_cmake_options() |
| 667 | add_subdirectory(third_party/spirv_headers EXCLUDE_FROM_ALL) |
| 668 | add_subdirectory(build_tools/third_party/spirv-tools EXCLUDE_FROM_ALL) |
| 669 | add_subdirectory(build_tools/third_party/tint EXCLUDE_FROM_ALL) |
| 670 | endif() |
| 671 | |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 672 | #------------------------------------------------------------------------------- |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 673 | # IREE top-level targets |
| 674 | #------------------------------------------------------------------------------- |
| 675 | |
Jerry Wu | 16e2d9c | 2022-11-22 06:19:46 +0000 | [diff] [blame] | 676 | if(IREE_BUILD_BENCHMARKS OR IREE_BUILD_EXPERIMENTAL_E2E_TEST_ARTIFACTS) |
Scott Todd | 9ca7563 | 2022-04-13 10:47:11 -0700 | [diff] [blame] | 677 | # Add top-level custom targets to drive generating benchmark suites. |
| 678 | |
| 679 | # iree-benchmark-import-models imports benchmark models from their source |
| 680 | # formats, such as .tflite flatbuffers, to IREE-compatible .mlir files. |
| 681 | add_custom_target(iree-benchmark-import-models) |
| 682 | |
| 683 | # iree-benchmark-suites fully prepares benchmark models for benchmarking: |
| 684 | # * importing from source formats to IREE-compatible .mlir files |
| 685 | # * compiling from .mlir files to benchmark-ready .vmfb files |
| 686 | # * generating flagfiles for executing the benchmark .vmfb files |
Lei Zhang | fe4403e | 2021-06-01 15:09:43 -0400 | [diff] [blame] | 687 | add_custom_target(iree-benchmark-suites) |
| 688 | endif() |
| 689 | |
Jerry Wu | d41d073 | 2022-11-23 01:43:55 +0000 | [diff] [blame] | 690 | # TODO(#11263): This conditional block should be merged with the block above |
| 691 | # once we remove IREE_BUILD_BENCHMARKS. |
| 692 | if(IREE_BUILD_EXPERIMENTAL_E2E_TEST_ARTIFACTS) |
Jerry Wu | fb87ad1 | 2022-12-21 05:59:02 +0000 | [diff] [blame] | 693 | # iree-e2e-compile-stats-suites compiles the benchmark models with specific |
| 694 | # flags to collect the compilation statistics. |
| 695 | add_custom_target(iree-e2e-compile-stats-suites) |
| 696 | |
Jerry Wu | d41d073 | 2022-11-23 01:43:55 +0000 | [diff] [blame] | 697 | # iree-e2e-test-artifacts builds all e2e test artifacts, including benchmarks |
| 698 | # and model tests. |
| 699 | add_custom_target(iree-e2e-test-artifacts) |
Jerry Wu | d41d073 | 2022-11-23 01:43:55 +0000 | [diff] [blame] | 700 | add_dependencies(iree-e2e-test-artifacts |
| 701 | iree-benchmark-import-models |
| 702 | iree-benchmark-suites |
Jerry Wu | fb87ad1 | 2022-12-21 05:59:02 +0000 | [diff] [blame] | 703 | iree-e2e-compile-stats-suites |
Jerry Wu | d41d073 | 2022-11-23 01:43:55 +0000 | [diff] [blame] | 704 | ) |
| 705 | endif() |
| 706 | |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 707 | if(IREE_BUILD_MICROBENCHMARKS) |
Han-Chung Wang | a6fbb76 | 2022-04-15 14:25:04 -0700 | [diff] [blame] | 708 | # Add top-level custom targets to drive generating microbenchmark suites. |
| 709 | add_custom_target(iree-microbenchmark-suites) |
| 710 | endif() |
| 711 | |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 712 | if(IREE_BUILD_DOCS) |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 713 | # Add a top-level custom target to drive generating all documentation. |
| 714 | # Register it to the default target given that IREE_BUILD_DOCS is explicitly |
| 715 | # requested. |
| 716 | add_custom_target(iree-doc ALL) |
| 717 | endif() |
| 718 | |
Jakub Kuderski | 3f76468 | 2023-02-07 17:14:23 -0500 | [diff] [blame] | 719 | # Samples may require additional files to be built/configured and will add |
| 720 | # dependencies to this target. |
| 721 | # Note: These will be automatically built with test dependencies |
| 722 | # (`iree-test-deps`). |
| 723 | add_custom_target(iree-sample-deps |
| 724 | COMMENT |
| 725 | "Building IREE sample data targets" |
| 726 | ) |
| 727 | |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 728 | # Testing rules that require generation will add dependencies to this target. |
| 729 | # This allows them to be EXCLUDE_FROM_ALL but still invokable. |
Jakub Kuderski | 3f76468 | 2023-02-07 17:14:23 -0500 | [diff] [blame] | 730 | add_custom_target(iree-test-deps |
| 731 | COMMENT |
| 732 | "Building IREE test deps" |
| 733 | DEPENDS |
| 734 | iree-sample-deps |
| 735 | ) |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 736 | |
CindyLiu | 99373e0 | 2022-10-12 09:22:24 -0700 | [diff] [blame] | 737 | # Testing rules that generate test scripts for iree-run-module-test will add |
| 738 | # dependencies to this target. It is a subset of `iree-test-deps`. |
| 739 | add_custom_target(iree-run-module-test-deps |
| 740 | COMMENT |
| 741 | "Building IREE run module test targets" |
| 742 | ) |
| 743 | |
Stella Laurenzo | e2dfc65 | 2023-02-15 18:12:03 -0800 | [diff] [blame] | 744 | # Convenience target for running IREE tests. |
| 745 | add_custom_target(iree-run-tests |
| 746 | COMMENT |
| 747 | "Run IREE unit tests" |
| 748 | WORKING_DIRECTORY |
| 749 | "${CMAKE_CURRENT_BINARY_DIR}" |
| 750 | USES_TERMINAL |
| 751 | COMMAND |
| 752 | "${CMAKE_COMMAND}" -E echo |
| 753 | "The 'iree-run-tests' target is a helper for running ctest. For advanced" |
| 754 | "options, build dependencies and invoke ctest independently as in:" |
| 755 | COMMAND |
| 756 | "${CMAKE_COMMAND}" -E echo |
| 757 | " \\(cd ${CMAKE_CURRENT_BINARY_DIR} \\&\\& cmake --build . --target iree-test-deps \\&\\& ctest --output-on-failure\\)" |
| 758 | COMMAND |
| 759 | "${CMAKE_COMMAND}" -E echo |
| 760 | "Run tests in parallel by setting a variable like CTEST_PARALLEL_LEVEL=25." |
| 761 | COMMAND |
| 762 | "${CMAKE_CTEST_COMMAND}" |
| 763 | --output-on-failure |
| 764 | ) |
| 765 | add_dependencies(iree-run-tests iree-test-deps) |
| 766 | |
| 767 | |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 768 | #------------------------------------------------------------------------------- |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 769 | # IREE top-level libraries |
| 770 | #------------------------------------------------------------------------------- |
| 771 | |
Rob Suderman | d42e002 | 2022-06-08 16:38:45 -0700 | [diff] [blame] | 772 | if(IREE_ENABLE_CLANG_TIDY) |
| 773 | set(CMAKE_CXX_CLANG_TIDY clang-tidy -warnings-as-errors=*) |
| 774 | endif() |
| 775 | |
Marius Brehler | f5022e8 | 2019-12-13 15:20:25 -0800 | [diff] [blame] | 776 | add_subdirectory(build_tools/embed_data/) |
| 777 | |
Jerry Wu | 16e2d9c | 2022-11-22 06:19:46 +0000 | [diff] [blame] | 778 | if(IREE_BUILD_BENCHMARKS OR IREE_BUILD_EXPERIMENTAL_E2E_TEST_ARTIFACTS) |
Stella Laurenzo | a6bf65c | 2022-01-11 20:47:51 -0800 | [diff] [blame] | 779 | find_program(IREE_IMPORT_TFLITE_PATH iree-import-tflite) |
| 780 | if(IREE_IMPORT_TFLITE_PATH) |
| 781 | message(STATUS "Found ${IREE_IMPORT_TFLITE_PATH} to generate benchmark artifacts") |
| 782 | else() |
| 783 | message(STATUS "iree-import-tflite not found. Some benchmarks may not configure") |
| 784 | endif() |
Jerry Wu | 60798ca | 2022-06-21 23:36:40 +0000 | [diff] [blame] | 785 | find_program(IREE_IMPORT_TF_PATH iree-import-tf) |
| 786 | if(IREE_IMPORT_TF_PATH) |
| 787 | message(STATUS "Found ${IREE_IMPORT_TF_PATH} to generate benchmark artifacts") |
| 788 | else() |
| 789 | message(STATUS "iree-import-tf not found. Some benchmarks may not configure") |
| 790 | endif() |
Jerry Wu | 16e2d9c | 2022-11-22 06:19:46 +0000 | [diff] [blame] | 791 | endif() |
| 792 | |
| 793 | # Note: Test deps are not built as part of all (use the iree-test-deps target). |
| 794 | add_subdirectory(tests EXCLUDE_FROM_ALL) |
| 795 | |
| 796 | if(IREE_BUILD_BENCHMARKS) |
Lei Zhang | 08cea04 | 2021-07-20 12:44:01 -0400 | [diff] [blame] | 797 | add_subdirectory(benchmarks) |
Lei Zhang | ff38a68 | 2021-06-08 21:12:24 -0400 | [diff] [blame] | 798 | endif() |
| 799 | |
Jacques Pienaar | 702929a | 2022-12-30 14:46:22 -0800 | [diff] [blame] | 800 | # tools/ can depend on compiler/ and runtime/. |
| 801 | # Note: tools sub directory is added before compiler/ so that phony targets for |
| 802 | # files with the same names from different rules are disambiguated towards |
| 803 | # those in tools/. |
| 804 | add_subdirectory(tools) |
| 805 | |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 806 | if(IREE_BUILD_COMPILER) |
Stella Laurenzo | 41a2ceb | 2022-04-29 12:49:36 -0700 | [diff] [blame] | 807 | add_subdirectory(compiler) |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 808 | endif() |
Ben Vanik | 6b112ef | 2019-10-03 10:45:14 -0700 | [diff] [blame] | 809 | |
Scott Todd | 4f16b99 | 2022-05-17 10:33:53 -0700 | [diff] [blame] | 810 | add_subdirectory(runtime) |
| 811 | |
Rob Suderman | d42e002 | 2022-06-08 16:38:45 -0700 | [diff] [blame] | 812 | if(IREE_ENABLE_CLANG_TIDY) |
| 813 | set(CMAKE_CXX_CLANG_TIDY "") |
| 814 | endif() |
| 815 | |
Stella Laurenzo | d3770ff | 2021-10-18 22:54:18 -0700 | [diff] [blame] | 816 | if(IREE_BUILD_TRACY) |
Stella Laurenzo | 3149b6d | 2021-10-24 18:45:17 -0700 | [diff] [blame] | 817 | if(NOT CMAKE_SYSTEM_NAME MATCHES "Linux") |
Stella Laurenzo | d3770ff | 2021-10-18 22:54:18 -0700 | [diff] [blame] | 818 | message(WARNING "Building Tracy (IREE_BUILD_TRACY) on non-Linux is unsupported and may fail below.") |
| 819 | endif() |
| 820 | add_subdirectory(build_tools/third_party/tracy ${CMAKE_CURRENT_BINARY_DIR}/tracy) |
| 821 | if(NOT TARGET IREETracyCaptureServer) |
| 822 | message(SEND_ERROR "Could not build Tracy. Either unset IREE_BUILD_TRACY or look for missing dependencies above and install them.") |
| 823 | endif() |
| 824 | endif() |
| 825 | |
Scott Todd | f57ab75 | 2022-05-23 10:36:44 -0700 | [diff] [blame] | 826 | # Order constraint: The python bindings install tools targets from tools/ |
Stella Laurenzo | d3770ff | 2021-10-18 22:54:18 -0700 | [diff] [blame] | 827 | # and tracy, and must come after it. |
Stella Laurenzo | 3b44a0a | 2022-04-18 19:57:57 -0700 | [diff] [blame] | 828 | if(IREE_BUILD_PYTHON_BINDINGS) |
Stella Laurenzo | 6012859 | 2022-04-17 21:52:09 -0700 | [diff] [blame] | 829 | # Write out a .env file to make IDEs and developers happy. |
| 830 | # 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] | 831 | # it gets clobbered, it is fine (it is also ignored in .gitignore). |
Stella Laurenzo | 41a2ceb | 2022-04-29 12:49:36 -0700 | [diff] [blame] | 832 | 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] | 833 | file(GENERATE OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/.env" CONTENT "${_PYTHONPATH_ENV}") |
| 834 | file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/.env" CONTENT "${_PYTHONPATH_ENV}") |
| 835 | # Similarly, write out .env.bat for Windows. |
| 836 | set(_PYTHONPATH_ENV_BAT "set PYTHONPATH=$<SHELL_PATH:${CMAKE_CURRENT_BINARY_DIR}/compiler/bindings/python;${CMAKE_CURRENT_BINARY_DIR}/runtime/bindings/python>\n") |
| 837 | 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] | 838 | endif() |
| 839 | |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 840 | if(IREE_BUILD_BINDINGS_TFLITE) |
Scott Todd | ada25e6 | 2022-05-03 16:16:15 -0700 | [diff] [blame] | 841 | add_subdirectory(runtime/bindings/tflite) |
Ben Vanik | cd1132f | 2021-01-29 15:58:17 -0800 | [diff] [blame] | 842 | endif() |
| 843 | |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 844 | if(IREE_BUILD_EXPERIMENTAL_WEB_SAMPLES) |
Scott Todd | 15fce0a | 2022-02-14 12:43:23 -0800 | [diff] [blame] | 845 | add_subdirectory(experimental/web) |
Scott Todd | f237b5e | 2022-01-28 11:02:25 -0800 | [diff] [blame] | 846 | endif() |
| 847 | |
Stella Laurenzo | 03e48db | 2020-06-11 18:35:13 -0700 | [diff] [blame] | 848 | set(IREE_PUBLIC_INCLUDE_DIRS "${IREE_COMMON_INCLUDE_DIRS}" |
| 849 | CACHE INTERNAL "IREE: Include Directories" FORCE) |
Stella Laurenzo | 688670f | 2021-09-24 18:16:25 -0700 | [diff] [blame] | 850 | |
Jerry Wu | 623d174 | 2022-03-31 18:16:02 +0000 | [diff] [blame] | 851 | #------------------------------------------------------------------------------- |
| 852 | # IREE benchmark tools |
| 853 | #------------------------------------------------------------------------------- |
| 854 | |
| 855 | add_subdirectory(build_tools/benchmarks) |
Stella Laurenzo | 3b44a0a | 2022-04-18 19:57:57 -0700 | [diff] [blame] | 856 | |
| 857 | #------------------------------------------------------------------------------- |
Jerry Wu | 71562cc | 2022-09-20 18:56:41 -0700 | [diff] [blame] | 858 | # IREE build tools python modules |
| 859 | #------------------------------------------------------------------------------- |
| 860 | |
| 861 | add_subdirectory(build_tools/python) |
| 862 | |
| 863 | #------------------------------------------------------------------------------- |
Scott Todd | 4f16b99 | 2022-05-17 10:33:53 -0700 | [diff] [blame] | 864 | # Samples |
Stella Laurenzo | 3b44a0a | 2022-04-18 19:57:57 -0700 | [diff] [blame] | 865 | #------------------------------------------------------------------------------- |
| 866 | |
Scott Todd | 4c022df | 2022-05-10 16:55:18 -0700 | [diff] [blame] | 867 | # samples/ can depend on anything, so we include it last |
Stella Laurenzo | 1e8d1fa | 2022-04-22 09:50:43 -0700 | [diff] [blame] | 868 | if(IREE_BUILD_SAMPLES) |
| 869 | add_subdirectory(samples) |
| 870 | endif() |
Geoffrey Martin-Noble | 10f1822 | 2022-06-09 16:00:13 -0700 | [diff] [blame] | 871 | |
| 872 | if(IREE_BUILD_TESTS) |
| 873 | iree_create_ctest_customization() |
| 874 | endif() |