Kokkos Core Kernels Package
Version of the Day
|
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 |
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:
INSERT_FAILED
: The insert failed. This usually means that the UnorderedMap ran out of space. INSERT_SUCCESS
: The insert succeeded, and the key did not exist in the table before. 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. Key | Type 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. |
Value | Type 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. |
Device | The Kokkos Device type. |
Hasher | Definition of the hash function for instances of Key . The default will calculate a bitwise hash. |
EqualTo | Definition 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.
|
inline |
Constructor.
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.
|
inline |
Clear all entries in the table.
Definition at line 344 of file Kokkos_UnorderedMap.hpp.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
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.
|
inline |
Find the given key k
, if it exists in the table.
This is a device function; it may be called in a parallel kernel.
Definition at line 646 of file Kokkos_UnorderedMap.hpp.
|
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.
|
inline |
Get the value with i
as its direct index.
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.
|
inline |
Get the key with i
as its direct index.
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.