Kokkos Core Kernels Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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

Public member functions
 UnorderedMap ()
 
 UnorderedMap (size_type capacity_hint, hasher_type hasher=hasher_type(), equal_to_type equal_to=equal_to_type())
 Constructor. More...
 
void reset_failed_insert_flag ()
 
histogram_type get_histogram ()
 
void clear ()
 Clear all entries in the table. More...
 
bool rehash (size_type requested_capacity=0)
 Change the capacity of the the map. More...
 
bool rehash (size_type requested_capacity, bool bounded_insert)
 
size_type size () const
 The number of entries in the table. More...
 
bool failed_insert () const
 The current number of failed insert() calls. More...
 
bool erasable () const
 
bool begin_erase ()
 
bool end_erase ()
 
KOKKOS_FORCEINLINE_FUNCTION
size_type 
capacity () const
 The maximum number of entries that the table can hold. More...
 
KOKKOS_INLINE_FUNCTION size_type hash_capacity () const
 The number of hash table "buckets.". More...
 
KOKKOS_INLINE_FUNCTION
insert_result 
insert (key_type const &k, impl_value_type const &v=impl_value_type()) const
 
KOKKOS_INLINE_FUNCTION bool erase (key_type const &k) const
 
KOKKOS_INLINE_FUNCTION size_type find (const key_type &k) const
 Find the given key k, if it exists in the table. More...
 
KOKKOS_INLINE_FUNCTION bool exists (const key_type &k) const
 Does the key exist in the map. More...
 
KOKKOS_FORCEINLINE_FUNCTION
Impl::if_c< (is_set||has_const_value),
impl_value_type,
impl_value_type & >::type 
value_at (size_type i) const
 Get the value with i as its direct index. More...
 
KOKKOS_FORCEINLINE_FUNCTION
key_type 
key_at (size_type i) const
 Get the key with i as its direct index. More...
 
KOKKOS_FORCEINLINE_FUNCTION bool valid_at (size_type i) const
 
template<typename SKey , typename SValue >
 UnorderedMap (UnorderedMap< SKey, SValue, Device, Hasher, EqualTo > const &src, typename Impl::enable_if< Impl::UnorderedMapCanAssign< declared_key_type, declared_value_type, SKey, SValue >::value, int >::type=0)
 
template<typename SKey , typename SValue >
Impl::enable_if
< Impl::UnorderedMapCanAssign
< declared_key_type,
declared_value_type, SKey,
SValue >::value,declared_map_type & >
::type 
operator= (UnorderedMap< SKey, SValue, Device, Hasher, EqualTo > const &src)
 
template<typename SKey , typename SValue , typename SDevice >
Impl::enable_if< std::is_same
< typename Impl::remove_const
< SKey >::type, key_type >
::value &&std::is_same
< typename Impl::remove_const
< SValue >::type, value_type >
::value >::type 
create_copy_view (UnorderedMap< SKey, SValue, SDevice, Hasher, EqualTo > const &src)
 

Public types and constants

typedef Key declared_key_type
 
typedef Impl::remove_const
< declared_key_type >::type 
key_type
 
typedef Impl::add_const
< key_type >::type 
const_key_type
 
typedef Value declared_value_type
 
typedef Impl::remove_const
< declared_value_type >::type 
value_type
 
typedef Impl::add_const
< value_type >::type 
const_value_type
 
typedef Device device_type
 
typedef Device::execution_space execution_space
 
typedef Hasher hasher_type
 
typedef EqualTo equal_to_type
 
typedef uint32_t size_type
 
typedef UnorderedMap
< declared_key_type,
declared_value_type,
device_type, hasher_type,
equal_to_type > 
declared_map_type
 
typedef UnorderedMap< key_type,
value_type, device_type,
hasher_type, equal_to_type > 
insertable_map_type
 
typedef UnorderedMap
< const_key_type, value_type,
device_type, hasher_type,
equal_to_type > 
modifiable_map_type
 
typedef UnorderedMap
< const_key_type,
const_value_type, device_type,
hasher_type, equal_to_type > 
const_map_type
 
typedef UnorderedMapInsertResult insert_result
 
typedef UnorderedMap< Key,
Value, host_mirror_space,
Hasher, EqualTo > 
HostMirror
 
typedef
Impl::UnorderedMapHistogram
< const_map_type
histogram_type
 
static const bool is_set = std::is_same<void,value_type>::value
 
static const bool has_const_key = std::is_same<const_key_type,declared_key_type>::value
 
static const bool has_const_value = is_set || std::is_same<const_value_type,declared_value_type>::value
 
