table.cc 4.0 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/table/table.h"
T
tangwei12 已提交
16

T
tangwei12 已提交
17 18 19
#include "glog/logging.h"
#include "paddle/fluid/distributed/common/registerer.h"

20
#include "paddle/fluid/distributed/ps/table/common_graph_table.h"
21 22
#include "paddle/fluid/distributed/ps/table/memory_dense_table.h"

23
#include "paddle/fluid/distributed/ps/table/ctr_accessor.h"
24
#include "paddle/fluid/distributed/ps/table/ctr_double_accessor.h"
25
#include "paddle/fluid/distributed/ps/table/ctr_dymf_accessor.h"
26
#include "paddle/fluid/distributed/ps/table/memory_sparse_geo_table.h"
27
#include "paddle/fluid/distributed/ps/table/memory_sparse_table.h"
28
#include "paddle/fluid/distributed/ps/table/sparse_accessor.h"
Z
zhaocaibei123 已提交
29
#include "paddle/fluid/distributed/ps/table/ssd_sparse_table.h"
30 31
#include "paddle/fluid/distributed/ps/table/tensor_accessor.h"
#include "paddle/fluid/distributed/ps/table/tensor_table.h"
T
tangwei12 已提交
32 33 34

namespace paddle {
namespace distributed {
S
seemingwang 已提交
35
REGISTER_PSCORE_CLASS(Table, GraphTable);
36
REGISTER_PSCORE_CLASS(Table, MemoryDenseTable);
T
tangwei12 已提交
37 38 39 40
REGISTER_PSCORE_CLASS(Table, BarrierTable);
REGISTER_PSCORE_CLASS(Table, TensorTable);
REGISTER_PSCORE_CLASS(Table, DenseTensorTable);
REGISTER_PSCORE_CLASS(Table, GlobalStepTable);
Z
zhaocaibei123 已提交
41
REGISTER_PSCORE_CLASS(Table, MemorySparseTable);
Z
zhaocaibei123 已提交
42
REGISTER_PSCORE_CLASS(Table, SSDSparseTable);
Z
zhaocaibei123 已提交
43
REGISTER_PSCORE_CLASS(Table, MemorySparseGeoTable);
44

T
tangwei12 已提交
45
REGISTER_PSCORE_CLASS(ValueAccessor, CommMergeAccessor);
Z
zhaocaibei123 已提交
46
REGISTER_PSCORE_CLASS(ValueAccessor, CtrCommonAccessor);
47
REGISTER_PSCORE_CLASS(ValueAccessor, CtrDoubleAccessor);
48
REGISTER_PSCORE_CLASS(ValueAccessor, CtrDymfAccessor);
49
REGISTER_PSCORE_CLASS(ValueAccessor, SparseAccessor);
Z
zhaocaibei123 已提交
50 51 52 53
REGISTER_PSCORE_CLASS(SparseValueSGDRule, StdAdaGradSGDRule);
REGISTER_PSCORE_CLASS(SparseValueSGDRule, SparseAdamSGDRule);
REGISTER_PSCORE_CLASS(SparseValueSGDRule, SparseNaiveSGDRule);
REGISTER_PSCORE_CLASS(SparseValueSGDRule, SparseAdaGradSGDRule);
T
tangwei12 已提交
54

Z
zhaocaibei123 已提交
55
int32_t TableManager::Initialize() {
T
tangwei12 已提交
56 57 58 59 60 61 62 63
  static bool initialized = false;
  if (initialized) {
    return 0;
  }
  initialized = true;
  return 0;
}

Z
zhaocaibei123 已提交
64
int32_t Table::Initialize(const TableParameter &config,
T
tangwei12 已提交
65 66
                          const FsClientParameter &fs_config) {
  _config = config;
Z
zhaocaibei123 已提交
67
  if (InitializeAccessor() != 0) {
T
tangwei12 已提交
68 69 70
    LOG(WARNING) << "Table accessor initialize failed";
    return -1;
  }
Z
zhaocaibei123 已提交
71 72 73 74 75

  if (_afs_client.initialize(fs_config) != 0) {
    LOG(WARNING) << "Table fs_client initialize failed";
    // return -1;
  }
Z
zhaocaibei123 已提交
76
  return Initialize();
T
tangwei12 已提交
77 78
}

Z
zhaocaibei123 已提交
79
int32_t Table::InitializeAccessor() {
T
tangwei12 已提交
80 81 82 83 84
  if (!_config.has_accessor() || !_config.accessor().has_accessor_class()) {
    LOG(ERROR) << "missing accessor config in table, table_id:"
               << _config.table_id();
    return -1;
  }
Z
zhaocaibei123 已提交
85 86 87

  LOG(INFO) << "accessor initializing: table_id: " << _config.table_id()
            << ", accessor_name: " << _config.accessor().accessor_class();
88 89 90 91
  auto *accessor =
      CREATE_PSCORE_CLASS(ValueAccessor, _config.accessor().accessor_class());

  if (accessor == NULL) {
T
tangwei12 已提交
92 93 94 95
    LOG(ERROR) << "accessor is unregisteg, table_id:" << _config.table_id()
               << ", accessor_name:" << _config.accessor().accessor_class();
    return -1;
  }
96
  if (accessor->Configure(_config.accessor()) || accessor->Initialize() != 0) {
T
tangwei12 已提交
97 98 99 100 101 102 103
    LOG(ERROR) << " accessor initialize failed, table_id:" << _config.table_id()
               << ", accessor_name:" << _config.accessor().accessor_class();
    return -1;
  }
  _value_accesor.reset(accessor);
  return 0;
}
S
seemingwang 已提交
104

T
tangwei12 已提交
105 106
}  // namespace distributed
}  // namespace paddle