tensor_accessor.cc 3.5 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/tensor_accessor.h"
T
tangwei12 已提交
16 17 18 19 20
#include "Eigen/Dense"

namespace paddle {
namespace distributed {

21
int CommMergeAccessor::Initialize() { return 0; }
T
tangwei12 已提交
22

23
void CommMergeAccessor::SetTableInfo(AccessorInfo &info) {
24 25 26 27
  info.select_dim = SelectDim();
  info.select_size = SelectSize();
  info.update_dim = UpdateDim();
  info.update_size = UpdateSize();
Y
yaoxuefeng 已提交
28 29 30
  info.fea_dim = fea_dim();
}

31 32 33
size_t CommMergeAccessor::GetTableInfo(InfoKey key) {
  switch (key) {
    case SELECT_DIM:
34
      return SelectDim();
35
    case SELECT_SIZE:
36
      return SelectSize();
37
    case UPDATE_DIM:
38
      return UpdateDim();
39
    case UPDATE_SIZE:
40
      return UpdateSize();
41 42
    case FEA_DIM:
      return fea_dim();
43 44
    default:
      return 0;
45 46 47 48
  }
  return 0;
}

T
tangwei12 已提交
49
// pull value 维度
50
size_t CommMergeAccessor::SelectDim() { return _config.embedx_dim(); }
T
tangwei12 已提交
51 52

// pull value 各个维度的size
53
size_t CommMergeAccessor::SelectDimSize(size_t dim) { return sizeof(float); }
T
tangwei12 已提交
54 55

// pull value 各维度相加总size
56
size_t CommMergeAccessor::SelectSize() { return SelectDim() * sizeof(float); }
T
tangwei12 已提交
57 58

// push value 维度
59
size_t CommMergeAccessor::UpdateDim() { return _config.embedx_dim(); }
T
tangwei12 已提交
60 61

// push value 各个维度的size
62
size_t CommMergeAccessor::UpdateDimSize(size_t dim) { return sizeof(float); }
T
tangwei12 已提交
63 64

// push value 各维度相加总size
65
size_t CommMergeAccessor::UpdateSize() { return UpdateDim() * sizeof(float); }
T
tangwei12 已提交
66 67

// 判断该value 是否进行shrink
68
bool CommMergeAccessor::Shrink(float * /*value*/) { return false; }
T
tangwei12 已提交
69 70 71

// 判断该value 是否在save阶段dump,
// param作为参数用于标识save阶段,如downpour的xbox与batch_model
72
bool CommMergeAccessor::Save(float * /*value*/, int /*param*/) { return true; }
T
tangwei12 已提交
73 74

// keys不存在时,为values生成随机值
75
int32_t CommMergeAccessor::Create(float **value, size_t num) { return 0; }
T
tangwei12 已提交
76 77

// 从values中选取到select_values中
78
int32_t CommMergeAccessor::Select(float **select_values, const float **values,
T
tangwei12 已提交
79 80 81 82 83
                                  size_t num) {
  return 0;
}

// 将update_values聚合到一起
84
int32_t CommMergeAccessor::Merge(float **update_values,
T
tangwei12 已提交
85 86 87 88 89 90 91 92 93 94 95
                                 const float **other_update_values,
                                 size_t num) {
  Eigen::Map<Eigen::MatrixXf> u_mat(update_values[0], 1, num);
  Eigen::Map<const Eigen::MatrixXf> o_mat(other_update_values[0], 1, num);
  u_mat += o_mat;
  return 0;
}

// 将update_values聚合到一起,通过it.next判定是否进入下一个key
//  int32_t merge(float** update_values, iterator it);
// 将update_values更新应用到values中
96
int32_t CommMergeAccessor::Update(float **values, const float **update_values,
T
tangwei12 已提交
97 98 99 100
                                  size_t num) {
  return 0;
}

101 102
int CommMergeAccessor::SetWeight(float **values, const float **update_values,
                                 size_t num) {
T
tangwei12 已提交
103 104 105 106 107
  return 0;
}

}  // namespace distributed
}  // namespace paddle