Skip to content

Commit 95dbbf7

Browse files
cyyeverpytorchmergebot
authored andcommitted
[Distributed] [9/N] Fix clang-tidy warnings in torch/csrc/distributed/rpc (pytorch#130109)
Follows pytorch#125102 Pull Request resolved: pytorch#130109 Approved by: https://github.com/ezyang
1 parent 7b2e802 commit 95dbbf7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+202
-413
lines changed

torch/csrc/distributed/c10d/ProcessGroupGloo.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ ReduceFunc toFunction(const ReduceOp& r) {
199199
TORCH_CHECK(false, "Cannot use ReduceOp.PREMUL_SUM with Gloo");
200200
break;
201201
case ReduceOp::UNUSED:
202+
default:
202203
break;
203204
}
204205

@@ -262,6 +263,7 @@ ReduceFunc toFunction(const ReduceOp& r) {
262263
TORCH_CHECK(false, "Cannot use ReduceOp.PREMUL_SUM with Gloo");
263264
break;
264265
case ReduceOp::UNUSED:
266+
default:
265267
break;
266268
}
267269

@@ -498,7 +500,8 @@ inline void ProcessGroupGloo::AsyncWork::recordAsyncWorkProfilingInfo(
498500
profilingTitle,
499501
c10::ArrayRef<const c10::IValue>(inputs.data(), inputs.size()));
500502
};
501-
recordFunctionBeforeCallback_ = at::wrapPropagateTLSState(before_handler);
503+
recordFunctionBeforeCallback_ =
504+
at::wrapPropagateTLSState(std::move(before_handler));
502505
std::function<void()> end_handler = [recordingFunction]() {
503506
recordingFunction->end();
504507
};

torch/csrc/distributed/rpc/agent_utils.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#include <fmt/format.h>
22
#include <torch/csrc/distributed/rpc/agent_utils.h>
33

4-
namespace torch {
5-
namespace distributed {
6-
namespace rpc {
4+
namespace torch::distributed::rpc {
75

86
std::unordered_map<std::string, worker_id_t> collectNames(
97
::c10d::PrefixStore store,
@@ -197,6 +195,4 @@ int syncCallCount(
197195
return totalCallCount;
198196
}
199197

200-
} // namespace rpc
201-
} // namespace distributed
202-
} // namespace torch
198+
} // namespace torch::distributed::rpc

torch/csrc/distributed/rpc/init.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919
#include <pybind11/chrono.h>
2020
#include <pybind11/operators.h>
2121

22-
namespace torch {
23-
namespace distributed {
24-
namespace rpc {
22+
namespace torch::distributed::rpc {
2523

2624
namespace {
2725

@@ -857,6 +855,4 @@ PyMethodDef* python_functions() {
857855
return methods;
858856
}
859857

860-
} // namespace rpc
861-
} // namespace distributed
862-
} // namespace torch
858+
} // namespace torch::distributed::rpc

torch/csrc/distributed/rpc/message.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#include <torch/csrc/distributed/rpc/message.h>
22
#include <torch/custom_class.h>
33

4-
namespace torch {
5-
namespace distributed {
6-
namespace rpc {
4+
namespace torch::distributed::rpc {
75

86
Message::Message() = default;
97

@@ -113,6 +111,4 @@ static const auto message = torch::class_<Message>("rpc", "_Message");
113111

114112
} // namespace
115113

116-
} // namespace rpc
117-
} // namespace distributed
118-
} // namespace torch
114+
} // namespace torch::distributed::rpc

torch/csrc/distributed/rpc/metrics/RpcMetricsHandler.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
#include <c10/util/Registry.h>
33
#include <string>
44

5-
namespace torch {
6-
namespace distributed {
7-
namespace rpc {
8-
// All metrics are prefixed with the following key.
5+
namespace torch::distributed::rpc {
6+
// All metrics are prefixed with the following key.
97
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays)
108
constexpr char kRpcMetricsKeyPrefix[] = "torch.distributed.rpc.";
119
// APIs for logging time-series metrics for RPC-based distributed
@@ -39,6 +37,4 @@ C10_DECLARE_REGISTRY(
3937
RpcMetricsHandlerRegistry,
4038
torch::distributed::rpc::RpcMetricsHandler);
4139

42-
} // namespace rpc
43-
} // namespace distributed
44-
} // namespace torch
40+
} // namespace torch::distributed::rpc
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
#include <torch/csrc/distributed/rpc/metrics/RpcMetricsHandler.h> // @manual
2-
namespace torch {
3-
namespace distributed {
4-
namespace rpc {
2+
3+
namespace torch::distributed::rpc {
54
C10_DEFINE_REGISTRY(
65
RpcMetricsHandlerRegistry,
76
torch::distributed::rpc::RpcMetricsHandler);
8-
} // namespace rpc
9-
} // namespace distributed
10-
} // namespace torch
7+
} // namespace torch::distributed::rpc

torch/csrc/distributed/rpc/profiler/remote_profiler_manager.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
#include <torch/csrc/jit/serialization/pickle.h>
55
#include <torch/csrc/utils/byte_order.h>
66

