Skip to content
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

Modularize Bazel build #421

Merged
merged 27 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5906ecb
organize platforms and toolchains
mofeing Dec 11, 2024
12845ef
hardcode libcxxwrap_julia path
mofeing Dec 12, 2024
0273a35
format code
mofeing Dec 12, 2024
750703b
remove outdated hardcoded symbolic links
mofeing Dec 12, 2024
038045d
add third party bazel wrapper to libcxxwrap_julia
mofeing Dec 12, 2024
54c167e
readd platforms
mofeing Dec 12, 2024
ee5908c
some small fixes
mofeing Dec 12, 2024
eb05d33
first step on moving externals to modular organization
mofeing Dec 12, 2024
4e9e3eb
refactor libcxxwrap_julia on top of `cc_import`
mofeing Dec 13, 2024
3631928
use modular workspaces
mofeing Dec 13, 2024
aaf730c
add `libcxxwrap_julia` as dependency
mofeing Dec 13, 2024
4b1a16a
hardcode julia dep
mofeing Dec 13, 2024
0763788
export `reactant_*` functions
mofeing Dec 17, 2024
29ea440
downgrade libcxxwrap_julia to v0.13.3
mofeing Dec 17, 2024
4a305ac
fix major version when linking to libcxxwrap_julia
mofeing Dec 17, 2024
0901a97
remove legacy export
mofeing Dec 17, 2024
985edd4
move `API.cpp` to new `src/` folder to start modularizing code
mofeing Dec 17, 2024
c810660
export `register_julia_module` from libcxxwrap_julia
mofeing Dec 17, 2024
2d799ef
fix symbol visibility
mofeing Dec 23, 2024
c8c6a86
clean code
mofeing Dec 23, 2024
eadaa06
format code
mofeing Dec 23, 2024
d98e9e5
import hedron compile commands from Enzyme-JAX
mofeing Dec 28, 2024
8faf88d
move deps commits to `workspace.bzl`
mofeing Dec 28, 2024
aab138a
Merge branch 'main' into modularize-bazel
mofeing Dec 29, 2024
389269e
Merge branch 'main' into modularize-bazel
mofeing Dec 29, 2024
6981d17
Merge branch 'main' into modularize-bazel
mofeing Dec 30, 2024
0694a6b
Merge branch 'main' into modularize-bazel
mofeing Dec 30, 2024
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
371 changes: 179 additions & 192 deletions deps/ReactantExtra/BUILD

Large diffs are not rendered by default.

183 changes: 44 additions & 139 deletions deps/ReactantExtra/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,121 +1,29 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

NSYNC_COMMIT = "82b118aa7ace3132e517e2c467f8732978cf4023"
NSYNC_SHA256 = ""
http_archive(
name = "nsync",
sha256 = NSYNC_SHA256,
strip_prefix = "nsync-" + NSYNC_COMMIT,
urls = ["https://github.com/wsmoses/nsync/archive/{commit}.tar.gz".format(commit = NSYNC_COMMIT)],
)

ENZYMEXLA_COMMIT = "74046d05089c02946058f8fd94ed23efd0bf3ccc"
ENZYMEXLA_SHA256 = ""

http_archive(
name = "enzyme_ad",
sha256 = ENZYMEXLA_SHA256,
strip_prefix = "Enzyme-JAX-" + ENZYMEXLA_COMMIT,
urls = ["https://github.com/EnzymeAD/Enzyme-JAX/archive/{commit}.tar.gz".format(commit = ENZYMEXLA_COMMIT)],
)


http_archive(
name = "rules_python",
sha256 = "778aaeab3e6cfd56d681c89f5c10d7ad6bf8d2f1a72de9de55b23081b2d31618",
strip_prefix = "rules_python-0.34.0",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.34.0/rules_python-0.34.0.tar.gz",
)
workspace(name = "Reactant")

# Hedron's Compile Commands Extractor for Bazel
# https://github.com/hedronvision/bazel-compile-commands-extractor
http_archive(
name = "hedron_compile_commands",
load("//third_party/nsync:workspace.bzl", nsync_workspace = "repo")
nsync_workspace()

# Replace the commit hash (0e990032f3c5a866e72615cf67e5ce22186dcb97) in both places (below) with the latest (https://github.com/hedronvision/bazel-compile-commands-extractor/commits/main), rather than using the stale one here.
# Even better, set up Renovate and let it do the work for you (see "Suggestion: Updates" in the README).
url = "https://github.com/hedronvision/bazel-compile-commands-extractor/archive/4f28899228fb3ad0126897876f147ca15026151e.tar.gz",
strip_prefix = "bazel-compile-commands-extractor-4f28899228fb3ad0126897876f147ca15026151e",
# When you first run this tool, it'll recommend a sha256 hash to put here with a message like: "DEBUG: Rule 'hedron_compile_commands' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = ..."
)
load("@hedron_compile_commands//:workspace_setup.bzl", "hedron_compile_commands_setup")
hedron_compile_commands_setup()
load("@hedron_compile_commands//:workspace_setup_transitive.bzl", "hedron_compile_commands_setup_transitive")
hedron_compile_commands_setup_transitive()
load("@hedron_compile_commands//:workspace_setup_transitive_transitive.bzl", "hedron_compile_commands_setup_transitive_transitive")
hedron_compile_commands_setup_transitive_transitive()
load("@hedron_compile_commands//:workspace_setup_transitive_transitive_transitive.bzl", "hedron_compile_commands_setup_transitive_transitive_transitive")
hedron_compile_commands_setup_transitive_transitive_transitive()
load("//third_party/rules_python:workspace.bzl", rules_python_workspace = "repo")
rules_python_workspace()

load("@enzyme_ad//:workspace.bzl", "JAX_COMMIT", "JAX_SHA256", "ENZYME_COMMIT", "ENZYME_SHA256", "XLA_PATCHES")

XLA_PATCHES = XLA_PATCHES + [
"""
sed -i.bak0 "s/__cpp_lib_hardware_interference_size/HW_INTERFERENCE_SIZE/g" xla/backends/cpu/runtime/thunk_executor.h
""",
"""
sed -i.bak0 "s/__cpp_lib_hardware_interference_size/HW_INTERFERENCE_SIZE/g" xla/stream_executor/host/host_kernel.cc
""",
"""
sed -i.bak0 "s/__cpp_lib_hardware_interference_size/HW_INTERFERENCE_SIZE/g" xla/tsl/concurrency/async_value_ref.h
""",
"""
sed -i.bak0 "s/patch_cmds = \\[/patch_cmds = \\[\\\"find . -type f -name config.bzl -exec sed -i.bak0 's\\/HAVE_LINK_H=1\\/HAVE_LINK_H=0\\/g' {} +\\\",/g" third_party/llvm/workspace.bzl
""",
"""
sed -i.bak0 "s/patch_cmds = \\[/patch_cmds = \\[\\\"find . -type f -name config.bzl -exec sed -i.bak0 's\\/LLVM_ENABLE_THREADS=1\\/LLVM_ENABLE_THREADS=0\\/g' {} +\\\",/g" third_party/llvm/workspace.bzl
""",
"""
sed -i.bak0 "s/patch_cmds = \\[/patch_cmds = \\[\\\"find . -type f -name config.bzl -exec sed -i.bak0 's\\/HAVE_MALLINFO=1\\/DONT_HAVE_ANY_MALLINFO=0\\/g' {} +\\\",/g" third_party/llvm/workspace.bzl
""",
"""
sed -i.bak0 "s/patch_cmds = \\[/patch_cmds = \\[\\\"find . -type f -name config.bzl -exec sed -i.bak0 's\\/HAVE_PTHREAD_GETNAME_NP=1\\/FAKE_HAVE_PTHREAD_GETNAME_NP=0\\/g' {} +\\\",/g" third_party/llvm/workspace.bzl
""",
"""
sed -i.bak0 "s/patch_cmds = \\[/patch_cmds = \\[\\\"find . -type f -name config.bzl -exec sed -i.bak0 's\\/HAVE_PTHREAD_SETNAME_NP=1\\/FAKE_HAVE_PTHREAD_SETNAME_NP=0\\/g' {} +\\\",/g" third_party/llvm/workspace.bzl
""",
"""
sed -i.bak0 "s/patch_cmds = \\[/patch_cmds = \\[\\\"find . -type f -name config.h -exec sed -i.bak0 's\\/ENABLE_CRASH_OVERRIDES 1\\/ENABLE_CRASH_OVERRIDES 0\\/g' {} +\\\",/g" third_party/llvm/workspace.bzl
""",
"""
sed -i.bak0 "s/patch_cmds = \\[/patch_cmds = \\[\\\"find . -type f -name config.h -exec sed -i.bak0 's\\/HAVE_PTHREAD_GETNAME_NP\\/FAKE_HAVE_PTHREAD_GETNAME_NP\\/g' {} +\\\",/g" third_party/llvm/workspace.bzl
""",
"""
sed -i.bak0 "s/patch_cmds = \\[/patch_cmds = \\[\\\"find . -type f -name config.h -exec sed -i.bak0 's\\/HAVE_PTHREAD_SETNAME_NP\\/FAKE_HAVE_PTHREAD_SETNAME_NP\\/g' {} +\\\",/g" third_party/llvm/workspace.bzl
""",
# """
# sed -i.bak0 "s/patch_cmds = \\[/patch_cmds = \\['find . -type f -name BUILD.bazel -exec sed -i.bak0 \\\\\\'s\\/\\\"CAPIIR\\\",\\/\\\"CAPIIR\\\",alwayslink=1,\\/g\\\\\\\\' {} +',/g" third_party/llvm/workspace.bzl
# """,
]
load("//third_party/enzyme_ad:workspace.bzl", enzyme_ad_workspace = "repo")
enzyme_ad_workspace()

