Skip to content
forked from iree-org/iree

Commit 3b0f8bc

Browse files
committed
bazel test
1 parent 24ab0d6 commit 3b0f8bc

29 files changed

+1161
-47
lines changed

.bazelrc

+2
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ import %workspace%/configured.bazelrc
1515
# The user.bazelrc file is not checked in but available for local mods.
1616
# Always keep this at the end of the file so that user flags override.
1717
try-import %workspace%/user.bazelrc
18+
19+
common --enable_bzlmod

.gitmodules

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
url = https://github.com/powderluv/musl.git
3131
[submodule "third_party/stablehlo"]
3232
path = third_party/stablehlo
33-
url = https://github.com/iree-org/stablehlo.git
33+
url = https://github.com/RooflineAI/stablehlo.git
3434
[submodule "third_party/torch-mlir"]
3535
path = third_party/torch-mlir
3636
url = https://github.com/RooflineAI/torch-mlir.git

BUILD.bazel

+7
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@
44
# See https://llvm.org/LICENSE.txt for license information.
55
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66

7+
load("//build_tools/bazel:workspace_root.bzl", "workspace_root")
8+
79
package(
810
default_visibility = ["//visibility:public"],
911
features = ["layering_check"],
1012
licenses = ["notice"], # Apache 2.0
1113
)
14+
15+
16+
workspace_root(name = "workspace_root")
17+
18+
exports_files(["third_party/nvidia_sdk_download/fetch_cuda_toolkit.py"])

WORKSPACE.bzlmod

+149
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
# Copyright 2019 The IREE Authors
2+
#
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
6+
7+
# Workspace file for the IREE project.
8+
# buildozer: disable=positional-args
9+
10+
workspace(name = "iree_core")
11+
12+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
13+
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
14+
15+
###############################################################################
16+
# Skylib
17+
http_archive(
18+
name = "bazel_skylib",
19+
sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506",
20+
urls = [
21+
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
22+
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
23+
],
24+
)
25+
26+
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
27+
28+
bazel_skylib_workspace()
29+
###############################################################################
30+
31+
###############################################################################
32+
# llvm-project
33+
34+
new_local_repository(
35+
name = "llvm-raw",
36+
build_file_content = "# empty",
37+
path = "third_party/llvm-project",
38+
)
39+
40+
load("@llvm-raw//utils/bazel:configure.bzl", "llvm_configure")
41+
42+
llvm_configure(
43+
name = "llvm-project",
44+
# Keep this in sync with the targets in iree_llvm.cmake.
45+
targets = [
46+
"AArch64",
47+
"ARM",
48+
"RISCV",
49+
"X86",
50+
"NVPTX",
51+
"AMDGPU",
52+
"WebAssembly",
53+
],
54+
)
55+
56+
###############################################################################
57+
58+
###############################################################################
59+
# All other IREE submodule dependencies
60+
61+
load("//build_tools/bazel:workspace.bzl", "configure_iree_cuda_deps", "configure_iree_submodule_deps")
62+
63+
configure_iree_submodule_deps()
64+
65+
configure_iree_cuda_deps(script = "//:third-party/nvidia_sdk_download/fetch_cuda_toolkit.py")
66+
67+
###############################################################################
68+
maybe(
69+
http_archive,
70+
name = "llvm_zlib",
71+
build_file = "@llvm-raw//utils/bazel/third_party_build:zlib-ng.BUILD",
72+
sha256 = "e36bb346c00472a1f9ff2a0a4643e590a254be6379da7cddd9daeb9a7f296731",
73+
strip_prefix = "zlib-ng-2.0.7",
74+
urls = [
75+
"https://github.com/zlib-ng/zlib-ng/archive/refs/tags/2.0.7.zip",
76+
],
77+
)
78+
79+
###############################################################################
80+
maybe(
81+
http_archive,
82+
name = "llvm_zstd",
83+
build_file = "@llvm-raw//utils/bazel/third_party_build:zstd.BUILD",
84+
sha256 = "7c42d56fac126929a6a85dbc73ff1db2411d04f104fae9bdea51305663a83fd0",
85+
strip_prefix = "zstd-1.5.2",
86+
urls = [
87+
"https://github.com/facebook/zstd/releases/download/v1.5.2/zstd-1.5.2.tar.gz",
88+
],
89+
)
90+
91+
maybe(
92+
http_archive,
93+
name = "robin_map",
94+
strip_prefix = "robin-map-1.3.0",
95+
sha256 = "a8424ad3b0affd4c57ed26f0f3d8a29604f0e1f2ef2089f497f614b1c94c7236",
96+
build_file = "@llvm-raw//utils/bazel/third_party_build:robin_map.BUILD",
97+
url = "https://github.com/Tessil/robin-map/archive/refs/tags/v1.3.0.tar.gz",
98+
)
99+
100+
maybe(
101+
http_archive,
102+
name = "nanobind",
103+
build_file = "@llvm-raw//utils/bazel/third_party_build:nanobind.BUILD",
104+
sha256 = "bb35deaed7efac5029ed1e33880a415638352f757d49207a8e6013fefb6c49a7",
105+
strip_prefix = "nanobind-2.4.0",
106+
url = "https://github.com/wjakob/nanobind/archive/refs/tags/v2.4.0.tar.gz",
107+
)
108+
109+
maybe(
110+
http_archive,
111+
name = "rules_python",
112+
sha256 = "4f7e2aa1eb9aa722d96498f5ef514f426c1f55161c3c9ae628c857a7128ceb07",
113+
strip_prefix = "rules_python-1.0.0",
114+
url = "https://github.com/bazelbuild/rules_python/releases/download/1.0.0/rules_python-1.0.0.tar.gz",
115+
)
116+
117+
load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains")
118+
119+
py_repositories()
120+
121+
python_register_toolchains(
122+
name = "python_3_11",
123+
python_version = "3.11",
124+
)
125+
126+
load("@rules_python//python:pip.bzl", "pip_parse")
127+
128+
pip_parse(
129+
name = "pypi",
130+
requirements_lock = "//runtime:requirements.txt"
131+
)
132+
133+
load("@pypi//:requirements.bzl", "install_deps")
134+
135+
install_deps()
136+
137+
# new_local_repository(
138+
# name = "numpy_headers",
139+
# # This path points to where rules_python unpacks NumPy. Adjust for your environment:
140+
# path = "external/py_deps/pypi__numpy/numpy/core/include",
141+
# build_file_content = """
142+
# filegroup(
143+
# name = "includes",
144+
# srcs = glob(["**/*.h"]),
145+
# visibility = ["//visibility:public"],
146+
# )
147+
# """,
148+
# )
149+