7-
namespace torch {
8-
namespace distributed {
9-
namespace rpc {
7+
namespace torch::distributed::rpc {
108
const std::string REMOTE_PROFILING_KEY_PREFIX = "#remote_op: ";
119
constexpr int kAutoIncrementBits = 48;
1210
/*static */ thread_local std::optional<std::string>
@@ -28,7 +26,7 @@ void RemoteProfilerManager::setCurrentKey(std::string key) {
2826
}
2927

3028
bool RemoteProfilerManager::isCurrentKeySet() const {
31-
return currentThreadLocalKey_ ? true : false;
29+
return currentThreadLocalKey_.has_value();
3230
}
3331

3432
void RemoteProfilerManager::unsetCurrentKey() {
@@ -85,6 +83,4 @@ RemoteProfilerManager::RemoteProfilerManager() {
8583
static_cast<int64_t>(RpcAgent::getCurrentRpcAgent()->getWorkerInfo().id_);
8684
currentLocalId_ = workerId << kAutoIncrementBits;
8785
}
88-
} // namespace rpc
89-
} // namespace distributed
90-
} // namespace torch
86+
} // namespace torch::distributed::rpc

torch/csrc/distributed/rpc/profiler/remote_profiler_manager.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
#include <optional>
66
#include <unordered_map>
77

8-
namespace torch {
9-
namespace distributed {
10-
namespace rpc {
8+
namespace torch::distributed::rpc {
119
extern const std::string REMOTE_PROFILING_KEY_PREFIX;
1210

1311
class TORCH_API RemoteProfilerManager {
@@ -54,6 +52,4 @@ class TORCH_API RemoteProfilerManager {
5452
std::mutex mutex_;
5553
local_id_t currentLocalId_;
5654
};
57-
} // namespace rpc
58-
} // namespace distributed
59-
} // namespace torch
55+
} // namespace torch::distributed::rpc

torch/csrc/distributed/rpc/profiler/server_process_global_profiler.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#include <torch/csrc/distributed/rpc/profiler/server_process_global_profiler.h>
22

3-
namespace torch {
4-
namespace distributed {
5-
namespace rpc {
6-
namespace profiler {
7-
namespace processglobal {
3+
namespace torch::distributed::rpc::profiler::processglobal {
84

95
using namespace torch::autograd::profiler;
106

@@ -58,8 +54,4 @@ std::vector<thread_event_lists> disableServer() {
5854
return statePtr->results();
5955
}
6056

61-
} // namespace processglobal
62-
} // namespace profiler
63-
} // namespace rpc
64-
} // namespace distributed
65-
} // namespace torch
57+
} // namespace torch::distributed::rpc::profiler::processglobal

torch/csrc/distributed/rpc/profiler/server_process_global_profiler.h

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
#pragma once
22

33
#include <shared_mutex>
4+
#include <utility>
45

56
#include <torch/csrc/autograd/profiler.h>
67

7-
namespace torch {
8-
namespace distributed {
9-
namespace rpc {
10-
namespace profiler {
11-
namespace processglobal {
8+
namespace torch::distributed::rpc::profiler::processglobal {
129

1310
using namespace torch::autograd::profiler;
1411

@@ -27,7 +24,7 @@ using namespace torch::autograd::profiler;
2724
// threads.
2825
class State {
2926
public:
30-
explicit State(const ProfilerConfig& config) : config_(config) {}
27+
explicit State(ProfilerConfig config) : config_(std::move(config)) {}
3128
~State() = default;
3229

3330
const ProfilerConfig& config() const {
@@ -104,7 +101,9 @@ class StateStackEntry {
104101
}
105102

106103
private:
104+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
107105
const std::shared_ptr<StateStackEntry> prevPtr_{nullptr};
106+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
108107
const std::shared_ptr<State> statePtr_{nullptr};
109108
};
110109

@@ -127,8 +126,4 @@ TORCH_API void enableServer(const ProfilerConfig& new_config);
127126
// This enables all RPC threads running server-side request callbacks.
128127
TORCH_API std::vector<thread_event_lists> disableServer();
129128

130-
} // namespace processglobal
131-
} // namespace profiler
132-
} // namespace rpc
133-
} // namespace distributed
134-
} // namespace torch
129+
} // namespace torch::distributed::rpc::profiler::processglobal

torch/csrc/distributed/rpc/py_rref.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
#include <torch/csrc/jit/python/module_python.h>
1010
#include <torch/csrc/jit/python/pybind_utils.h>
1111

12-
namespace torch {
13-
namespace distributed {
14-
namespace rpc {
12+
namespace torch::distributed::rpc {
1513

1614
///////////////////// Pickle/Unpickle Helplers ////////////////////////////
1715

@@ -363,6 +361,4 @@ void PyRRef::backward(
363361
}
364362
}
365363

366-
} // namespace rpc
367-
} // namespace distributed
368-
} // namespace torch
364+
} // namespace torch::distributed::rpc

torch/csrc/distributed/rpc/python_call.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#include <torch/csrc/distributed/rpc/python_call.h>
22

3-
namespace torch {
4-
namespace distributed {
5-
namespace rpc {
3+
namespace torch::distributed::rpc {
64

75
PythonCall::PythonCall(SerializedPyObj&& serializedPyObj, bool isAsyncExecution)
86
: serializedPyObj_(std::move(serializedPyObj)),
@@ -44,6 +42,4 @@ const SerializedPyObj& PythonCall::serializedPyObj() const {
4442
return serializedPyObj_;
4543
}
4644

47-
} // namespace rpc
48-
} // namespace distributed
49-
} // namespace torch
45+
} // namespace torch::distributed::rpc

torch/csrc/distributed/rpc/python_call.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
#include <torch/csrc/distributed/rpc/rpc_command_base.h>
44
#include <torch/csrc/distributed/rpc/types.h>
55

6-
namespace torch {
7-
namespace distributed {
8-
namespace rpc {
6+
namespace torch::distributed::rpc {
97

108
// RPC call representing calling a Python function over RPC.
119
class TORCH_API PythonCall final : public RpcCommandBase {
@@ -27,6 +25,4 @@ class TORCH_API PythonCall final : public RpcCommandBase {
2725
const bool isAsyncExecution_;
2826
};
2927

30-
} // namespace rpc
31-
} // namespace distributed
32-
} // namespace torch
28+
} // namespace torch::distributed::rpc

torch/csrc/distributed/rpc/python_functions.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
#include <torch/csrc/utils/python_compat.h>
1919
#include <exception>
2020

21-
namespace torch {
22-
namespace distributed {
23-
namespace rpc {
21+
namespace torch::distributed::rpc {
2422

2523
namespace {
2624

@@ -421,6 +419,4 @@ PyRRef pyRemoteTorchscript(
421419
return PyRRef(rrefPtr);
422420
}
423421

424-
} // namespace rpc
425-
} // namespace distributed
426-
} // namespace torch
422+
} // namespace torch::distributed::rpc

torch/csrc/distributed/rpc/python_functions.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
#include <torch/csrc/jit/python/pybind_utils.h>
66
#include <torch/csrc/utils/pybind.h>
77

8-
namespace torch {
9-
namespace distributed {
10-
namespace rpc {
8+
namespace torch::distributed::rpc {
119

1210
// Converts an internal ivalue::Future of Message into a user-facing
1311
// ivalue::Future of py::object type by creating a new ivalue::Future and call
@@ -65,6 +63,4 @@ PyRRef pyRemoteTorchscript(
6563
const py::args& args,
6664
const py::kwargs& kwargs);
6765

68-
} // namespace rpc
69-
} // namespace distributed
70-
} // namespace torch
66+
} // namespace torch::distributed::rpc

torch/csrc/distributed/rpc/python_remote_call.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
#include <torch/csrc/distributed/rpc/rpc_agent.h>
33
#include <torch/csrc/jit/serialization/pickle.h>
44

5-
namespace torch {
6-
namespace distributed {
7-
namespace rpc {
5+
namespace torch::distributed::rpc {
86

97
PythonRemoteCall::PythonRemoteCall(
108
SerializedPyObj&& serializedPyObj,
@@ -64,6 +62,4 @@ std::unique_ptr<PythonRemoteCall> PythonRemoteCall::fromMessage(
6462
isAsyncExecution);
6563
}
6664

67-
} // namespace rpc
68-
} // namespace distributed
69-
} // namespace torch
65+
} // namespace torch::distributed::rpc

torch/csrc/distributed/rpc/python_remote_call.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
#include <torch/csrc/jit/serialization/pickler.h>
77
#include <vector>
88

9-
namespace torch {
10-
namespace distributed {
11-
namespace rpc {
9+
namespace torch::distributed::rpc {
1210

1311
class TORCH_API PythonRemoteCall : public RpcCommandBase {
1412
public:
@@ -44,6 +42,4 @@ class TORCH_API PythonRemoteCall : public RpcCommandBase {
4442
const bool isAsyncExecution_;
4543
};
4644

47-
} // namespace rpc
48-
} // namespace distributed
49-
} // namespace torch
45+
} // namespace torch::distributed::rpc

torch/csrc/distributed/rpc/python_resp.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#include <torch/csrc/distributed/rpc/python_resp.h>
22

3-
namespace torch {
4-
namespace distributed {
5-
namespace rpc {
3+
namespace torch::distributed::rpc {
64

75
PythonResp::PythonResp(SerializedPyObj&& serializedPyObj)
86
: serializedPyObj_(std::move(serializedPyObj)) {}
@@ -27,6 +25,4 @@ const SerializedPyObj& PythonResp::serializedPyObj() const {
2725
return serializedPyObj_;
2826
}
2927

30-
} // namespace rpc
31-
} // namespace distributed
32-
} // namespace torch
28+
} // namespace torch::distributed::rpc

0 commit comments

Comments
 (0)