ps_client.cc 3.2 KB
Newer Older
T
tangwei12 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// 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.

15
#include "paddle/fluid/distributed/ps/service/ps_client.h"
T
tangwei12 已提交
16
#include "glog/logging.h"
17 18 19 20
#include "paddle/fluid/distributed/ps/service/brpc_ps_client.h"
#include "paddle/fluid/distributed/ps/service/graph_brpc_client.h"
#include "paddle/fluid/distributed/ps/service/ps_local_client.h"
#include "paddle/fluid/distributed/ps/table/table.h"
T
tangwei12 已提交
21 22 23

namespace paddle {
namespace distributed {
T
tangwei12 已提交
24
REGISTER_PSCORE_CLASS(PSClient, BrpcPsClient);
T
Thunderbrook 已提交
25
REGISTER_PSCORE_CLASS(PSClient, PsLocalClient);
S
seemingwang 已提交
26
REGISTER_PSCORE_CLASS(PSClient, GraphBrpcClient);
T
Thunderbrook 已提交
27

T
tangwei12 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
int32_t PSClient::configure(
    const PSParameter &config,
    const std::map<uint64_t, std::vector<paddle::distributed::Region>> &regions,
    PSEnvironment &env, size_t client_id) {
  _env = &env;
  _config = config;
  _dense_pull_regions = regions;
  _client_id = client_id;
  _config.mutable_worker_param()
      ->mutable_downpour_worker_param()
      ->mutable_downpour_table_param()
      ->CopyFrom(_config.server_param()
                     .downpour_server_param()
                     .downpour_table_param());

  const auto &work_param = _config.worker_param().downpour_worker_param();

  for (size_t i = 0; i < work_param.downpour_table_param_size(); ++i) {
T
tangwei12 已提交
46
    auto *accessor = CREATE_PSCORE_CLASS(
T
tangwei12 已提交
47 48
        ValueAccessor,
        work_param.downpour_table_param(i).accessor().accessor_class());
49 50
    accessor->Configure(work_param.downpour_table_param(i).accessor());
    accessor->Initialize();
T
tangwei12 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
    _table_accessors[work_param.downpour_table_param(i).table_id()].reset(
        accessor);
  }
  return initialize();
}

PSClient *PSClientFactory::create(const PSParameter &ps_config) {
  const auto &config = ps_config.server_param();
  if (!config.has_downpour_server_param()) {
    LOG(ERROR) << "miss downpour_server_param in ServerParameter";
    return NULL;
  }

  if (!config.downpour_server_param().has_service_param()) {
    LOG(ERROR) << "miss service_param in ServerParameter.downpour_server_param";
    return NULL;
  }

  if (!config.downpour_server_param().service_param().has_client_class()) {
    LOG(ERROR) << "miss client_class in "
                  "ServerParameter.downpour_server_param.service_param";
    return NULL;
  }

  const auto &service_param = config.downpour_server_param().service_param();
T
tangwei12 已提交
76 77
  PSClient *client =
      CREATE_PSCORE_CLASS(PSClient, service_param.client_class());
T
tangwei12 已提交
78 79 80 81 82 83 84
  if (client == NULL) {
    LOG(ERROR) << "client is not registered, server_name:"
               << service_param.client_class();
    return NULL;
  }

  TableManager::instance().initialize();
T
tangwei12 已提交
85
  VLOG(3) << "Create PSClient[" << service_param.client_class() << "] success";
T
tangwei12 已提交
86 87 88
  return client;
}
}  // namespace distributed
T
Thunderbrook 已提交
89
}  // namespace paddle