Skip to content

Commit

Permalink
Cleanup the code [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
maawad committed Jan 24, 2024
1 parent c45e2a8 commit dff559c
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions examples/array.cu
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,30 @@ __global__ void test_kernel(HashMap map, Keys* keys) {
auto find_result = map.find(pair.first, tile);

if (tile.thread_rank() == 0) {
printf("value for keys[%i] = %i\n", key_id, find_result);
printf("found value for keys[%i] is %i, expected %i\n",
key_id,
find_result,
pair.second);
}
}

struct custom_key_hash {
using key_type = cuda::std::array<std::uint8_t, 20>;
template <typename Key>
struct array_hash {
using key_type = Key;
using result_type = std::size_t;
constexpr custom_key_hash(uint32_t hash_x, uint32_t hash_y)
constexpr array_hash(uint32_t hash_x, uint32_t hash_y)
: hash_x_(hash_x), hash_y_(hash_y) {}

// just hash the first entry
constexpr result_type __host__ __device__ operator()(const key_type& key) const {
return (((hash_x_ ^ key[0]) + hash_y_) % prime_divisor);
}

custom_key_hash(const custom_key_hash&) = default;
custom_key_hash() = default;
custom_key_hash(custom_key_hash&&) = default;
custom_key_hash& operator=(custom_key_hash const&) = default;
custom_key_hash& operator=(custom_key_hash&&) = default;
~custom_key_hash() = default;
array_hash(const array_hash&) = default;
array_hash() = default;
array_hash(array_hash&&) = default;
array_hash& operator=(array_hash const&) = default;
array_hash& operator=(array_hash&&) = default;
~array_hash() = default;
static constexpr uint32_t prime_divisor = 4294967291u;

private:
Expand All @@ -63,16 +66,18 @@ int main() {
using Config = cuda::std::array<std::uint8_t, 20>;
using V = int;

const auto sentinel_key = Config{0, 0, 0};
const auto sentinel_key = Config{0};
const auto sentinel_value = 0;

const std::size_t capacity = 5;

thrust::device_vector<Config> keys(2);
keys[0] = cuda::std::array<std::uint8_t, 20>{1};
keys[1] = cuda::std::array<std::uint8_t, 20>{2};
const std::size_t num_keys = 10;
thrust::device_vector<Config> keys(num_keys);
for (std::size_t i = 0; i < num_keys; i++) {
keys[i] = Config{static_cast<std::uint8_t>(i)};
}

bght::bcht<Config, V, custom_key_hash> table(capacity, sentinel_key, sentinel_value);
bght::bcht<Config, V, array_hash<Config>> table(capacity, sentinel_key, sentinel_value);

// for simplicity launch one block per key and set the block size to tile/bucket size
const auto block_size = bght::bcht<Config, V>::bucket_size;
Expand Down

0 comments on commit dff559c

Please sign in to comment.