Skip to content

Commit

Permalink
Enable nested namespace check in clang-tidy (pytorch#118506)
Browse files Browse the repository at this point in the history
It is time to enable nested namespaces in the code.

Pull Request resolved: pytorch#118506
Approved by: https://github.com/albanD
  • Loading branch information
cyyever authored and pytorchmergebot committed Jan 31, 2024
1 parent 1b03423 commit 4a01904
Show file tree
Hide file tree
Showing 33 changed files with 65 additions and 142 deletions.
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ misc-*,
-misc-non-private-member-variables-in-classes,
-misc-confusable-identifiers,
modernize-*,
-modernize-concat-nested-namespaces,
-modernize-macro-to-enum,
-modernize-return-braced-init-list,
-modernize-use-auto,
Expand Down
6 changes: 2 additions & 4 deletions c10/core/WrapDimMinimal.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <c10/core/WrapDimMinimal.h>

namespace c10 {
namespace detail {
namespace c10::detail {

template <typename T>
T maybe_wrap_dim_slow(T dim, T dim_post_expr, bool wrap_scalar) {
Expand Down Expand Up @@ -40,5 +39,4 @@ maybe_wrap_dim_slow(int64_t dim, int64_t dim_post_expr, bool wrap_scalar);
template C10_API SymInt
maybe_wrap_dim_slow(SymInt dim, SymInt dim_post_expr, bool wrap_scalar);

} // namespace detail
} // namespace c10
} // namespace c10::detail
6 changes: 2 additions & 4 deletions c10/core/impl/DeviceGuardImplInterface.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <c10/core/impl/DeviceGuardImplInterface.h>

namespace c10 {
namespace impl {
namespace c10::impl {

// NOLINTNEXTLINE(modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays)
std::atomic<const DeviceGuardImplInterface*>
Expand All @@ -14,5 +13,4 @@ DeviceGuardImplRegistrar::DeviceGuardImplRegistrar(
device_guard_impl_registry[static_cast<size_t>(type)].store(impl);
}

} // namespace impl
} // namespace c10
} // namespace c10::impl
6 changes: 2 additions & 4 deletions c10/core/impl/FakeGuardImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

#include <array>

namespace c10 {
namespace impl {
namespace c10::impl {

// FakeGuardImpl is hardcoded to have eight devices. Not for
// any good reason, just to simplify code.
Expand Down Expand Up @@ -100,5 +99,4 @@ template <DeviceType T>
thread_local std::array<StreamId, kFakeGuardImplMaxDevices>
FakeGuardImpl<T>::current_streams_ = {0, 0, 0, 0, 0, 0, 0, 0};

} // namespace impl
} // namespace c10
} // namespace c10::impl
6 changes: 2 additions & 4 deletions c10/core/impl/GPUTrace.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include <c10/core/impl/GPUTrace.h>
#include <c10/util/CallOnce.h>

namespace c10 {
namespace impl {
namespace c10::impl {

std::atomic<const PyInterpreter*> GPUTrace::gpuTraceState{nullptr};

Expand All @@ -16,5 +15,4 @@ void GPUTrace::set_trace(const PyInterpreter* trace) {
});
}

} // namespace impl
} // namespace c10
} // namespace c10::impl
6 changes: 2 additions & 4 deletions c10/core/impl/GPUTrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

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

namespace c10 {
namespace impl {
namespace c10::impl {

struct C10_API GPUTrace {
// On the x86 architecture the atomic operations are lock-less.
Expand All @@ -26,5 +25,4 @@ struct C10_API GPUTrace {
}
};

} // namespace impl
} // namespace c10
} // namespace c10::impl
6 changes: 2 additions & 4 deletions c10/core/impl/HermeticPyObjectTLS.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <c10/core/impl/HermeticPyObjectTLS.h>

namespace c10 {
namespace impl {
namespace c10::impl {

thread_local std::atomic<bool> hermeticPyObjectState{false};

Expand All @@ -19,5 +18,4 @@ void HermeticPyObjectTLS::init_state() {
haveState_ = true;
}

} // namespace impl
} // namespace c10
} // namespace c10::impl
6 changes: 2 additions & 4 deletions c10/core/impl/LocalDispatchKeySet.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <c10/core/impl/LocalDispatchKeySet.h>