LLVM_TARGETS = select({
"@bazel_tools//src/conditions:windows": ["AMDGPU", "NVPTX"],
"@bazel_tools//src/conditions:darwin": [],
"//conditions:default": ["AMDGPU", "NVPTX"],
}) + ["AArch64", "X86", "ARM"]
load("//third_party/rules_cc:workspace.bzl", rules_cc_workspace = "repo")
rules_cc_workspace()

http_archive(
name = "jax",
sha256 = JAX_SHA256,
strip_prefix = "jax-" + JAX_COMMIT,
urls = ["https://github.com/google/jax/archive/{commit}.tar.gz".format(commit = JAX_COMMIT)],
patch_args = ["-p1"],
patches = ["@enzyme_ad//:patches/jax.patch"],
)
load("@rules_cc//cc:repositories.bzl", "rules_cc_dependencies")
rules_cc_dependencies()

load("@jax//third_party/xla:workspace.bzl", "XLA_COMMIT", "XLA_SHA256")
load("//third_party/jax:workspace.bzl", jax_workspace = "repo")
jax_workspace()

http_archive(
name = "xla",
sha256 = XLA_SHA256,
strip_prefix = "xla-" + XLA_COMMIT,
urls = ["https://github.com/wsmoses/xla/archive/{commit}.tar.gz".format(commit = XLA_COMMIT)],
patch_cmds = XLA_PATCHES
)
load("//third_party/xla:workspace.bzl", xla_workspace = "repo")
xla_workspace()

load("@xla//third_party/py:python_init_rules.bzl", "python_init_rules")
python_init_rules()

