service.h 2.4 KB
Newer Older
T
tangwei12 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/* Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */

#pragma once

#include <map>
#include <memory>
#include <string>
#include <vector>

#include <glog/logging.h>
#include "paddle/fluid/distributed/ps.pb.h"
#include "paddle/fluid/distributed/service/ps_client.h"
#include "paddle/fluid/distributed/service/sendrecv.pb.h"
#include "paddle/fluid/distributed/service/server.h"

namespace paddle {
namespace distributed {

T
tangwei12 已提交
31 32 33 34
using paddle::distributed::PsRequestMessage;
using paddle::distributed::PsResponseMessage;
using paddle::distributed::PsService;

T
tangwei12 已提交
35 36 37 38 39
class PSCore {
 public:
  explicit PSCore() {}
  virtual ~PSCore() {}

C
Chengmo 已提交
40 41 42
  virtual int init_server(
      const std::string& dist_desc,
      const std::vector<std::string>* host_sign_list, int node_num, int index,
43
      int trainers,
C
Chengmo 已提交
44
      const std::vector<framework::ProgramDesc>& server_sub_program = {});
T
tangwei12 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
  virtual int init_worker(
      const std::string& dist_desc,
      const std::map<uint64_t, std::vector<paddle::distributed::Region>>&
          regions,
      const std::vector<std::string>* host_sign_list, int node_num, int index);
  virtual uint64_t run_server(const std::string& ip, uint32_t port);
  virtual int stop_server();
  virtual int finalize_worker();
  virtual std::vector<uint64_t> get_client_info();
  virtual int create_client2client_connection(int pserver_timeout_ms,
                                              int pserver_connect_timeout_ms,
                                              int max_retry);
  std::shared_ptr<paddle::distributed::PSServer>
      _server_ptr;  // pointer to server
  std::shared_ptr<paddle::distributed::PSClient>
      _worker_ptr;  // pointer to worker
  virtual paddle::distributed::PSParameter* get_param();

 private:
  void init_gflag(const std::string& gflags);
  paddle::distributed::PSParameter _ps_param;
  paddle::distributed::PaddlePSEnvironment _ps_env;
};

}  // namespace distributed
}  // namespace paddle