build_tools/bazel/build_defs.oss.bzl

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def iree_compiler_cc_library(deps = [], **kwargs):
8484
"""
8585
iree_cc_library(
8686
deps = deps + [
87-
"//compiler/src:defs",
87+
"@iree//compiler/src:defs",
8888
],
8989
**kwargs
9090
)
@@ -117,7 +117,7 @@ def iree_compiler_cc_binary(deps = [], **kwargs):
117117
"""
118118
native.cc_binary(
119119
deps = deps + [
120-
"//compiler/src:defs",
120+
"@iree//compiler/src:defs",
121121
],
122122
**kwargs
123123
)

build_tools/bazel/iree_bitcode_library.bzl

+4-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def iree_bitcode_library(
128128
"-isystem $(BINDIR)/%s" % builtin_headers_path,
129129
" ".join(base_copts + copts),
130130
" ".join(["-I $(BINDIR)/runtime/src"]),
131-
" ".join(["-I runtime/src"]),
131+
" ".join(["-I $(WORKSPACE_ROOT)/runtime/src"]),
132132
"-o $(location %s)" % (bitcode_out),
133133
"$(location %s)" % (src),
134134
]),
@@ -138,6 +138,7 @@ def iree_bitcode_library(
138138
],
139139
message = "Compiling %s to %s..." % (src, bitcode_out),
140140
output_to_bindir = 1,
141+
toolchains = ["//:workspace_root"],
141142
**kwargs
142143
)
143144

@@ -319,13 +320,14 @@ def iree_amdgpu_bitcode_library(
319320
"$(location %s)" % (clang_tool),
320321
"$(location %s)" % (src),
321322
"-o $(location %s)" % (out),
322-
"-I .",
323+
"-I $(WORKSPACE_ROOT)",
323324
] + base_copts + copts),
324325
tools = [
325326
clang_tool,
326327
],
327328
message = "Compiling %s to %s..." % (src, out),
328329
output_to_bindir = 1,
330+
toolchains = ["//:workspace_root"],
329331
**kwargs
330332
)
331333

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
load("@with_cfg.bzl", "with_cfg")
2+
3+
def copy_to_path(name, src, output_dir, file_name, *args, **kwargs):
4+
output_path = output_dir + "/" + file_name
5+
native.genrule(
6+
name = name,
7+
srcs = [src],
8+
outs = [output_path],
9+
cmd = "mkdir -p output_dir && cp $< $@",
10+
)
11+
12+
13+
14+
tracy_copy_to_path, _tracy_copy_to_path_internal = with_cfg(copy_to_path).set(Label("//runtime/src/iree/base/tracing:tracing_provider"), "tracy").build()

build_tools/bazel/iree_flatcc.bzl

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def iree_flatbuffer_c_library(
1717

1818
flags = [
1919
"-o$(RULEDIR)",
20-
"-I runtime/src",
20+
"-I $(WORKSPACE_ROOT)/runtime/src",
2121
] + flatcc_args
2222

2323
out_stem = "%s" % (srcs[0].replace(".fbs", ""))
@@ -41,6 +41,7 @@ def iree_flatbuffer_c_library(
4141
tools = [flatcc],
4242
cmd = "$(location %s) %s %s" % (flatcc, " ".join(flags), " ".join(["$(location {})".format(src) for src in srcs])),
4343
testonly = testonly,
44+
toolchains = ["//:workspace_root"]
4445
)
4546
native.cc_library(
4647
name = name,

build_tools/bazel/workspace.bzl

+33-16
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,39 @@ CUDA_DEPS_DIR_FOR_CI_ENV_KEY = "IREE_CUDA_DEPS_DIR"
2222

2323
def cuda_auto_configure_impl(repository_ctx):
2424
env = repository_ctx.os.environ
25-
cuda_toolkit_root = None
2625
iree_repo_alias = repository_ctx.attr.iree_repo_alias
26+
cuda_toolkit_root = None
2727

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.
28+
script_file = repository_ctx.attr.script
29+
if script_file and False:
30+
# Only support Linux and Windows.
31+
# (Assuming repository_ctx.os.name returns a lowercase string like "linux" or "windows".)
32+
if repository_ctx.os.name.lower() not in ["linux", "windows"]:
33+
fail("CUDA auto configuration downloading is only supported on Linux and Windows, but the current OS is: " + repository_ctx.os.name)
34+
# Link and run the download script.
35+
script_path = repository_ctx.path(script_file)
36+
repository_ctx.symlink(script_path, "download.py")
37+
output_dir = repository_ctx.path("cuda_root")
38+
39+
result = repository_ctx.execute(["python3", "download.py", output_dir], timeout=40)
40+
if result.return_code != 0:
41+
fail("download.py execution failed:\n" + result.stderr)
42+
43+
cuda_toolkit_root = "cuda_root/12.2.1/linux-x86_64"
44+
else:
45+
# Probe environment for CUDA toolkit location.
46+
env_cuda_toolkit_root = env.get(CUDA_TOOLKIT_ROOT_ENV_KEY)
47+
env_cuda_deps_dir_for_ci = env.get(CUDA_DEPS_DIR_FOR_CI_ENV_KEY)
48+
if env_cuda_toolkit_root:
49+
cuda_toolkit_root = env_cuda_toolkit_root
50+
elif env_cuda_deps_dir_for_ci:
51+
cuda_toolkit_root = env_cuda_deps_dir_for_ci
52+
53+
# If we found a CUDA toolkit root (either via download or the environment),
54+
# create symlinks for the directories and libdevice.
3755
libdevice_rel_path = "iree_local/libdevice.bc"
38-
if cuda_toolkit_root != None:
39-
# Symlink top-level directories we care about.
56+
if cuda_toolkit_root:
4057
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.
4458
repository_ctx.symlink(
4559
cuda_toolkit_root + "/nvvm/libdevice/libdevice.10.bc",
4660
libdevice_rel_path,
@@ -64,14 +78,17 @@ cuda_auto_configure = repository_rule(
6478
implementation = cuda_auto_configure_impl,
6579
attrs = {
6680
"iree_repo_alias": attr.string(default = "@iree_core"),
81+
"script": attr.label(allow_files = True, default=None),
6782
},
83+
local = True
6884
)
6985

70-
def configure_iree_cuda_deps(iree_repo_alias = None):
86+
def configure_iree_cuda_deps(iree_repo_alias = None, script = ""):
7187
maybe(
7288
cuda_auto_configure,
7389
name = "iree_cuda",
7490
iree_repo_alias = iree_repo_alias,
91+
script = script,
7592
)
7693

7794
def configure_iree_submodule_deps(iree_repo_alias = "@", iree_path = "./"):

build_tools/bazel/workspace_root.bzl

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
def _workspace_root_impl(ctx):
2+
"""Dynamically determine the workspace root from the current context.
3+
The path is made available as a `WORKSPACE_ROOT` environmment variable and
4+
may for instance be consumed in the `toolchains` attributes for `cc_library`
5+
and `genrule` targets.
6+
"""
7+
workspace_root = ctx.label.workspace_root if ctx.label.workspace_root else "."
8+
return [
9+
platform_common.TemplateVariableInfo({
10+
"WORKSPACE_ROOT": workspace_root,
11+
}),
12+
]
13+
14+
workspace_root = rule(
15+
implementation = _workspace_root_impl,
16+
attrs = {},
17+
)

0 commit comments

Comments
 (0)