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

Remove perf prints from MST #623

Merged
merged 3 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
54 changes: 2 additions & 52 deletions cpp/include/raft/sparse/mst/detail/mst_solver_inl.cuh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, NVIDIA CORPORATION.
* Copyright (c) 2020-2022, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,7 +16,6 @@

#pragma once

#include <chrono>
#include <curand.h>

#include "mst_kernels.cuh"
Expand All @@ -36,7 +35,6 @@

namespace raft {
namespace mst {
typedef std::chrono::high_resolution_clock Clock;

// curand generator uniform
inline curandStatus_t curand_generate_uniformX(curandGenerator_t generator,
Expand Down Expand Up @@ -115,22 +113,13 @@ MST_solver<vertex_t, edge_t, weight_t, alteration_t>::solve()
RAFT_EXPECTS(offsets != nullptr, "Null offsets.");
RAFT_EXPECTS(indices != nullptr, "Null indices.");
RAFT_EXPECTS(weights != nullptr, "Null weights.");
#ifdef MST_TIME
double timer0 = 0, timer1 = 0, timer2 = 0, timer3 = 0, timer4 = 0, timer5 = 0;
auto start = Clock::now();
#endif

// Alterating the weights
// this is done by identifying the lowest cost edge weight gap that is not 0, call this theta.
// For each edge, add noise that is less than theta. That is, generate a random number in the
// range [0.0, theta) and add it to each edge weight.
alteration();

#ifdef MST_TIME
auto stop = Clock::now();
timer0 = duration_us(stop - start);
#endif

auto max_mst_edges = symmetrize_output ? 2 * v - 2 : v - 1;

Graph_COO<vertex_t, edge_t, weight_t> mst_result(max_mst_edges, stream);
Expand All @@ -140,69 +129,33 @@ MST_solver<vertex_t, edge_t, weight_t, alteration_t>::solve()
// track completion with mst_edge_found status and v as upper bound
auto mst_iterations = iterations > 0 ? iterations : v;
for (auto i = 0; i < mst_iterations; i++) {
#ifdef MST_TIME
start = Clock::now();
#endif

// Finds the minimum edge from each vertex to the lowest color
// by working at each vertex of the supervertex
min_edge_per_vertex();

#ifdef MST_TIME
stop = Clock::now();
timer1 += duration_us(stop - start);
start = Clock::now();
#endif
// Finds the minimum edge from each supervertex to the lowest color
min_edge_per_supervertex();

#ifdef MST_TIME
stop = Clock::now();
timer2 += duration_us(stop - start);
start = Clock::now();
#endif

// check if msf/mst done, count new edges added
check_termination();

#ifdef MST_TIME
stop = Clock::now();
timer3 += duration_us(stop - start);
#endif

auto curr_mst_edge_count = mst_edge_count.value(stream);
RAFT_EXPECTS(curr_mst_edge_count <= max_mst_edges,
"Number of edges found by MST is invalid. This may be due to "
"loss in precision. Try increasing precision of weights.");

if (curr_mst_edge_count == prev_mst_edge_count.value(stream)) {
#ifdef MST_TIME
std::cout << "Iterations: " << i << std::endl;
std::cout << timer0 << "," << timer1 << "," << timer2 << "," << timer3 << "," << timer4 << ","
<< timer5 << std::endl;
#endif
// exit here when reaching steady state
break;
}

#ifdef MST_TIME
start = Clock::now();
#endif
// append the newly found MST edges to the final output
append_src_dst_pair(mst_result.src.data(), mst_result.dst.data(), mst_result.weights.data());
#ifdef MST_TIME
stop = Clock::now();
timer4 += duration_us(stop - start);
start = Clock::now();
#endif

// updates colors of vertices by propagating the lower color to the higher
label_prop(mst_result.src.data(), mst_result.dst.data());

#ifdef MST_TIME
stop = Clock::now();
timer5 += duration_us(stop - start);
#endif

// copy this iteration's results and store
prev_mst_edge_count.set_value_async(curr_mst_edge_count, stream);
}
Expand Down Expand Up @@ -317,9 +270,6 @@ void MST_solver<vertex_t, edge_t, weight_t, alteration_t>::label_prop(vertex_t*

detail::final_color_indices<<<min_pair_nblocks, min_pair_nthreads, 0, stream>>>(
v, color_ptr, color_index);
#ifdef MST_TIME
std::cout << "Label prop iterations: " << i << std::endl;
#endif
}

// Finds the minimum edge from each vertex to the lowest color
Expand Down
22 changes: 1 addition & 21 deletions cpp/include/raft/sparse/mst/detail/utils.cuh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/*
* Copyright (c) 2020, NVIDIA CORPORATION.
* Copyright (c) 2020-2022, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,7 +19,6 @@

#include <iostream>
#include <rmm/device_uvector.hpp>
#define MST_TIME

namespace raft {
namespace mst {
Expand All @@ -31,25 +30,6 @@ __device__ idx_t get_1D_idx()
return blockIdx.x * blockDim.x + threadIdx.x;
}

// somewhat smart vector print
template <typename T>
void printv(rmm::device_uvector<T>& vec, const std::string& name = "", const size_t displ = 5)
{
#ifdef MST_TIME
std::cout.precision(15);
std::cout << name << " size = " << vec.size() << std::endl;
if (displ < vec.size()) {
thrust::copy(vec.begin(), vec.begin() + displ, std::ostream_iterator<T>(std::cout, " "));
std::cout << " ... ";
thrust::copy(vec.end() - displ, vec.end(), std::ostream_iterator<T>(std::cout, " "));
} else {
thrust::copy(vec.begin(), vec.end(), std::ostream_iterator<T>(std::cout, " "));
}
std::cout << std::endl << std::endl;
#endif
}
#define duration_us(a) std::chrono::duration_cast<std::chrono::microseconds>(a).count()

} // namespace detail
} // namespace mst
} // namespace raft