Skip to content

Commit

Permalink
Remove some unnecessary <iostream> includes from headers (pytorch#106914
Browse files Browse the repository at this point in the history
)

In almost all cases this is only included for writing the output formatter, which
only uses `std::ostream` so including `<ostream>` is sufficient.

The istream header is ~1000 lines so the difference is non-trivial.

Pull Request resolved: pytorch#106914
Approved by: https://github.com/lezcano
  • Loading branch information
peterbell10 authored and pytorchmergebot committed Aug 25, 2023
1 parent 78a053b commit a6c29b7
Show file tree
Hide file tree
Showing 57 changed files with 53 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/ci_commit_pins/xla.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
709c75a04d9b35d83a9509e1534a8aa2046b8912
c3c16ccac41cb2db6ba88fb31342f4af62c7e15a
3 changes: 0 additions & 3 deletions aten/src/ATen/DLConvertor.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#include <ATen/DLConvertor.h>
#include <ATen/Functions.h>

#include <iostream>
#include <sstream>

using namespace std;
namespace at {

Expand Down
1 change: 0 additions & 1 deletion aten/src/ATen/autocast_mode.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <ATen/autocast_mode.h>

#include <iostream>
#include <exception>
#include <mutex>
#include <ATen/CachedTensorUtils.h>
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/core/Range.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <ATen/core/Range.h>

#include <iostream>
#include <ostream>

namespace at {

Expand Down
4 changes: 4 additions & 0 deletions aten/src/ATen/core/dispatch/Dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
#include <ATen/core/grad_mode.h>
#include <ATen/core/enum_tag.h>

#ifndef NDEBUG
#include <iostream>
#endif

namespace c10 {

TORCH_API bool show_dispatch_trace();
Expand Down
3 changes: 2 additions & 1 deletion aten/src/ATen/core/function_schema_inl.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include <iostream>
#include <ostream>
#include <sstream>

// note: windows build doesn't find symbols in operator files unless
// this is a header file
Expand Down
1 change: 0 additions & 1 deletion aten/src/ATen/core/interned_strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <ATen/core/interned_strings.h>
#include <cstdint>
#include <cstring>
#include <iostream>
#include <mutex>
#include <sstream>
#include <string>
Expand Down
3 changes: 2 additions & 1 deletion aten/src/ATen/core/union_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#include <ATen/core/type_factory.h>
#include <c10/macros/Macros.h>
#include <c10/util/irange.h>
#include <iostream>
#include <ostream>
#include <sstream>
#include <utility>

namespace c10 {
Expand Down
1 change: 0 additions & 1 deletion aten/src/ATen/cpu/vec/vec256/vec256_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <ATen/cpu/vec/vec_base.h>
#include <c10/macros/Macros.h>
#include <c10/util/irange.h>
#include <iostream>

namespace at {
namespace vec {
Expand Down
1 change: 0 additions & 1 deletion aten/src/ATen/cpu/vec/vec256/vec256_qint.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#include <array>
#include <cmath>
#include <iostream>

// This file defines Vectorized<> for the quantized types.
//
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/cpu/vec/vec512/vec512.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <iostream>
#include <ostream>

namespace at {
namespace vec {
Expand Down
2 changes: 2 additions & 0 deletions aten/src/ATen/functorch/TensorWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <torch/library.h>
#include <ATen/core/dispatch/Dispatcher.h>

#include <iostream>

namespace at {
namespace functorch {

Expand Down
2 changes: 1 addition & 1 deletion c10/util/logging_is_not_google_glog.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include <chrono>
#include <climits>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <map>
#include <ostream>
#include <set>
#include <sstream>
#include <string>
Expand Down
2 changes: 1 addition & 1 deletion functorch/csrc/dim/minpybind.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <utility>
#include <iostream>
#include <ostream>
#include <memory>

#define PY_BEGIN try {
Expand Down
1 change: 1 addition & 0 deletions torch/csrc/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <torch/csrc/THConcat.h>
#include <torch/csrc/utils/pybind.h>
#include <cstdlib>
#include <iostream>
#include <unordered_map>

#include <ATen/ThreadLocalPythonObjects.h>
Expand Down
1 change: 0 additions & 1 deletion torch/csrc/dynamo/compiled_autograd.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <torch/csrc/autograd/engine.h>
#include <torch/csrc/utils/python_stub.h>
#include <torch/csrc/utils/torch_dispatch_mode.h>
#include <iostream>
#include <typeindex>
#include <vector>

Expand Down
2 changes: 2 additions & 0 deletions torch/csrc/functorch/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <ATen/functorch/TensorWrapper.h>
#include <c10/core/AutogradState.h>

#include <iostream>

// This file contains functorch's Python bindings.

namespace torch {
Expand Down
2 changes: 2 additions & 0 deletions torch/csrc/jit/api/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <torch/csrc/jit/passes/inliner.h>
#include <torch/csrc/jit/runtime/operator.h>

#include <iostream>

namespace torch::jit {

namespace {
Expand Down
2 changes: 0 additions & 2 deletions torch/csrc/jit/codegen/fuser/codegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
#include <torch/csrc/jit/codegen/fuser/tensor_desc.h>
#include <torch/csrc/jit/ir/ir.h>

#include <iostream>
#include <string>
#include <tuple>
#include <vector>

namespace torch {
Expand Down
2 changes: 1 addition & 1 deletion torch/csrc/jit/codegen/fuser/tensor_desc.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <torch/csrc/Export.h>

#include <algorithm>
#include <iostream>
#include <ostream>
#include <vector>

namespace torch {
Expand Down
2 changes: 2 additions & 0 deletions torch/csrc/jit/frontend/concrete_module_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <c10/util/irange.h>
#include <torch/csrc/jit/python/pybind_utils.h>

#include <iostream>

namespace torch::jit {

ClassTypePtr ConcreteModuleTypeBuilder::createTypeFromThis() const {
Expand Down
3 changes: 2 additions & 1 deletion torch/csrc/jit/frontend/source_range.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
#include <c10/util/Optional.h>

#include <algorithm>
#include <iostream>
#include <iterator>
#include <memory>
#include <numeric>
#include <ostream>
#include <sstream>
#include <unordered_map>

namespace torch {
Expand Down
1 change: 0 additions & 1 deletion torch/csrc/jit/frontend/tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <torch/csrc/utils/variadic.h>

#include <cstdint>
#include <iostream>
#include <memory>
#include <mutex>
#include <unordered_map>
Expand Down
1 change: 1 addition & 0 deletions torch/csrc/jit/ir/alias_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <torch/csrc/jit/runtime/operator.h>
#include <torch/csrc/utils/memory.h>
#include <fstream>
#include <iostream>

namespace torch::jit {

Expand Down
2 changes: 1 addition & 1 deletion torch/csrc/jit/ir/ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <c10/util/Optional.h>

#include <functional>
#include <iostream>
#include <iosfwd>
#include <unordered_set>
#include <vector>

Expand Down
1 change: 1 addition & 0 deletions torch/csrc/jit/jit_log.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <unordered_map>
Expand Down
1 change: 0 additions & 1 deletion torch/csrc/jit/mobile/model_tracer/MobileModelRunner.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include <iostream>
#include <mutex>
#include <sstream>

Expand Down
2 changes: 0 additions & 2 deletions torch/csrc/jit/mobile/register_ops_common_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#include <torch/csrc/jit/runtime/jit_exception.h>
#include <torch/csrc/jit/runtime/vararg_functions.h>

#include <iostream>

namespace torch {
namespace jit {

Expand Down
1 change: 0 additions & 1 deletion torch/csrc/jit/operator_upgraders/upgraders.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once
#include <c10/macros/Export.h>
#include <torch/csrc/jit/ir/ir.h>
#include <iostream>
#include <mutex>
#include <string>
#include <unordered_map>
Expand Down
3 changes: 0 additions & 3 deletions torch/csrc/jit/operator_upgraders/upgraders_entry.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#pragma once
#include <c10/macros/Export.h>
#include <torch/csrc/jit/ir/ir.h>
#include <iostream>
#include <mutex>
#include <string>
#include <unordered_map>
#include <vector>

namespace torch {
namespace jit {
Expand Down
2 changes: 0 additions & 2 deletions torch/csrc/jit/operator_upgraders/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#include <c10/macros/Export.h>
#include <c10/util/Optional.h>
#include <torch/csrc/jit/operator_upgraders/version_map.h>
#include <iostream>
#include <regex>
#include <string>
#include <vector>

Expand Down
1 change: 1 addition & 0 deletions torch/csrc/jit/passes/liveness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <torch/csrc/jit/ir/alias_analysis.h>
#include <torch/csrc/jit/ir/ir_views.h>
#include <torch/csrc/jit/passes/constant_pooling.h>
#include <iostream>
#include <memory>

namespace torch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include <ATen/ScalarOps.h>

#include <iostream>

// EDITING THIS FILE? READ THIS FIRST!
// see Note [Edit Pattern Conversion] in pattern_conversion.h

Expand Down
1 change: 1 addition & 0 deletions torch/csrc/jit/passes/remove_inplace_ops.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <torch/csrc/jit/passes/remove_inplace_ops.h>
#include <iostream>

namespace torch {
namespace jit {
Expand Down
2 changes: 2 additions & 0 deletions torch/csrc/jit/runtime/argument_spec.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <c10/util/irange.h>
#include <torch/csrc/jit/runtime/argument_spec.h>

#include <iostream>

namespace torch {
namespace jit {

Expand Down
2 changes: 1 addition & 1 deletion torch/csrc/jit/runtime/argument_spec.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <torch/csrc/Export.h>
#include <torch/csrc/autograd/variable.h>
#include <torch/csrc/jit/ir/ir.h>
#include <iostream>
#include <ostream>
#include <vector>

C10_CLANG_DIAGNOSTIC_PUSH()
Expand Down
1 change: 1 addition & 0 deletions torch/csrc/jit/runtime/print_handler.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <torch/csrc/jit/runtime/print_handler.h>

#include <atomic>
#include <iostream>
#include <string>

Expand Down
4 changes: 1 addition & 3 deletions torch/csrc/jit/runtime/print_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

#include <torch/csrc/Export.h>

#include <atomic>
#include <functional>
#include <iostream>
#include <string>

namespace torch {
namespace jit {
Expand Down
1 change: 1 addition & 0 deletions torch/csrc/jit/runtime/static/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <torch/csrc/jit/runtime/vararg_functions.h>
#include <algorithm>
#include <cstdint>
#include <iostream>

#ifndef AT_PER_OPERATOR_HEADERS
#include <ATen/NativeFunctions.h>
Expand Down
1 change: 0 additions & 1 deletion torch/csrc/jit/serialization/python_print.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <torch/csrc/Export.h>
#include <torch/csrc/jit/api/module.h>
#include <torch/csrc/jit/ir/ir.h>
#include <iostream>
#include <vector>

namespace torch {
Expand Down
2 changes: 2 additions & 0 deletions torch/csrc/jit/tensorexpr/bounds_inference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include <c10/util/irange.h>

#include <iostream>

namespace torch::jit::tensorexpr {

using namespace analysis;
Expand Down
2 changes: 2 additions & 0 deletions torch/csrc/jit/tensorexpr/bounds_overlap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <torch/csrc/jit/tensorexpr/ir_visitor.h>
#include <torch/csrc/jit/tensorexpr/stmt.h>

#include <iostream>

namespace torch::jit::tensorexpr::analysis {

// Returns true if the given expression is guaranteed to be positive.
Expand Down
2 changes: 2 additions & 0 deletions torch/csrc/jit/tensorexpr/ir_printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include <c10/util/irange.h>

#include <iostream>

namespace torch::jit::tensorexpr {

std::string IRPrinter::dtypeToCppString(const Dtype& dtype) {
Expand Down
2 changes: 1 addition & 1 deletion torch/csrc/jit/tensorexpr/ir_printer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <iostream>
#include <ostream>

#include <torch/csrc/jit/tensorexpr/fwd_decls.h>
#include <torch/csrc/jit/tensorexpr/ir.h>
Expand Down
2 changes: 0 additions & 2 deletions torch/csrc/jit/tensorexpr/ir_verifier.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

#include <iostream>

#include <torch/csrc/jit/tensorexpr/fwd_decls.h>
#include <torch/csrc/jit/tensorexpr/ir_visitor.h>

Expand Down
1 change: 1 addition & 0 deletions torch/csrc/jit/tensorexpr/loopnest.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <torch/csrc/jit/tensorexpr/loopnest.h>

#include <algorithm>
#include <iostream>
#include <stdexcept>
#include <typeinfo>
#include <unordered_map>
Expand Down
Loading

0 comments on commit a6c29b7

Please sign in to comment.