12#ifdef MOOSE_KOKKOS_SCOPE
13#include "Kokkos_Functional.hpp"
25#ifdef MOOSE_KOKKOS_SCOPE
34KOKKOS_FUNCTION uint32_t
37 return ::Kokkos::pod_hash<T>()(key, seed);
40template <
typename T1,
typename T2>
46template <
typename T1,
typename T2>
47KOKKOS_FUNCTION uint32_t
54template <
typename T1,
typename T2,
typename index_type,
template <
typename...>
class MapType>
57template <
typename T1,
typename T2,
typename index_type,
template <
typename...>
class MapType>
58void dataStore(std::ostream & stream, MapBase<T1, T2, index_type, MapType> & map,
void * context);
59template <
typename T1,
typename T2,
typename index_type,
template <
typename...>
class MapType>
60void dataLoad(std::istream & stream, MapBase<T1, T2, index_type, MapType> & map,
void * context);
67template <
typename T1,
typename T2,
typename index_type,
template <
typename...>
class MapType>
90 auto end()
const {
return get().cend(); }
98 _map_host = std::make_shared<MapType<T1, T2>>();
109 _map_host = std::make_shared<MapType<T1, T2>>();
124#ifdef MOOSE_KOKKOS_SCOPE
143 KOKKOS_FUNCTION index_type
size()
const
145 KOKKOS_IF_ON_HOST(
return get().
size();)
154 KOKKOS_FUNCTION index_type
find(
const T1 &
key)
const;
166 KOKKOS_FUNCTION
const T1 &
key(index_type idx)
const
177 KOKKOS_FUNCTION
const T2 &
value(index_type idx)
const
191 KOKKOS_IF_ON_HOST(
return get().at(
key);)
207 static constexpr index_type
invalid_id = std::numeric_limits<index_type>::max();
210#ifdef MOOSE_KOKKOS_SCOPE
235 friend void dataStore<T1, T2, index_type, MapType>(std::ostream &,
238 friend void dataLoad<T1, T2, index_type, MapType>(std::istream &,
243template <
typename T1,
typename T2,
typename index_type,
template <
typename...>
class MapType>
254#ifdef MOOSE_KOKKOS_SCOPE
255template <
typename T1,
typename T2,
typename index_type,
template <
typename...>
class MapType>
259 _keys.create(size());
260 _values.create(size());
261 _offset.create(size() + 1);
264 for (
const auto & [key, value] : get())
266 auto bucket =
hashKey(key) % size();
271 std::exclusive_scan(_offset.begin(), _offset.end(), _offset.begin(), index_type(0));
273 _offset.copyToDevice();
275 std::vector<index_type> idx(size(), 0);
277 for (
const auto & [key, value] : get())
279 auto bucket =
hashKey(key) % size();
281 _keys[_offset[bucket] + idx[bucket]] = key;
282 _values[_offset[bucket] + idx[bucket]] = value;
287template <
typename T1,
typename T2,
typename index_type,
template <
typename...>
class MapType>
293 _keys.copyToDevice();
294 _values.copyToDevice();
297template <
typename T1,
typename T2,
typename index_type,
template <
typename...>
class MapType>
303 _keys.copyToDeviceNested();
304 _values.copyToDeviceNested();
307template <
typename T1,
typename T2,
typename index_type,
template <
typename...>
class MapType>
311 get().swap(map.
get());
312 _keys.swap(map.
_keys);
317template <
typename T1,
typename T2,
typename index_type,
template <
typename...>
class MapType>
318KOKKOS_FUNCTION index_type
324 auto bucket =
hashKey(key) % size();
325 auto begin = _offset[bucket];
326 auto end = _offset[bucket + 1];
328 for (index_type i = begin; i < end; ++i)
335template <
typename T1,
typename T2,
typename index_type,
template <
typename...>
class MapType>
347template <
typename T1,
typename T2,
typename index_type,
template <
typename...>
class MapType>
360template <
typename T1,
typename T2,
typename index_type = MOOSE_KOKKOS_INDEX_TYPE>
363template <
typename T1,
typename T2,
typename index_type = MOOSE_KOKKOS_INDEX_TYPE>
KOKKOS_FUNCTION index_type size() const
Get the total array size.
The Kokkos wrapper class for standard map.
KOKKOS_FUNCTION index_type size() const
Get the size of map.
auto begin()
Get the beginning writeable iterator of the host map.
void copyToDeviceNested()
Copy host map to device, perform nested copy for Kokkos arrays.
void clear()
Clear the underlying data.
auto & get()
Get the underlying writeable host map.
const auto & get() const
Get the underlying const host map.
KOKKOS_FUNCTION const T1 & key(index_type idx) const
Get the key of an index.
KOKKOS_FUNCTION const T2 & operator[](const T1 &key) const
Get the value corresponding to a key.
Array< index_type, 1, index_type > _offset
Beginning offset into device arrays of each bucket.
void copyToDevice()
Copy host map to device.
Array< T2, 1, index_type > _values
Values on device.
KOKKOS_FUNCTION index_type find(const T1 &key) const
Find the index of a key.
Array< T1, 1, index_type > _keys
Keys on device.
static constexpr index_type invalid_id
KOKKOS_FUNCTION bool exists(const T1 &key) const
Get whether a key exists.
auto begin() const
Get the beginning const iterator of the host map.
KOKKOS_FUNCTION const T2 & value(index_type idx) const
Get the value of an index.
T2 & operator[](const T1 &key)
Call host map's operator[].
KOKKOS_FUNCTION const T2 & operator()(const T1 &key) const
auto end()
Get the end writeable iterator of the host map.
std::shared_ptr< MapType< T1, T2 > > _map_host
Standard map on host Stored as a shared pointer to avoid deep copy.
auto end() const
Get the end const iterator of the host map.
void copy()
Internal method to copy host map to device.
void swap(MapBase< T1, T2, index_type, MapType > &map)
Swap with another Kokkos map.
void dataLoad(std::istream &stream, Array< T, dimension, index_type, layout > &array, void *context)
KOKKOS_FUNCTION uint32_t hashKey(const T &key, uint32_t seed=0)
Hash a key for the device hash table using the MurmurHash3 implementation of Kokkos,...
void dataStore(std::ostream &stream, Array< T, dimension, index_type, layout > &array, void *context)