Skip to content
forked from iree-org/iree
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bazel test #29

Merged
merged 1 commit into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ import %workspace%/configured.bazelrc
# The user.bazelrc file is not checked in but available for local mods.
# Always keep this at the end of the file so that user flags override.
try-import %workspace%/user.bazelrc

common --enable_bzlmod
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
url = https://github.com/powderluv/musl.git
[submodule "third_party/stablehlo"]
path = third_party/stablehlo
url = https://github.com/iree-org/stablehlo.git
url = https://github.com/RooflineAI/stablehlo.git
[submodule "third_party/torch-mlir"]
path = third_party/torch-mlir
url = https://github.com/RooflineAI/torch-mlir.git
Expand Down
7 changes: 7 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load("//build_tools/bazel:workspace_root.bzl", "workspace_root")

package(
default_visibility = ["//visibility:public"],
features = ["layering_check"],
licenses = ["notice"], # Apache 2.0
)


workspace_root(name = "workspace_root")

exports_files(["third_party/nvidia_sdk_download/fetch_cuda_toolkit.py"])
149 changes: 149 additions & 0 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# Copyright 2019 The IREE Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# Workspace file for the IREE project.
# buildozer: disable=positional-args

workspace(name = "iree_core")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

###############################################################################
# Skylib
http_archive(
name = "bazel_skylib",
sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
],
)

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()
###############################################################################

###############################################################################
# llvm-project

new_local_repository(
name = "llvm-raw",
build_file_content = "# empty",
path = "third_party/llvm-project",
)

load("@llvm-raw//utils/bazel:configure.bzl", "llvm_configure")

llvm_configure(
name = "llvm-project",
# Keep this in sync with the targets in iree_llvm.cmake.
targets = [
"AArch64",
"ARM",
"RISCV",
"X86",
"NVPTX",
"AMDGPU",
"WebAssembly",
],
)

###############################################################################

###############################################################################
# All other IREE submodule dependencies

load("//build_tools/bazel:workspace.bzl", "configure_iree_cuda_deps", "configure_iree_submodule_deps")

configure_iree_submodule_deps()

configure_iree_cuda_deps(script = "//:third-party/nvidia_sdk_download/fetch_cuda_toolkit.py")

###############################################################################
maybe(
http_archive,
name = "llvm_zlib",
build_file = "@llvm-raw//utils/bazel/third_party_build:zlib-ng.BUILD",
sha256 = "e36bb346c00472a1f9ff2a0a4643e590a254be6379da7cddd9daeb9a7f296731",
strip_prefix = "zlib-ng-2.0.7",
urls = [
"https://github.com/zlib-ng/zlib-ng/archive/refs/tags/2.0.7.zip",
],
)

###############################################################################
maybe(
http_archive,
name = "llvm_zstd",
build_file = "@llvm-raw//utils/bazel/third_party_build:zstd.BUILD",
sha256 = "7c42d56fac126929a6a85dbc73ff1db2411d04f104fae9bdea51305663a83fd0",
strip_prefix = "zstd-1.5.2",
urls = [
"https://github.com/facebook/zstd/releases/download/v1.5.2/zstd-1.5.2.tar.gz",
],
)

maybe(
http_archive,
name = "robin_map",
strip_prefix = "robin-map-1.3.0",
sha256 = "a8424ad3b0affd4c57ed26f0f3d8a29604f0e1f2ef2089f497f614b1c94c7236",
build_file = "@llvm-raw//utils/bazel/third_party_build:robin_map.BUILD",
url = "https://github.com/Tessil/robin-map/archive/refs/tags/v1.3.0.tar.gz",
)

maybe(
http_archive,
name = "nanobind",
build_file = "@llvm-raw//utils/bazel/third_party_build:nanobind.BUILD",
sha256 = "bb35deaed7efac5029ed1e33880a415638352f757d49207a8e6013fefb6c49a7",
strip_prefix = "nanobind-2.4.0",
url = "https://github.com/wjakob/nanobind/archive/refs/tags/v2.4.0.tar.gz",
)

maybe(
http_archive,
name = "rules_python",
sha256 = "4f7e2aa1eb9aa722d96498f5ef514f426c1f55161c3c9ae628c857a7128ceb07",
strip_prefix = "rules_python-1.0.0",
url = "https://github.com/bazelbuild/rules_python/releases/download/1.0.0/rules_python-1.0.0.tar.gz",
)

load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains")

py_repositories()

python_register_toolchains(
name = "python_3_11",
python_version = "3.11",
)

