Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix paddle namespace conflict when using paddle_flags #56913

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions paddle/fluid/distributed/ps/service/heter_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void HeterClient::CreateClient2XpuConnection() {
xpu_channels_[i].reset(new brpc::Channel());
if (xpu_channels_[i]->Init(xpu_list_[i].c_str(), "", &options) != 0) {
VLOG(0) << "HeterClient channel init fail. Try Again";
auto ip_port = ::paddle::string::Split(xpu_list_[i], ':');
auto ip_port = paddle::string::Split(xpu_list_[i], ':');
std::string ip = ip_port[0];
int port = std::stoi(ip_port[1]);
std::string int_ip_port = GetIntTypeEndpoint(ip, port);
Expand All @@ -100,7 +100,7 @@ void HeterClient::CreateClient2XpuConnection() {
if (previous_xpu_channels_[i]->Init(
previous_xpu_list_[i].c_str(), "", &options) != 0) {
VLOG(0) << "HeterClient channel init fail. Try Again";
auto ip_port = ::paddle::string::Split(previous_xpu_list_[i], ':');
auto ip_port = paddle::string::Split(previous_xpu_list_[i], ':');
std::string ip = ip_port[0];
int port = std::stoi(ip_port[1]);
std::string int_ip_port = GetIntTypeEndpoint(ip, port);
Expand Down Expand Up @@ -167,25 +167,25 @@ void HeterClient::SendAndRecvAsync(
// int idx = 1; // for test
// LOG(INFO) << "xpu_channels_ size: " << xpu_channels_.size();
// channel = xpu_channels_[idx].get(); // 为了适配 send_and_recv op
// ::paddle::distributed::PsService_Stub stub(channel);
// paddle::distributed::PsService_Stub stub(channel);
// stub.SendToSwitch(&closure->cntl, &request, &closure->response,
// closure); fut.wait();
VLOG(4) << "calling switch service done";
return;
}
::paddle::distributed::PsService_Stub stub(channel);
paddle::distributed::PsService_Stub stub(channel);
stub.SendAndRecvVariable(
&closure->cntl, &request, &closure->response, closure);
}

std::future<int32_t> HeterClient::SendCmd(
uint32_t table_id, int cmd_id, const std::vector<std::string>& params) {
size_t request_call_num = xpu_channels_.size();
::paddle::distributed::DownpourBrpcClosure* closure =
new ::paddle::distributed::DownpourBrpcClosure(
paddle::distributed::DownpourBrpcClosure* closure =
new paddle::distributed::DownpourBrpcClosure(
request_call_num, [request_call_num, cmd_id](void* done) {
int ret = 0;
auto* closure = (::paddle::distributed::DownpourBrpcClosure*)done;
auto* closure = (paddle::distributed::DownpourBrpcClosure*)done;
for (size_t i = 0; i < request_call_num; ++i) {
if (closure->check_response(i, cmd_id) != 0) {
ret = -1;
Expand All @@ -204,7 +204,7 @@ std::future<int32_t> HeterClient::SendCmd(
for (const auto& param : params) {
closure->request(i)->add_params(param);
}
::paddle::distributed::PsService_Stub rpc_stub(xpu_channels_[i].get());
paddle::distributed::PsService_Stub rpc_stub(xpu_channels_[i].get());
closure->cntl(i)->set_timeout_ms(
FLAGS_pserver_timeout_ms); // cmd msg don't limit timeout for save/load
rpc_stub.service(
Expand Down Expand Up @@ -270,7 +270,7 @@ int HeterClient::Send(const platform::DeviceContext& ctx,
}
brpc::Channel* channel = send_switch_channels_[0].get();
// brpc::Channel* channel = xpu_channels_[0].get();
::paddle::distributed::PsService_Stub stub(channel);
paddle::distributed::PsService_Stub stub(channel);
stub.SendToSwitch(&closure->cntl, &request, &closure->ps_response, closure);

VLOG(4) << "waiting SendToSwitch response result......";
Expand Down Expand Up @@ -317,7 +317,7 @@ int HeterClient::Send(int group_id,
send_switch_channels_.push_back(xpu_channels_[0]);
}
brpc::Channel* channel = send_switch_channels_[0].get();
::paddle::distributed::PsService_Stub stub(channel);
paddle::distributed::PsService_Stub stub(channel);
stub.SendToSwitch(&closure->cntl, &request, &closure->ps_response, closure);
fut.wait();
delete closure;
Expand Down Expand Up @@ -362,7 +362,7 @@ int HeterClient::Recv(const platform::DeviceContext& ctx,
recv_switch_channels_.push_back(xpu_channels_[1]);
}
brpc::Channel* channel = recv_switch_channels_[0].get();
::paddle::distributed::PsService_Stub stub(channel);
paddle::distributed::PsService_Stub stub(channel);
stub.RecvFromSwitch(&closure->cntl, &request, &closure->response, closure);
fut.wait();
VLOG(4) << "RecvFromSwitch done";
Expand Down Expand Up @@ -412,7 +412,7 @@ int HeterClient::Recv(int group_id,
recv_switch_channels_.push_back(xpu_channels_[0]);
}
brpc::Channel* channel = recv_switch_channels_[0].get();
::paddle::distributed::PsService_Stub stub(channel);
paddle::distributed::PsService_Stub stub(channel);
stub.RecvFromSwitch(&closure->cntl, &request, &closure->response, closure);
fut.wait();
VLOG(4) << "RecvFromSwitch done";
Expand Down
12 changes: 4 additions & 8 deletions paddle/phi/core/flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,20 @@
#else // PADDLE_WITH_GFLAGS

#define PHI_DECLARE_VARIABLE(type, shorttype, name) \
namespace paddle { \
namespace flags { \
namespace paddle_flags { \
extern PHI_IMPORT_FLAG type FLAGS_##name; \
} \
} \
using paddle::flags::FLAGS_##name
using paddle_flags::FLAGS_##name

#define PHI_DEFINE_VARIABLE(type, shorttype, name, default_value, description) \
namespace paddle { \
namespace flags { \
namespace paddle_flags { \
static const type FLAGS_##name##_default = default_value; \
PHI_EXPORT_FLAG type FLAGS_##name = default_value; \
/* Register FLAG */ \
static ::paddle::flags::FlagRegisterer flag_##name##_registerer( \
#name, description, __FILE__, &FLAGS_##name##_default, &FLAGS_##name); \
} \
} \
using paddle::flags::FLAGS_##name
using paddle_flags::FLAGS_##name

#endif

Expand Down
12 changes: 4 additions & 8 deletions paddle/utils/flags_native.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,10 @@ void PrintAllFlagHelp(bool to_file = false,

// ----------------------------DECLARE FLAGS----------------------------
#define PD_DECLARE_VARIABLE(type, name) \
namespace paddle { \
namespace flags { \
namespace paddle_flags { \
extern type FLAGS_##name; \
} \
} \
using paddle::flags::FLAGS_##name
using paddle_flags::FLAGS_##name

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

// ----------------------------DEFINE FLAGS----------------------------
#define PD_DEFINE_VARIABLE(type, name, default_value, description) \
namespace paddle { \
namespace flags { \
namespace paddle_flags { \
static const type FLAGS_##name##_default = default_value; \
type FLAGS_##name = default_value; \
/* Register FLAG */ \
static ::paddle::flags::FlagRegisterer flag_##name##_registerer( \
#name, description, __FILE__, &FLAGS_##name##_default, &FLAGS_##name); \
} \
} \
using paddle::flags::FLAGS_##name
using paddle_flags::FLAGS_##name

#define PD_DEFINE_bool(name, val, txt) PD_DEFINE_VARIABLE(bool, name, val, txt)
#define PD_DEFINE_int32(name, val, txt) \
Expand Down