Skip to content
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
43 changes: 40 additions & 3 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,52 @@ ForEachMacros:
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Regroup
# Include Groups (by priority):
# 1. C system headers: `#include <*.h>`
#
# 2. C++ system headers: `#include <*>`
#
# 3. PyTorch headers:
# a) API headers: `#include <torch/*.h>`
# b) ATen headers: `#include <ATen/*.h>`
# c) c10 headers: `#include <c10/*.h>`
#
# Note that PyTorch headers should be included with angle-brackets so as to
# keep consistency with PyTorch source code. This should also prevent
# headers to be included twice because of different paths.
#
# Google C++ Style Guide dictates (3) and (4) should belong to the same
# group. However, this breaks PyTorch/XLA build. The problem is that both
# PyTorch and abseil-cpp (included by OpenXLA) define (among many) the
# `LOG()` macro. This leads to problems, such as OpenXLA functions calling
# PyTorch `LOG()` macro due to include order.
#
# In order to avoid such a problem, we make PyTorch into its own group,
# just after the system libraries. This works because including OpenXLA
# headers will redefine PyTorch `LOG()` macro, solving the problem above.
# This, however might fail one day, if PyTorch starts calling `LOG()` macro
# in one of the headers we include in PyTorch/XLA.
Comment on lines +74 to +93
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to move PyTorch headers to their own group, right after the C++ system libraries. Otherwise, we would get a build error where some OpenXLA files would call the LOG() macro defined by PyTorch, rather than the one defined by abseil-cpp. See the comment above for more details.

#
# 4. External headers:
# a) abseil-cpp headers: `#include "absl/*.h"
# b) OpenXLA headers: `#include "xla/*.h"
#
# 5. Project headers:
# a) _XLAC headers: `#include "torch_xla/csrc/*.h"`
# b) Test headers: `#include "test/*.h"`
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
- Regex: '^<torch/.*>'
Priority: 3
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '"torch_xla/.*"'
Priority: 5
- Regex: '"test/.*"'
Priority: 5
- Regex: '.*'
Priority: 3
Priority: 4
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentPPDirectives: None
Expand Down
4 changes: 3 additions & 1 deletion test/cpp/cpp_test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
#define XLA_TEST_CPP_CPP_TEST_UTIL_H_

#include <gtest/gtest.h>
#include <torch/torch.h>

#include <cmath>
#include <functional>
#include <string>
#include <unordered_set>

#include <torch/torch.h>

#include "absl/types/span.h"

#include "torch_xla/csrc/debug_util.h"
#include "torch_xla/csrc/device.h"
#include "torch_xla/csrc/dtype.h"
Expand Down
3 changes: 2 additions & 1 deletion test/cpp/metrics_snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

#include <regex>

#include "torch/csrc/lazy/core/metrics.h"
#include <torch/csrc/lazy/core/metrics.h>

#include "torch_xla/csrc/runtime/tf_logging.h"
#include "torch_xla/csrc/runtime/util.h"

Expand Down
3 changes: 2 additions & 1 deletion test/cpp/metrics_snapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
#include <unordered_set>
#include <vector>

#include "torch_xla/csrc/runtime/metrics.h"
#include "xla/types.h"

#include "torch_xla/csrc/runtime/metrics.h"