load("@xla//third_party/py:python_init_repositories.bzl", "python_init_repositories")
python_init_repositories(
requirements = {
Expand All @@ -126,7 +34,7 @@ python_init_repositories(
"3.13": "//build:requirements_lock_3_13.txt",
},
)

load("@xla//third_party/py:python_init_toolchains.bzl", "python_init_toolchains")
python_init_toolchains()
#
Expand All @@ -144,42 +52,24 @@ python_init_toolchains()
#
# pip_install_dependencies()

http_archive(
name = "enzyme",
sha256 = ENZYME_SHA256,
strip_prefix = "Enzyme-" + ENZYME_COMMIT + "/enzyme",
urls = ["https://github.com/EnzymeAD/Enzyme/archive/{commit}.tar.gz".format(commit = ENZYME_COMMIT)],
)
load("//third_party/enzyme:workspace.bzl", enzyme_workspace = "repo")
enzyme_workspace()

http_archive(
name = "build_bazel_rules_apple",
sha256 = "34c41bfb59cdaea29ac2df5a2fa79e5add609c71bb303b2ebb10985f93fa20e7",
url = "https://github.com/bazelbuild/rules_apple/releases/download/3.1.1/rules_apple.3.1.1.tar.gz",
)
load("//third_party/build_bazel_rules_apple:workspace.bzl", build_bazel_rules_apple_workspace = "repo")
build_bazel_rules_apple_workspace()

load(
"@build_bazel_rules_apple//apple:repositories.bzl",
"apple_rules_dependencies",
)

apple_rules_dependencies()


http_archive(
name = "upb",
sha256 = "61d0417abd60e65ed589c9deee7c124fe76a4106831f6ad39464e1525cef1454",
strip_prefix = "upb-9effcbcb27f0a665f9f345030188c0b291e32482",
patch_cmds = [
"sed -i.bak0 's/@bazel_tools\\/\\/platforms:windows/@platforms\\/\\/os:windows/g' BUILD",
"sed -i.bak0 's/-Werror//g' BUILD"
],
url = "https://github.com/protocolbuffers/upb/archive/9effcbcb27f0a665f9f345030188c0b291e32482.tar.gz"
)
load("//third_party/upb:workspace.bzl", upb_workspace = "repo")
upb_workspace()

load("@jax//third_party/xla:workspace.bzl", jax_xla_workspace = "repo")
jax_xla_workspace()


load("@xla//:workspace4.bzl", "xla_workspace4")
xla_workspace4()

Expand All @@ -188,6 +78,12 @@ xla_workspace3()

load("@xla//:workspace2.bzl", "xla_workspace2")

LLVM_TARGETS = select({
"@bazel_tools//src/conditions:windows": ["AMDGPU", "NVPTX"],
"@bazel_tools//src/conditions:darwin": [],
"//conditions:default": ["AMDGPU", "NVPTX"],
}) + ["AArch64", "X86", "ARM"]

load("@llvm-raw//utils/bazel:configure.bzl", "llvm_configure")
llvm_configure(name = "llvm-project", targets = LLVM_TARGETS)
xla_workspace2()
Expand All @@ -205,7 +101,6 @@ load(
"@tsl//third_party/gpus/cuda/hermetic:cuda_json_init_repository.bzl",
"cuda_json_init_repository",
)

cuda_json_init_repository()

load(
Expand All @@ -218,11 +113,9 @@ load(
"cuda_redist_init_repositories",
"cudnn_redist_init_repository",
)

cuda_redist_init_repositories(
cuda_redistributions = CUDA_REDISTRIBUTIONS,
)

cudnn_redist_init_repository(
cudnn_redistributions = CUDNN_REDISTRIBUTIONS,
)
Expand All @@ -231,19 +124,31 @@ load(
"@tsl//third_party/gpus/cuda/hermetic:cuda_configure.bzl",
"cuda_configure",
)

cuda_configure(name = "local_config_cuda")

load(
"@tsl//third_party/nccl/hermetic:nccl_redist_init_repository.bzl",
"nccl_redist_init_repository",
)

nccl_redist_init_repository()

load(
"@tsl//third_party/nccl/hermetic:nccl_configure.bzl",
"nccl_configure",
)

nccl_configure(name = "local_config_nccl")

load("@enzyme_ad//third_party/hedron_compile_commands:workspace.bzl", hedron_compile_commands_workspace = "repo")
hedron_compile_commands_workspace()

load("@hedron_compile_commands//:workspace_setup.bzl", "hedron_compile_commands_setup")
hedron_compile_commands_setup()

load("@hedron_compile_commands//:workspace_setup_transitive.bzl", "hedron_compile_commands_setup_transitive")
hedron_compile_commands_setup_transitive()

load("@hedron_compile_commands//:workspace_setup_transitive_transitive.bzl", "hedron_compile_commands_setup_transitive_transitive")
hedron_compile_commands_setup_transitive_transitive()

load("@hedron_compile_commands//:workspace_setup_transitive_transitive_transitive.bzl", "hedron_compile_commands_setup_transitive_transitive_transitive")
hedron_compile_commands_setup_transitive_transitive_transitive()
File renamed without changes.
1 change: 1 addition & 0 deletions deps/ReactantExtra/third_party/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
licenses(["notice"])
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""Loads bazel rules for apple."""

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

def repo():
http_archive(
name = "build_bazel_rules_apple",
sha256 = "34c41bfb59cdaea29ac2df5a2fa79e5add609c71bb303b2ebb10985f93fa20e7",
url = "https://github.com/bazelbuild/rules_apple/releases/download/3.1.1/rules_apple.3.1.1.tar.gz",
)
Empty file.
12 changes: 12 additions & 0 deletions deps/ReactantExtra/third_party/enzyme/workspace.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""Loads Enzyme."""

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@enzyme_ad//:workspace.bzl", "ENZYME_COMMIT", "ENZYME_SHA256")

def repo():
http_archive(
name = "enzyme",
sha256 = ENZYME_SHA256,
strip_prefix = "Enzyme-" + ENZYME_COMMIT + "/enzyme",
urls = ["https://github.com/EnzymeAD/Enzyme/archive/{commit}.tar.gz".format(commit = ENZYME_COMMIT)],
)
Empty file.
12 changes: 12 additions & 0 deletions deps/ReactantExtra/third_party/enzyme_ad/workspace.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""Loads Enzyme-JAX."""

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("//:workspace.bzl", "ENZYMEXLA_COMMIT", "ENZYMEXLA_SHA256")

def repo():
http_archive(
name = "enzyme_ad",
sha256 = ENZYMEXLA_SHA256,
strip_prefix = "Enzyme-JAX-" + ENZYMEXLA_COMMIT,
urls = ["https://github.com/EnzymeAD/Enzyme-JAX/archive/{commit}.tar.gz".format(commit = ENZYMEXLA_COMMIT)],
)
Empty file.
14 changes: 14 additions & 0 deletions deps/ReactantExtra/third_party/jax/workspace.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""Loads Enzyme-JAX."""

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@enzyme_ad//:workspace.bzl", "JAX_COMMIT", "JAX_SHA256")

def repo():
http_archive(
name = "jax",
sha256 = JAX_SHA256,
strip_prefix = "jax-" + JAX_COMMIT,
urls = ["https://github.com/google/jax/archive/{commit}.tar.gz".format(commit = JAX_COMMIT)],
patch_args = ["-p1"],
patches = ["@enzyme_ad//:patches/jax.patch"],
)
Empty file.
12 changes: 12 additions & 0 deletions deps/ReactantExtra/third_party/nsync/workspace.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""Loads nsync."""

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("//:workspace.bzl", "NSYNC_COMMIT", "NSYNC_SHA256")

def repo():
http_archive(
name = "nsync",
sha256 = NSYNC_SHA256,
strip_prefix = "nsync-" + NSYNC_COMMIT,
urls = ["https://github.com/wsmoses/nsync/archive/{commit}.tar.gz".format(commit = NSYNC_COMMIT)],
)
Empty file.
14 changes: 14 additions & 0 deletions deps/ReactantExtra/third_party/rules_cc/workspace.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""Loads bazel rules_cc."""

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("//:workspace.bzl", "RULES_CC_COMMIT", "RULES_CC_SHA256")

def repo():
http_archive(
name = "rules_cc",
sha256 = RULES_CC_SHA256,
strip_prefix = "rules_cc-" + RULES_CC_COMMIT,
urls = [
"https://github.com/bazelbuild/rules_cc/archive/{commit}.tar.gz".format(commit = RULES_CC_COMMIT),
],
)
Empty file.
12 changes: 12 additions & 0 deletions deps/ReactantExtra/third_party/rules_python/workspace.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""Loads rules_python (downgrades over the one used by XLA due to a bug in the latest release)."""

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("//:workspace.bzl", "RULES_PYTHON_SHA256", "RULES_PYTHON_VERSION")

def repo():
http_archive(
name = "rules_python",
sha256 = RULES_PYTHON_SHA256,
strip_prefix = "rules_python-" + RULES_PYTHON_VERSION,
url = "https://github.com/bazelbuild/rules_python/releases/download/{commit}/rules_python-{commit}.tar.gz".format(commit = RULES_PYTHON_VERSION),
)
Empty file.
16 changes: 16 additions & 0 deletions deps/ReactantExtra/third_party/upb/workspace.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Loads upb."""

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("//:workspace.bzl", "UPB_COMMIT", "UPB_SHA256")

def repo():
http_archive(
name = "upb",
sha256 = UPB_SHA256,
strip_prefix = "upb-" + UPB_COMMIT,
patch_cmds = [
"sed -i.bak0 's/@bazel_tools\\/\\/platforms:windows/@platforms\\/\\/os:windows/g' BUILD",
"sed -i.bak0 's/-Werror//g' BUILD",
],
url = "https://github.com/protocolbuffers/upb/archive/{commit}.tar.gz".format(commit = UPB_COMMIT),
)
Empty file.
Loading
Loading