namespace c10 {
namespace impl {
namespace c10::impl {

// NB: POD, must be zero initialized!
// Note [TLS Initialization]
Expand Down Expand Up @@ -115,5 +114,4 @@ bool tls_is_dispatch_keyset_excluded(DispatchKeySet ks) {
bool tls_is_dispatch_keyset_included(DispatchKeySet ks) {
return raw_local_dispatch_key_set.included().isSupersetOf(ks);
}
} // namespace impl
} // namespace c10
} // namespace c10::impl
6 changes: 2 additions & 4 deletions c10/core/impl/PyInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
#include <c10/core/TensorImpl.h>
#include <c10/core/impl/PyInterpreter.h>

namespace c10 {
namespace impl {
namespace c10::impl {

struct NoopPyInterpreterVTable final : public PyInterpreterVTable {
std::string name() const override {
Expand Down Expand Up @@ -125,5 +124,4 @@ void PyInterpreter::disarm() noexcept {
vtable_ = &noop_vtable;
}

} // namespace impl
} // namespace c10
} // namespace c10::impl
6 changes: 2 additions & 4 deletions c10/core/impl/PyObjectSlot.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <c10/core/impl/PyObjectSlot.h>

namespace c10 {
namespace impl {
namespace c10::impl {

PyObjectSlot::PyObjectSlot() : pyobj_interpreter_(nullptr), pyobj_(nullptr) {}

Expand Down Expand Up @@ -71,5 +70,4 @@ void PyObjectSlot::set_owns_pyobj(bool b) {
reinterpret_cast<uintptr_t>(_unchecked_untagged_pyobj()) | b);
}

} // namespace impl
} // namespace c10
} // namespace c10::impl
6 changes: 2 additions & 4 deletions c10/core/impl/PythonDispatcherTLS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
#include <c10/core/impl/LocalDispatchKeySet.h>
#include <c10/core/impl/PythonDispatcherTLS.h>

namespace c10 {
namespace impl {
namespace c10::impl {

thread_local PyInterpreter* pythonDispatcherState;

Expand All @@ -27,5 +26,4 @@ void PythonDispatcherTLS::reset_state() {
DispatchKey::PythonDispatcher, false);
}

} // namespace impl
} // namespace c10
} // namespace c10::impl
6 changes: 2 additions & 4 deletions c10/core/impl/PythonDispatcherTLS.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#include <c10/core/impl/PyInterpreter.h>
#include <c10/macros/Export.h>

namespace c10 {
namespace impl {
namespace c10::impl {

struct C10_API PythonDispatcherTLS {
static void set_state(PyInterpreter* state);
Expand All @@ -22,5 +21,4 @@ struct C10_API DisablePythonDispatcher {
PyInterpreter* old_;
};

} // namespace impl
} // namespace c10
} // namespace c10::impl
6 changes: 2 additions & 4 deletions c10/core/impl/SizesAndStrides.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <c10/core/impl/SizesAndStrides.h>

namespace c10 {
namespace impl {
namespace c10::impl {

void SizesAndStrides::resizeSlowPath(
const size_t newSize,
Expand Down Expand Up @@ -77,5 +76,4 @@ void SizesAndStrides::resizeSlowPath(
size_ = newSize;
}

} // namespace impl
} // namespace c10
} // namespace c10::impl
6 changes: 2 additions & 4 deletions c10/core/impl/TorchDispatchModeTLS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

#include <utility>

namespace c10 {
namespace impl {
namespace c10::impl {

thread_local TorchDispatchModeTLS torchDispatchModeState;

Expand Down Expand Up @@ -192,5 +191,4 @@ std::string to_string(TorchDispatchModeKey mode_key) {
}
}

} // namespace impl
} // namespace c10
} // namespace c10::impl
6 changes: 2 additions & 4 deletions c10/core/impl/TorchDispatchModeTLS.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/Export.h>

namespace c10 {
namespace impl {
namespace c10::impl {

enum class TorchDispatchModeKey : int8_t {
FAKE,
Expand Down Expand Up @@ -61,5 +60,4 @@ C10_API bool dispatch_mode_enabled();

C10_API std::string to_string(TorchDispatchModeKey mode_key);

} // namespace impl
} // namespace c10
} // namespace c10::impl
8 changes: 2 additions & 6 deletions c10/cuda/CUDAAllocatorConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
#include <c10/cuda/driver_api.h>
#endif

namespace c10 {
namespace cuda {
namespace CUDACachingAllocator {
namespace c10::cuda::CUDACachingAllocator {

constexpr size_t kRoundUpPowerOfTwoIntervals = 16;

Expand Down Expand Up @@ -354,6 +352,4 @@ void setAllocatorSettings(const std::string& env) {
CUDACachingAllocator::CUDAAllocatorConfig::instance().parseArgs(env.c_str());
}

} // namespace CUDACachingAllocator
} // namespace cuda
} // namespace c10
} // namespace c10::cuda::CUDACachingAllocator
7 changes: 3 additions & 4 deletions c10/cuda/CUDACachingAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ namespace c10 {

C10_DEFINE_REGISTRY(FreeCudaMemoryCallbacksRegistry, FreeMemoryCallback);

namespace cuda {
namespace CUDACachingAllocator {
namespace cuda::CUDACachingAllocator {

// Included here as this is externally used in CUDAAllocatorConfig
const size_t kLargeBuffer =
Expand Down Expand Up @@ -3347,6 +3346,6 @@ struct BackendStaticInitializer {
std::atomic<CUDAAllocator*> allocator;
BackendStaticInitializer backend_static_initializer;

} // namespace CUDACachingAllocator
} // namespace cuda
} // namespace cuda::CUDACachingAllocator

} // namespace c10
6 changes: 2 additions & 4 deletions c10/cuda/CUDADeviceAssertionHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
false); \
} while (0)

namespace c10 {
namespace cuda {
namespace c10::cuda {

namespace {

Expand Down Expand Up @@ -343,5 +342,4 @@ bool CUDAKernelLaunchRegistry::has_failed() const {
return false;
}

} // namespace cuda
} // namespace c10
} // namespace c10::cuda
6 changes: 2 additions & 4 deletions c10/cuda/CUDAException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

#include <string>

namespace c10 {
namespace cuda {
namespace c10::cuda {

void c10_cuda_check_implementation(
const int32_t err,
Expand Down Expand Up @@ -44,5 +43,4 @@ void c10_cuda_check_implementation(
TORCH_CHECK(false, check_message);
}

} // namespace cuda
} // namespace c10
} // namespace c10::cuda
10 changes: 2 additions & 8 deletions c10/cuda/CUDAMallocAsyncAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
#include <unordered_set>
#include <vector>

namespace c10 {
namespace cuda {
namespace CUDACachingAllocator {
namespace CudaMallocAsync {
namespace c10::cuda::CUDACachingAllocator::CudaMallocAsync {

#if CUDA_VERSION >= 11040
// CUDA device allocator that uses cudaMallocAsync to implement
Expand Down Expand Up @@ -898,7 +895,4 @@ CUDAAllocator* allocator() {

#endif

} // namespace CudaMallocAsync
} // namespace CUDACachingAllocator
} // namespace cuda
} // namespace c10
} // namespace c10::cuda::CUDACachingAllocator::CudaMallocAsync
6 changes: 2 additions & 4 deletions c10/cuda/CUDAMiscFunctions.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include <c10/cuda/CUDAMiscFunctions.h>
#include <stdlib.h>

namespace c10 {
namespace cuda {
namespace c10::cuda {

const char* get_cuda_check_suffix() noexcept {
static char* device_blocking_flag = getenv("CUDA_LAUNCH_BLOCKING");
Expand All @@ -21,5 +20,4 @@ std::mutex* getFreeMutex() {
return &cuda_free_mutex;
}

} // namespace cuda
} // namespace c10
} // namespace c10::cuda
6 changes: 2 additions & 4 deletions c10/cuda/CUDAStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
#include <mutex>
#include <vector>

namespace c10 {
namespace cuda {
namespace c10::cuda {

namespace {

Expand Down Expand Up @@ -339,5 +338,4 @@ std::ostream& operator<<(std::ostream& stream, const CUDAStream& s) {
return stream << s.unwrap();
}

} // namespace cuda
} // namespace c10
} // namespace c10::cuda
7 changes: 3 additions & 4 deletions c10/cuda/driver_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <c10/util/Exception.h>
#include <dlfcn.h>
#include <iostream>
namespace c10 {
namespace cuda {

namespace c10::cuda {

namespace {

Expand Down Expand Up @@ -42,7 +42,6 @@ C10_EXPORT DriverAPI* DriverAPI::get() {
return &singleton;
}

} // namespace cuda
} // namespace c10
} // namespace c10::cuda

#endif
Loading

0 comments on commit 4a01904

Please sign in to comment.