提交 95f20b94 编写于 作者: Q qiaolongfei

add comment and refine code

上级 f9a65b08
...@@ -19,7 +19,7 @@ source "$bin_dir/env.sh" ...@@ -19,7 +19,7 @@ source "$bin_dir/env.sh"
paddle pserver \ paddle pserver \
--nics=`get_nics` \ --nics=`get_nics` \
--port=7164 \ --port=7164 \
--ports_num=2 \ --ports_num=1 \
--ports_num_for_sparse=1 \ --ports_num_for_sparse=1 \
--num_gradient_servers=1 \ --num_gradient_servers=1 \
--comment="paddle_pserver" \ --comment="paddle_pserver" \
......
...@@ -16,30 +16,11 @@ limitations under the License. */ ...@@ -16,30 +16,11 @@ limitations under the License. */
namespace paddle { namespace paddle {
ParameterServerConfig* PServerUtil::initConfig() {
ParameterServerConfig* config = new ParameterServerConfig();
config->set_nics(FLAGS_nics);
config->set_port(FLAGS_port);
config->set_ports_num(FLAGS_ports_num);
config->set_rdma_tcp(FLAGS_rdma_tcp);
return config;
}
PServerUtil* PServerUtil::create() {
auto& pServerConfig = *paddle::PServerUtil::initConfig();
return PServerUtil::create(pServerConfig);
}
PServerUtil* PServerUtil::create(const ParameterServerConfig& config) {
return new PServerUtil(config);
}
PServerUtil::PServerUtil(const ParameterServerConfig& config) { PServerUtil::PServerUtil(const ParameterServerConfig& config) {
// round robin to load balance RDMA server ENGINE // round robin to load balance RDMA server ENGINE
std::vector<std::string> devices; std::vector<std::string> devices;
int rdmaCpu = 0; int rdmaCpu = 0;
int onlineCpus = rdma::numCpus(); int onlineCpus = rdma::numCpus();
;
int numPorts = config.ports_num() + config.ports_num_for_sparse(); int numPorts = config.ports_num() + config.ports_num_for_sparse();
if (FLAGS_nics.empty()) { if (FLAGS_nics.empty()) {
...@@ -78,6 +59,24 @@ PServerUtil::PServerUtil(const ParameterServerConfig& config) { ...@@ -78,6 +59,24 @@ PServerUtil::PServerUtil(const ParameterServerConfig& config) {
PServerUtil::~PServerUtil() { this->join(); } PServerUtil::~PServerUtil() { this->join(); }
ParameterServerConfig* PServerUtil::initConfig() {
ParameterServerConfig* config = new ParameterServerConfig();
config->set_nics(FLAGS_nics);
config->set_port(FLAGS_port);
config->set_ports_num(FLAGS_ports_num);
config->set_rdma_tcp(FLAGS_rdma_tcp);
return config;
}
PServerUtil* PServerUtil::createWithGflags() {
auto& pServerConfig = *paddle::PServerUtil::initConfig();
return create(pServerConfig);
}
PServerUtil* PServerUtil::create(const ParameterServerConfig& config) {
return new PServerUtil(config);
}
void PServerUtil::start() { void PServerUtil::start() {
LOG(INFO) << "pserver sizes : " << pservers_.size(); LOG(INFO) << "pserver sizes : " << pservers_.size();
int i = 0; int i = 0;
......
...@@ -24,16 +24,47 @@ namespace paddle { ...@@ -24,16 +24,47 @@ namespace paddle {
class PServerUtil { class PServerUtil {
public: public:
DISABLE_COPY(PServerUtil); DISABLE_COPY(PServerUtil);
static PServerUtil* create();
static PServerUtil* create(const ParameterServerConfig& config); /**
* @brief Ctor, Create a PServerUtil from ParameterServerConfig.
*/
explicit PServerUtil(const ParameterServerConfig& config); explicit PServerUtil(const ParameterServerConfig& config);
/**
* @brief Dtor.
*/
~PServerUtil(); ~PServerUtil();
static ParameterServerConfig* initConfig();
/**
* @brief create PServerUtil from gflags, this is used for
* compatibility with the old usage of configuration by gflags.
*/
static PServerUtil* createWithGflags();
/**
* @brief create PServerUtil with ParameterServerConfig, remove gflags
* from ParameterServer. Init all pservers thread according to the config.
*/
static PServerUtil* create(const ParameterServerConfig& config);
/**
* @brief start all pserver thread in this PServerUtil.
*/
void start(); void start();
/**
* @brief join and wait for all pserver thread in this PServerUtil.
*/
void join(); void join();
private: private:
std::vector<std::shared_ptr<ParameterServer2>> pservers_; std::vector<std::shared_ptr<ParameterServer2>> pservers_;
/**
* @brief create ParameterServerConfig from gflags, this is used for
* compatibility with the old usage of configuration by gflags.
*/
static ParameterServerConfig* initConfig();
}; };
} // namespace paddle } // namespace paddle
...@@ -21,7 +21,8 @@ using namespace paddle; // NOLINT ...@@ -21,7 +21,8 @@ using namespace paddle; // NOLINT
int main(int argc, char** argv) { int main(int argc, char** argv) {
initMain(argc, argv); initMain(argc, argv);
std::unique_ptr<PServerUtil> pServerPtr(paddle::PServerUtil::create()); std::unique_ptr<PServerUtil> pServerPtr(
paddle::PServerUtil::createWithGflags());
pServerPtr->start(); pServerPtr->start();
pServerPtr->join(); pServerPtr->join();
......
...@@ -38,7 +38,7 @@ int main(int argc, char** argv) { ...@@ -38,7 +38,7 @@ int main(int argc, char** argv) {
initPython(argc, argv); initPython(argc, argv);
if (FLAGS_start_pserver) { if (FLAGS_start_pserver) {
PServerUtil* pServerUtil = paddle::PServerUtil::create(); PServerUtil* pServerUtil = paddle::PServerUtil::createWithGflags();
pServerUtil->start(); pServerUtil->start();
} }
Trainer trainer; Trainer trainer;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册