static const bool is_insertable_map = !has_const_key && (is_set || !has_const_value)
 
static const bool is_modifiable_map = has_const_key && !has_const_value
 
static const bool is_const_map = has_const_key && has_const_value
 

Detailed Description

template<typename Key, typename Value, typename Device = Kokkos::DefaultExecutionSpace, typename Hasher = pod_hash<typename Impl::remove_const<Key>::type>, typename EqualTo = pod_equal_to<typename Impl::remove_const<Key>::type>>
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 215 of file Kokkos_UnorderedMap.hpp.

Constructor & Destructor Documentation

template<typename Key , typename Value , typename Device = Kokkos::DefaultExecutionSpace, typename Hasher = pod_hash<typename Impl::remove_const<Key>::type>, typename EqualTo = pod_equal_to<typename Impl::remove_const<Key>::type>>
Kokkos::UnorderedMap< Key, Value, Device, Hasher, EqualTo >::UnorderedMap ( size_type  capacity_hint,
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 313 of file Kokkos_UnorderedMap.hpp.

Member Function Documentation

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

Clear all entries in the table.

Definition at line 344 of file Kokkos_UnorderedMap.hpp.

template<typename Key , typename Value , typename Device = Kokkos::DefaultExecutionSpace, typename Hasher = pod_hash<typename Impl::remove_const<Key>::type>, typename EqualTo = pod_equal_to<typename Impl::remove_const<Key>::type>>
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 377 of file Kokkos_UnorderedMap.hpp.

template<typename Key , typename Value , typename Device = Kokkos::DefaultExecutionSpace, typename Hasher = pod_hash<typename Impl::remove_const<Key>::type>, typename EqualTo = pod_equal_to<typename Impl::remove_const<Key>::type>>
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.

Definition at line 411 of file Kokkos_UnorderedMap.hpp.

template<typename Key , typename Value , typename Device = Kokkos::DefaultExecutionSpace, typename Hasher = pod_hash<typename Impl::remove_const<Key>::type>, typename EqualTo = pod_equal_to<typename Impl::remove_const<Key>::type>>
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 426 of file Kokkos_UnorderedMap.hpp.

template<typename Key , typename Value , typename Device = Kokkos::DefaultExecutionSpace, typename Hasher = pod_hash<typename Impl::remove_const<Key>::type>, typename EqualTo = pod_equal_to<typename Impl::remove_const<Key>::type>>
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 465 of file Kokkos_UnorderedMap.hpp.

template<typename Key , typename Value , typename Device = Kokkos::DefaultExecutionSpace, typename Hasher = pod_hash<typename Impl::remove_const<Key>::type>, typename EqualTo = pod_equal_to<typename Impl::remove_const<Key>::type>>
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 479 of file Kokkos_UnorderedMap.hpp.

template<typename Key , typename Value , typename Device = Kokkos::DefaultExecutionSpace, typename Hasher = pod_hash<typename Impl::remove_const<Key>::type>, typename EqualTo = pod_equal_to<typename Impl::remove_const<Key>::type>>
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 495 of file Kokkos_UnorderedMap.hpp.

template<typename Key , typename Value , typename Device = Kokkos::DefaultExecutionSpace, typename Hasher = pod_hash<typename Impl::remove_const<Key>::type>, typename EqualTo = pod_equal_to<typename Impl::remove_const<Key>::type>>
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 646 of file Kokkos_UnorderedMap.hpp.

template<typename Key , typename Value , typename Device = Kokkos::DefaultExecutionSpace, typename Hasher = pod_hash<typename Impl::remove_const<Key>::type>, typename EqualTo = pod_equal_to<typename Impl::remove_const<Key>::type>>
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 664 of file Kokkos_UnorderedMap.hpp.

template<typename Key , typename Value , typename Device = Kokkos::DefaultExecutionSpace, typename Hasher = pod_hash<typename Impl::remove_const<Key>::type>, typename EqualTo = pod_equal_to<typename Impl::remove_const<Key>::type>>
KOKKOS_FORCEINLINE_FUNCTION Impl::if_c< (is_set || has_const_value), impl_value_type, impl_value_type &>::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 680 of file Kokkos_UnorderedMap.hpp.

template<typename Key , typename Value , typename Device = Kokkos::DefaultExecutionSpace, typename Hasher = pod_hash<typename Impl::remove_const<Key>::type>, typename EqualTo = pod_equal_to<typename Impl::remove_const<Key>::type>>
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 692 of file Kokkos_UnorderedMap.hpp.


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