namespace torch_xla {
namespace cpp_test {

Expand Down
8 changes: 5 additions & 3 deletions test/cpp/test_aten_xla_tensor_1.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#include <gtest/gtest.h>
#include <torch/torch.h>

#include <iostream>

#include <torch/torch.h>

#include "xla/permutation_util.h"
#include "xla/util.h"

#include "test/cpp/cpp_test_util.h"
#include "test/cpp/torch_xla_test.h"
#include "torch_xla/csrc/aten_xla_bridge.h"
Expand All @@ -12,8 +16,6 @@
#include "torch_xla/csrc/ops/ops.h"
#include "torch_xla/csrc/runtime/metrics.h"
#include "torch_xla/csrc/torch_util.h"
#include "xla/permutation_util.h"
#include "xla/util.h"

namespace torch_xla {
namespace cpp_test {
Expand Down
8 changes: 5 additions & 3 deletions test/cpp/test_aten_xla_tensor_2.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#include <gtest/gtest.h>
#include <torch/torch.h>

#include <iostream>
#include <tuple>

#include <torch/torch.h>

#include "xla/permutation_util.h"
#include "xla/util.h"

#include "test/cpp/cpp_test_util.h"
#include "test/cpp/torch_xla_test.h"
#include "torch_xla/csrc/aten_xla_bridge.h"
Expand All @@ -13,8 +17,6 @@
#include "torch_xla/csrc/ops/ops.h"
#include "torch_xla/csrc/runtime/metrics.h"
#include "torch_xla/csrc/torch_util.h"
#include "xla/permutation_util.h"
#include "xla/util.h"

namespace torch_xla {
namespace cpp_test {
Expand Down
8 changes: 5 additions & 3 deletions test/cpp/test_aten_xla_tensor_3.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#include <gtest/gtest.h>
#include <torch/torch.h>

#include <iostream>

#include <torch/torch.h>

#include "xla/permutation_util.h"
#include "xla/util.h"

#include "test/cpp/cpp_test_util.h"
#include "test/cpp/torch_xla_test.h"
#include "torch_xla/csrc/aten_xla_bridge.h"
Expand All @@ -12,8 +16,6 @@
#include "torch_xla/csrc/ops/ops.h"
#include "torch_xla/csrc/runtime/metrics.h"
#include "torch_xla/csrc/torch_util.h"
#include "xla/permutation_util.h"
#include "xla/util.h"

namespace torch_xla {
namespace cpp_test {
Expand Down
8 changes: 5 additions & 3 deletions test/cpp/test_aten_xla_tensor_4.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#include <gtest/gtest.h>
#include <torch/torch.h>

#include <iostream>

#include <torch/torch.h>

#include "xla/permutation_util.h"
#include "xla/util.h"

#include "test/cpp/cpp_test_util.h"
#include "test/cpp/torch_xla_test.h"
#include "torch_xla/csrc/aten_xla_bridge.h"
Expand All @@ -12,8 +16,6 @@
#include "torch_xla/csrc/ops/ops.h"
#include "torch_xla/csrc/runtime/metrics.h"
#include "torch_xla/csrc/torch_util.h"
#include "xla/permutation_util.h"
#include "xla/util.h"

namespace torch_xla {
namespace cpp_test {
Expand Down
8 changes: 5 additions & 3 deletions test/cpp/test_aten_xla_tensor_5.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#include <gtest/gtest.h>
#include <torch/torch.h>

#include <iostream>

#include <torch/torch.h>

#include "xla/permutation_util.h"
#include "xla/util.h"

#include "test/cpp/cpp_test_util.h"
#include "test/cpp/torch_xla_test.h"
#include "torch_xla/csrc/aten_xla_bridge.h"
Expand All @@ -12,8 +16,6 @@
#include "torch_xla/csrc/ops/ops.h"
#include "torch_xla/csrc/runtime/metrics.h"
#include "torch_xla/csrc/torch_util.h"
#include "xla/permutation_util.h"
#include "xla/util.h"

namespace torch_xla {
namespace cpp_test {
Expand Down
8 changes: 5 additions & 3 deletions test/cpp/test_aten_xla_tensor_6.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#include <gtest/gtest.h>
#include <torch/torch.h>

#include <iostream>

#include <torch/torch.h>

#include "xla/permutation_util.h"
#include "xla/util.h"

#include "test/cpp/cpp_test_util.h"
#include "test/cpp/torch_xla_test.h"
#include "torch_xla/csrc/aten_xla_bridge.h"
Expand All @@ -12,8 +16,6 @@
#include "torch_xla/csrc/ops/ops.h"
#include "torch_xla/csrc/runtime/metrics.h"
#include "torch_xla/csrc/torch_util.h"
#include "xla/permutation_util.h"
#include "xla/util.h"

namespace torch_xla {
namespace cpp_test {
Expand Down
1 change: 1 addition & 0 deletions test/cpp/test_device.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <gtest/gtest.h>

#include "absl/strings/str_cat.h"

#include "torch_xla/csrc/device.h"

static void CheckFormatError(const std::string& spec) {
Expand Down
6 changes: 4 additions & 2 deletions test/cpp/test_lazy.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include <gtest/gtest.h>

#include <torch/csrc/lazy/core/shape.h>

#include "xla/shape.h"

#include "test/cpp/torch_xla_test.h"
#include "torch/csrc/lazy/core/shape.h"
#include "torch_xla/csrc/helpers.h"
#include "xla/shape.h"

namespace torch_xla {
namespace cpp_test {
Expand Down
5 changes: 3 additions & 2 deletions test/cpp/test_replication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <iostream>

#include "absl/synchronization/blocking_counter.h"
#include "xla/hlo/builder/xla_builder.h"
#include "xla/shape_util.h"

#include "test/cpp/cpp_test_util.h"
#include "test/cpp/torch_xla_test.h"
#include "torch_xla/csrc/aten_xla_bridge.h"
Expand All @@ -14,8 +17,6 @@
#include "torch_xla/csrc/tensor_util.h"
#include "torch_xla/csrc/thread_pool.h"
#include "torch_xla/csrc/torch_util.h"
#include "xla/hlo/builder/xla_builder.h"
#include "xla/shape_util.h"

namespace torch_xla {
namespace cpp_test {
Expand Down
1 change: 1 addition & 0 deletions test/cpp/test_status_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "absl/status/status.h"
#include "absl/status/statusor.h"

#include "test/cpp/cpp_test_util.h"
#include "torch_xla/csrc/runtime/env_vars.h"
#include "torch_xla/csrc/status.h"
Expand Down
4 changes: 3 additions & 1 deletion test/cpp/test_tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
#include <limits>
#include <vector>

#include <torch/csrc/autograd/variable.h>

#include "absl/base/nullability.h"

#include "test/cpp/cpp_test_util.h"
#include "test/cpp/torch_xla_test.h"
#include "torch/csrc/autograd/variable.h"
#include "torch_xla/csrc/aten_xla_bridge.h"
#include "torch_xla/csrc/tensor.h"
#include "torch_xla/csrc/tensor_methods.h"
Expand Down
3 changes: 2 additions & 1 deletion test/cpp/test_xla_generator.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <torch/torch.h>

#include <cstdlib>

#include <torch/torch.h>

#include "test/cpp/torch_xla_test.h"
#include "torch_xla/csrc/xla_generator.h"

Expand Down
8 changes: 5 additions & 3 deletions test/cpp/test_xla_sharding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
#include <google/protobuf/repeated_field.h>
#include <gtest/gtest.h>
#include <stdlib.h>
#include <torch/csrc/lazy/core/lazy_graph_executor.h>

#include <iostream>

#include <torch/csrc/lazy/core/lazy_graph_executor.h>

#include "xla/protobuf_util.h"
#include "xla/xla_data.pb.h"

#include "test/cpp/cpp_test_util.h"
#include "test/cpp/torch_xla_test.h"
#include "torch_xla/csrc/aten_xla_bridge.h"
Expand All @@ -19,8 +23,6 @@
#include "torch_xla/csrc/tensor_methods.h"
#include "torch_xla/csrc/tensor_util.h"
#include "torch_xla/csrc/xla_sharding_util.h"
#include "xla/protobuf_util.h"
#include "xla/xla_data.pb.h"

namespace torch_xla {
namespace cpp_test {
Expand Down
1 change: 1 addition & 0 deletions test/cpp/torch_xla_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <ATen/ATen.h>

#include "absl/memory/memory.h"

#include "torch_xla/csrc/aten_xla_bridge.h"
#include "torch_xla/csrc/device.h"
#include "torch_xla/csrc/helpers.h"
Expand Down
3 changes: 2 additions & 1 deletion torch_xla/csrc/aten_fallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
#include <ATen/native/CPUFallback.h>
#include <ATen/ops/_copy_from_and_resize.h>
#include <ATen/ops/_to_cpu.h>
#include <torch/csrc/utils/device_lazy_init.h>

#include <unordered_map>
#include <vector>

#include <torch/csrc/utils/device_lazy_init.h>

#include "torch_xla/csrc/function_call_tracker.h"
#include "torch_xla/csrc/runtime/metrics.h"
#include "torch_xla/csrc/runtime/tf_logging.h"
Expand Down
4 changes: 3 additions & 1 deletion torch_xla/csrc/aten_xla_bridge.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#include "torch_xla/csrc/aten_xla_bridge.h"

#include <ATen/FunctionalTensorWrapper.h>
#include <torch/csrc/lazy/core/tensor_util.h>

#include <map>
#include <string>
#include <vector>

#include <torch/csrc/lazy/core/tensor_util.h>

#include "absl/log/absl_check.h"
#include "absl/strings/str_cat.h"

#include "torch_xla/csrc/device.h"
#include "torch_xla/csrc/runtime/debug_macros.h"
#include "torch_xla/csrc/runtime/runtime.h"
Expand Down
1 change: 1 addition & 0 deletions torch_xla/csrc/aten_xla_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "absl/base/nullability.h"
#include "absl/status/statusor.h"
#include "absl/types/span.h"

#include "torch_xla/csrc/device.h"
#include "torch_xla/csrc/tensor.h"

Expand Down
Loading