service.h 2.5 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
/* 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 "paddle/fluid/distributed/ps.pb.h"
23 24 25
#include "paddle/fluid/distributed/ps/service/ps_client.h"
#include "paddle/fluid/distributed/ps/service/sendrecv.pb.h"
#include "paddle/fluid/distributed/ps/service/server.h"
T
tangwei12 已提交
26 27 28 29

namespace paddle {
namespace distributed {

30 31 32 33 34 35
class PSClient;
class PSServer;
class PsRequestMessage;
class PsResponseMessage;
class PsService;

T
tangwei12 已提交
36 37 38 39
using paddle::distributed::PsRequestMessage;
using paddle::distributed::PsResponseMessage;
using paddle::distributed::PsService;

T
tangwei12 已提交
40 41 42 43 44
class PSCore {
 public:
  explicit PSCore() {}
  virtual ~PSCore() {}

Z
zhaocaibei123 已提交
45
  virtual int InitServer(
46 47
      const std::string& dist_desc,
      const std::vector<std::string>* host_sign_list, int node_num, int index,
T
tangwei12 已提交
48
      int trainers,
49
      const std::vector<framework::ProgramDesc>& server_sub_program = {});
Z
zhaocaibei123 已提交
50
  virtual int InitWorker(
T
tangwei12 已提交
51 52 53 54
      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);
Z
zhaocaibei123 已提交
55 56 57 58 59 60 61
  virtual uint64_t RunServer(const std::string& ip, uint32_t port);
  virtual int StopServer();
  virtual int FinalizeWorker();
  virtual std::vector<uint64_t> GetClientInfo();
  virtual int CreateClient2ClientConnection(int pserver_timeout_ms,
                                            int pserver_connect_timeout_ms,
                                            int max_retry);
T
tangwei12 已提交
62 63 64 65
  std::shared_ptr<paddle::distributed::PSServer>
      _server_ptr;  // pointer to server
  std::shared_ptr<paddle::distributed::PSClient>
      _worker_ptr;  // pointer to worker
Z
zhaocaibei123 已提交
66
  virtual paddle::distributed::PSParameter* GetParam();
T
tangwei12 已提交
67 68

 private:
Z
zhaocaibei123 已提交
69
  void InitGFlag(const std::string& gflags);
T
tangwei12 已提交
70 71 72 73 74 75
  paddle::distributed::PSParameter _ps_param;
  paddle::distributed::PaddlePSEnvironment _ps_env;
};

}  // namespace distributed
}  // namespace paddle