Skip to content

Commit

Permalink
[2/N] Cleanup header inclusions in torch_cpu by iwyu (pytorch#109964)
Browse files Browse the repository at this point in the history
Further cleaning up of torch_cpu header inclusions.

Pull Request resolved: pytorch#109964
Approved by: https://github.com/ezyang, https://github.com/Skylion007
  • Loading branch information
cyyever authored and pytorchmergebot committed Nov 19, 2023
1 parent 0bd4d1f commit 226384b
Show file tree
Hide file tree
Showing 49 changed files with 27 additions and 105 deletions.
1 change: 0 additions & 1 deletion aten/src/ATen/detail/CPUGuardImpl.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <c10/core/impl/DeviceGuardImplInterface.h>
#include <c10/macros/Macros.h>

namespace at {
namespace detail {
Expand Down
3 changes: 0 additions & 3 deletions aten/src/ATen/detail/CUDAHooksInterface.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#include <ATen/detail/CUDAHooksInterface.h>

#include <c10/util/Exception.h>
#include <c10/util/CallOnce.h>

#include <cstddef>
#include <memory>
#include <mutex>

namespace at {
namespace detail {
Expand Down
8 changes: 1 addition & 7 deletions aten/src/ATen/detail/CUDAHooksInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@

#include <c10/core/Allocator.h>
#include <c10/util/Exception.h>
#include <c10/util/Optional.h>
#include <c10/util/Registry.h>

#include <cstddef>
#include <functional>
#include <memory>

// Forward-declares at::Context, at::Generator and at::cuda::NVRTC
// Forward-declares at::Generator and at::cuda::NVRTC
namespace at {
class Context;
struct Generator;
namespace cuda {
struct NVRTC;
Expand Down
3 changes: 1 addition & 2 deletions aten/src/ATen/detail/HIPHooksInterface.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#include <ATen/detail/HIPHooksInterface.h>

#include <c10/util/Exception.h>
#include <c10/util/CallOnce.h>
#include <c10/util/Registry.h>

#include <cstddef>
#include <memory>
#include <mutex>

namespace at {
namespace detail {
Expand Down
3 changes: 1 addition & 2 deletions aten/src/ATen/detail/HIPHooksInterface.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#pragma once

#include <c10/core/Allocator.h>
#include <ATen/core/Generator.h>
#include <c10/core/GeneratorImpl.h>
#include <c10/util/Exception.h>

#include <c10/util/Registry.h>

#include <cstddef>
#include <functional>
#include <memory>

namespace at {
Expand Down
1 change: 0 additions & 1 deletion aten/src/ATen/detail/MPSHooksInterface.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright © 2022 Apple Inc.

#include <ATen/detail/MPSHooksInterface.h>
#include <c10/util/Exception.h>
#include <c10/util/CallOnce.h>

namespace at {
Expand Down
5 changes: 0 additions & 5 deletions aten/src/ATen/detail/MPSHooksInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
#include <c10/util/Registry.h>

#include <cstddef>
#include <functional>

namespace at {
class Context;
}

namespace at {

Expand Down
4 changes: 1 addition & 3 deletions aten/src/ATen/detail/MTIAHooksInterface.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
#include <ATen/detail/MTIAHooksInterface.h>

#include <c10/util/CallOnce.h>
#include <c10/util/Exception.h>

#include <cstddef>
#include <memory>
#include <mutex>

namespace at {
namespace detail {

static MTIAHooksInterface* MTIA_hooks = nullptr;

const MTIAHooksInterface &getMTIAHooks() {
static MTIAHooksInterface* MTIA_hooks = nullptr;
static c10::once_flag once;
c10::call_once(once, [] {
MTIA_hooks =
Expand Down
10 changes: 1 addition & 9 deletions aten/src/ATen/detail/MTIAHooksInterface.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
#pragma once

#include <c10/core/Device.h>
#include <c10/util/Exception.h>

#include <c10/util/Registry.h>

#include <cstddef>
#include <functional>
#include <memory>
#include <string>

namespace at {
class Context;
}

// We use forward declaration here instead of #include <ATen/dlpack.h> to avoid
// leaking DLPack implementation detail to every project that includes `ATen/Context.h`, which in turn
// would lead to a conflict when linked with another project using DLPack (for example TVM)
struct DLDevice_;

namespace at {

constexpr const char* MTIA_HELP =
Expand Down
3 changes: 1 addition & 2 deletions aten/src/ATen/detail/ORTHooksInterface.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#include <ATen/detail/ORTHooksInterface.h>

#include <c10/util/Exception.h>
#include <c10/util/CallOnce.h>
#include <c10/util/Registry.h>

#include <cstddef>
#include <memory>
#include <mutex>

namespace at {
namespace detail {
Expand Down
7 changes: 2 additions & 5 deletions aten/src/ATen/detail/XPUHooksInterface.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
#include <ATen/detail/XPUHooksInterface.h>

#include <c10/util/CallOnce.h>
#include <c10/util/Exception.h>

#include <cstddef>
#include <memory>
#include <mutex>

namespace at {
namespace detail {

static XPUHooksInterface *xpu_hooks = nullptr;

const XPUHooksInterface &getXPUHooks() {
const XPUHooksInterface& getXPUHooks() {
static XPUHooksInterface* xpu_hooks = nullptr;
static c10::once_flag once;
c10::call_once(once, [] {
xpu_hooks =
Expand Down
4 changes: 0 additions & 4 deletions aten/src/ATen/detail/XPUHooksInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
#include <functional>
#include <memory>

namespace at {
class Context;
}

// We use forward declaration here instead of #include <ATen/dlpack.h> to avoid
// leaking DLPack implementation detail to every project that includes `ATen/Context.h`, which in turn
// would lead to a conflict when linked with another project using DLPack (for example TVM)
Expand Down
1 change: 0 additions & 1 deletion aten/src/ATen/native/DilatedMaxPool3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <ATen/Dispatch.h>
#include <ATen/NamedTensorUtils.h>
#include <ATen/native/Pool.h>
#include <c10/util/irange.h>

#ifndef AT_PER_OPERATOR_HEADERS
#include <ATen/Functions.h>
Expand Down
1 change: 0 additions & 1 deletion aten/src/ATen/native/PointwiseOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <ATen/native/PointwiseOps.h>

#include <ATen/core/Tensor.h>
#include <ATen/TensorIterator.h>
#include <ATen/TensorMeta.h>

#ifndef AT_PER_OPERATOR_HEADERS
Expand Down
1 change: 0 additions & 1 deletion aten/src/ATen/native/xnnpack/RegisterOpContextClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <ATen/native/xnnpack/Convolution.h>
#include <ATen/native/xnnpack/Linear.h>
#include <ATen/native/xnnpack/OpContext.h>
#include <ATen/Tensor.h>
#include <torch/custom_class.h>

namespace at::native::xnnpack {
Expand Down
4 changes: 2 additions & 2 deletions c10/util/Type_no_demangle.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <c10/util/Type.h>
#include <c10/macros/Macros.h>

#if HAS_DEMANGLE == 0
#include <string>
#include <c10/util/Type.h>

namespace c10 {
std::string demangle(const char* name) {
Expand Down
1 change: 1 addition & 0 deletions test/cpp/jit/test_argument_spec.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <gtest/gtest.h>

#include <ATen/ATen.h>
#include <torch/csrc/jit/api/function_impl.h>
#include <torch/csrc/jit/runtime/argument_spec.h>
#include <torch/jit.h>
Expand Down
1 change: 1 addition & 0 deletions test/cpp/jit/test_concat_opt.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <gtest/gtest.h>

#include <ATen/Functions.h>
#include <test/cpp/jit/test_utils.h>
#include <torch/csrc/jit/ir/irparser.h>
#include <torch/csrc/jit/passes/concat_opt.h>
Expand Down
1 change: 1 addition & 0 deletions test/cpp/jit/test_shape_analysis.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <gtest/gtest.h>

#include <ATen/ATen.h>
#include <ATen/core/interned_strings.h>
#include <c10/util/Exception.h>
#include <c10/util/Optional.h>
Expand Down
1 change: 1 addition & 0 deletions test/cpp/jit/test_stack_opt.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <ATen/Functions.h>
#include <gtest/gtest.h>

#include <test/cpp/jit/test_utils.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <ATen/Functions.h>
#include <aten/src/ATen/TensorOperators.h>
#include <gtest/gtest.h>
#include <test/cpp/jit/test_utils.h>
#include <torch/csrc/autograd/generated/variable_factories.h>
Expand Down
1 change: 1 addition & 0 deletions test/cpp/lite_interpreter_runtime/test_mobile_profiler.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <ATen/Functions.h>
#include <gtest/gtest.h>
#include <test/cpp/jit/test_utils.h>
#include <torch/csrc/jit/api/module.h>
Expand Down
17 changes: 1 addition & 16 deletions tools/iwyu/aten.imp
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,19 @@
{ include: ["@<ATen/cpu/vec/vec256/.*>", private, "<ATen/cpu/vec/vec.h>", public] },
{ include: ["<ATen/cpu/vec/vec_base.h>", private, "<ATen/cpu/vec/vec.h>", public] },
{ include: ["<ATen/cpu/vec/functional_base.h>", private, "<ATen/cpu/vec/functional.h>", public] },
{ include: ["<ATen/core/IListRef_inl.h>", private, "<ATen/core/IListRef.h>", public] },
{ include: ["<ATen/cpu/vec/functional_bfloat16.h>", private, "<ATen/cpu/vec/functional.h>", public] },

{ include: ["<ATen/core/Dict_inl.h>", private, "<ATen/core/Dict.h>", public] },
{ include: ["<ATen/core/ivalue_inl.h>", private, "<ATen/core/ivalue.h>", public] },
{ include: ["<ATen/core/DimVector.h>", public, "<ATen/DimVector.h>", public] },
{ include: ["<ATen/core/Dimname.h>", public, "<ATen/Dimname.h>", public] },
{ include: ["<ATen/core/symbol.h>", public, "<ATen/core/Dimname.h>", public] },
{ include: ["<ATen/TensorIterator.h>", public, "<ATen/core/TensorIterator.h>", public] },

{ include: ["<c10/core/WrapDimMinimal.h>", public, "<ATen/WrapDimUtils.h>", public] },
{ include: ["<c10/util/SmallVector.h>", public, "<ATen/core/DimVector.h>", public] },

{ include: ["<c10/util/MaybeOwned.h>", public, "<ATen/core/TensorBase.h>", public] },
{ include: ["<c10/core/TensorImpl.h>", public, "<ATen/core/TensorBase.h>", public] },
{ include: ["<c10/core/UndefinedTensorImpl.h>", public, "<ATen/core/TensorBase.h>", public] },
{ include: ["<c10/core/TensorOptions.h>", public, "<ATen/core/TensorBase.h>", public] },

{ include: ["<ATen/core/TensorBase.h>", public, "<ATen/core/Tensor.h>", public] },
{ include: ["<ATen/core/TensorBody.h>", private, "<ATen/core/Tensor.h>", public] },
{ symbol: ["at::Tensor", private, "<ATen/core/Tensor.h>", public] },

{ include: ["<ATen/Parallel-inl.h>", private, "<ATen/Parallel.h>", public] },
{ include: ["<ATen/ParallelOpenMP.h>", private, "<ATen/Parallel.h>", public] },
{ include: ["<ATen/ParallelNative.h>", private, "<ATen/Parallel.h>", public] },
{ include: ["<ATen/ParallelNativeTBB.h>", private, "<ATen/Parallel.h>", public] },

{ include: ["<qnnpack/common.h>", public, "<pack_block_sparse.h>", public] },
{ include: ["<qnnpack/math.h>", public, "<pack_block_sparse.h>", public] },
{ include: ["<qnnpack/operator.h>", public, "<qnnpack_func.h>", public] },
{ include: ["<qnnpack/log.h>", public, "<pytorch_qnnpack.h>", public] },
]
2 changes: 2 additions & 0 deletions tools/iwyu/c10.imp
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@
{ include: ["<c10/core/StorageImpl.h>", private, "<c10/core/Storage.h>", public ] },
{ symbol: [ "C10_API", private, "<c10/macros/Export.h>", public ] },
{ symbol: [ "c10::complex", private, "<c10/util/complex.h>", public ] },
{ symbol: [ "fmt::format", private, "<fmt/format.h>", public ] },
{ symbol: [ "fmt::vformat", private, "<fmt/format.h>", public ] },
]
1 change: 1 addition & 0 deletions tools/iwyu/torch.imp
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[
{ include: ["<bits/chrono.h>", private, "<chrono>", public ] },
]
1 change: 0 additions & 1 deletion torch/csrc/jit/passes/freeze_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <torch/csrc/jit/passes/eliminate_no_ops.h>
#include <torch/csrc/jit/passes/inliner.h>
#include <torch/csrc/jit/passes/lower_tuples.h>
#include <torch/csrc/jit/passes/remove_mutation.h>
#include <torch/csrc/jit/runtime/graph_executor_impl.h>

#include <stack>
Expand Down
1 change: 0 additions & 1 deletion torch/csrc/jit/passes/specialize_autogradzero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <c10/util/Exception.h>
#include <torch/csrc/jit/ir/ir.h>
#include <torch/csrc/jit/jit_log.h>
#include <torch/csrc/jit/passes/clear_undefinedness.h>
#include <torch/csrc/jit/runtime/graph_executor.h>
#include <torch/csrc/jit/runtime/profiling_record.h>

Expand Down
2 changes: 0 additions & 2 deletions torch/csrc/jit/passes/tensorexpr_fuser.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
namespace torch {
namespace jit {

struct Graph;

// Run TensorExpressions-based fuser.
// If add_composed_op is true, creates a single operation that
// performs both the runtime check that types align
Expand Down
1 change: 0 additions & 1 deletion torch/csrc/jit/passes/vulkan_rewrite.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <ATen/core/jit_type.h>
#include <torch/csrc/jit/ir/ir.h>
#include <torch/csrc/jit/ir/subgraph_matcher.h>
#include <torch/csrc/jit/passes/constant_pooling.h>
#include <torch/csrc/jit/passes/dead_code_elimination.h>
#include <torch/csrc/jit/passes/fold_conv_bn.h>
#include <torch/csrc/jit/passes/freeze_module.h>
Expand Down
3 changes: 0 additions & 3 deletions torch/csrc/jit/passes/xnnpack_rewrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
#include <ATen/native/xnnpack/OpContext.h>

#include <torch/csrc/jit/ir/ir.h>
#include <torch/csrc/jit/ir/subgraph_matcher.h>
#include <torch/csrc/jit/passes/constant_pooling.h>
#include <torch/csrc/jit/passes/constant_propagation.h>
#include <torch/csrc/jit/passes/fold_conv_bn.h>
#include <torch/csrc/jit/passes/freeze_module.h>
#include <torch/csrc/jit/passes/fuse_linear.h>
#include <torch/csrc/jit/passes/fuse_relu.h>
#include <torch/csrc/jit/passes/graph_rewrite_helper.h>
#include <torch/csrc/jit/passes/hoist_conv_packed_params.h>
#include <torch/csrc/jit/passes/inliner.h>
#include <torch/csrc/jit/passes/mobile_optimizer_type.h>
#include <torch/csrc/jit/passes/prepack_folding.h>
#include <torch/csrc/jit/passes/remove_dropout.h>
Expand Down
2 changes: 0 additions & 2 deletions torch/csrc/jit/runtime/autodiff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
#include <ATen/core/functional.h>
#include <c10/util/Exception.h>
#include <c10/util/irange.h>
#include <torch/csrc/jit/frontend/ir_emitter.h>
#include <torch/csrc/jit/jit_log.h>
#include <torch/csrc/jit/passes/common_subexpression_elimination.h>
#include <torch/csrc/jit/passes/constant_pooling.h>
#include <torch/csrc/jit/passes/dead_code_elimination.h>
#include <torch/csrc/jit/passes/inliner.h>
#include <torch/csrc/jit/passes/lower_tuples.h>
Expand Down
2 changes: 0 additions & 2 deletions torch/csrc/jit/runtime/autodiff.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#include <torch/csrc/Export.h>
#include <torch/csrc/jit/ir/ir.h>

#include <ATen/ATen.h>

#include <memory>
#include <vector>

Expand Down
1 change: 0 additions & 1 deletion torch/csrc/jit/runtime/operator.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <torch/csrc/jit/runtime/operator.h>

#include <ATen/ATen.h>
#include <ATen/core/alias_info.h>
#include <ATen/core/interned_strings.h>
#include <c10/util/irange.h>
#include <torch/csrc/jit/frontend/edit_distance.h>
Expand Down
1 change: 0 additions & 1 deletion torch/csrc/jit/runtime/profiling_record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <torch/csrc/jit/codegen/cuda/interface.h>
#include <torch/csrc/jit/jit_log.h>
#include <torch/csrc/jit/passes/clear_profiling.h>
#include <torch/csrc/jit/passes/constant_propagation.h>
#include <torch/csrc/jit/passes/tensorexpr_fuser.h>
#include <torch/csrc/jit/runtime/autodiff.h>
#include <torch/csrc/jit/runtime/graph_executor.h>
Expand Down
1 change: 0 additions & 1 deletion torch/csrc/jit/runtime/register_c10_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <torch/csrc/jit/frontend/tracer.h>
#include <torch/csrc/jit/ir/ir.h>
#include <torch/csrc/jit/runtime/operator.h>
#include <unordered_set>

namespace torch::jit {

Expand Down
1 change: 0 additions & 1 deletion torch/csrc/jit/runtime/simple_graph_executor_impl.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <torch/csrc/jit/runtime/profiling_graph_executor_impl.h>

#include <c10/util/Optional.h>
#include <torch/csrc/jit/jit_log.h>
#include <torch/csrc/jit/runtime/simple_graph_executor_impl.h>
#include <mutex>

Expand Down
Loading

0 comments on commit 226384b

Please sign in to comment.