graph_gpu_ps_table.h 2.7 KB
Newer Older
S
seemingwang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// Copyright (c) 2022 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
16
#include <thrust/host_vector.h>
S
seemingwang 已提交
17
#include "heter_comm.h"
18 19
#include "paddle/fluid/distributed/ps/table/common_graph_table.h"
#include "paddle/fluid/framework/fleet/heter_ps/gpu_graph_node.h"
S
seemingwang 已提交
20 21 22 23 24 25 26 27 28 29
#include "paddle/fluid/platform/enforce.h"
#ifdef PADDLE_WITH_HETERPS
namespace paddle {
namespace framework {

class GpuPsGraphTable : public HeterComm<int64_t, int, int> {
 public:
  GpuPsGraphTable(std::shared_ptr<HeterPsResource> resource)
      : HeterComm<int64_t, int, int>(1, resource) {
    load_factor_ = 0.25;
30 31 32 33 34 35 36
    rw_lock.reset(new pthread_rwlock_t());
    cpu_table_status = -1;
  }
  ~GpuPsGraphTable() {
    if (cpu_table_status != -1) {
      end_graph_sampling();
    }
S
seemingwang 已提交
37 38 39 40 41 42 43
  }
  void build_graph_from_cpu(std::vector<GpuPsCommGraph> &cpu_node_list);
  NodeQueryResult *graph_node_sample(int gpu_id, int sample_size);
  NeighborSampleResult *graph_neighbor_sample(int gpu_id, int64_t *key,
                                              int sample_size, int len);
  NodeQueryResult *query_node_list(int gpu_id, int start, int query_size);
  void clear_graph_info();
44 45 46 47 48 49 50
  void move_neighbor_sample_result_to_source_gpu(
      int gpu_id, int gpu_num, int *h_left, int *h_right,
      int64_t *src_sample_res, thrust::host_vector<int> &total_sample_size);
  void move_neighbor_sample_size_to_source_gpu(int gpu_id, int gpu_num,
                                               int *h_left, int *h_right,
                                               int *actual_sample_size,
                                               int *total_sample_size);
51 52 53 54 55
  int init_cpu_table(const paddle::distributed::GraphParameter &graph);
  int load(const std::string &path, const std::string &param);
  virtual int32_t end_graph_sampling() {
    return cpu_graph_table->end_graph_sampling();
  }
S
seemingwang 已提交
56 57 58

 private:
  std::vector<GpuPsCommGraph> gpu_graph_list;
59 60 61 62 63
  std::shared_ptr<paddle::distributed::GraphTable> cpu_graph_table;
  std::shared_ptr<pthread_rwlock_t> rw_lock;
  mutable std::mutex mutex_;
  std::condition_variable cv_;
  int cpu_table_status;
S
seemingwang 已提交
64 65 66 67 68
};
}
};
#include "paddle/fluid/framework/fleet/heter_ps/graph_gpu_ps_table_inl.h"
#endif