Enable nested namespace check in clang-tidy (#118506)

It is time to enable nested namespaces in the code.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/118506
Approved by: https://github.com/albanD
This commit is contained in:
cyy
2024-01-31 00:32:35 +00:00
committed by PyTorch MergeBot
parent 1b03423526
commit 4a019047ad
33 changed files with 65 additions and 142 deletions

View File

@ -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,

View File

@ -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) {
@ -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

View File

@ -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*>
@ -14,5 +13,4 @@ DeviceGuardImplRegistrar::DeviceGuardImplRegistrar(
device_guard_impl_registry[static_cast<size_t>(type)].store(impl);
}
} // namespace impl
} // namespace c10
} // namespace c10::impl

View File

@ -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.
@ -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

View File

@ -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};
@ -16,5 +15,4 @@ void GPUTrace::set_trace(const PyInterpreter* trace) {
});
}
} // namespace impl
} // namespace c10
} // namespace c10::impl

View File

@ -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.
@ -26,5 +25,4 @@ struct C10_API GPUTrace {
}
};
} // namespace impl
} // namespace c10
} // namespace c10::impl

View File

@ -1,7 +1,6 @@
#include <c10/core/impl/HermeticPyObjectTLS.h>
namespace c10 {
namespace impl {
namespace c10::impl {
thread_local std::atomic<bool> hermeticPyObjectState{false};
@ -19,5 +18,4 @@ void HermeticPyObjectTLS::init_state() {
haveState_ = true;
}
} // namespace impl
} // namespace c10
} // namespace c10::impl

View File

@ -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]
@ -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

View File

@ -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 {
@ -125,5 +124,4 @@ void PyInterpreter::disarm() noexcept {
vtable_ = &noop_vtable;
}
} // namespace impl
} // namespace c10
} // namespace c10::impl

View File

@ -1,7 +1,6 @@
#include <c10/core/impl/PyObjectSlot.h>
namespace c10 {
namespace impl {
namespace c10::impl {
PyObjectSlot::PyObjectSlot() : pyobj_interpreter_(nullptr), pyobj_(nullptr) {}
@ -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

View File

@ -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;
@ -27,5 +26,4 @@ void PythonDispatcherTLS::reset_state() {
DispatchKey::PythonDispatcher, false);
}
} // namespace impl
} // namespace c10
} // namespace c10::impl

View File

@ -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);
@ -22,5 +21,4 @@ struct C10_API DisablePythonDispatcher {
PyInterpreter* old_;
};
} // namespace impl
} // namespace c10
} // namespace c10::impl

View File

@ -1,7 +1,6 @@
#include <c10/core/impl/SizesAndStrides.h>
namespace c10 {
namespace impl {
namespace c10::impl {
void SizesAndStrides::resizeSlowPath(
const size_t newSize,
@ -77,5 +76,4 @@ void SizesAndStrides::resizeSlowPath(
size_ = newSize;
}
} // namespace impl
} // namespace c10
} // namespace c10::impl

View File

@ -6,8 +6,7 @@
#include <utility>
namespace c10 {
namespace impl {
namespace c10::impl {
thread_local TorchDispatchModeTLS torchDispatchModeState;
@ -192,5 +191,4 @@ std::string to_string(TorchDispatchModeKey mode_key) {
}
}
} // namespace impl
} // namespace c10
} // namespace c10::impl

View File

@ -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,
@ -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

View File

@ -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;
@ -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

View File

@ -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 =
@ -3347,6 +3346,6 @@ struct BackendStaticInitializer {
std::atomic<CUDAAllocator*> allocator;
BackendStaticInitializer backend_static_initializer;
} // namespace CUDACachingAllocator
} // namespace cuda
} // namespace cuda::CUDACachingAllocator
} // namespace c10

View File

@ -26,8 +26,7 @@
false); \
} while (0)
namespace c10 {
namespace cuda {
namespace c10::cuda {
namespace {
@ -343,5 +342,4 @@ bool CUDAKernelLaunchRegistry::has_failed() const {
return false;
}
} // namespace cuda
} // namespace c10
} // namespace c10::cuda

View File

@ -6,8 +6,7 @@
#include <string>
namespace c10 {
namespace cuda {
namespace c10::cuda {
void c10_cuda_check_implementation(
const int32_t err,
@ -44,5 +43,4 @@ void c10_cuda_check_implementation(
TORCH_CHECK(false, check_message);
}
} // namespace cuda
} // namespace c10
} // namespace c10::cuda

View File

@ -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
@ -898,7 +895,4 @@ CUDAAllocator* allocator() {
#endif
} // namespace CudaMallocAsync
} // namespace CUDACachingAllocator
} // namespace cuda
} // namespace c10
} // namespace c10::cuda::CUDACachingAllocator::CudaMallocAsync

View File

@ -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");
@ -21,5 +20,4 @@ std::mutex* getFreeMutex() {
return &cuda_free_mutex;
}
} // namespace cuda
} // namespace c10
} // namespace c10::cuda

View File

