Skip to content

Commit

Permalink
sync gpugraph to gpugraph_v2 (PaddlePaddle#86)
Browse files Browse the repository at this point in the history
* change load node and edge from local to cpu (PaddlePaddle#83)

* change load node and edge

* remove useless code

Co-authored-by: root <root@yq01-inf-hic-k8s-a100-ab2-0009.yq01.baidu.com>

* extract pull sparse as single stage(PaddlePaddle#85)

Co-authored-by: yangjunchao <yangjunchao@baidu.com>

Co-authored-by: miaoli06 <106585574+miaoli06@users.noreply.github.com>
Co-authored-by: root <root@yq01-inf-hic-k8s-a100-ab2-0009.yq01.baidu.com>
Co-authored-by: chao9527 <33347532+chao9527@users.noreply.github.com>
Co-authored-by: yangjunchao <yangjunchao@baidu.com>
  • Loading branch information
5 people authored Aug 18, 2022
1 parent 4782a8f commit a26eaa5
Show file tree
Hide file tree
Showing 7 changed files with 310 additions and 213 deletions.
45 changes: 38 additions & 7 deletions paddle/fluid/distributed/ps/table/common_graph_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1079,14 +1079,44 @@ std::string GraphTable::get_inverse_etype(std::string &etype) {
return res;
}

int32_t GraphTable::load_node_and_edge_file(std::string etype,
std::string ntype,
std::string epath,
std::string npath,
int32_t GraphTable::parse_type_to_typepath(std::string &type2files,
std::string graph_data_local_path,
std::vector<std::string> &res_type,
std::unordered_map<std::string, std::string> &res_type2path) {
auto type2files_split = paddle::string::split_string<std::string>(type2files, ",");
if (type2files_split.size() == 0) {
return -1;
}
for (auto one_type2file : type2files_split) {
auto one_type2file_split = paddle::string::split_string<std::string>(one_type2file, ":");
auto type = one_type2file_split[0];
auto type_dir = one_type2file_split[1];
res_type.push_back(type);
res_type2path[type] = graph_data_local_path + "/" + type_dir;
}
return 0;
}

int32_t GraphTable::load_node_and_edge_file(std::string etype2files,
std::string ntype2files,
std::string graph_data_local_path,
int part_num,
bool reverse) {
auto etypes = paddle::string::split_string<std::string>(etype, ",");
auto ntypes = paddle::string::split_string<std::string>(ntype, ",");
std::vector<std::string> etypes;
std::unordered_map<std::string, std::string> edge_to_edgedir;
int res = parse_type_to_typepath(etype2files, graph_data_local_path, etypes, edge_to_edgedir);
if (res != 0) {
VLOG(0) << "parse edge type and edgedir failed!";
return -1;
}
std::vector<std::string> ntypes;
std::unordered_map<std::string, std::string> node_to_nodedir;
res = parse_type_to_typepath(ntype2files, graph_data_local_path, ntypes, node_to_nodedir);
if (res != 0) {
VLOG(0) << "parse node type and nodedir failed!";
return -1;
}

VLOG(0) << "etypes size: " << etypes.size();
VLOG(0) << "whether reverse: " << reverse;
is_load_reverse_edge = reverse;
Expand All @@ -1098,7 +1128,7 @@ int32_t GraphTable::load_node_and_edge_file(std::string etype,
tasks.push_back(
_shards_task_pool[i % task_pool_size_]->enqueue([&, i, this]() -> int {
if (i < etypes.size()) {
std::string etype_path = epath + "/" + etypes[i];
std::string etype_path = edge_to_edgedir[etypes[i]];
auto etype_path_list = paddle::framework::localfs_list(etype_path);
std::string etype_path_str;
if (part_num > 0 && part_num < (int)etype_path_list.size()) {
Expand All @@ -1116,6 +1146,7 @@ int32_t GraphTable::load_node_and_edge_file(std::string etype,
this->load_edges(etype_path_str, true, r_etype);
}
} else {
std::string npath = node_to_nodedir[ntypes[0]];
auto npath_list = paddle::framework::localfs_list(npath);
std::string npath_str;
if (part_num > 0 && part_num < (int)npath_list.size()) {
Expand Down
12 changes: 8 additions & 4 deletions paddle/fluid/distributed/ps/table/common_graph_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -537,14 +537,18 @@ class GraphTable : public Table {
virtual int32_t Initialize(const GraphParameter &config);
int32_t Load(const std::string &path, const std::string &param);

int32_t load_node_and_edge_file(std::string etype,
std::string ntype,
std::string epath,
std::string npath,
int32_t load_node_and_edge_file(std::string etype2files,
std::string ntype2files,
std::string graph_data_local_path,
int part_num,
bool reverse);

std::string get_inverse_etype(std::string &etype);

int32_t parse_type_to_typepath(std::string &type2files,
std::string graph_data_local_path,
std::vector<std::string> &res_type,
std::unordered_map<std::string, std::string> &res_type2path);

int32_t load_edges(const std::string &path,
bool reverse,
Expand Down
13 changes: 6 additions & 7 deletions paddle/fluid/framework/fleet/heter_ps/graph_gpu_wrapper.cu
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,14 @@ void GraphGpuWrapper::load_node_file(std::string name, std::string filepath) {
}
}

void GraphGpuWrapper::load_node_and_edge(std::string etype,
std::string ntype,
std::string epath,
std::string npath,
void GraphGpuWrapper::load_node_and_edge(std::string etype2files,
std::string ntype2files,
std::string graph_data_local_path,
int part_num,
bool reverse) {
((GpuPsGraphTable *)graph_table)
->cpu_graph_table_->load_node_and_edge_file(
etype, ntype, epath, npath, part_num, reverse);
((GpuPsGraphTable *)graph_table)
->cpu_graph_table_->load_node_and_edge_file(
etype2files, ntype2files, graph_data_local_path, part_num, reverse);
}

void GraphGpuWrapper::add_table_feat_conf(std::string table_name,
Expand Down
7 changes: 3 additions & 4 deletions paddle/fluid/framework/fleet/heter_ps/graph_gpu_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ class GraphGpuWrapper {
int feat_shape);
void load_edge_file(std::string name, std::string filepath, bool reverse);
void load_node_file(std::string name, std::string filepath);
void load_node_and_edge(std::string etype,
std::string ntype,
std::string epath,
std::string npath,
void load_node_and_edge(std::string etype2files,
std::string ntype2files,
std::string graph_data_local_path,
int part_num,
bool reverse);
int32_t load_next_partition(int idx);
Expand Down
Loading

0 comments on commit a26eaa5

Please sign in to comment.