Skip to content

Commit

Permalink
[BE] [3/N] Use nested namespaces (pytorch#110314)
Browse files Browse the repository at this point in the history
Mostly in torch/csrc/jit/runtime and in `ATen/cuda/`

Pull Request resolved: pytorch#110314
Approved by: https://github.com/seemethere
  • Loading branch information
malfet authored and pytorchmergebot committed Sep 30, 2023
1 parent 8745d2d commit ad8aef0
Show file tree
Hide file tree
Showing 151 changed files with 317 additions and 652 deletions.
6 changes: 2 additions & 4 deletions aten/src/ATen/CachedTensorUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

#include <c10/util/flat_hash_map.h>

namespace at {
namespace caching {
namespace at::caching {


using weakref_type = c10::weak_intrusive_ptr<TensorImpl, UndefinedTensorImpl>;
Expand Down Expand Up @@ -45,5 +44,4 @@ size_t adjusted_use_count(const at::Tensor& t) {
return t.use_count() - (is_cached_tensor(t) ? 1 : 0);
}

}
}
} // namespace at::caching
6 changes: 2 additions & 4 deletions aten/src/ATen/CachedTensorUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

#include <ATen/ATen.h>

namespace at {
namespace caching {
namespace at::caching {

// Some systems (just cudagraphs currently) will persist a static tensor output
// whose TensorImpl does not change across iterations. For these tensors caching
Expand All @@ -22,5 +21,4 @@ TORCH_API void set_cached_tensors_enabled(bool enable);
// count of tensors with hooks.
TORCH_API size_t adjusted_use_count(const at::Tensor& t);

} // namespace caching
} // namespace at
} // namespace at::caching
5 changes: 2 additions & 3 deletions aten/src/ATen/EmptyTensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

#include <limits>

namespace at {
namespace detail {
namespace at::detail {
namespace {
c10::Allocator* GetCPUAllocatorMaybePinned(bool pin_memory) {
if (pin_memory) {
Expand Down Expand Up @@ -441,4 +440,4 @@ TensorBase empty_strided_symint_meta(
options.pinned_memory_opt());
}

}} // namespace at::detail
} // namespace at::detail
6 changes: 2 additions & 4 deletions aten/src/ATen/EmptyTensor.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#pragma once
#include <ATen/core/TensorBase.h>

namespace at {
namespace detail {
namespace at::detail {

inline void check_size_nonnegative(ArrayRef<int64_t> size) {
for (const auto& x : size) {
Expand Down Expand Up @@ -158,5 +157,4 @@ TORCH_API TensorBase empty_strided_symint_meta(
SymIntArrayRef stride,
const TensorOptions& options);

} // namespace detail
} // namespace at
} // namespace at::detail
2 changes: 1 addition & 1 deletion aten/src/ATen/ExpandUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace internal {
TensorBase expand_slow_path(const TensorBase &self, IntArrayRef size) {
return OptionalTensorRef(self)->expand(size);
}
}
} // namespace internal

namespace {
// NOTE: are_expandable did a similar check, please keep them sync if change is needed
Expand Down
4 changes: 2 additions & 2 deletions aten/src/ATen/FuncTorchTLS.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <ATen/FuncTorchTLS.h>

namespace at { namespace functorch {
namespace at::functorch {

namespace {

Expand Down Expand Up @@ -28,4 +28,4 @@ std::unique_ptr<FuncTorchTLSBase>& functorchTLSAccessor() {
}


}}
} // namespace at::functorch
6 changes: 2 additions & 4 deletions aten/src/ATen/FuncTorchTLS.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#include <c10/macros/Macros.h>
#include <memory>

namespace at {
namespace functorch {
namespace at::functorch {

// NOTE [functorch TLS in pytorch/pytorch]
//
Expand Down Expand Up @@ -44,5 +43,4 @@ TORCH_API void setFuncTorchTLS(
// get a mutable reference to the functorch tls
TORCH_API std::unique_ptr<FuncTorchTLSBase>& functorchTLSAccessor();

} // namespace functorch
} // namespace at
} // namespace at::functorch
6 changes: 2 additions & 4 deletions aten/src/ATen/FunctionalInverses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
#include <ATen/WrapDimUtilsMulti.h>

#include <utility>
namespace at {
namespace functionalization {
namespace at::functionalization {

// This logic is similar to autograd code for view backwards calls.
// We can't easily share it though, because (eventually) these functions
Expand Down Expand Up @@ -348,5 +347,4 @@ Tensor FunctionalInverses::alias_copy_inverse(const Tensor& base, const Tensor&
}
}

} // functionalization
} // at
} // namespace at::functionalization
6 changes: 2 additions & 4 deletions aten/src/ATen/FunctionalStorageImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
#include <c10/util/Exception.h>
#include <vector>

namespace at {
namespace functionalization {
namespace at::functionalization {

ViewMeta ViewMeta::to_out_idx(int64_t out_idx) {
if (out_idx == this->out_index) return *this;
Expand Down Expand Up @@ -122,5 +121,4 @@ bool FunctionalStorageImpl::apply_updates() {
return any_updates;
}

} // namespace functionalization
} // namespace at
} // namespace at::functionalization
6 changes: 2 additions & 4 deletions aten/src/ATen/FunctionalStorageImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

#include <ATen/Tensor.h>

namespace at {
namespace functionalization {
namespace at::functionalization {

// See Note [Functionalization Pass In Core]

Expand Down Expand Up @@ -117,5 +116,4 @@ struct TORCH_API FunctionalStorageImpl : public c10::StorageImpl {
bool frozen_ = false;
};

} // namespace functionalization
} // namespace at
} // namespace at::functionalization
6 changes: 2 additions & 4 deletions aten/src/ATen/LegacyVmapMode.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <ATen/LegacyVmapMode.h>

namespace at {
namespace impl {
namespace at::impl {

thread_local int64_t VmapMode_current_vmap_level = 0;

Expand All @@ -24,5 +23,4 @@ int64_t VmapMode::decrement_nesting() {
}
return VmapMode_current_vmap_level;
}
} // namespace impl
} // namespace at
} // namespace at::impl
6 changes: 2 additions & 4 deletions aten/src/ATen/LegacyVmapMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

#include <c10/core/impl/LocalDispatchKeySet.h>

namespace at {
namespace impl {
namespace at::impl {

// VmapMode contains a thread local count of how many nested vmaps
// we are currently inside. That number is known as the `vmap level`.
Expand All @@ -24,5 +23,4 @@ struct TORCH_API VmapMode {
static int64_t decrement_nesting();
};

} // namespace impl
} // namespace at
} // namespace at::impl
6 changes: 2 additions & 4 deletions aten/src/ATen/NestedTensorImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#include <c10/util/Metaprogramming.h>
#include <c10/util/irange.h>

namespace at {
namespace native {
namespace at::native {
struct NestedTensorImpl;
inline bool nested_tensor_impl_is_contiguous(const NestedTensorImpl* nt);
int64_t get_numel_from_nested_size_tensor(const at::Tensor& tensor);
Expand Down Expand Up @@ -276,5 +275,4 @@ inline const at::Tensor& get_nested_sizes(const at::Tensor& tensor) {
return get_nested_tensor_impl(tensor)->get_nested_sizes();
}

} // namespace native
} // namespace at
} // namespace at::native
7 changes: 2 additions & 5 deletions aten/src/ATen/ParallelNative.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@

#define INTRA_OP_PARALLEL

namespace at {
namespace internal {
namespace at::internal {

TORCH_API void invoke_parallel(
const int64_t begin,
const int64_t end,
const int64_t grain_size,
const std::function<void(int64_t, int64_t)>& f);

} // namespace internal

} // namespace at
} // namespace at::internal
6 changes: 2 additions & 4 deletions aten/src/ATen/ParallelNativeTBB.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@

#define INTRA_OP_PARALLEL

namespace at {
namespace internal {
namespace at::internal {

template <typename F>
inline void invoke_parallel(
Expand Down Expand Up @@ -50,5 +49,4 @@ inline void invoke_parallel(
}
}

} // namespace internal
} // namespace at
} // namespace at::internal
6 changes: 2 additions & 4 deletions aten/src/ATen/PythonTorchFunctionTLS.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include <ATen/PythonTorchFunctionTLS.h>
#include <c10/core/TensorImpl.h>

namespace at {
namespace impl {
namespace at::impl {

static thread_local PythonTorchFunctionTLS pythonTorchFunctionState;

Expand Down Expand Up @@ -47,5 +46,4 @@ bool torch_function_mode_enabled() {
PythonTorchFunctionTLS::stack_len() > 0;
}

} // namespace impl
} // namespace at
} // namespace at::impl
6 changes: 2 additions & 4 deletions aten/src/ATen/PythonTorchFunctionTLS.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#include <c10/core/SafePyObject.h>
#include <c10/macros/Macros.h>

namespace at {
namespace impl {
namespace at::impl {

enum TorchFunctionDisabledState { ENABLED, SUBCLASSES_DISABLED, ALL_DISABLED };

Expand Down Expand Up @@ -32,5 +31,4 @@ struct TORCH_API PythonTorchFunctionTLS {

TORCH_API bool torch_function_mode_enabled();

} // namespace impl
} // namespace at
} // namespace at::impl
12 changes: 4 additions & 8 deletions aten/src/ATen/ScalarOps.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
#include <ATen/ops/scalar_tensor.h>
#endif

namespace at {
namespace detail {
namespace at::detail {
// When filling a number to 1-element CPU tensor, we want to skip
// everything but manipulate data ptr directly.
// Ideally this fast pass should be implemented in TensorIterator,
Expand All @@ -21,8 +20,7 @@ TORCH_API Tensor scalar_tensor_static(
const Scalar& s,
c10::optional<ScalarType> dtype_opt,
c10::optional<Device> device_opt);
} // namespace detail
} // namespace at
} // namespace at::detail

// This is in the c10 namespace because we use ADL to find the functions in it.
namespace c10 {
Expand Down Expand Up @@ -60,8 +58,7 @@ inline at::Tensor scalar_to_tensor(

} // namespace c10

namespace at {
namespace native {
namespace at::native {

inline Tensor wrapped_scalar_tensor(
const Scalar& scalar,
Expand All @@ -71,5 +68,4 @@ inline Tensor wrapped_scalar_tensor(
return tensor;
}

} // namespace native
} // namespace at
} // namespace at::native
6 changes: 2 additions & 4 deletions aten/src/ATen/SequenceNumber.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <ATen/SequenceNumber.h>

namespace at {
namespace sequence_number {
namespace at::sequence_number {

namespace {
thread_local uint64_t sequence_nr_ = 0;
Expand All @@ -15,5 +14,4 @@ uint64_t get_and_increment() {
return sequence_nr_++;
}

} // namespace sequence_number
} // namespace at
} // namespace at::sequence_number
7 changes: 2 additions & 5 deletions aten/src/ATen/SequenceNumber.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
#include <c10/macros/Export.h>
#include <cstdint>

namespace at {

// A simple thread local enumeration, used to link forward and backward pass
// ops and is used by autograd and observers framework
namespace sequence_number {
namespace at::sequence_number {

TORCH_API uint64_t peek();
TORCH_API uint64_t get_and_increment();

} // namespace sequence_number
} // namespace at
} // namespace at::sequence_number
6 changes: 2 additions & 4 deletions aten/src/ATen/TensorIndexing.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@

#include <utility>

namespace at {
namespace indexing {
namespace at::indexing {

const int64_t INDEX_MIN = c10::SymInt::min_representable_int();
const int64_t INDEX_MAX = -(INDEX_MIN + 1);
Expand Down Expand Up @@ -728,5 +727,4 @@ static inline void set_item(
return;
}

} // namespace indexing
} // namespace at
} // namespace at::indexing
4 changes: 2 additions & 2 deletions aten/src/ATen/TensorNames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <ATen/WrapDimUtils.h>
#include <c10/util/irange.h>

namespace at { namespace namedinference {
namespace at::namedinference {


Dimname TensorName::toDimname() const {
Expand Down Expand Up @@ -126,4 +126,4 @@ std::vector<Dimname> TensorNames::toDimnameVec() const {
}


}} // namespace at::namedinference
} // namespace at::namedinference
6 changes: 2 additions & 4 deletions aten/src/ATen/TensorNames.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

#include <ATen/WrapDimUtils.h>

namespace at {
namespace namedinference {
namespace at::namedinference {

// TensorName and TensorNames are wrappers around Dimname and DimnameList
// that contain helper functions to make writing name inference rules easier.
Expand Down Expand Up @@ -71,5 +70,4 @@ struct TORCH_API TensorNames {
TensorNameVec names_;
};

} // namespace namedinference
} // namespace at
} // namespace at::namedinference
Loading

0 comments on commit ad8aef0

Please sign in to comment.