Skip to content

Commit 7d8402a

Browse files
authored
fix paddle namespace conflict when using paddle_flags (#56913)
* update * update * update
1 parent 25a0b46 commit 7d8402a

File tree

3 files changed

+20
-28
lines changed

3 files changed

+20
-28
lines changed

paddle/fluid/distributed/ps/service/heter_client.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void HeterClient::CreateClient2XpuConnection() {
8585
xpu_channels_[i].reset(new brpc::Channel());
8686
if (xpu_channels_[i]->Init(xpu_list_[i].c_str(), "", &options) != 0) {
8787
VLOG(0) << "HeterClient channel init fail. Try Again";
88-
auto ip_port = ::paddle::string::Split(xpu_list_[i], ':');
88+
auto ip_port = paddle::string::Split(xpu_list_[i], ':');
8989
std::string ip = ip_port[0];
9090
int port = std::stoi(ip_port[1]);
9191
std::string int_ip_port = GetIntTypeEndpoint(ip, port);
@@ -100,7 +100,7 @@ void HeterClient::CreateClient2XpuConnection() {
100100
if (previous_xpu_channels_[i]->Init(
101101
previous_xpu_list_[i].c_str(), "", &options) != 0) {
102102
VLOG(0) << "HeterClient channel init fail. Try Again";
103-
auto ip_port = ::paddle::string::Split(previous_xpu_list_[i], ':');
103+
auto ip_port = paddle::string::Split(previous_xpu_list_[i], ':');
104104
std::string ip = ip_port[0];
105105
int port = std::stoi(ip_port[1]);
106106
std::string int_ip_port = GetIntTypeEndpoint(ip, port);
@@ -167,25 +167,25 @@ void HeterClient::SendAndRecvAsync(
167167
// int idx = 1; // for test
168168
// LOG(INFO) << "xpu_channels_ size: " << xpu_channels_.size();
169169
// channel = xpu_channels_[idx].get(); // 为了适配 send_and_recv op
170-
// ::paddle::distributed::PsService_Stub stub(channel);
170+
// paddle::distributed::PsService_Stub stub(channel);
171171
// stub.SendToSwitch(&closure->cntl, &request, &closure->response,
172172
// closure); fut.wait();
173173
VLOG(4) << "calling switch service done";
174174
return;
175175
}
176-
::paddle::distributed::PsService_Stub stub(channel);
176+
paddle::distributed::PsService_Stub stub(channel);
177177
stub.SendAndRecvVariable(
178178
&closure->cntl, &request, &closure->response, closure);
179179
}
180180

181181
std::future<int32_t> HeterClient::SendCmd(
182182
uint32_t table_id, int cmd_id, const std::vector<std::string>& params) {
183183
size_t request_call_num = xpu_channels_.size();
184-
::paddle::distributed::DownpourBrpcClosure* closure =
185-
new ::paddle::distributed::DownpourBrpcClosure(
184+
paddle::distributed::DownpourBrpcClosure* closure =
185+
new paddle::distributed::DownpourBrpcClosure(
186186
request_call_num, [request_call_num, cmd_id](void* done) {
187187
int ret = 0;
188-
auto* closure = (::paddle::distributed::DownpourBrpcClosure*)done;
188+
auto* closure = (paddle::distributed::DownpourBrpcClosure*)done;
189189
for (size_t i = 0; i < request_call_num; ++i) {
190190
if (closure->check_response(i, cmd_id) != 0) {
191191
ret = -1;
@@ -204,7 +204,7 @@ std::future<int32_t> HeterClient::SendCmd(
204204
for (const auto& param : params) {
205205
closure->request(i)->add_params(param);
206206
}
207-
::paddle::distributed::PsService_Stub rpc_stub(xpu_channels_[i].get());
207+
paddle::distributed::PsService_Stub rpc_stub(xpu_channels_[i].get());
208208
closure->cntl(i)->set_timeout_ms(
209209
FLAGS_pserver_timeout_ms); // cmd msg don't limit timeout for save/load
210210
rpc_stub.service(
@@ -270,7 +270,7 @@ int HeterClient::Send(const platform::DeviceContext& ctx,
270270
}
271271
brpc::Channel* channel = send_switch_channels_[0].get();
272272
// brpc::Channel* channel = xpu_channels_[0].get();
273-
::paddle::distributed::PsService_Stub stub(channel);
273+
paddle::distributed::PsService_Stub stub(channel);
274274
stub.SendToSwitch(&closure->cntl, &request, &closure->ps_response, closure);
275275

276276
VLOG(4) << "waiting SendToSwitch response result......";
@@ -317,7 +317,7 @@ int HeterClient::Send(int group_id,
317317
send_switch_channels_.push_back(xpu_channels_[0]);
318318
}
319319
brpc::Channel* channel = send_switch_channels_[0].get();
320-
::paddle::distributed::PsService_Stub stub(channel);
320+
paddle::distributed::PsService_Stub stub(channel);
321321
stub.SendToSwitch(&closure->cntl, &request, &closure->ps_response, closure);
322322
fut.wait();
323323
delete closure;
@@ -362,7 +362,7 @@ int HeterClient::Recv(const platform::DeviceContext& ctx,
362362
recv_switch_channels_.push_back(xpu_channels_[1]);
363363
}
364364
brpc::Channel* channel = recv_switch_channels_[0].get();
365-
::paddle::distributed::PsService_Stub stub(channel);
365+
paddle::distributed::PsService_Stub stub(channel);
366366
stub.RecvFromSwitch(&closure->cntl, &request, &closure->response, closure);
367367
fut.wait();
368368
VLOG(4) << "RecvFromSwitch done";
@@ -412,7 +412,7 @@ int HeterClient::Recv(int group_id,
412412
recv_switch_channels_.push_back(xpu_channels_[0]);
413413
}
414414
brpc::Channel* channel = recv_switch_channels_[0].get();
415-
::paddle::distributed::PsService_Stub stub(channel);
415+
paddle::distributed::PsService_Stub stub(channel);
416416
stub.RecvFromSwitch(&closure->cntl, &request, &closure->response, closure);
417417
fut.wait();
418418
VLOG(4) << "RecvFromSwitch done";

paddle/phi/core/flags.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,20 @@
5959
#else // PADDLE_WITH_GFLAGS
6060

6161
#define PHI_DECLARE_VARIABLE(type, shorttype, name) \
62-
namespace paddle { \
63-
namespace flags { \
62+
namespace paddle_flags { \
6463
extern PHI_IMPORT_FLAG type FLAGS_##name; \
6564
} \
66-
} \
67-
using paddle::flags::FLAGS_##name
65+
using paddle_flags::FLAGS_##name
6866

6967
#define PHI_DEFINE_VARIABLE(type, shorttype, name, default_value, description) \
70-
namespace paddle { \
71-
namespace flags { \
68+
namespace paddle_flags { \
7269
static const type FLAGS_##name##_default = default_value; \
7370
PHI_EXPORT_FLAG type FLAGS_##name = default_value; \
7471
/* Register FLAG */ \
7572
static ::paddle::flags::FlagRegisterer flag_##name##_registerer( \
7673
#name, description, __FILE__, &FLAGS_##name##_default, &FLAGS_##name); \
7774
} \
78-
} \
79-
using paddle::flags::FLAGS_##name
75+
using paddle_flags::FLAGS_##name
8076

8177
#endif
8278

paddle/utils/flags_native.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,10 @@ void PrintAllFlagHelp(bool to_file = false,
7474

7575
// ----------------------------DECLARE FLAGS----------------------------
7676
#define PD_DECLARE_VARIABLE(type, name) \
77-
namespace paddle { \
78-
namespace flags { \
77+
namespace paddle_flags { \
7978
extern type FLAGS_##name; \
8079
} \
81-
} \
82-
using paddle::flags::FLAGS_##name
80+
using paddle_flags::FLAGS_##name
8381

8482
#define PD_DECLARE_bool(name) PD_DECLARE_VARIABLE(bool, name)
8583
#define PD_DECLARE_int32(name) PD_DECLARE_VARIABLE(int32_t, name)
@@ -105,16 +103,14 @@ class FlagRegisterer {
105103

106104
// ----------------------------DEFINE FLAGS----------------------------
107105
#define PD_DEFINE_VARIABLE(type, name, default_value, description) \
108-
namespace paddle { \
109-
namespace flags { \
106+
namespace paddle_flags { \
110107
static const type FLAGS_##name##_default = default_value; \
111108
type FLAGS_##name = default_value; \
112109
/* Register FLAG */ \
113110
static ::paddle::flags::FlagRegisterer flag_##name##_registerer( \
114111
#name, description, __FILE__, &FLAGS_##name##_default, &FLAGS_##name); \
115112
} \
116-
} \
117-
using paddle::flags::FLAGS_##name
113+
using paddle_flags::FLAGS_##name
118114

119115
#define PD_DEFINE_bool(name, val, txt) PD_DEFINE_VARIABLE(bool, name, val, txt)
120116
#define PD_DEFINE_int32(name, val, txt) \

0 commit comments

Comments
 (0)