Kokkos Core Kernels Package Version of the Day
Loading...
Searching...
No Matches
List of all members
Kokkos::UnorderedMap< Key, Value, Device, Hasher, EqualTo > Class Template Reference

Thread-safe, performance-portable lookup table. More...

#include <Kokkos_UnorderedMap.hpp>

Public member functions

 UnorderedMap (size_type capacity_hint=0, hasher_type hasher=hasher_type(), equal_to_type equal_to=equal_to_type())
 Constructor.
 
void clear ()
 Clear all entries in the table.
 
bool rehash (size_type requested_capacity=0)
 Change the capacity of the the map.
 
size_type size () const
 The number of entries in the table.
 
bool failed_insert () const
 The current number of failed insert() calls.
 
KOKKOS_FORCEINLINE_FUNCTION size_type capacity () const
 The maximum number of entries that the table can hold.
 
KOKKOS_INLINE_FUNCTION size_type hash_capacity () const
 The number of hash table "buckets.".
 
KOKKOS_INLINE_FUNCTION insert_result insert (key_type const &k, impl_value_type const &v=impl_value_type()) const
 
KOKKOS_INLINE_FUNCTION size_type find (const key_type &k) const
 Find the given key k, if it exists in the table.
 
KOKKOS_INLINE_FUNCTION bool exists (const key_type &k) const
 Does the key exist in the map.
 
template<typename Dummy = value_type>
KOKKOS_FORCEINLINE_FUNCTION std::enable_if_t< !std::is_void< Dummy >::value, std::conditional_t< has_const_value, impl_value_type, impl_value_type & > > value_at (size_type i) const
 Get the value with i as its direct index.
 
KOKKOS_FORCEINLINE_FUNCTION key_type key_at (size_type i) const
 Get the key with i as its direct index.
 

Detailed Description

template<typename Key, typename Value, typename Device = Kokkos::DefaultExecutionSpace, typename Hasher = pod_hash<std::remove_const_t<Key>>, typename EqualTo = pod_equal_to<std::remove_const_t<Key>>>
class Kokkos::UnorderedMap< Key, Value, Device, Hasher, EqualTo >

Thread-safe, performance-portable lookup table.

This class provides a lookup table. In terms of functionality, this class compares to std::unordered_map (new in C++11). "Unordered" means that keys are not stored in any particular order, unlike (for example) std::map. "Thread-safe" means that lookups, insertion, and deletion are safe to call by multiple threads in parallel. "Performance-portable" means that parallel performance of these operations is reasonable, on multiple hardware platforms. Platforms on which performance has been tested include conventional Intel x86 multicore processors, Intel Xeon Phi ("MIC"), and NVIDIA GPUs.

Parallel performance portability entails design decisions that might differ from one's expectation for a sequential interface. This particularly affects insertion of single elements. In an interface intended for sequential use, insertion might reallocate memory if the original allocation did not suffice to hold the new element. In this class, insertion does not reallocate memory. This means that it might fail. insert() returns an enum which indicates whether the insert failed. There are three possible conditions:

  1. INSERT_FAILED: The insert failed. This usually means that the UnorderedMap ran out of space.
  2. INSERT_SUCCESS: The insert succeeded, and the key did not exist in the table before.
  3. INSERT_EXISTING: The insert succeeded, and the key did exist in the table before. The new value was ignored and the old value was left in place.
Template Parameters
KeyType of keys of the lookup table. If const, users are not allowed to add or remove keys, though they are allowed to change values. In that case, the implementation may make optimizations specific to the Device. For example, if Device is Cuda, it may use texture fetches to access keys.
ValueType of values stored in the lookup table. You may use void here, in which case the table will be a set of keys. If const, users are not allowed to change entries. In that case, the implementation may make optimizations specific to the Device, such as using texture fetches to access values.
DeviceThe Kokkos Device type.
HasherDefinition of the hash function for instances of Key. The default will calculate a bitwise hash.
EqualToDefinition of the equality function for instances of Key. The default will do a bitwise equality comparison.

Definition at line 181 of file Kokkos_UnorderedMap.hpp.

Constructor & Destructor Documentation

◆ UnorderedMap()

