debugging.cpp 3.4 KB
Newer Older
1
2
3
4
5
// -------------------------------------------------------------
// cuDPP -- CUDA Data Parallel Primitives library
// -------------------------------------------------------------
// $Revision:$
// $Date:$
6
// -------------------------------------------------------------
7
8
// This source code is distributed under the terms of license.txt in
// the root directory of this source distribution.
9
// -------------------------------------------------------------
10
11
12
13
14
15
16
17

/**
 * @file
 * debugging.cpp
 *
 * @brief Debugging/statistics/performance utilities for hash tables.
 */

traveller59's avatar
traveller59 committed
18
19
#include <cuhash/debugging.h>
#include <cuhash/definitions.h>
20
21
22

#include <algorithm>
#include <cstring>
traveller59's avatar
traveller59 committed
23
#include <cuhash/cuda_util.h>
24

traveller59's avatar
traveller59 committed
25
namespace cuhash {
26

27
void OutputRetrievalStatistics(const unsigned n_queries,
28
                               const unsigned *d_retrieval_probes,
29
                               const unsigned n_functions) {
30
  unsigned *retrieval_probes = new unsigned[n_queries];
31
  CUDA_SAFE_CALL(cudaMemcpy(retrieval_probes, d_retrieval_probes,
32
33
34
                            sizeof(unsigned) * n_queries,
                            cudaMemcpyDeviceToHost));

35
36
  // Create a histogram showing how many items needed how many probes to be
  // found.
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
  unsigned possible_probes = n_functions + 2;
  unsigned *histogram = new unsigned[possible_probes];
  memset(histogram, 0, sizeof(unsigned) * (possible_probes));
  for (unsigned i = 0; i < n_queries; ++i) {
    histogram[retrieval_probes[i]]++;
  }

  // Dump it.
  char buffer[10000];
  sprintf(buffer, "Probes for retrieval: ");
  PrintMessage(buffer);
  for (unsigned i = 0; i < possible_probes; ++i) {
    sprintf(buffer, "\t(%u, %u)", i, histogram[i]);
    PrintMessage(buffer);
  }
52
53
  delete[] retrieval_probes;
  delete[] histogram;
54
55
}

56
void OutputBuildStatistics(const unsigned n,
57
58
59
                           const unsigned *d_iterations_taken) {
  // Output how many iterations each thread took until it found an empty slot.
  unsigned *iterations_taken = new unsigned[n];
60
61
  CUDA_SAFE_CALL(cudaMemcpy(iterations_taken, d_iterations_taken,
                            sizeof(unsigned) * n, cudaMemcpyDeviceToHost));
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
  std::sort(iterations_taken, iterations_taken + n);
  unsigned total_iterations = 0;
  unsigned max_iterations_taken = 0;
  for (unsigned i = 0; i < n; ++i) {
    total_iterations += iterations_taken[i];
    max_iterations_taken = std::max(max_iterations_taken, iterations_taken[i]);
  }

  unsigned current_value = iterations_taken[0];
  unsigned count = 1;
  char buffer[10000];
  sprintf(buffer, "Iterations taken:\n");
  for (unsigned i = 1; i < n; ++i) {
    if (iterations_taken[i] != current_value) {
      sprintf(buffer, "%s\t(%u, %u)\n", buffer, current_value, count);
      current_value = iterations_taken[i];
      count = 1;
    } else {
      count++;
    }
  }
  sprintf(buffer, "%s\t(%u, %u)", buffer, current_value, count);
  PrintMessage(buffer);
  sprintf(buffer, "Total iterations: %u", total_iterations);
  PrintMessage(buffer);
87
88
89
  sprintf(buffer, "Avg/Med/Max iterations: (%f %u %u)",
          (float)total_iterations / n, iterations_taken[n / 2],
          iterations_taken[n - 1]);
90
  PrintMessage(buffer);
91
  delete[] iterations_taken;
92
93
94
95
96
97

  // Print the length of the longest eviction chain.
  sprintf(buffer, "Max iterations: %u", max_iterations_taken);
  PrintMessage(buffer);
}

98
}; // namespace cuhash
99
100
101
102
103
104

// Leave this at the end of the file
// Local Variables:
// mode:c++
// c-file-style: "NVIDIA"
// End: