Unverified Commit 56962858 authored by Quan (Andy) Gan's avatar Quan (Andy) Gan Committed by GitHub
Browse files

[Performance] Make IdHashMap parallel (#4881)

* make IdHashMap parallel

* fix

* Update array_utils.h
parent 00c27cb2
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#define DGL_ARRAY_CPU_ARRAY_UTILS_H_ #define DGL_ARRAY_CPU_ARRAY_UTILS_H_
#include <dgl/aten/types.h> #include <dgl/aten/types.h>
#include <dgl/runtime/parallel_for.h>
#include <parallel_hashmap/phmap.h> #include <parallel_hashmap/phmap.h>
#include <unordered_map> #include <unordered_map>
...@@ -81,9 +82,13 @@ class IdHashMap { ...@@ -81,9 +82,13 @@ class IdHashMap {
const IdType* ids_data = static_cast<IdType*>(ids->data); const IdType* ids_data = static_cast<IdType*>(ids->data);
const int64_t len = ids->shape[0]; const int64_t len = ids->shape[0];
IdArray values = NewIdArray(len, ids->ctx, ids->dtype.bits); IdArray values = NewIdArray(len, ids->ctx, ids->dtype.bits);
IdType* values_data = static_cast<IdType*>(values->data); IdType* values_data = values.Ptr<IdType>();
for (int64_t i = 0; i < len; ++i) runtime::parallel_for(
0, len, 1000, [=] (size_t begin, size_t end) {
for (size_t i = begin; i < end; ++i) {
values_data[i] = Map(ids_data[i], default_val); values_data[i] = Map(ids_data[i], default_val);
}
});
return values; return values;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment