diff --git a/paddle/fluid/operators/test_send_nccl_id.cc b/paddle/fluid/operators/test_send_nccl_id.cc index 2c3c5ea0a0ddeeb2a0c5265cebad7fe014e6f6dd..bbae1d54aa3524fd45cb8ab13c86df8d54b8e643 100644 --- a/paddle/fluid/operators/test_send_nccl_id.cc +++ b/paddle/fluid/operators/test_send_nccl_id.cc @@ -24,6 +24,7 @@ limitations under the License. */ #include "paddle/fluid/operators/listen_and_serv_op.h" #include "paddle/fluid/operators/math/math_function.h" #include "paddle/fluid/operators/math/selected_rows_functor.h" +#include "paddle/fluid/platform/nccl_helper.h" #include "paddle/fluid/string/printf.h" USE_NO_KERNEL_OP(listen_and_serv); @@ -36,7 +37,7 @@ namespace string = paddle::string; std::unique_ptr rpc_service; -void StartServer() { +void StartServer(std::atomic* initialized) { f::Scope scope; p::CPUPlace place; scope.Var(NCCL_ID_VARNAME); @@ -54,6 +55,7 @@ void StartServer() { std::thread server_thread( std::bind(&detail::AsyncGRPCServer::RunSyncUpdate, rpc_service.get())); + *initialized = true; rpc_service->SetCond(0); auto recv = rpc_service->Get(); LOG(INFO) << "got nccl id and stop server..."; @@ -62,9 +64,13 @@ void StartServer() { } TEST(SendNcclId, Normal) { - std::thread server_thread(StartServer); + std::atomic initialized{false}; + std::thread server_thread(StartServer, &initialized); + while (!initialized) { + } // wait server to start - rpc_service.WaitServerReady(); + // sleep(2); + rpc_service->WaitServerReady(); f::Scope scope; p::CPUPlace place;