@ -11,8 +11,7 @@
#include <mutex>
#include <vector>
namespace c10 {
namespace cuda {
namespace c10::cuda {
namespace {
@ -339,5 +338,4 @@ std::ostream& operator<<(std::ostream& stream, const CUDAStream& s) {
return stream << s.unwrap();
}
} // namespace cuda
} // namespace c10
} // namespace c10::cuda

View File

@ -4,8 +4,8 @@
#include <c10/util/Exception.h>
#include <dlfcn.h>
#include <iostream>
namespace c10 {
namespace cuda {
namespace c10::cuda {
namespace {
@ -42,7 +42,6 @@ C10_EXPORT DriverAPI* DriverAPI::get() {
return &singleton;
}
} // namespace cuda
} // namespace c10
} // namespace c10::cuda
#endif

View File

@ -1,11 +1,7 @@
#include <c10/cuda/impl/CUDAGuardImpl.h>
namespace c10 {
namespace cuda {
namespace impl {
namespace c10::cuda::impl {
C10_REGISTER_GUARD_IMPL(CUDA, CUDAGuardImpl);
} // namespace impl
} // namespace cuda
} // namespace c10
} // namespace c10::cuda::impl

View File

@ -18,9 +18,7 @@
#include <cuda_runtime_api.h>
#include <cstdint>
namespace c10 {
namespace cuda {
namespace impl {
namespace c10::cuda::impl {
struct CUDAGuardImpl final : public c10::impl::DeviceGuardImplInterface {
static constexpr DeviceType static_type = DeviceType::CUDA;
@ -211,6 +209,4 @@ struct CUDAGuardImpl final : public c10::impl::DeviceGuardImplInterface {
}
};
} // namespace impl
} // namespace cuda
} // namespace c10
} // namespace c10::cuda::impl

View File

@ -5,9 +5,7 @@
#include <cuda_runtime.h>
namespace c10 {
namespace cuda {
namespace impl {
namespace c10::cuda::impl {
bool has_cuda_gpu() {
int count = 0;
@ -29,6 +27,4 @@ int c10_cuda_private_test() {
return 2;
}
} // namespace impl
} // namespace cuda
} // namespace c10
} // namespace c10::cuda::impl

View File

@ -2,12 +2,8 @@
#include <c10/cuda/CUDAMacros.h>
namespace c10 {
namespace cuda {
namespace impl {
namespace c10::cuda::impl {
C10_CUDA_API int c10_cuda_test();
}
} // namespace cuda
} // namespace c10

View File

@ -2,8 +2,7 @@
#include <cstdlib>
namespace c10 {
namespace impl {
namespace c10::impl {
namespace {
PythonGILHooks* python_gil_hooks = nullptr;
@ -28,5 +27,4 @@ void SetPythonGILHooks(PythonGILHooks* hooks) {
python_gil_hooks = hooks;
}
} // namespace impl
} // namespace c10
} // namespace c10::impl

View File

@ -420,8 +420,7 @@ MessageLogger::~MessageLogger() {
#endif // !C10_USE_GLOG
namespace c10 {
namespace detail {
namespace c10::detail {
namespace {
void setLogLevelFlagFromEnv() {
@ -467,5 +466,4 @@ void setLogLevelFlagFromEnv() {
}
} // namespace
} // namespace detail
} // namespace c10
} // namespace c10::detail

View File

@ -1,9 +1,7 @@
#include <c10/util/UniqueVoidPtr.h>
namespace c10 {
namespace detail {
namespace c10::detail {
void deleteNothing(void*) {}
} // namespace detail
} // namespace c10
} // namespace c10::detail

View File

@ -1,8 +1,7 @@
#include <torch/csrc/itt_wrapper.h>
#include <torch/csrc/utils/pybind.h>
namespace torch {
namespace profiler {
namespace torch::profiler {
void initIttBindings(PyObject* module) {
auto m = py::handle(module).cast<py::module>();
@ -12,5 +11,4 @@ void initIttBindings(PyObject* module) {
itt.def("rangePop", itt_range_pop);
itt.def("mark", itt_mark);
}
} // namespace profiler
} // namespace torch
} // namespace torch::profiler

View File

@ -2,8 +2,7 @@
#include <torch/csrc/itt_wrapper.h>
#include <torch/csrc/profiler/stubs/base.h>
namespace torch {
namespace profiler {
namespace torch::profiler {
__itt_domain* _itt_domain = __itt_domain_create("PyTorch");
bool itt_is_available() {
@ -24,5 +23,4 @@ void itt_mark(const char* msg) {
__itt_task_begin(_itt_domain, __itt_null, __itt_null, hsMsg);
__itt_task_end(_itt_domain);
}
} // namespace profiler
} // namespace torch
} // namespace torch::profiler

View File

@ -2,13 +2,11 @@
#define PROFILER_ITT_H
#include <c10/macros/Export.h>
namespace torch {
namespace profiler {
namespace torch::profiler {
TORCH_API bool itt_is_available();
TORCH_API void itt_range_push(const char* msg);
TORCH_API void itt_range_pop();
TORCH_API void itt_mark(const char* msg);
} // namespace profiler
} // namespace torch
} // namespace torch::profiler
#endif // PROFILER_ITT_H