template<typename Key , typename Value , typename Device = Kokkos::DefaultExecutionSpace, typename Hasher = pod_hash<std::remove_const_t<Key>>, typename EqualTo = pod_equal_to<std::remove_const_t<Key>>>
Kokkos::UnorderedMap< Key, Value, Device, Hasher, EqualTo >::UnorderedMap ( size_type capacity_hint = 0,
hasher_type hasher = hasher_type(),
equal_to_type equal_to = equal_to_type() )
inline

Constructor.

Parameters
capacity_hint[in] Initial guess of how many unique keys will be inserted into the map
hash[in] Hasher function for Key instances. The default value usually suffices.

Definition at line 273 of file Kokkos_UnorderedMap.hpp.

Member Function Documentation

◆ clear()

template<typename Key , typename Value , typename Device = Kokkos::DefaultExecutionSpace, typename Hasher = pod_hash<std::remove_const_t<Key>>, typename EqualTo = pod_equal_to<std::remove_const_t<Key>>>
void Kokkos::UnorderedMap< Key, Value, Device, Hasher, EqualTo >::clear ( )
inline

Clear all entries in the table.

Definition at line 304 of file Kokkos_UnorderedMap.hpp.

◆ rehash()

template<typename Key , typename Value , typename Device = Kokkos::DefaultExecutionSpace, typename Hasher = pod_hash<std::remove_const_t<Key>>, typename EqualTo = pod_equal_to<std::remove_const_t<Key>>>
bool Kokkos::UnorderedMap< Key, Value, Device, Hasher, EqualTo >::rehash ( size_type requested_capacity = 0)
inline

Change the capacity of the the map.

If there are no failed inserts the current size of the map will be used as a lower bound for the input capacity. If the map is not empty and does not have failed inserts and the capacity changes then the current data is copied into the resized / rehashed map.

This is not a device function; it may not be called in a parallel kernel.

Definition at line 336 of file Kokkos_UnorderedMap.hpp.

◆ size()

template<typename Key , typename Value , typename Device = Kokkos::DefaultExecutionSpace, typename Hasher = pod_hash<std::remove_const_t<Key>>, typename EqualTo = pod_equal_to<std::remove_const_t<Key>>>
size_type Kokkos::UnorderedMap< Key, Value, Device, Hasher, EqualTo >::size ( ) const
inline

The number of entries in the table.

This method has undefined behavior when erasable() is true.

Note that this is not a device function; it cannot be called in a parallel kernel. The value is not stored as a variable; it must be computed. m_size is a mutable cache of that value.

Definition at line 369 of file Kokkos_UnorderedMap.hpp.

◆ failed_insert()

template<typename Key , typename Value , typename Device = Kokkos::DefaultExecutionSpace, typename Hasher = pod_hash<std::remove_const_t<Key>>, typename EqualTo = pod_equal_to<std::remove_const_t<Key>>>
bool Kokkos::UnorderedMap< Key, Value, Device, Hasher, EqualTo >::failed_insert ( ) const
inline

The current number of failed insert() calls.

This is not a device function; it may not be called in a parallel kernel. The value is not stored as a variable; it must be computed.

Definition at line 383 of file Kokkos_UnorderedMap.hpp.

◆ capacity()

template<typename Key , typename Value , typename Device = Kokkos::DefaultExecutionSpace, typename Hasher = pod_hash<std::remove_const_t<Key>>, typename EqualTo = pod_equal_to<std::remove_const_t<Key>>>
KOKKOS_FORCEINLINE_FUNCTION size_type Kokkos::UnorderedMap< Key, Value, Device, Hasher, EqualTo >::capacity ( ) const
inline

The maximum number of entries that the table can hold.

This is a device function; it may be called in a parallel kernel.

Definition at line 419 of file Kokkos_UnorderedMap.hpp.

◆ hash_capacity()

template<typename Key , typename Value , typename Device = Kokkos::DefaultExecutionSpace, typename Hasher = pod_hash<std::remove_const_t<Key>>, typename EqualTo = pod_equal_to<std::remove_const_t<Key>>>
KOKKOS_INLINE_FUNCTION size_type Kokkos::UnorderedMap< Key, Value, Device, Hasher, EqualTo >::hash_capacity ( ) const
inline

