ParameterServerController.h 2.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.

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 "ParameterServer2.h"
#include "ParameterServerConfig.pb.h"
#include "RDMANetwork.h"
#include "paddle/utils/StringUtil.h"

namespace paddle {

24 25 26 27 28 29
/**
 * @brief ParameterServerController is used for create, init and manage multi
 * parameter server instances. The num of the instances is decided by port
 * num(the ports number for parameter send) and network devices configured
 * by gflags or proto.
 */
30
class ParameterServerController final {
31
public:
32
  DISABLE_COPY(ParameterServerController);
Q
qiaolongfei 已提交
33 34

  /**
35
   * @brief Ctor, Create a ParameterServerController from ParameterServerConfig.
Q
qiaolongfei 已提交
36
   */
37
  explicit ParameterServerController(const ParameterServerConfig& config);
Q
qiaolongfei 已提交
38 39 40 41

  /**
   * @brief Dtor.
   */
42
  ~ParameterServerController();
Q
qiaolongfei 已提交
43 44

  /**
45
   * @brief create ParameterServerController from gflags, this is used for
Q
qiaolongfei 已提交
46 47
   * compatibility with the old usage of configuration by gflags.
   */
48
  static ParameterServerController* createFromGflags();
Q
qiaolongfei 已提交
49 50

  /**
51
   * @brief create ParameterServerController with ParameterServerConfig, remove
52 53 54
   * gflags from ParameterServer. Init all ParameterServer2 instances according
   * to
   * the config.
Q
qiaolongfei 已提交
55
   */
56
  static ParameterServerController* create(const ParameterServerConfig& config);
Q
qiaolongfei 已提交
57 58

  /**
59 60
   * @brief start all ParameterServer2 instances in this
   * ParameterServerController.
Q
qiaolongfei 已提交
61
   */
62
  void start();
Q
qiaolongfei 已提交
63 64

  /**
65
   * @brief join and wait for all ParameterServer2 instances thread in this
66
   * ParameterServerController.
Q
qiaolongfei 已提交
67
   */
68
  void wait();
69 70

private:
71
  std::vector<std::unique_ptr<ParameterServer2>> parameterServers_;
72 73 74
};

}  // namespace paddle