Skip to content

Commit cb4604a

Browse files
authored
[Performance] Remove phmap dependency. (#7658)
1 parent 55cf23f commit cb4604a

File tree

7 files changed

+26
-26
lines changed

7 files changed

+26
-26
lines changed

.gitmodules

-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
[submodule "third_party/METIS"]
1111
path = third_party/METIS
1212
url = https://github.com/KarypisLab/METIS.git
13-
[submodule "third_party/phmap"]
14-
path = third_party/phmap
15-
url = https://github.com/greg7mdp/parallel-hashmap.git
1613
[submodule "third_party/nanoflann"]
1714
path = third_party/nanoflann
1815
url = https://github.com/jlblancoc/nanoflann

CMakeLists.txt

+2-8
Original file line numberDiff line numberDiff line change
@@ -340,15 +340,9 @@ else(EXTERNAL_DMLC_PATH)
340340
set(GOOGLE_TEST 0) # Turn off dmlc-core test
341341
endif(EXTERNAL_DMLC_PATH)
342342

343-
if(EXTERNAL_PHMAP_PATH)
344-
include_directories(SYSTEM ${EXTERNAL_PHMAP_PATH})
345-
else(EXTERNAL_PHMAP_PATH)
346-
target_include_directories(dgl PRIVATE "third_party/phmap")
347-
endif(EXTERNAL_PHMAP_PATH)
348-
349-
350343
target_include_directories(dgl PRIVATE "tensoradapter/include")
351344
target_include_directories(dgl PRIVATE "third_party/pcg/include")
345+
target_include_directories(dgl PRIVATE "third_party/tsl_robin_map/include")
352346

353347
if(EXTERNAL_NANOFLANN_PATH)
354348
include_directories(SYSTEM ${EXTERNAL_NANOFLANN_PATH})
@@ -473,7 +467,7 @@ if(BUILD_CPP_TEST)
473467
include_directories("include")
474468
include_directories("third_party/dlpack/include")
475469
include_directories("third_party/dmlc-core/include")
476-
include_directories("third_party/phmap")
470+
include_directories("third_party/tsl_robin_map/include")
477471
include_directories("third_party/libxsmm/include")
478472
include_directories("third_party/pcg/include")
479473
file(GLOB_RECURSE TEST_SRC_FILES ${PROJECT_SOURCE_DIR}/tests/cpp/*.cc)

src/array/cpu/array_utils.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#define DGL_ARRAY_CPU_ARRAY_UTILS_H_
88

99
#include <dgl/aten/types.h>
10-
#include <parallel_hashmap/phmap.h>
10+
#include <tsl/robin_map.h>
1111

1212
#include <unordered_map>
1313
#include <utility>
@@ -53,8 +53,7 @@ class IdHashMap {
5353
const int64_t len = ids->shape[0];
5454
for (int64_t i = 0; i < len; ++i) {
5555
const IdType id = ids_data[i];
56-
// phmap::flat_hash_map::insert assures that an insertion will not happen
57-
// if the key already exists.
56+
// Insertion will not happen if the key already exists.
5857
oldv2newv_.insert({id, oldv2newv_.size()});
5958
filter_[id & kFilterMask] = true;
6059
}
@@ -106,7 +105,7 @@ class IdHashMap {
106105
// lookups.
107106
std::vector<bool> filter_;
108107
// The hashmap from old vid to new vid
109-
phmap::flat_hash_map<IdType, IdType> oldv2newv_;
108+
tsl::robin_map<IdType, IdType> oldv2newv_;
110109
};
111110

112111
/**

src/array/cpu/csr_mm.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
#include <dgl/array.h>
88
#include <dgl/runtime/parallel_for.h>
9-
#include <parallel_hashmap/phmap.h>
9+
#include <tsl/robin_map.h>
10+
#include <tsl/robin_set.h>
1011

1112
#include <vector>
1213

@@ -28,7 +29,7 @@ void CountNNZPerRow(
2829
const IdType* B_indices, IdType* C_indptr_data, int64_t M) {
2930
parallel_for(0, M, [=](size_t b, size_t e) {
3031
for (auto i = b; i < e; ++i) {
31-
phmap::flat_hash_set<IdType> set;
32+
tsl::robin_set<IdType> set;
3233
for (IdType u = A_indptr[i]; u < A_indptr[i + 1]; ++u) {
3334
IdType w = A_indices[u];
3435
for (IdType v = B_indptr[w]; v < B_indptr[w + 1]; ++v)
@@ -60,7 +61,7 @@ void ComputeIndicesAndData(
6061
IdType* C_indices_data, DType* C_weights_data, int64_t M) {
6162
parallel_for(0, M, [=](size_t b, size_t e) {
6263
for (auto i = b; i < e; ++i) {
63-
phmap::flat_hash_map<IdType, DType> map;
64+
tsl::robin_map<IdType, DType> map;
6465
for (IdType u = A_indptr[i]; u < A_indptr[i + 1]; ++u) {
6566
IdType w = A_indices[u];
6667
DType vA = A_data[A_eids ? A_eids[u] : u];

src/array/cpu/csr_sum.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
#include <dgl/array.h>
88
#include <dgl/runtime/parallel_for.h>
9-
#include <parallel_hashmap/phmap.h>
9+
#include <tsl/robin_map.h>
10+
#include <tsl/robin_set.h>
1011

1112
#include <vector>
1213

@@ -30,7 +31,7 @@ void CountNNZPerRow(
3031

3132
runtime::parallel_for(0, M, [=](size_t b, size_t e) {
3233
for (size_t i = b; i < e; ++i) {
33-
phmap::flat_hash_set<IdType> set;
34+
tsl::robin_set<IdType> set;
3435
for (int64_t k = 0; k < n; ++k) {
3536
for (IdType u = A_indptr[k][i]; u < A_indptr[k][i + 1]; ++u)
3637
set.insert(A_indices[k][u]);
@@ -63,7 +64,7 @@ void ComputeIndicesAndData(
6364
int64_t n = A_indptr.size();
6465
runtime::parallel_for(0, M, [=](size_t b, size_t e) {
6566
for (auto i = b; i < e; ++i) {
66-
phmap::flat_hash_map<IdType, DType> map;
67+
tsl::robin_map<IdType, DType> map;
6768
for (int64_t k = 0; k < n; ++k) {
6869
for (IdType u = A_indptr[k][i]; u < A_indptr[k][i + 1]; ++u) {
6970
IdType kA = A_indices[k][u];

src/array/cpu/labor_pick.h

+13-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include <dgl/random.h>
2727
#include <dgl/runtime/parallel_for.h>
2828
#include <dmlc/omp.h>
29-
#include <parallel_hashmap/phmap.h>
29+
#include <tsl/robin_map.h>
3030

3131
#include <algorithm>
3232
#include <cmath>
@@ -45,6 +45,13 @@ namespace impl {
4545

4646
using dgl::random::continuous_seed;
4747

48+
template <typename K, typename V>
49+
using map_t = tsl::robin_map<K, V>;
50+
template <typename iterator>
51+
auto& mutable_value_ref(iterator it) {
52+
return it.value();
53+
}
54+
4855
constexpr double eps = 0.0001;
4956

5057
template <typename IdxType, typename FloatType>
@@ -61,7 +68,7 @@ auto compute_importance_sampling_probabilities(
6168

6269
double prev_ex_nodes = max_degree * num_rows;
6370

64-
phmap::flat_hash_map<IdxType, FloatType> hop_map, hop_map2;
71+
map_t<IdxType, FloatType> hop_map, hop_map2;
6572
for (int iters = 0; iters < importance_sampling || importance_sampling < 0;
6673
iters++) {
6774
// NOTE(mfbalin) When the graph is unweighted, the first c values in
@@ -83,7 +90,9 @@ auto compute_importance_sampling_probabilities(
8390
for (auto j = indptr[rid]; j < indptr[rid + 1]; j++) {
8491
const auto ct = c * (weighted && iters == 1 ? A[j] : 1);
8592
auto itb = hop_map2.emplace(indices[j], ct);
86-
if (!itb.second) itb.first->second = std::max(ct, itb.first->second);
93+
if (!itb.second) {
94+
mutable_value_ref(itb.first) = std::max(ct, itb.first->second);
95+
}
8796
}
8897
}
8998
if (hop_map.empty())
@@ -203,7 +212,7 @@ std::pair<COOMatrix, FloatArray> CSRLaborPick(
203212
hop_size += act_degree;
204213
}
205214

206-
phmap::flat_hash_map<IdxType, FloatType> hop_map;
215+
map_t<IdxType, FloatType> hop_map;
207216

208217
if (importance_sampling)
209218
hop_map = compute_importance_sampling_probabilities<IdxType, FloatType>(

third_party/phmap

-1
This file was deleted.

0 commit comments

Comments
 (0)