diff --git a/examples/array.cu b/examples/array.cu index b947763..aa8d551 100644 --- a/examples/array.cu +++ b/examples/array.cu @@ -31,14 +31,17 @@ __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; +template +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 @@ -46,12 +49,12 @@ struct custom_key_hash { 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: @@ -63,16 +66,18 @@ int main() { using Config = cuda::std::array; 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 keys(2); - keys[0] = cuda::std::array{1}; - keys[1] = cuda::std::array{2}; + const std::size_t num_keys = 10; + thrust::device_vector keys(num_keys); + for (std::size_t i = 0; i < num_keys; i++) { + keys[i] = Config{static_cast(i)}; + } - bght::bcht table(capacity, sentinel_key, sentinel_value); + bght::bcht> 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::bucket_size;