diff --git a/paddle/fluid/operators/async_listen_and_serv_op.cc b/paddle/fluid/operators/async_listen_and_serv_op.cc index bdb20240f69449d44c2ec89d2f3cb0d206f0b9b2..14d9121eff06250c5f619fd0ab136c9f35f125ad 100644 --- a/paddle/fluid/operators/async_listen_and_serv_op.cc +++ b/paddle/fluid/operators/async_listen_and_serv_op.cc @@ -24,6 +24,24 @@ limitations under the License. */ namespace paddle { namespace operators { +static void split(const std::string &str, char sep, + std::vector *pieces) { + pieces->clear(); + if (str.empty()) { + return; + } + size_t pos = 0; + size_t next = str.find(sep, pos); + while (next != std::string::npos) { + pieces->push_back(str.substr(pos, next - pos)); + pos = next + 1; + next = str.find(sep, pos); + } + if (!str.substr(pos).empty()) { + pieces->push_back(str.substr(pos)); + } +} + void RunServer(std::shared_ptr service) { service->RunAsyncUpdate(); VLOG(4) << "RunServer thread end"; @@ -74,7 +92,7 @@ void AsyncListenAndServOp::RunImpl(const framework::Scope &scope, auto grad_map_str = Attr>("grad_map"); for (auto &grad_and_id : grad_map_str) { std::vector pieces; - paddle::str::split(grad_and_id, ' ', &pieces); + split(grad_and_id, ' ', &pieces); PADDLE_ENFORCE_EQ(pieces.size(), 2); PADDLE_ENFORCE_EQ(grad_to_id.count(pieces[0]), 0); int block_id = std::stoi(pieces[1]);