|
|
|
@ -116,6 +116,7 @@ void AddOp(const std::string &type, const f::VariableNameMap &inputs,
|
|
|
|
|
void StartServerNet(bool is_sparse, std::atomic<bool> *initialized) {
|
|
|
|
|
f::Scope scope;
|
|
|
|
|
p::CPUPlace place;
|
|
|
|
|
VLOG(4) << "before init tensor";
|
|
|
|
|
if (is_sparse) {
|
|
|
|
|
InitSelectedRowsInScope(place, &scope);
|
|
|
|
|
} else {
|
|
|
|
@ -137,6 +138,7 @@ void StartServerNet(bool is_sparse, std::atomic<bool> *initialized) {
|
|
|
|
|
attrs.insert({"PrefetchBlock", prefetch_block});
|
|
|
|
|
attrs.insert({"grad_to_block_id", std::vector<std::string>({""})});
|
|
|
|
|
attrs.insert({"sync_mode", true});
|
|
|
|
|
VLOG(4) << "before init op";
|
|
|
|
|
listen_and_serv_op =
|
|
|
|
|
f::OpRegistry::CreateOp("listen_and_serv", {{"X", {"x1"}}}, {}, attrs);
|
|
|
|
|
*initialized = true;
|
|
|
|
@ -149,7 +151,9 @@ TEST(SendRecvOp, CPUDense) {
|
|
|
|
|
std::thread server_thread(StartServerNet, false, &initialized);
|
|
|
|
|
while (!initialized) {
|
|
|
|
|
}
|
|
|
|
|
sleep(5); // wait server to start
|
|
|
|
|
static_cast<paddle::operators::ListenAndServOp *>(listen_and_serv_op.get())
|
|
|
|
|
->WaitServerReady();
|
|
|
|
|
|
|
|
|
|
// local net
|
|
|
|
|
f::Scope scope;
|
|
|
|
|
p::CPUPlace place;
|
|
|
|
@ -185,6 +189,7 @@ TEST(SendRecvOp, CPUDense) {
|
|
|
|
|
listen_and_serv_op->Stop();
|
|
|
|
|
server_thread.join();
|
|
|
|
|
listen_and_serv_op.reset(nullptr);
|
|
|
|
|
paddle::operators::ListenAndServOp::ResetPort();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(SendRecvOp, CPUSparse) {
|
|
|
|
@ -193,7 +198,12 @@ TEST(SendRecvOp, CPUSparse) {
|
|
|
|
|
std::thread server_thread(StartServerNet, true, &initialized);
|
|
|
|
|
while (!initialized) {
|
|
|
|
|
}
|
|
|
|
|
sleep(5); // wait server to start
|
|
|
|
|
auto *listen_and_serv_op_ptr =
|
|
|
|
|
static_cast<paddle::operators::ListenAndServOp *>(
|
|
|
|
|
listen_and_serv_op.get());
|
|
|
|
|
ASSERT_TRUE(listen_and_serv_op_ptr != nullptr);
|
|
|
|
|
listen_and_serv_op_ptr->WaitServerReady();
|
|
|
|
|
|
|
|
|
|
// local net
|
|
|
|
|
f::Scope scope;
|
|
|
|
|
p::CPUPlace place;
|
|
|
|
@ -201,10 +211,6 @@ TEST(SendRecvOp, CPUSparse) {
|
|
|
|
|
InitSelectedRowsInScope(place, &scope);
|
|
|
|
|
scope.Var("RPC_CLIENT_VAR");
|
|
|
|
|
f::AttributeMap attrs;
|
|
|
|
|
auto *listen_and_serv_op_ptr =
|
|
|
|
|
static_cast<paddle::operators::ListenAndServOp *>(
|
|
|
|
|
listen_and_serv_op.get());
|
|
|
|
|
ASSERT_TRUE(listen_and_serv_op_ptr != nullptr);
|
|
|
|
|
selected_port = listen_and_serv_op_ptr->GetSelectedPort();
|
|
|
|
|
std::string endpoint = paddle::string::Sprintf("127.0.0.1:%d", selected_port);
|
|
|
|
|
attrs.insert({"endpoints", std::vector<std::string>({endpoint})});
|
|
|
|
@ -236,4 +242,5 @@ TEST(SendRecvOp, CPUSparse) {
|
|
|
|
|
listen_and_serv_op->Stop();
|
|
|
|
|
server_thread.join();
|
|
|
|
|
listen_and_serv_op.reset();
|
|
|
|
|
paddle::operators::ListenAndServOp::ResetPort();
|
|
|
|
|
}
|
|
|
|
|