Geoffrey Martin-Noble | 552d3f8 | 2021-05-25 17:56:09 -0700 | [diff] [blame] | 1 | # Copyright 2021 The IREE Authors |
Geoffrey Martin-Noble | f5b323e | 2021-01-12 18:32:08 -0800 | [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 |
Geoffrey Martin-Noble | f5b323e | 2021-01-12 18:32:08 -0800 | [diff] [blame] | 6 | """Helper functions for configuring IREE and dependent project WORKSPACE files.""" |
| 7 | |
Geoffrey Martin-Noble | f5b323e | 2021-01-12 18:32:08 -0800 | [diff] [blame] | 8 | load("@bazel_skylib//lib:paths.bzl", "paths") |
Stella Laurenzo | 04259d0 | 2023-09-19 13:07:56 -0700 | [diff] [blame] | 9 | load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") |
Geoffrey Martin-Noble | f5b323e | 2021-01-12 18:32:08 -0800 | [diff] [blame] | 10 | |
Stella Laurenzo | a9d23f6 | 2022-12-27 17:28:58 -0800 | [diff] [blame] | 11 | CUDA_TOOLKIT_ROOT_ENV_KEY = "IREE_CUDA_TOOLKIT_ROOT" |
| 12 | |
| 13 | # Our CI docker images use a stripped down CUDA directory tree in some |
| 14 | # images, and it is tailored just to support building key elements. |
| 15 | # When this is done, the IREE_CUDA_DEPS_DIR env var is set, and we |
| 16 | # respect that here in order to match the CMake side (which needs it |
| 17 | # because CUDA toolkit detection differs depending on whether it is |
| 18 | # stripped down or not). |
| 19 | # TODO: Simplify this on the CMake/docker side and update here to match. |
Scott Todd | 0636abd | 2024-09-18 18:58:34 -0700 | [diff] [blame] | 20 | # TODO(#15332): Dockerfiles no longer include these deps. Simplify. |
Stella Laurenzo | a9d23f6 | 2022-12-27 17:28:58 -0800 | [diff] [blame] | 21 | CUDA_DEPS_DIR_FOR_CI_ENV_KEY = "IREE_CUDA_DEPS_DIR" |
| 22 | |
| 23 | def cuda_auto_configure_impl(repository_ctx): |
| 24 | env = repository_ctx.os.environ |
| 25 | cuda_toolkit_root = None |
| 26 | iree_repo_alias = repository_ctx.attr.iree_repo_alias |
| 27 | |
| 28 | # Probe environment for CUDA toolkit location. |
| 29 | env_cuda_toolkit_root = env.get(CUDA_TOOLKIT_ROOT_ENV_KEY) |
| 30 | env_cuda_deps_dir_for_ci = env.get(CUDA_DEPS_DIR_FOR_CI_ENV_KEY) |
| 31 | if env_cuda_toolkit_root: |
| 32 | cuda_toolkit_root = env_cuda_toolkit_root |
| 33 | elif env_cuda_deps_dir_for_ci: |
| 34 | cuda_toolkit_root = env_cuda_deps_dir_for_ci |
| 35 | |
| 36 | # Symlink the tree. |
| 37 | libdevice_rel_path = "iree_local/libdevice.bc" |
| 38 | if cuda_toolkit_root != None: |
| 39 | # Symlink top-level directories we care about. |
| 40 | repository_ctx.symlink(cuda_toolkit_root + "/include", "include") |
| 41 | |
| 42 | # TODO: Should be probing for the libdevice, as it can change from |
| 43 | # version to version. |
| 44 | repository_ctx.symlink( |
| 45 | cuda_toolkit_root + "/nvvm/libdevice/libdevice.10.bc", |
| 46 | libdevice_rel_path, |
| 47 | ) |
| 48 | |
| 49 | repository_ctx.template( |
| 50 | "BUILD", |
| 51 | Label("%s//:build_tools/third_party/cuda/BUILD.template" % iree_repo_alias), |
| 52 | { |
| 53 | "%ENABLED%": "True" if cuda_toolkit_root else "False", |
Jacques Pienaar | 4db7c1a | 2023-10-19 06:56:00 -0700 | [diff] [blame] | 54 | "%LIBDEVICE_REL_PATH%": libdevice_rel_path if cuda_toolkit_root else "BUILD", |
Stella Laurenzo | a9d23f6 | 2022-12-27 17:28:58 -0800 | [diff] [blame] | 55 | "%IREE_REPO_ALIAS%": iree_repo_alias, |
| 56 | }, |
| 57 | ) |
| 58 | |
| 59 | cuda_auto_configure = repository_rule( |
| 60 | environ = [ |
| 61 | CUDA_DEPS_DIR_FOR_CI_ENV_KEY, |
| 62 | CUDA_TOOLKIT_ROOT_ENV_KEY, |
| 63 | ], |
| 64 | implementation = cuda_auto_configure_impl, |
| 65 | attrs = { |
| 66 | "iree_repo_alias": attr.string(default = "@iree_core"), |
| 67 | }, |
| 68 | ) |
| 69 | |
| 70 | def configure_iree_cuda_deps(iree_repo_alias = None): |
| 71 | maybe( |
| 72 | cuda_auto_configure, |
| 73 | name = "iree_cuda", |
| 74 | iree_repo_alias = iree_repo_alias, |
| 75 | ) |
| 76 | |
Geoffrey Martin-Noble | f5b323e | 2021-01-12 18:32:08 -0800 | [diff] [blame] | 77 | def configure_iree_submodule_deps(iree_repo_alias = "@", iree_path = "./"): |
| 78 | """Configure all of IREE's simple repository dependencies that come from submodules. |
| 79 | |
| 80 | Simple is defined here as just calls to `local_repository` or |
| 81 | `new_local_repository`. This assumes you have a directory that includes IREE |
| 82 | and all its submodules. Note that fetching a GitHub archive does not include |
| 83 | submodules. |
| 84 | Yes it is necessary to have both the workspace alias and path argument... |
| 85 | |
| 86 | Args: |
| 87 | iree_repo_alias: The alias for the IREE repository. |
| 88 | iree_path: The path to the IREE repository containing submodules |
| 89 | """ |
| 90 | |
| 91 | maybe( |
| 92 | native.local_repository, |
Geoffrey Martin-Noble | f5b323e | 2021-01-12 18:32:08 -0800 | [diff] [blame] | 93 | name = "com_google_googletest", |
| 94 | path = paths.join(iree_path, "third_party/googletest"), |
| 95 | ) |
| 96 | |
| 97 | maybe( |
| 98 | native.new_local_repository, |
| 99 | name = "com_github_dvidelabs_flatcc", |
| 100 | build_file = iree_repo_alias + "//:build_tools/third_party/flatcc/BUILD.overlay", |
| 101 | path = paths.join(iree_path, "third_party/flatcc"), |
| 102 | ) |
| 103 | |
Ben Vanik | a903649 | 2021-06-25 09:39:53 -0700 | [diff] [blame] | 104 | maybe( |
| 105 | native.new_local_repository, |
Geoffrey Martin-Noble | a328761 | 2021-08-25 10:53:26 -0700 | [diff] [blame] | 106 | name = "vulkan_headers", |
Geoffrey Martin-Noble | f5b323e | 2021-01-12 18:32:08 -0800 | [diff] [blame] | 107 | build_file = iree_repo_alias + "//:build_tools/third_party/vulkan_headers/BUILD.overlay", |
| 108 | path = paths.join(iree_path, "third_party/vulkan_headers"), |
| 109 | ) |
| 110 | |
| 111 | maybe( |
Geoffrey Martin-Noble | f5b323e | 2021-01-12 18:32:08 -0800 | [diff] [blame] | 112 | native.local_repository, |
Jakub Kuderski | 3546f2a | 2023-06-14 13:18:44 -0400 | [diff] [blame] | 113 | name = "stablehlo", |
| 114 | path = paths.join(iree_path, "third_party/stablehlo"), |
Geoffrey Martin-Noble | f5b323e | 2021-01-12 18:32:08 -0800 | [diff] [blame] | 115 | ) |
| 116 | |
| 117 | maybe( |
| 118 | native.local_repository, |
| 119 | name = "com_google_benchmark", |
| 120 | path = paths.join(iree_path, "third_party/benchmark"), |
| 121 | ) |
| 122 | |
| 123 | maybe( |
Lei Zhang | f8e8574 | 2023-05-15 08:32:00 -0700 | [diff] [blame] | 124 | native.local_repository, |
Geoffrey Martin-Noble | f5b323e | 2021-01-12 18:32:08 -0800 | [diff] [blame] | 125 | name = "cpuinfo", |
Geoffrey Martin-Noble | f5b323e | 2021-01-12 18:32:08 -0800 | [diff] [blame] | 126 | path = paths.join(iree_path, "third_party/cpuinfo"), |
| 127 | ) |
| 128 | |
| 129 | maybe( |
| 130 | native.new_local_repository, |
Geoffrey Martin-Noble | f5b323e | 2021-01-12 18:32:08 -0800 | [diff] [blame] | 131 | name = "spirv_cross", |
| 132 | build_file = iree_repo_alias + "//:build_tools/third_party/spirv_cross/BUILD.overlay", |
| 133 | path = paths.join(iree_path, "third_party/spirv_cross"), |
| 134 | ) |
Yi Zhang | acf3e8d | 2022-03-28 21:59:35 -0400 | [diff] [blame] | 135 | |
| 136 | maybe( |
| 137 | native.new_local_repository, |
Stella Laurenzo | 4cf4b5a | 2022-12-27 14:01:06 -0800 | [diff] [blame] | 138 | name = "tracy_client", |
| 139 | build_file = iree_repo_alias + "//:build_tools/third_party/tracy_client/BUILD.overlay", |
| 140 | path = paths.join(iree_path, "third_party/tracy"), |
| 141 | ) |
Okwan Kwon | c31c8a0 | 2023-01-13 16:36:40 -0800 | [diff] [blame] | 142 | |
| 143 | maybe( |
| 144 | native.new_local_repository, |
| 145 | name = "nccl", |
| 146 | build_file = iree_repo_alias + "//:build_tools/third_party/nccl/BUILD.overlay", |
| 147 | path = paths.join(iree_path, "third_party/nccl"), |
| 148 | ) |
Scott Todd | ad321b6 | 2023-06-05 14:39:30 -0700 | [diff] [blame] | 149 | |
| 150 | maybe( |
| 151 | native.new_local_repository, |
| 152 | name = "webgpu_headers", |
| 153 | build_file = iree_repo_alias + "//:build_tools/third_party/webgpu-headers/BUILD.overlay", |
| 154 | path = paths.join(iree_path, "third_party/webgpu-headers"), |
| 155 | ) |