Skip to content

Commit

Permalink
Update MIS-2 and aggregation
Browse files Browse the repository at this point in the history
Bringing in newest versions from work on the IPDPS paper.
  • Loading branch information
brian-kelley committed Oct 19, 2021
1 parent 8433c0e commit 6d3adfa
Show file tree
Hide file tree
Showing 6 changed files with 517 additions and 159 deletions.
18 changes: 9 additions & 9 deletions example/wiki/graph/KokkosGraph_wiki_coarsening.cpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
#include "KokkosGraph_wiki_9pt_stencil.hpp"
#include "KokkosGraph_MIS2.hpp"

int main()
{
int main() {
Kokkos::initialize();
{
using GraphDemo::numVertices;
RowmapType rowmapDevice;
ColindsType colindsDevice;
//Step 1: Generate the graph on host, allocate space on device, and copy.
//See function "generate9pt" below.
// Step 1: Generate the graph on host, allocate space on device, and copy.
// See function "generate9pt" below.
GraphDemo::generate9pt(rowmapDevice, colindsDevice);
//Step 2: Run MIS-2 based coarsening and print the result
// Step 2: Run MIS-2 based coarsening and print the result
{
std::cout << "Coarsened vertex labels:\n";
Ordinal numClusters = 0;
auto labels = KokkosGraph::Experimental::graph_mis2_coarsen<ExecSpace, RowmapType, ColindsType>(
rowmapDevice, colindsDevice, numClusters, KokkosGraph::MIS2_FAST);
//coarsening labels can be printed in the same way as colors
auto labels =
KokkosGraph::Experimental::graph_mis2_aggregate<ExecSpace, RowmapType,
ColindsType>(
rowmapDevice, colindsDevice, numClusters);
// coarsening labels can be printed in the same way as colors
GraphDemo::printColoring(labels, numClusters);
putchar('\n');
}
}
Kokkos::finalize();
return 0;
}

35 changes: 35 additions & 0 deletions src/common/KokkosKernels_SimpleUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,41 @@ void kk_view_reduce_max(
ReduceMaxFunctor<view_type>(view_to_reduce), max_reduction);
}

// xorshift hash/pseudorandom function (supported for 32- and 64-bit integer
// types only)
template <typename Value>
KOKKOS_FORCEINLINE_FUNCTION Value xorshiftHash(Value v) {
static_assert(std::is_unsigned<Value>::value,
"xorshiftHash: value must be an unsigned integer type");
uint64_t x = v;
x ^= x >> 12;
x ^= x << 25;
x ^= x >> 27;
if (std::is_same<Value, uint32_t>::value) {
return static_cast<Value>((x * 2685821657736338717ULL - 1) >> 16);
}
return static_cast<Value>(x * 2685821657736338717ULL - 1);
}

template <typename V>
struct SequentialFillFunctor {
using size_type = typename V::size_type;
using val_type = typename V::non_const_value_type;
SequentialFillFunctor(const V &v_, val_type start_) : v(v_), start(start_) {}
KOKKOS_INLINE_FUNCTION void operator()(size_type i) const {
v(i) = start + (val_type)i;
}
V v;
val_type start;
};

template <typename V>
void sequential_fill(const V &v, typename V::non_const_value_type start = 0) {
Kokkos::parallel_for(
Kokkos::RangePolicy<typename V::execution_space>(0, v.extent(0)),
SequentialFillFunctor<V>(v, start));
}

} // namespace Impl
} // namespace KokkosKernels

Expand Down
39 changes: 31 additions & 8 deletions src/graph/KokkosGraph_MIS2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,42 @@ template <typename device_t, typename rowmap_t, typename colinds_t,
typename labels_t = typename colinds_t::non_const_type>
labels_t graph_mis2_coarsen(
const rowmap_t& rowmap, const colinds_t& colinds,
typename colinds_t::non_const_value_type& numClusters,
MIS2_Algorithm algo = MIS2_FAST) {
typename colinds_t::non_const_value_type& numClusters) {
if (rowmap.extent(0) <= 1) {
// there are no vertices to label
numClusters = 0;
return labels_t();
}
labels_t mis2 = graph_d2_mis<device_t, rowmap_t, colinds_t, labels_t>(
rowmap, colinds, algo);
numClusters = mis2.extent(0);
Impl::D2_MIS_Coarsening<device_t, rowmap_t, colinds_t, labels_t> coarsening(
rowmap, colinds, mis2);
return coarsening.compute();
Impl::D2_MIS_Aggregation<device_t, rowmap_t, colinds_t, labels_t> aggregation(
rowmap, colinds);
aggregation.compute(false);
numClusters = aggregation.numAggs;
return aggregation.labels;
}

template <typename device_t, typename rowmap_t, typename colinds_t,
typename labels_t = typename colinds_t::non_const_type>
labels_t graph_mis2_aggregate(
const rowmap_t& rowmap, const colinds_t& colinds,
typename colinds_t::non_const_value_type& numAggregates) {
if (rowmap.extent(0) <= 1) {
// there are no vertices to label
numAggregates = 0;
return labels_t();
}
Impl::D2_MIS_Aggregation<device_t, rowmap_t, colinds_t, labels_t> aggregation(
rowmap, colinds);
aggregation.compute(true);
numAggregates = aggregation.numAggs;
return aggregation.labels;
}

inline const char* mis2_algorithm_name(MIS2_Algorithm algo) {
switch (algo) {
case MIS2_QUALITY: return "MIS2_QUALITY";
case MIS2_FAST: return "MIS2_FAST";
}
return "*** Invalid MIS2 algo enum value.\n";
}

} // end namespace Experimental
Expand Down
Loading

0 comments on commit 6d3adfa

Please sign in to comment.