Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Performance] Remove phmap dependency. #7658

Merged
merged 4 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
[submodule "third_party/METIS"]
path = third_party/METIS
url = https://github.com/KarypisLab/METIS.git
[submodule "third_party/phmap"]
path = third_party/phmap
url = https://github.com/greg7mdp/parallel-hashmap.git
[submodule "third_party/nanoflann"]
path = third_party/nanoflann
url = https://github.com/jlblancoc/nanoflann
Expand Down
10 changes: 2 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,9 @@ else(EXTERNAL_DMLC_PATH)
set(GOOGLE_TEST 0) # Turn off dmlc-core test
endif(EXTERNAL_DMLC_PATH)

if(EXTERNAL_PHMAP_PATH)
include_directories(SYSTEM ${EXTERNAL_PHMAP_PATH})
else(EXTERNAL_PHMAP_PATH)
target_include_directories(dgl PRIVATE "third_party/phmap")
endif(EXTERNAL_PHMAP_PATH)


target_include_directories(dgl PRIVATE "tensoradapter/include")
target_include_directories(dgl PRIVATE "third_party/pcg/include")
target_include_directories(dgl PRIVATE "third_party/tsl_robin_map/include")

if(EXTERNAL_NANOFLANN_PATH)
include_directories(SYSTEM ${EXTERNAL_NANOFLANN_PATH})
Expand Down Expand Up @@ -473,7 +467,7 @@ if(BUILD_CPP_TEST)
include_directories("include")
include_directories("third_party/dlpack/include")
include_directories("third_party/dmlc-core/include")
include_directories("third_party/phmap")
include_directories("third_party/tsl_robin_map/include")
include_directories("third_party/libxsmm/include")
include_directories("third_party/pcg/include")
file(GLOB_RECURSE TEST_SRC_FILES ${PROJECT_SOURCE_DIR}/tests/cpp/*.cc)
Expand Down
7 changes: 3 additions & 4 deletions src/array/cpu/array_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define DGL_ARRAY_CPU_ARRAY_UTILS_H_

#include <dgl/aten/types.h>
#include <parallel_hashmap/phmap.h>
#include <tsl/robin_map.h>

#include <unordered_map>
#include <utility>
Expand Down Expand Up @@ -53,8 +53,7 @@ class IdHashMap {
const int64_t len = ids->shape[0];
for (int64_t i = 0; i < len; ++i) {
const IdType id = ids_data[i];
// phmap::flat_hash_map::insert assures that an insertion will not happen
// if the key already exists.
// Insertion will not happen if the key already exists.
oldv2newv_.insert({id, oldv2newv_.size()});
filter_[id & kFilterMask] = true;
}
Expand Down Expand Up @@ -106,7 +105,7 @@ class IdHashMap {
// lookups.
std::vector<bool> filter_;
// The hashmap from old vid to new vid
phmap::flat_hash_map<IdType, IdType> oldv2newv_;
tsl::robin_map<IdType, IdType> oldv2newv_;
};

/**
Expand Down
7 changes: 4 additions & 3 deletions src/array/cpu/csr_mm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

#include <dgl/array.h>
#include <dgl/runtime/parallel_for.h>
#include <parallel_hashmap/phmap.h>
#include <tsl/robin_map.h>
#include <tsl/robin_set.h>

#include <vector>

Expand All @@ -28,7 +29,7 @@ void CountNNZPerRow(
const IdType* B_indices, IdType* C_indptr_data, int64_t M) {
parallel_for(0, M, [=](size_t b, size_t e) {
for (auto i = b; i < e; ++i) {
phmap::flat_hash_set<IdType> set;
tsl::robin_set<IdType> set;
for (IdType u = A_indptr[i]; u < A_indptr[i + 1]; ++u) {
IdType w = A_indices[u];
for (IdType v = B_indptr[w]; v < B_indptr[w + 1]; ++v)
Expand Down Expand Up @@ -60,7 +61,7 @@ void ComputeIndicesAndData(
IdType* C_indices_data, DType* C_weights_data, int64_t M) {
parallel_for(0, M, [=](size_t b, size_t e) {
for (auto i = b; i < e; ++i) {
phmap::flat_hash_map<IdType, DType> map;
tsl::robin_map<IdType, DType> map;
for (IdType u = A_indptr[i]; u < A_indptr[i + 1]; ++u) {
IdType w = A_indices[u];
DType vA = A_data[A_eids ? A_eids[u] : u];
Expand Down
7 changes: 4 additions & 3 deletions src/array/cpu/csr_sum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

#include <dgl/array.h>
#include <dgl/runtime/parallel_for.h>
#include <parallel_hashmap/phmap.h>
#include <tsl/robin_map.h>
#include <tsl/robin_set.h>

#include <vector>

Expand All @@ -30,7 +31,7 @@ void CountNNZPerRow(

runtime::parallel_for(0, M, [=](size_t b, size_t e) {
for (size_t i = b; i < e; ++i) {
phmap::flat_hash_set<IdType> set;
tsl::robin_set<IdType> set;
for (int64_t k = 0; k < n; ++k) {
for (IdType u = A_indptr[k][i]; u < A_indptr[k][i + 1]; ++u)
set.insert(A_indices[k][u]);
Expand Down Expand Up @@ -63,7 +64,7 @@ void ComputeIndicesAndData(
int64_t n = A_indptr.size();
runtime::parallel_for(0, M, [=](size_t b, size_t e) {
for (auto i = b; i < e; ++i) {
phmap::flat_hash_map<IdType, DType> map;
tsl::robin_map<IdType, DType> map;
for (int64_t k = 0; k < n; ++k) {
for (IdType u = A_indptr[k][i]; u < A_indptr[k][i + 1]; ++u) {
IdType kA = A_indices[k][u];
Expand Down
17 changes: 13 additions & 4 deletions src/array/cpu/labor_pick.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <dgl/random.h>
#include <dgl/runtime/parallel_for.h>
#include <dmlc/omp.h>
#include <parallel_hashmap/phmap.h>
#include <tsl/robin_map.h>

#include <algorithm>
#include <cmath>
Expand All @@ -45,6 +45,13 @@ namespace impl {

using dgl::random::continuous_seed;

template <typename K, typename V>
using map_t = tsl::robin_map<K, V>;
template <typename iterator>
auto& mutable_value_ref(iterator it) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why wrap the value access with a function? Is it necessary? It's different from std::unordered_map?

Copy link
Collaborator Author

@mfbalin mfbalin Aug 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it->second is const with this map implementation by default. Use .value() to modify it. I wrapped it so that when we change map again for any reason, we have to only change this function.

return it.value();
}

constexpr double eps = 0.0001;

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

double prev_ex_nodes = max_degree * num_rows;

phmap::flat_hash_map<IdxType, FloatType> hop_map, hop_map2;
map_t<IdxType, FloatType> hop_map, hop_map2;
for (int iters = 0; iters < importance_sampling || importance_sampling < 0;
iters++) {
// NOTE(mfbalin) When the graph is unweighted, the first c values in
Expand All @@ -83,7 +90,9 @@ auto compute_importance_sampling_probabilities(
for (auto j = indptr[rid]; j < indptr[rid + 1]; j++) {
const auto ct = c * (weighted && iters == 1 ? A[j] : 1);
auto itb = hop_map2.emplace(indices[j], ct);
if (!itb.second) itb.first->second = std::max(ct, itb.first->second);
if (!itb.second) {
mutable_value_ref(itb.first) = std::max(ct, itb.first->second);
}
}
}
if (hop_map.empty())
Expand Down Expand Up @@ -203,7 +212,7 @@ std::pair<COOMatrix, FloatArray> CSRLaborPick(
hop_size += act_degree;
}

phmap::flat_hash_map<IdxType, FloatType> hop_map;
map_t<IdxType, FloatType> hop_map;

if (importance_sampling)
hop_map = compute_importance_sampling_probabilities<IdxType, FloatType>(
Expand Down
1 change: 0 additions & 1 deletion third_party/phmap
Submodule phmap deleted from 65775f
Loading