load("@rules_python//python:pip.bzl", "pip_parse")

pip_parse(
name = "pypi",
requirements_lock = "//runtime:requirements.txt"
)

load("@pypi//:requirements.bzl", "install_deps")

install_deps()

# new_local_repository(
# name = "numpy_headers",
# # This path points to where rules_python unpacks NumPy. Adjust for your environment:
# path = "external/py_deps/pypi__numpy/numpy/core/include",
# build_file_content = """
# filegroup(
# name = "includes",
# srcs = glob(["**/*.h"]),
# visibility = ["//visibility:public"],
# )
# """,
# )

4 changes: 2 additions & 2 deletions build_tools/bazel/build_defs.oss.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def iree_compiler_cc_library(deps = [], **kwargs):
"""
iree_cc_library(
deps = deps + [
"//compiler/src:defs",
"@iree//compiler/src:defs",
],
**kwargs
)
Expand Down Expand Up @@ -117,7 +117,7 @@ def iree_compiler_cc_binary(deps = [], **kwargs):
"""
native.cc_binary(
deps = deps + [
"//compiler/src:defs",
"@iree//compiler/src:defs",
],
**kwargs
)
Expand Down
2 changes: 1 addition & 1 deletion build_tools/bazel/iree.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ build --force_pic
###############################################################################
# Build settings flag aliases. See https://bazel.build/rules/config
###############################################################################
build --flag_alias=iree_drivers=//runtime/src/iree/hal/drivers:enabled_drivers
build --flag_alias=iree_drivers=@iree//runtime/src/iree/hal/drivers:enabled_drivers
build --flag_alias=iree_link_compiler_shared=//compiler/src/iree/compiler/API:link_shared
# Equivalent to CMake flag IREE_ENABLE_RUNTIME_TRACING + IREE_TRACING_PROVIDER.
# Builds the runtime with tracing support enabled.
Expand Down
6 changes: 4 additions & 2 deletions build_tools/bazel/iree_bitcode_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def iree_bitcode_library(
"-isystem $(BINDIR)/%s" % builtin_headers_path,
" ".join(base_copts + copts),
" ".join(["-I $(BINDIR)/runtime/src"]),
" ".join(["-I runtime/src"]),
" ".join(["-I $(WORKSPACE_ROOT)/runtime/src"]),
"-o $(location %s)" % (bitcode_out),
"$(location %s)" % (src),
]),
Expand All @@ -138,6 +138,7 @@ def iree_bitcode_library(
],
message = "Compiling %s to %s..." % (src, bitcode_out),
output_to_bindir = 1,
toolchains = ["//:workspace_root"],
**kwargs
)

Expand Down Expand Up @@ -319,13 +320,14 @@ def iree_amdgpu_bitcode_library(
"$(location %s)" % (clang_tool),
"$(location %s)" % (src),
"-o $(location %s)" % (out),
"-I .",
"-I $(WORKSPACE_ROOT)",
] + base_copts + copts),
tools = [
clang_tool,
],
message = "Compiling %s to %s..." % (src, out),
output_to_bindir = 1,
toolchains = ["//:workspace_root"],
**kwargs
)

Expand Down
14 changes: 14 additions & 0 deletions build_tools/bazel/iree_copy_to_path.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
load("@with_cfg.bzl", "with_cfg")

def copy_to_path(name, src, output_dir, file_name, *args, **kwargs):
output_path = output_dir + "/" + file_name
native.genrule(
name = name,
srcs = [src],
outs = [output_path],
cmd = "mkdir -p output_dir && cp $< $@",
)



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()
3 changes: 2 additions & 1 deletion build_tools/bazel/iree_flatcc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def iree_flatbuffer_c_library(

flags = [
"-o$(RULEDIR)",
"-I runtime/src",
"-I $(WORKSPACE_ROOT)/runtime/src",
] + flatcc_args

out_stem = "%s" % (srcs[0].replace(".fbs", ""))
Expand All @@ -41,6 +41,7 @@ def iree_flatbuffer_c_library(
tools = [flatcc],
cmd = "$(location %s) %s %s" % (flatcc, " ".join(flags), " ".join(["$(location {})".format(src) for src in srcs])),
testonly = testonly,
toolchains = ["//:workspace_root"]
)
native.cc_library(
name = name,
Expand Down
49 changes: 33 additions & 16 deletions build_tools/bazel/workspace.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,39 @@ CUDA_DEPS_DIR_FOR_CI_ENV_KEY = "IREE_CUDA_DEPS_DIR"

def cuda_auto_configure_impl(repository_ctx):
env = repository_ctx.os.environ
cuda_toolkit_root = None
iree_repo_alias = repository_ctx.attr.iree_repo_alias
cuda_toolkit_root = None

# Probe environment for CUDA toolkit location.
env_cuda_toolkit_root = env.get(CUDA_TOOLKIT_ROOT_ENV_KEY)
env_cuda_deps_dir_for_ci = env.get(CUDA_DEPS_DIR_FOR_CI_ENV_KEY)
if env_cuda_toolkit_root:
cuda_toolkit_root = env_cuda_toolkit_root
elif env_cuda_deps_dir_for_ci:
cuda_toolkit_root = env_cuda_deps_dir_for_ci

# Symlink the tree.
script_file = repository_ctx.attr.script
if script_file and False:
# Only support Linux and Windows.
# (Assuming repository_ctx.os.name returns a lowercase string like "linux" or "windows".)
if repository_ctx.os.name.lower() not in ["linux", "windows"]:
fail("CUDA auto configuration downloading is only supported on Linux and Windows, but the current OS is: " + repository_ctx.os.name)
# Link and run the download script.
script_path = repository_ctx.path(script_file)
repository_ctx.symlink(script_path, "download.py")
output_dir = repository_ctx.path("cuda_root")

result = repository_ctx.execute(["python3", "download.py", output_dir], timeout=40)
if result.return_code != 0:
fail("download.py execution failed:\n" + result.stderr)

cuda_toolkit_root = "cuda_root/12.2.1/linux-x86_64"
else:
# Probe environment for CUDA toolkit location.
env_cuda_toolkit_root = env.get(CUDA_TOOLKIT_ROOT_ENV_KEY)
env_cuda_deps_dir_for_ci = env.get(CUDA_DEPS_DIR_FOR_CI_ENV_KEY)
if env_cuda_toolkit_root:
cuda_toolkit_root = env_cuda_toolkit_root
elif env_cuda_deps_dir_for_ci:
cuda_toolkit_root = env_cuda_deps_dir_for_ci

# If we found a CUDA toolkit root (either via download or the environment),
# create symlinks for the directories and libdevice.
libdevice_rel_path = "iree_local/libdevice.bc"
if cuda_toolkit_root != None:
# Symlink top-level directories we care about.
if cuda_toolkit_root:
repository_ctx.symlink(cuda_toolkit_root + "/include", "include")

# TODO: Should be probing for the libdevice, as it can change from
# version to version.
repository_ctx.symlink(
cuda_toolkit_root + "/nvvm/libdevice/libdevice.10.bc",
libdevice_rel_path,
Expand All @@ -64,14 +78,17 @@ cuda_auto_configure = repository_rule(
implementation = cuda_auto_configure_impl,
attrs = {
"iree_repo_alias": attr.string(default = "@iree_core"),
"script": attr.label(allow_files = True, default=None),
},
local = True
)

def configure_iree_cuda_deps(iree_repo_alias = None):
def configure_iree_cuda_deps(iree_repo_alias = None, script = ""):
maybe(
cuda_auto_configure,
name = "iree_cuda",
iree_repo_alias = iree_repo_alias,
script = script,
)

def configure_iree_submodule_deps(iree_repo_alias = "@", iree_path = "./"):
Expand Down
17 changes: 17 additions & 0 deletions build_tools/bazel/workspace_root.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def _workspace_root_impl(ctx):
"""Dynamically determine the workspace root from the current context.
The path is made available as a `WORKSPACE_ROOT` environmment variable and
may for instance be consumed in the `toolchains` attributes for `cc_library`
and `genrule` targets.
"""
workspace_root = ctx.label.workspace_root if ctx.label.workspace_root else "."
return [
platform_common.TemplateVariableInfo({
"WORKSPACE_ROOT": workspace_root,
}),
]

workspace_root = rule(
implementation = _workspace_root_impl,
attrs = {},
)
4 changes: 3 additions & 1 deletion compiler/bindings/c/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ cc_test(
"iree/compiler/loader/loader_test.c",
],
args = [
"lib/libIREECompiler.so",
"$(WORKSPACE_ROOT)/lib/libIREECompiler.so",
],
data = [
"//lib:libIREECompiler.so",
Expand All @@ -55,4 +55,6 @@ cc_test(
":headers",
":loader",
],
toolchains = ["//:workspace_root"],
)

Loading