The number of hash table "buckets.".

This is different than the number of entries that the table can hold. Each key hashes to an index in [0, hash_capacity() - 1]. That index can hold zero or more entries. This class decides what hash_capacity() should be, given the user's upper bound on the number of entries the table must be able to hold.

This is a device function; it may be called in a parallel kernel.

Definition at line 432 of file Kokkos_UnorderedMap.hpp.

◆ insert()

template<typename Key , typename Value , typename Device = Kokkos::DefaultExecutionSpace, typename Hasher = pod_hash<std::remove_const_t<Key>>, typename EqualTo = pod_equal_to<std::remove_const_t<Key>>>
KOKKOS_INLINE_FUNCTION insert_result Kokkos::UnorderedMap< Key, Value, Device, Hasher, EqualTo >::insert ( key_type const & k,
impl_value_type const & v = impl_value_type() ) const
inline

This is a device function; it may be called in a parallel kernel. As discussed in the class documentation, it need not succeed. The return value tells you if it did.

Parameters
k[in] The key to attempt to insert.
v[in] The corresponding value to attempt to insert. If using this class as a set (with Value = void), then you need not provide this value.

Definition at line 446 of file Kokkos_UnorderedMap.hpp.

◆ find()

template<typename Key , typename Value , typename Device = Kokkos::DefaultExecutionSpace, typename Hasher = pod_hash<std::remove_const_t<Key>>, typename EqualTo = pod_equal_to<std::remove_const_t<Key>>>
KOKKOS_INLINE_FUNCTION size_type Kokkos::UnorderedMap< Key, Value, Device, Hasher, EqualTo >::find ( const key_type & k) const
inline

Find the given key k, if it exists in the table.

Returns
If the key exists in the table, the index of the value corresponding to that key; otherwise, an invalid index.

This is a device function; it may be called in a parallel kernel.

Definition at line 626 of file Kokkos_UnorderedMap.hpp.

◆ exists()

template<typename Key , typename Value , typename Device = Kokkos::DefaultExecutionSpace, typename Hasher = pod_hash<std::remove_const_t<Key>>, typename EqualTo = pod_equal_to<std::remove_const_t<Key>>>
KOKKOS_INLINE_FUNCTION bool Kokkos::UnorderedMap< Key, Value, Device, Hasher, EqualTo >::exists ( const key_type & k) const
inline

Does the key exist in the map.

This is a device function; it may be called in a parallel kernel.

Definition at line 646 of file Kokkos_UnorderedMap.hpp.

◆ value_at()

template<typename Key , typename Value , typename Device = Kokkos::DefaultExecutionSpace, typename Hasher = pod_hash<std::remove_const_t<Key>>, typename EqualTo = pod_equal_to<std::remove_const_t<Key>>>
template<typename Dummy = value_type>
KOKKOS_FORCEINLINE_FUNCTION std::enable_if_t< !std::is_void< Dummy >::value, std::conditional_t< has_const_value, impl_value_type, impl_value_type & > > Kokkos::UnorderedMap< Key, Value, Device, Hasher, EqualTo >::value_at ( size_type i) const
inline

Get the value with i as its direct index.

Parameters
i[in] Index directly into the array of entries.

This is a device function; it may be called in a parallel kernel.

'const value_type' via Cuda texture fetch must return by value.

Definition at line 660 of file Kokkos_UnorderedMap.hpp.

◆ key_at()

template<typename Key , typename Value , typename Device = Kokkos::DefaultExecutionSpace, typename Hasher = pod_hash<std::remove_const_t<Key>>, typename EqualTo = pod_equal_to<std::remove_const_t<Key>>>
KOKKOS_FORCEINLINE_FUNCTION key_type Kokkos::UnorderedMap< Key, Value, Device, Hasher, EqualTo >::key_at ( size_type i) const
inline

Get the key with i as its direct index.

Parameters
i[in] Index directly into the array of entries.

This is a device function; it may be called in a parallel kernel.

Definition at line 672 of file Kokkos_UnorderedMap.hpp.


The documentation for this class was generated from the following file: