From f8d0c648f2983d91ad2bfbcee08855ec71f0e4ba Mon Sep 17 00:00:00 2001 From: Zhanyong Wan Date: Tue, 13 May 2025 22:42:44 +0000 Subject: [PATCH 1/2] Fix an clang compilation error. --- torch_xla/csrc/helpers.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/torch_xla/csrc/helpers.cpp b/torch_xla/csrc/helpers.cpp index 36c95b7630f4..f689d2dcfa9d 100644 --- a/torch_xla/csrc/helpers.cpp +++ b/torch_xla/csrc/helpers.cpp @@ -6,7 +6,6 @@ #include #include -#include "absl/status/status.h" #include "absl/strings/str_join.h" #include "torch_xla/csrc/convert_ops.h" #include "torch_xla/csrc/dtype.h" @@ -1043,11 +1042,9 @@ absl::StatusOr XlaHelpers::WrapXlaComputation( xla::XlaOp orig_result = xla::Call(&builder, computation, inner_params); // Rebuild aliasing. - if (buffer_donor_indices.size() > 0) { - for (size_t i : buffer_donor_indices) { - builder.AddBufferDonor(/*param_number=*/0, - /*param_index=*/xla::ShapeIndex({i})); - } + for (const int64_t i : buffer_donor_indices) { + builder.AddBufferDonor(/*param_number=*/0, + /*param_index=*/xla::ShapeIndex({i})); } return builder.Build(orig_result); From 22749577745d7d5d33731eb8a361abddd00df6ad Mon Sep 17 00:00:00 2001 From: Zhanyong Wan Date: Wed, 14 May 2025 18:17:32 +0000 Subject: [PATCH 2/2] Switch bazel spawn strategy to sandboxed by default. --- .bazelrc | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/.bazelrc b/.bazelrc index 59b545c3029f..8b87092b699b 100644 --- a/.bazelrc +++ b/.bazelrc @@ -27,26 +27,20 @@ build --config=short_logs # PyTorch/XLA uses exceptions to communicate with Python. build --copt=-fexceptions -# Force GCC because clang/bazel has issues. -build --action_env=CC=gcc -build --action_env=CXX=g++ -build --spawn_strategy=standalone - -########################################################################### - -build:clang --action_env=CC=/usr/bin/clang-17 -build:clang --action_env=CXX=/usr/bin/clang++-17 - -# clang requires the sandbox mode. Without this, `bazel build` generates an -# error like: +# Why we use the sandbox mode: +# +# 1. it's a good practice that enforces explicit dependency declarations +# (see https://bazel.build/docs/user-manual#spawn-strategy). +# 2. clang requires the sandbox mode. Without this, `bazel build` generates an +# error like: # -# ERROR: .../external/llvm-project/llvm/BUILD.bazel:2006:11: Compiling -# llvm/lib/CodeGenTypes/LowLevelType.cpp failed: undeclared inclusion(s) in -# rule '@llvm-project//llvm:CodeGenTypes': -# this rule is missing dependency declarations for the following files -# included by 'llvm/lib/CodeGenTypes/LowLevelType.cpp': -# 'bazel-out/k8-opt/bin/external/llvm-project/llvm/config.cppmap' -# 'bazel-out/k8-opt/bin/external/llvm-project/llvm/Demangle.cppmap' +# ERROR: .../external/llvm-project/llvm/BUILD.bazel:2006:11: Compiling +# llvm/lib/CodeGenTypes/LowLevelType.cpp failed: undeclared inclusion(s) in +# rule '@llvm-project//llvm:CodeGenTypes': +# this rule is missing dependency declarations for the following files +# included by 'llvm/lib/CodeGenTypes/LowLevelType.cpp': +# 'bazel-out/k8-opt/bin/external/llvm-project/llvm/config.cppmap' +# 'bazel-out/k8-opt/bin/external/llvm-project/llvm/Demangle.cppmap' # # The sandbox mode requires all source files to be readable by others, as # inside the docker we build PyTorch/XLA as root, not the original user who @@ -57,7 +51,16 @@ build:clang --action_env=CXX=/usr/bin/clang++-17 # execute permission to directories, and to files only if they already have # execute permission for the owner (or group or others). This is generally # safer than o+rx. -build:clang --spawn_strategy=sandboxed +build --spawn_strategy=sandboxed + +# Use GCC for C/C++ compilation. +build --action_env=CC=gcc +build --action_env=CXX=g++ + +########################################################################### + +build:clang --action_env=CC=/usr/bin/clang-17 +build:clang --action_env=CXX=/usr/bin/clang++-17 ###########################################################################