Skip to content

Commit f60b0e1

Browse files
Add Hermetic C++ Toolchains for Linux x86_64 builds.
Hermetic toolchains provide builds that are isolated from the host system, cutting down on unexpected dependencies and side effects. By default, JAX now builds for Linux x86_64 architectures (both CPU and CUDA-enabled GPU) using hermetic C++ toolchains. For non-hermetic builds, add the flag --config=clang_local. For remote builds with a non-hermetic toolchain, simply append _clang_local to the existing RBE flag. For example, if hermetic RBE build runs with --config=rbe_linux_cpu, the non-hermetic version would be --config=rbe_linux_cpu_clang_local. Example 1: Run CPU tests for Linux x86_64 For hermetic tests run the command for Linux x86_64 build without env variables CC, CXX, etc.: bazel test //tests:cpu_tests \ --config=avx_posix \ --config=clang \ --linkopt=-lrt \ --host_linkopt=-lrt \ --repo_env=HERMETIC_PYTHON_VERSION="3.13" \ --test_tag_filters=-multiaccelerator For non-hermetic tests use commands with the flag "--config=clang_local" and env variables CC, CXX, etc.: bazel test //tests:cpu_tests \ --config=clang_local \ --config=avx_posix \ --config=clang \ --linkopt=-lrt \ --host_linkopt=-lrt \ --repo_env=HERMETIC_PYTHON_VERSION="3.13" \ --test_tag_filters=-multiaccelerator \ --action_env=CLANG_COMPILER_PATH=/usr/lib/llvm-18/bin/clang \ --repo_env=CC=/usr/lib/llvm-18/bin/clang \ --repo_env=CXX=/usr/lib/llvm-18/bin/clang++ \ --repo_env=BAZEL_COMPILER=/usr/lib/llvm-18/bin/clang \ --action_env=CCC_OVERRIDE_OPTIONS="^--gcc-install-dir=/usr/lib/gcc/x86_64-linux-gnu/13" Example 2: Run CUDA GPU tests for Linux x86_64 For hermetic tests, run the command without env variables CC, CXX, etc.: bazel test //tests:gpu_tests \ --config=cuda \ --config=clang \ --config=build_cuda_with_nvcc \ --config=avx_posix \ --linkopt=-lrt \ --host_linkopt=-lrt \ --test_tag_filters=-multiaccelerator \ --repo_env=HERMETIC_PYTHON_VERSION=3.13 For non-hermetic tests use commands with the flag "--config=clang_local" and env variables CC, CXX, etc.: bazel test //tests:gpu_tests \ --config=clang_local \ --config=avx_posix \ --config=build_cuda_with_nvcc \ --config=clang \ --config=cuda \ --linkopt=-lrt \ --host_linkopt=-lrt \ --action_env=CCC_OVERRIDE_OPTIONS="^--gcc-install-dir=/usr/lib/gcc/x86_64-linux-gnu/9" \ --test_tag_filters=-multiaccelerator \ --action_env=CLANG_COMPILER_PATH=/usr/lib/llvm-18/bin/clang \ --repo_env=CC=/usr/lib/llvm-18/bin/clang \ --repo_env=CXX=/usr/lib/llvm-18/bin/clang++ \ --repo_env=BAZEL_COMPILER=/usr/lib/llvm-18/bin/clang \ --repo_env=HERMETIC_PYTHON_VERSION=3.13 Example 3: Run RBE build for Linux x86_64 For hermetic build, run the same command as before modification: bazel build \ --config=ci_linux_x86_64 \ --repo_env=HERMETIC_PYTHON_VERSION=3.13 \ //jaxlib/tools:jaxlib_wheel For non-hermetic builds, add "_clang_local" suffix to RBE configuration: bazel build \ --config=ci_linux_x86_64_clang_local \ --repo_env=HERMETIC_PYTHON_VERSION=3.13 \ //jaxlib/tools:jaxlib_wheel We don't support other "rbe_*_clang_local" configuration flags, and you could construct your own combinations. PiperOrigin-RevId: 774963837
1 parent 1c0f24b commit f60b0e1

File tree

5 files changed

+54
-36
lines changed

5 files changed

+54
-36
lines changed

.bazelrc

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
# TODO: Enable Bzlmod
55
common --noenable_bzlmod
66

7-
# TODO: Migrate for https://github.com/bazelbuild/bazel/issues/7260
8-
common --noincompatible_enable_cc_toolchain_resolution
9-
107
# Make Bazel print out all options from rc files.
118
common --announce_rc
129

@@ -19,6 +16,13 @@ build --enable_platform_specific_config
1916

2017
common --experimental_cc_shared_library
2118

19+
build --incompatible_enable_cc_toolchain_resolution
20+
build --repo_env USE_HERMETIC_CC_TOOLCHAIN=1
21+
22+
# TODO: Migrate for https://github.com/bazelbuild/bazel/issues/7260
23+
build:clang_local --noincompatible_enable_cc_toolchain_resolution
24+
build:clang_local --repo_env USE_HERMETIC_CC_TOOLCHAIN=0
25+
2226
# Do not use C-Ares when building gRPC.
2327
build --define=grpc_no_ares=true
2428

@@ -61,10 +65,13 @@ build:macos --host_linkopt=-Wl,-undefined,dynamic_lookup
6165

6266
# Use cc toolchains from apple_support for Apple builds.
6367
# https://github.com/bazelbuild/apple_support/tree/master?tab=readme-ov-file#bazel-6-setup
68+
build:macos --config=clang_local
6469
build:macos --apple_crosstool_top=@local_config_apple_cc//:toolchain
6570
build:macos --crosstool_top=@local_config_apple_cc//:toolchain
6671
build:macos --host_crosstool_top=@local_config_apple_cc//:toolchain
6772

73+
build:windows --config=clang_local
74+
6875
# Windows has a relatively short command line limit, which JAX has begun to hit.
6976
# See https://docs.bazel.build/versions/main/windows.html
7077
build:windows --features=compiler_param_file
@@ -159,7 +166,6 @@ build:cuda --repo_env TF_NCCL_USE_STUB=1
159166
# "sm" means we emit only cubin, which is forward compatible within a GPU generation.
160167
# "compute" means we emit both cubin and PTX, which is larger but also forward compatible to future GPU generations.
161168
build:cuda --repo_env HERMETIC_CUDA_COMPUTE_CAPABILITIES="sm_50,sm_60,sm_70,sm_80,sm_90,sm_100,compute_120"
162-
build:cuda --crosstool_top=@local_config_cuda//crosstool:toolchain
163169
build:cuda --@local_config_cuda//:enable_cuda
164170

165171
# Default hermetic CUDA, CUDNN and NVSHMEM versions.
@@ -194,10 +200,12 @@ build:build_cuda_with_nvcc --action_env=TF_NVCC_CLANG="1"
194200
build:build_cuda_with_nvcc --@local_config_cuda//:cuda_compiler=nvcc
195201

196202
# Requires MSVC and LLVM to be installed
203+
build:win_clang --config=clang_local
197204
build:win_clang --extra_toolchains=@local_config_cc//:cc-toolchain-x64_windows-clang-cl
198205
build:win_clang --extra_execution_platforms=//jax/tools/toolchains:x64_windows-clang-cl
199206
build:win_clang --compiler=clang-cl
200207

208+
build:rocm_base --config=clang_local
201209
build:rocm_base --crosstool_top=@local_config_rocm//crosstool:toolchain
202210
build:rocm_base --define=using_rocm=true --define=using_rocm_hipcc=true
203211
build:rocm_base --repo_env TF_NEED_ROCM=1
@@ -241,15 +249,18 @@ build:ci_linux_x86_64 --config=mkl_open_source_only
241249
build:ci_linux_x86_64 --config=clang --verbose_failures=true
242250
build:ci_linux_x86_64 --color=yes
243251

252+
# Deprecated CI config with non-hermetic toolchains.
244253
# TODO(b/356695103): We do not have a CPU only toolchain so we use the CUDA
245254
# toolchain for both CPU and GPU builds.
246-
build:ci_linux_x86_64 --host_crosstool_top="@local_config_cuda//crosstool:toolchain"
247-
build:ci_linux_x86_64 --crosstool_top="@local_config_cuda//crosstool:toolchain"
248-
build:ci_linux_x86_64 --extra_toolchains="@local_config_cuda//crosstool:toolchain-linux-x86_64"
249-
build:ci_linux_x86_64 --repo_env=TF_SYSROOT="/dt9"
255+
build:ci_linux_x86_64_clang_local --config=ci_linux_x86_64
256+
build:ci_linux_x86_64_clang_local --config=clang_local
257+
build:ci_linux_x86_64_clang_local --host_crosstool_top="@local_config_cuda//crosstool:toolchain"
258+
build:ci_linux_x86_64_clang_local --crosstool_top="@local_config_cuda//crosstool:toolchain"
259+
build:ci_linux_x86_64_clang_local --extra_toolchains="@local_config_cuda//crosstool:toolchain-linux-x86_64"
260+
build:ci_linux_x86_64_clang_local --repo_env=TF_SYSROOT="/dt9"
250261

251262
# Clang path needs to be set for remote toolchain to be configured correctly.
252-
build:ci_linux_x86_64 --action_env=CLANG_CUDA_COMPILER_PATH="/usr/lib/llvm-18/bin/clang"
263+
build:ci_linux_x86_64_clang_local --action_env=CLANG_CUDA_COMPILER_PATH="/usr/lib/llvm-18/bin/clang"
253264

254265
# The toolchain in `--config=cuda` needs to be read before the toolchain in
255266
# `--config=ci_linux_x86_64`. Otherwise, we run into issues with manylinux
@@ -258,6 +269,7 @@ build:ci_linux_x86_64_cuda --config=cuda --config=build_cuda_with_nvcc
258269
build:ci_linux_x86_64_cuda --config=ci_linux_x86_64
259270

260271
# Linux Aarch64 CI configs
272+
build:ci_linux_aarch64_base --config=clang_local
261273
build:ci_linux_aarch64_base --config=clang --verbose_failures=true
262274
build:ci_linux_aarch64_base --action_env=TF_SYSROOT="/dt10"
263275
build:ci_linux_aarch64_base --color=yes
@@ -279,12 +291,14 @@ build:ci_linux_aarch64_cuda --config=cuda --config=build_cuda_with_nvcc
279291
build:ci_linux_aarch64_cuda --action_env=CLANG_CUDA_COMPILER_PATH="/usr/lib/llvm-18/bin/clang"
280292

281293
# Mac Arm64 CI configs
294+
build:ci_darwin_arm64 --config=clang_local
282295
build:ci_darwin_arm64 --macos_minimum_os=11.0
283296
build:ci_darwin_arm64 --config=macos_cache_push
284297
build:ci_darwin_arm64 --verbose_failures=true
285298
build:ci_darwin_arm64 --color=yes
286299

287300
# Windows x86 CI configs
301+
build:ci_windows_amd64 --config=clang_local
288302
build:ci_windows_amd64 --config=avx_windows
289303
build:ci_windows_amd64 --compiler=clang-cl --config=clang --verbose_failures=true
290304
build:ci_windows_amd64 --crosstool_top="@xla//tools/toolchains/win2022/20241118:toolchain"
@@ -356,6 +370,7 @@ build:rbe_linux_x86_64_cuda --repo_env=USE_NVSHMEM_TAR_ARCHIVE_FILES=1
356370
# Set the remote worker pool
357371
common:rbe_windows_amd64 --remote_instance_name=projects/tensorflow-testing/instances/windows
358372

373+
build:rbe_windows_amd64 --config=clang_local
359374
build:rbe_windows_amd64 --config=rbe
360375

