diff --git a/.clang-tidy b/.clang-tidy index 7e2313b94c06..45b4374aa09c 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -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, diff --git a/c10/core/WrapDimMinimal.cpp b/c10/core/WrapDimMinimal.cpp index 2375dc3ac5cf..c95753432580 100644 --- a/c10/core/WrapDimMinimal.cpp +++ b/c10/core/WrapDimMinimal.cpp @@ -1,7 +1,6 @@ #include -namespace c10 { -namespace detail { +namespace c10::detail { template 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 diff --git a/c10/core/impl/DeviceGuardImplInterface.cpp b/c10/core/impl/DeviceGuardImplInterface.cpp index cc54c54c9708..581f32f1e130 100644 --- a/c10/core/impl/DeviceGuardImplInterface.cpp +++ b/c10/core/impl/DeviceGuardImplInterface.cpp @@ -1,7 +1,6 @@ #include -namespace c10 { -namespace impl { +namespace c10::impl { // NOLINTNEXTLINE(modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) std::atomic @@ -14,5 +13,4 @@ DeviceGuardImplRegistrar::DeviceGuardImplRegistrar( device_guard_impl_registry[static_cast(type)].store(impl); } -} // namespace impl -} // namespace c10 +} // namespace c10::impl diff --git a/c10/core/impl/FakeGuardImpl.h b/c10/core/impl/FakeGuardImpl.h index c9b472156edd..c8bfe91619ed 100644 --- a/c10/core/impl/FakeGuardImpl.h +++ b/c10/core/impl/FakeGuardImpl.h @@ -4,8 +4,7 @@ #include -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 thread_local std::array FakeGuardImpl::current_streams_ = {0, 0, 0, 0, 0, 0, 0, 0}; -} // namespace impl -} // namespace c10 +} // namespace c10::impl diff --git a/c10/core/impl/GPUTrace.cpp b/c10/core/impl/GPUTrace.cpp index 403f1e65ce56..ac1f08d7e091 100644 --- a/c10/core/impl/GPUTrace.cpp +++ b/c10/core/impl/GPUTrace.cpp @@ -1,8 +1,7 @@ #include #include -namespace c10 { -namespace impl { +namespace c10::impl { std::atomic GPUTrace::gpuTraceState{nullptr}; @@ -16,5 +15,4 @@ void GPUTrace::set_trace(const PyInterpreter* trace) { }); } -} // namespace impl -} // namespace c10 +} // namespace c10::impl diff --git a/c10/core/impl/GPUTrace.h b/c10/core/impl/GPUTrace.h index 377af88be034..3acb875b54a3 100644 --- a/c10/core/impl/GPUTrace.h +++ b/c10/core/impl/GPUTrace.h @@ -2,8 +2,7 @@ #include -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 diff --git a/c10/core/impl/HermeticPyObjectTLS.cpp b/c10/core/impl/HermeticPyObjectTLS.cpp index a7eb89430be8..ae1f6fd8ee6b 100644 --- a/c10/core/impl/HermeticPyObjectTLS.cpp +++ b/c10/core/impl/HermeticPyObjectTLS.cpp @@ -1,7 +1,6 @@ #include -namespace c10 { -namespace impl { +namespace c10::impl { thread_local std::atomic hermeticPyObjectState{false}; @@ -19,5 +18,4 @@ void HermeticPyObjectTLS::init_state() { haveState_ = true; } -} // namespace impl -} // namespace c10 +} // namespace c10::impl diff --git a/c10/core/impl/LocalDispatchKeySet.cpp b/c10/core/impl/LocalDispatchKeySet.cpp index 0b6cf6fa66f8..0b3d87fce241 100644 --- a/c10/core/impl/LocalDispatchKeySet.cpp +++ b/c10/core/impl/LocalDispatchKeySet.cpp @@ -1,7 +1,6 @@ #include -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 diff --git a/c10/core/impl/PyInterpreter.cpp b/c10/core/impl/PyInterpreter.cpp index f555ee5c3458..dc0ec52760c5 100644 --- a/c10/core/impl/PyInterpreter.cpp +++ b/c10/core/impl/PyInterpreter.cpp @@ -2,8 +2,7 @@ #include #include -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 diff --git a/c10/core/impl/PyObjectSlot.cpp b/c10/core/impl/PyObjectSlot.cpp index ac6d5915afb6..400903bc7a65 100644 --- a/c10/core/impl/PyObjectSlot.cpp +++ b/c10/core/impl/PyObjectSlot.cpp @@ -1,7 +1,6 @@ #include -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(_unchecked_untagged_pyobj()) | b); } -} // namespace impl -} // namespace c10 +} // namespace c10::impl diff --git a/c10/core/impl/PythonDispatcherTLS.cpp b/c10/core/impl/PythonDispatcherTLS.cpp index 5ca57a9da466..a53e293eaa32 100644 --- a/c10/core/impl/PythonDispatcherTLS.cpp +++ b/c10/core/impl/PythonDispatcherTLS.cpp @@ -2,8 +2,7 @@ #include #include -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 diff --git a/c10/core/impl/PythonDispatcherTLS.h b/c10/core/impl/PythonDispatcherTLS.h index 8998935279ee..9016c3e11e15 100644 --- a/c10/core/impl/PythonDispatcherTLS.h +++ b/c10/core/impl/PythonDispatcherTLS.h @@ -3,8 +3,7 @@ #include #include -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 diff --git a/c10/core/impl/SizesAndStrides.cpp b/c10/core/impl/SizesAndStrides.cpp index ca859ae0681d..6c63109ea5af 100644 --- a/c10/core/impl/SizesAndStrides.cpp +++ b/c10/core/impl/SizesAndStrides.cpp @@ -1,7 +1,6 @@ #include -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 diff --git a/c10/core/impl/TorchDispatchModeTLS.cpp b/c10/core/impl/TorchDispatchModeTLS.cpp index 1ee5aa85cc23..37c75003e200 100644 --- a/c10/core/impl/TorchDispatchModeTLS.cpp +++ b/c10/core/impl/TorchDispatchModeTLS.cpp @@ -6,8 +6,7 @@ #include -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 diff --git a/c10/core/impl/TorchDispatchModeTLS.h b/c10/core/impl/TorchDispatchModeTLS.h index 55d0d92b230f..50a92459e61e 100644 --- a/c10/core/impl/TorchDispatchModeTLS.h +++ b/c10/core/impl/TorchDispatchModeTLS.h @@ -3,8 +3,7 @@ #include #include -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 diff --git a/c10/cuda/CUDAAllocatorConfig.cpp b/c10/cuda/CUDAAllocatorConfig.cpp index 5a709f981b0e..eb7d8d49754f 100644 --- a/c10/cuda/CUDAAllocatorConfig.cpp +++ b/c10/cuda/CUDAAllocatorConfig.cpp @@ -6,9 +6,7 @@ #include #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 diff --git a/c10/cuda/CUDACachingAllocator.cpp b/c10/cuda/CUDACachingAllocator.cpp index ebe1fd2b72e8..f44703c5a9a0 100644 --- a/c10/cuda/CUDACachingAllocator.cpp +++ b/c10/cuda/CUDACachingAllocator.cpp @@ -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 allocator; BackendStaticInitializer backend_static_initializer; -} // namespace CUDACachingAllocator -} // namespace cuda +} // namespace cuda::CUDACachingAllocator + } // namespace c10 diff --git a/c10/cuda/CUDADeviceAssertionHost.cpp b/c10/cuda/CUDADeviceAssertionHost.cpp index 1a3b2a68c69c..b954dcf26ebe 100644 --- a/c10/cuda/CUDADeviceAssertionHost.cpp +++ b/c10/cuda/CUDADeviceAssertionHost.cpp @@ -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 diff --git a/c10/cuda/CUDAException.cpp b/c10/cuda/CUDAException.cpp index 24f3d928af69..2d725747c969 100644 --- a/c10/cuda/CUDAException.cpp +++ b/c10/cuda/CUDAException.cpp @@ -6,8 +6,7 @@ #include -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 diff --git a/c10/cuda/CUDAMallocAsyncAllocator.cpp b/c10/cuda/CUDAMallocAsyncAllocator.cpp index a4503e383039..b80c91d00819 100644 --- a/c10/cuda/CUDAMallocAsyncAllocator.cpp +++ b/c10/cuda/CUDAMallocAsyncAllocator.cpp @@ -9,10 +9,7 @@ #include #include -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 diff --git a/c10/cuda/CUDAMiscFunctions.cpp b/c10/cuda/CUDAMiscFunctions.cpp index 37225d2a9a0b..212139ddfacd 100644 --- a/c10/cuda/CUDAMiscFunctions.cpp +++ b/c10/cuda/CUDAMiscFunctions.cpp @@ -1,8 +1,7 @@ #include #include -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 diff --git a/c10/cuda/CUDAStream.cpp b/c10/cuda/CUDAStream.cpp index 08916cfee4a6..88150334d678 100644 --- a/c10/cuda/CUDAStream.cpp +++ b/c10/cuda/CUDAStream.cpp @@ -11,8 +11,7 @@ #include #include -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 diff --git a/c10/cuda/driver_api.cpp b/c10/cuda/driver_api.cpp index 56243e663c79..5fc4364e9f02 100644 --- a/c10/cuda/driver_api.cpp +++ b/c10/cuda/driver_api.cpp @@ -4,8 +4,8 @@ #include #include #include -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 diff --git a/c10/cuda/impl/CUDAGuardImpl.cpp b/c10/cuda/impl/CUDAGuardImpl.cpp index 584430f7a220..35161209a15f 100644 --- a/c10/cuda/impl/CUDAGuardImpl.cpp +++ b/c10/cuda/impl/CUDAGuardImpl.cpp @@ -1,11 +1,7 @@ #include -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 diff --git a/c10/cuda/impl/CUDAGuardImpl.h b/c10/cuda/impl/CUDAGuardImpl.h index f98f6a98a3fa..2be8cb1b1921 100644 --- a/c10/cuda/impl/CUDAGuardImpl.h +++ b/c10/cuda/impl/CUDAGuardImpl.h @@ -18,9 +18,7 @@ #include #include -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 diff --git a/c10/cuda/impl/CUDATest.cpp b/c10/cuda/impl/CUDATest.cpp index f2d4ae976512..287479dab945 100644 --- a/c10/cuda/impl/CUDATest.cpp +++ b/c10/cuda/impl/CUDATest.cpp @@ -5,9 +5,7 @@ #include -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 diff --git a/c10/cuda/impl/CUDATest.h b/c10/cuda/impl/CUDATest.h index 593905d15672..c4316e8a6b73 100644 --- a/c10/cuda/impl/CUDATest.h +++ b/c10/cuda/impl/CUDATest.h @@ -2,12 +2,8 @@ #include -namespace c10 { -namespace cuda { -namespace impl { +namespace c10::cuda::impl { C10_CUDA_API int c10_cuda_test(); } -} // namespace cuda -} // namespace c10 diff --git a/c10/util/DeadlockDetection.cpp b/c10/util/DeadlockDetection.cpp index bb95939fc53f..320fa7873c6f 100644 --- a/c10/util/DeadlockDetection.cpp +++ b/c10/util/DeadlockDetection.cpp @@ -2,8 +2,7 @@ #include -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 diff --git a/c10/util/Logging.cpp b/c10/util/Logging.cpp index 862bc8d19a0d..f4eef35b147e 100644 --- a/c10/util/Logging.cpp +++ b/c10/util/Logging.cpp @@ -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 diff --git a/c10/util/UniqueVoidPtr.cpp b/c10/util/UniqueVoidPtr.cpp index d4e9e32810ff..3554bcf8ee62 100644 --- a/c10/util/UniqueVoidPtr.cpp +++ b/c10/util/UniqueVoidPtr.cpp @@ -1,9 +1,7 @@ #include -namespace c10 { -namespace detail { +namespace c10::detail { void deleteNothing(void*) {} -} // namespace detail -} // namespace c10 +} // namespace c10::detail diff --git a/torch/csrc/itt.cpp b/torch/csrc/itt.cpp index 0e0ad78b4bac..868235d90ad7 100644 --- a/torch/csrc/itt.cpp +++ b/torch/csrc/itt.cpp @@ -1,8 +1,7 @@ #include #include -namespace torch { -namespace profiler { +namespace torch::profiler { void initIttBindings(PyObject* module) { auto m = py::handle(module).cast(); @@ -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 diff --git a/torch/csrc/itt_wrapper.cpp b/torch/csrc/itt_wrapper.cpp index 432ef4313559..2719e11e1952 100644 --- a/torch/csrc/itt_wrapper.cpp +++ b/torch/csrc/itt_wrapper.cpp @@ -2,8 +2,7 @@ #include #include -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 diff --git a/torch/csrc/itt_wrapper.h b/torch/csrc/itt_wrapper.h index a24fcb1a6991..502af374ff3d 100644 --- a/torch/csrc/itt_wrapper.h +++ b/torch/csrc/itt_wrapper.h @@ -2,13 +2,11 @@ #define PROFILER_ITT_H #include -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