sparse_geo_table.h 2.2 KB
Newer Older
T
tangwei12 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// 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 <assert.h>
#include <pthread.h>
19
#include <stdint.h>
T
tangwei12 已提交
20 21 22 23 24
#include <memory>
#include <mutex>  // NOLINT
#include <string>
#include <utility>
#include <vector>
25

T
tangwei12 已提交
26
#include "Eigen/Dense"
27 28 29 30 31 32 33
#include "paddle/fluid/distributed/ps/table/accessor.h"
#include "paddle/fluid/distributed/ps/table/common_sparse_table.h"
#include "paddle/fluid/distributed/ps/table/common_table.h"
#include "paddle/fluid/distributed/ps/table/depends/geo_recorder.h"
#include "paddle/fluid/distributed/ps/table/depends/initializers.h"
#include "paddle/fluid/distributed/ps/table/depends/large_scale_kv.h"
#include "paddle/fluid/distributed/ps/table/depends/sparse.h"
T
tangwei12 已提交
34
#include "paddle/fluid/string/string_helper.h"
35
#include "paddle/pten/core/utils/rw_lock.h"
T
tangwei12 已提交
36 37 38 39

namespace paddle {
namespace distributed {

40 41
class GeoRecorder;

T
tangwei12 已提交
42 43 44 45 46
class SparseGeoTable : public CommonSparseTable {
 public:
  explicit SparseGeoTable() : CommonSparseTable() { geo_recorder = nullptr; }
  virtual ~SparseGeoTable() {}

47 48
  virtual int32_t initialize_value();

T
tangwei12 已提交
49 50 51
  int32_t pull_geo_param(const uint32_t trainer_id, std::vector<float>* values,
                         std::vector<uint64_t>* keys);

52 53
  int32_t push_sparse(const uint64_t* keys, const float* values,
                      size_t num) override;
T
tangwei12 已提交
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68

  virtual int32_t initialize_recorder() {
    if (!geo_recorder) {
      auto trainers = _config.common().trainer_num();
      geo_recorder = std::make_shared<GeoRecorder>(trainers);
    }
    return 0;
  }

 private:
  std::shared_ptr<GeoRecorder> geo_recorder;
};

}  // namespace distributed
}  // namespace paddle