A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://kokkos.github.io/kokkos-core-wiki/API/containers/Unordered-Map.html below:

UnorderedMap - Kokkos documentation

UnorderedMap

Header file: <Kokkos_UnorderedMap.hpp>

Kokkos’s unordered map is designed to efficiently handle tens of thousands of concurrent insertions. Consequently, the API is significantly different from the standard unordered_map. The two key differences are fixed capacity and index based.

Description
template<typename Key, typename Value, typename Device = Kokkos::DefaultExecutionSpace>
class UnorderedMap
Template Parameters:
  • Key – Must be a POD (Plain Old Data type)

  • Value

    void indicates an unordered set. Otherwise the Value must be trivially copyable. If the map is created with the SequentialHostInit property, Value can be View.

    Changed in version 4.7: Value can now be View

  • Device – Device is any class or struct with the following public typedefs or type aliases: execution_space, memory_space, and device_type

Constructor

UnorderedMap(uint32_t capacity_hint);

Create map with enough space for at least capacity_hint number of objects

UnorderedMap(const ALLOC_PROP &prop, uint32_t capacity_hint);

Create map using the properties with enough space for at least capacity_hint number of objects

Added in version 4.2.

Changed in version 4.7: prop can now contain SequentialHostInit

Public Member Functions

clear();

Clear the map

bool rehash(uint32_t requested_capacity);

Rehash map to given capacity, the current size is used as a lower bound O(capacity)

uint32_t size() const;

Current size of the map, O(capacity)

KOKKOS_INLINE_FUNCTION uint32_t capacity() const;

Capacity of the map, O(1)

KOKKOS_INLINE_FUNCTION UnorderedMapInsertResult insert(key) const;

Insert the given key into the map with a default constructed value

KOKKOS_INLINE_FUNCTION UnorderedMapInsertResult insert(Key key, Value value, Insert op = NoOp) const;

Insert the given key/value pair into the map and optionally specify the operator, op, used for combining values if key already exists

KOKKOS_INLINE_FUNCTION uint32_t find(Key key) const

Return the index of the key if it exist, otherwise return invalid_index

KOKKOS_INLINE_FUNCTION bool exists(Key key) const;

Does the key exist in the map

KOKKOS_INLINE_FUNCTION bool valid_at(uint32_t index) const;

Is the current index a valid key/value pair

KOKKOS_INLINE_FUNCTION Key key_at(uint32_t index) const;

Return the current key at the index

KOKKOS_INLINE_FUNCTION Value value_at(uint32_t index) const;

Return the current value at the index

KOKKOS_INLINE_FUNCTION constexpr bool is_allocated() const;

Return true if the internal views (keys, values, hashmap) are allocated

create_copy_view(UnorderedMap<SKey, SValue, SDevice, Hasher, EqualTo> const &src);

For the calling UnorderedMap, allocate views to have the same capacity as src, and copy data from src.

allocate_view(UnorderedMap<SKey, SValue, SDevice, Hasher, EqualTo> const &src);

Allocate views of the calling UnorderedMap to have the same capacity as src.

deep_copy_view(UnorderedMap<SKey, SValue, SDevice, Hasher, EqualTo> const &src);

Copy data from src to the calling UnorderedMap.

Non-Member Functions

inline void deep_copy(UnorderedMap<DKey, DT, DDevice, Hasher, EqualTo> &dst, const UnorderedMap<SKey, ST, SDevice, Hasher, EqualTo> &src);

Copy an UnorderedMap from src to dst.

Warning

From Kokkos 4.4, src.capacity() == dst.capacity() is required

UnorderedMap<Key, ValueType, Device, Hasher, EqualTo>::HostMirror create_mirror(const UnorderedMap<Key, ValueType, Device, Hasher, EqualTo> &src);

Create a HostMirror for an UnorderedMap.

class UnorderedMapInsertResult

Public Methods

KOKKOS_INLINE_FUNCTION bool success() const;

Was the key/value pair successfully inserted into the map

KOKKOS_INLINE_FUNCTION bool existing() const;

Is the key already present in the map

KOKKOS_INLINE_FUNCTION bool failed() const;

Did the insert fail?

KOKKOS_INLINE_FUNCTION uint32_t index() const;

Index where the key exists in the map as long as failed() == false

template<class ValueTypeView, class ValuesIdxType>
struct UnorderedMapInsertOpTypes
Template Parameters:
  • ValueTypeView – The UnorderedMap value array type.

  • ValuesIdxType – The index type for lookups in the value array.

Public Insertion Operator Types

struct NoOp

Insert the given key/value pair into the map

struct AtomicAdd

Duplicate key insertions sum values together.

Insertion using default UnorderedMapInsertOpTypes::NoOp

There are 3 potential states for every insertion which are reported by the UnorderedMapInsertResult:

// use the default NoOp insert operation
using map_op_type = Kokkos::UnorderedMapInsertOpTypes<value_view_type, size_type>;
using noop_type   = typename map_op_type::NoOp;
noop_type noop;
parallel_for(N, KOKKOS_LAMBDA (uint32_t i) {
  map.insert(i, values(i), noop);
});
// OR;
parallel_for(N, KOKKOS_LAMBDA (uint32_t i) {
  map.insert(i, values(i));
});
Insertion using UnorderedMapInsertOpTypes::AtomicAdd

The behavior from Insertion using default UnorderedMapInsertOpTypes::NoOp holds true with the exception that the UnorderedMapInsertResult:

// use the AtomicAdd insert operation
using map_op_type     = Kokkos::UnorderedMapInsertOpTypes<value_view_type, size_type>;
using atomic_add_type = typename map_op_type::AtomicAdd;
atomic_add_type atomic_add;
parallel_for(N, KOKKOS_LAMBDA (uint32_t i) {
  map.insert(i, values(i), atomic_add);
});
Iteration

Iterating over Kokkos’ UnorderedMap is different from iterating over a standard container. The pattern is to iterate over the capacity of the map and check if the current index is valid.

Example
// assume umap is an existing Kokkos::UnorderedMap
parallel_for(umap.capacity(), KOKKOS_LAMBDA (uint32_t i) {
    if( umap.valid_at(i) ) {
        auto key   = umap.key_at(i);
        auto value = umap.value_at(i);
        ...
    }
});

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4