tensor_accessor.h 2.4 KB
Newer Older
T
tangwei12 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// 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 <stdint.h>
#include <stdio.h>
#include <string>
#include <vector>
20

T
tangwei12 已提交
21 22
#include "paddle/fluid/distributed/common/registerer.h"
#include "paddle/fluid/distributed/ps.pb.h"
23
#include "paddle/fluid/distributed/ps/table/accessor.h"
T
tangwei12 已提交
24 25 26 27 28 29 30 31

namespace paddle {
namespace distributed {

class CommMergeAccessor : public ValueAccessor {
 public:
  CommMergeAccessor() {}
  virtual ~CommMergeAccessor() {}
32
  virtual int Initialize();
33 34
  // 初始化AccessorInfo
  virtual void InitAccessorInfo();
T
tangwei12 已提交
35
  // 判断该value是否进行shrink
36
  virtual bool Shrink(float * /*value*/);
T
tangwei12 已提交
37 38
  // 判断该value是否在save阶段dump,
  // param作为参数用于标识save阶段,如downpour的xbox与batch_model
39
  virtual bool Save(float * /*value*/, int /*param*/);
T
tangwei12 已提交
40 41

  // keys不存在时,为values生成随机值
42
  virtual int32_t Create(float **value, size_t num);
T
tangwei12 已提交
43
  // 从values中选取到select_values中
44
  virtual int32_t Select(float **select_values, const float **values,
T
tangwei12 已提交
45 46
                         size_t num);
  // 将update_values聚合到一起
47
  virtual int32_t Merge(float **update_values,
T
tangwei12 已提交
48 49
                        const float **other_update_values, size_t num);
  // 将update_values聚合到一起,通过it.next判定是否进入下一个key
50
  // virtual int32_t Merge(float** update_values, iterator it);
T
tangwei12 已提交
51
  // 将update_values更新应用到values中
52
  virtual int32_t Update(float **values, const float **update_values,
T
tangwei12 已提交
53 54
                         size_t num);

55 56 57
  virtual int SetWeight(float **values, const float **update_values,
                        size_t num);
  virtual std::string ParseToString(const float *value, int param) {
T
tangwei12 已提交
58 59
    return "";
  }
60
  virtual int ParseFromString(const std::string &str, float *v) { return 0; }
T
tangwei12 已提交
61 62 63
};
}  // namespace distributed
}  // namespace paddle