361376
# Set the host, execution, and target platform
@@ -382,6 +397,7 @@ build:rbe_windows_amd64 --config=ci_windows_amd64
382397
# flags seem to be actually used to specify the execution platform details. It
383398
# seems it is this way because these flags are old and predate the distinction
384399
# between host and execution platform.
400+
build:cross_compile_base --config=clang_local
385401
build:cross_compile_base --host_cpu=k8
386402
build:cross_compile_base --host_crosstool_top=@xla//tools/toolchains/cross_compile/cc:cross_compile_toolchain_suite
387403
build:cross_compile_base --extra_execution_platforms=@xla//tools/toolchains/cross_compile/config:linux_x86_64

WORKSPACE

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,6 @@ load("@pypi//:requirements.bzl", "install_deps")
5454

5555
install_deps()
5656

57-
# Optional, to facilitate testing against newest versions of Python
58-
load("@xla//third_party/py:python_repo.bzl", "custom_python_interpreter")
59-
60-
custom_python_interpreter(
61-
name = "python_dev",
62-
strip_prefix = "Python-{version_variant}",
63-
urls = ["https://www.python.org/ftp/python/{version}/Python-{version_variant}.tgz"],
64-
version = "3.13.0",
65-
version_variant = "3.13.0rc2",
66-
)
67-
6857
load("@xla//:workspace2.bzl", "xla_workspace2")
6958

7059
xla_workspace2()
@@ -99,7 +88,18 @@ python_wheel_version_suffix_repository(
9988
)
10089

10190
load(
102-
"@xla//third_party/gpus/cuda/hermetic:cuda_json_init_repository.bzl",
91+
"@rules_ml_toolchain//cc_toolchain/deps:cc_toolchain_deps.bzl",
92+
"cc_toolchain_deps",
93+
)
94+
95+
cc_toolchain_deps()
96+
97+
register_toolchains("@rules_ml_toolchain//cc_toolchain:lx64_lx64")
98+
99+
register_toolchains("@rules_ml_toolchain//cc_toolchain:lx64_lx64_cuda")
100+
101+
load(
102+
"@rules_ml_toolchain//third_party/gpus/cuda/hermetic:cuda_json_init_repository.bzl",
103103
"cuda_json_init_repository",
104104
)
105105

@@ -111,7 +111,7 @@ load(
111111
"CUDNN_REDISTRIBUTIONS",
112112
)
113113
load(
114-
"@xla//third_party/gpus/cuda/hermetic:cuda_redist_init_repositories.bzl",
114+
"@rules_ml_toolchain//third_party/gpus/cuda/hermetic:cuda_redist_init_repositories.bzl",
115115
"cuda_redist_init_repositories",
116116
"cudnn_redist_init_repository",
117117
)
@@ -125,28 +125,28 @@ cudnn_redist_init_repository(
125125
)
126126

127127
load(
128-
"@xla//third_party/gpus/cuda/hermetic:cuda_configure.bzl",
128+
"@rules_ml_toolchain//third_party/gpus/cuda/hermetic:cuda_configure.bzl",
129129
"cuda_configure",
130130
)
131131

132132
cuda_configure(name = "local_config_cuda")
133133

134134
load(
135-
"@xla//third_party/nccl/hermetic:nccl_redist_init_repository.bzl",
135+
"@rules_ml_toolchain//third_party/nccl/hermetic:nccl_redist_init_repository.bzl",
136136
"nccl_redist_init_repository",
137137
)
138138

139139
nccl_redist_init_repository()
140140

141141
load(
142-
"@xla//third_party/nccl/hermetic:nccl_configure.bzl",
142+
"@rules_ml_toolchain//third_party/nccl/hermetic:nccl_configure.bzl",
143143
"nccl_configure",
144144
)
145145

146146
nccl_configure(name = "local_config_nccl")
147147

148148
load(
149-
"@xla//third_party/nvshmem/hermetic:nvshmem_json_init_repository.bzl",
149+
"@rules_ml_toolchain//third_party/nvshmem/hermetic:nvshmem_json_init_repository.bzl",
150150
"nvshmem_json_init_repository",
151151
)
152152

@@ -157,7 +157,7 @@ load(
157157
"NVSHMEM_REDISTRIBUTIONS",
158158
)
159159
load(
160-
"@xla//third_party/nvshmem/hermetic:nvshmem_redist_init_repository.bzl",
160+
"@rules_ml_toolchain//third_party/nvshmem/hermetic:nvshmem_redist_init_repository.bzl",
161161
"nvshmem_redist_init_repository",
162162
)
163163

@@ -166,7 +166,7 @@ nvshmem_redist_init_repository(
166166
)
167167

168168
load(
169-
"@xla//third_party/nvshmem/hermetic:nvshmem_configure.bzl",
169+
"@rules_ml_toolchain//third_party/nvshmem/hermetic:nvshmem_configure.bzl",
170170
"nvshmem_configure",
171171
)
172172

ci/utilities/run_auditwheel.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,16 @@ for wheel in $WHEELS; do
3737
wheel_name=$(basename $wheel)
3838
OUTPUT=${OUTPUT_FULL//${wheel_name}/}
3939

40-
# If a wheel is manylinux2014 compliant, `auditwheel show` will return the
41-
# platform tag as manylinux_2_17. manylinux2014 is an alias for
42-
# manylinux_2_17.
43-
if echo "$OUTPUT" | grep -q "manylinux_2_17"; then
40+
# If a wheel is manylinux_2_27 or manylinux2014 compliant, `auditwheel show`
41+
# will return platform tag as manylinux_2_27 or manylinux_2_17 respectively.
42+
# manylinux2014 is an alias for manylinux_2_17.
43+
if echo "$OUTPUT" | grep -q "manylinux_2_27"; then
44+
printf "\n$wheel_name is manylinux_2_27 compliant.\n"
45+
elif echo "$OUTPUT" | grep -q "manylinux_2_17"; then
4446
printf "\n$wheel_name is manylinux2014 compliant.\n"
4547
else
4648
echo "$OUTPUT_FULL"
47-
printf "\n$wheel_name is NOT manylinux2014 compliant.\n"
49+
printf "\n$wheel_name is NOT manylinux_2_27 or manylinux2014 compliant.\n"
4850
exit 1
4951
fi
5052
done

docs/developer.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ and re-run the requirements updater command for a selected version of Python.
299299
For example:
300300

301301
```
302-
echo -e "\n$(realpath jaxlib-0.4.27.dev20240416-cp312-cp312-manylinux2014_x86_64.whl)" >> build/requirements.in
302+
echo -e "\n$(realpath jaxlib-0.4.27.dev20240416-cp312-cp312-manylinux_2_27_x86_64.whl)" >> build/requirements.in
303303
python build/build.py requirements_update --python_version=3.12
304304
```
305305

@@ -542,7 +542,7 @@ python build/build.py requirements_update
542542
Alternatively, to install `jaxlib` from a local wheel (assuming Python 3.12):
543543

544544
```
545-
echo -e "\n$(realpath jaxlib-0.4.26-cp312-cp312-manylinux2014_x86_64.whl)" >> build/requirements.in
545+
echo -e "\n$(realpath jaxlib-0.4.26-cp312-cp312-manylinux_2_27_x86_64.whl)" >> build/requirements.in
546546
python build/build.py requirements_update --python_version=3.12
547547
```
548548

jaxlib/jax.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jax_test_util_visibility = []
5959
loops_visibility = []
6060

6161
PLATFORM_TAGS_DICT = {
62-
("Linux", "x86_64"): ("manylinux2014", "x86_64"),
62+
("Linux", "x86_64"): ("manylinux_2_27", "x86_64"),
6363
("Linux", "aarch64"): ("manylinux2014", "aarch64"),
6464
("Linux", "ppc64le"): ("manylinux2014", "ppc64le"),
6565
("Darwin", "x86_64"): ("macosx_11_0", "x86_64"),

0 commit comments

Comments
 (0)