definitions.h 3.68 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// -------------------------------------------------------------
// cuDPP -- CUDA Data Parallel Primitives library
// -------------------------------------------------------------
// $Revision:$
// $Date:$
// -------------------------------------------------------------
// This source code is distributed under the terms of license.txt in
// the root directory of this source distribution.
// -------------------------------------------------------------

/**
 * @file definitions.h
 *
 * @brief Stores configuration flags and definitions for hard-coded values in
 * hash table implementations.
 */

#ifndef CUDAHT__CUCKOO__SRC__LIBRARY__DEFINITIONS__H
#define CUDAHT__CUCKOO__SRC__LIBRARY__DEFINITIONS__H

#include <cstdio>
#include <limits>
#include <tensorview/tensorview.h>

/* --------------------------------------------------------------------------
   Debugging.
   -------------------------------------------------------------------------- */
#ifdef _DEBUG
//! Forces the hash functions to generate a full set of slots for each key when
//! not using subtables.
// #define FORCEFULLY_GENERATE_NO_CYCLES

//! Count how many iterations are taken to insert/find items.
#define TRACK_ITERATIONS

//! Count how many items fail to be inserted when the hash table fails to build.
#define COUNT_UNINSERTED

//! Take some statistics on the hash functions.
#define TAKE_HASH_FUNCTION_STATISTICS

#ifdef TAKE_HASH_FUNCTION_STATISTICS
//! Determine how many keys hash into each table slot.
#define COUNT_HOW_MANY_HASH_INTO_EACH_SLOT

//! Determine how many unique slots a key is assigned.
#define COUNT_HOW_MANY_HAVE_CYCLES
#endif
#endif

#ifdef USE_DAN_OUTPUT
#include <Utilities/output.h>
//! Logs any error messages.
inline void PrintMessage(const char *message, const bool error = false) {
  PrintIndentedMessage(message, error);
}
#else
//! Prints a message out to the console.
inline void PrintMessage(const char *message, const bool error = false) {
  if (error) {
traveller59's avatar
traveller59 committed
61
    printf("cudahash: %s\n", message);
62
63
64
65
66
67
68
69
70
  } else {
    printf("%s\n", message);
  }
}
#endif

/* -------------------------------------------------------------------------
   Hash table constants and definitions.
   ------------------------------------------------------------------------- */
traveller59's avatar
traveller59 committed
71
namespace cuhash {
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

/**
 * \addtogroup cudpp_hash_data_structures
 *
 * @{
 */

typedef unsigned long long
    Entry; //!< A key and its value are stored in a 64-bit number.  The key is
           //!< stored in the upper 32 bits.

const unsigned kMaxRestartAttempts = 10; //!< Number of build attempts.
const unsigned kKeyEmpty = 0xffffffffu; //!< Signifies empty slots in the table.
const unsigned kNotFound =
    0xffffffffu; //!< Signifies that a query key was not found.
const unsigned kMaxHashFunctions =
    5; //!< Maximum number of hash functions allowed.
const unsigned kStashSize =
    101; //!< How many slots the stash hash table contains.

//! Value indicating that a hash table slot has no valid item within it.
const Entry kEntryEmpty = Entry(kKeyEmpty) << 32;

//! Value returned when a query fails.
const Entry kEntryNotFound = (Entry(kKeyEmpty) << 32) + kNotFound;

//! Number of threads to put in a thread block.
const unsigned kBlockSize = 64;

//! Number of blocks to put along each axis of the grid.
const unsigned kGridSize = 16384;

//! Minimum table sizes for 2 through 5 functions.
const float kMinimumSpaceUsages[] = {std::numeric_limits<float>::max(),
                                     std::numeric_limits<float>::max(),
                                     2.01f,
                                     1.1f,
                                     1.03f,
                                     1.02f};

/** @} */ // end cudpp_hash_data_structures

traveller59's avatar
traveller59 committed
114
}; // namespace cuhash
115
116

#endif