16#ifndef CABANA_GRID_SPARSE_INDEXSPACE_HPP
17#define CABANA_GRID_SPARSE_INDEXSPACE_HPP
19#ifdef KOKKOS_ENABLE_SYCL
20#error Not supported with the Kokkos SYCL backend (device recursion)
26#include <Kokkos_Core.hpp>
27#include <Kokkos_UnorderedMap.hpp>
64template <
typename Integer>
65KOKKOS_INLINE_FUNCTION
constexpr Integer
bitLength( Integer input_int )
noexcept
68 return bitLength( input_int >> 1 ) +
static_cast<Integer
>( 1 );
79template <
typename Integer>
80KOKKOS_INLINE_FUNCTION
constexpr Integer
bitCount( Integer input_int )
noexcept
92template <
typename Integer>
93KOKKOS_INLINE_FUNCTION
constexpr Integer
98 return ( ( input_int & 1 ) << loc ) |
108template <
typename Integer>
113 if ( input_int == 0 )
114 return sizeof( Integer ) * 8;
115 while ( ( input_int & 1 ) == 0 )
116 res++, input_int >>= 1;
127KOKKOS_INLINE_FUNCTION
128constexpr int bitPack(
const uint64_t mask,
const uint64_t data )
130 uint64_t slresult = 0;
131 uint64_t& ulresult{ slresult };
132 uint64_t uldata = data;
137 unsigned char lz{ 0 };
145 ulresult |= ( uldata & 1 );
149 ulresult <<= 64 - count;
151 return (
int)slresult;
161KOKKOS_INLINE_FUNCTION
162constexpr uint64_t
bitSpread(
const uint64_t mask,
const int data )
167 unsigned char lz{ 0 };
171 result = result << lz | ( dat & 1 );
172 dat >>= 1, rmask <<= lz;
181template <
typename Key, HashTypes HashT>
184template <
typename Key, HashTypes HashT>
194template <
typename Key>
200 static constexpr HashTypes hash_type = HashTypes::Naive;
205 std::copy( tnum.begin(), tnum.end(), _tile_num.data() );
206 _tile_num_j_mul_k = _tile_num[1] * _tile_num[2];
214 _tile_num_j_mul_k = j * k;
221 KOKKOS_INLINE_FUNCTION
222 Key operator()(
int tile_i,
int tile_j,
int tile_k )
const
224 return tile_i * _tile_num_j_mul_k + tile_j * _tile_num[2] + tile_k;
229 Kokkos::Array<int, 3> _tile_num;
230 int _tile_num_j_mul_k;
238template <
typename Key>
242 using tid_to_key_type = TileID2HashKey<Key, HashTypes::Morton>;
244 static constexpr HashTypes hash_type = HashTypes::Morton;
247 TileID2HashKey( std::initializer_list<int> tnum )
249 std::copy( tnum.begin(), tnum.end(), _tile_num.data() );
252 TileID2HashKey(
int i,
int j,
int k )
261 page_kmask = ( 0x9249249249249249UL ),
262 page_jmask = ( 0x2492492492492492UL ),
263 page_imask = ( 0x4924924924924924UL )
270 KOKKOS_INLINE_FUNCTION
271 Key operator()(
int tile_i,
int tile_j,
int tile_k )
const
280 Kokkos::Array<int, 3> _tile_num;
289template <
typename Key>
293 using key_to_tid_type = HashKey2TileID<Key, HashTypes::Naive>;
295 static constexpr HashTypes hash_type = HashTypes::Naive;
298 HashKey2TileID( std::initializer_list<int> tnum )
301 std::copy( tnum.begin(), tnum.end(), _tile_num.data() );
304 HashKey2TileID(
int i,
int j,
int k )
316 KOKKOS_INLINE_FUNCTION
317 void operator()( Key tile_key,
int& tile_i,
int& tile_j,
int& tile_k )
const
319 tile_k = tile_key % _tile_num[2];
320 tile_j =
static_cast<Key
>( tile_key / _tile_num[2] ) % _tile_num[1];
321 tile_i =
static_cast<Key
>( tile_key / _tile_num[2] / _tile_num[1] ) %
327 Kokkos::Array<int, 3> _tile_num;
335template <
typename Key>
339 using key_to_tid_type = HashKey2TileID<Key, HashTypes::Morton>;
341 static constexpr HashTypes hash_type = HashTypes::Morton;
344 HashKey2TileID( std::initializer_list<int> tnum )
346 std::copy( tnum.begin(), tnum.end(), _tile_num.data() );
349 HashKey2TileID(
int i,
int j,
int k )
358 page_kmask = ( 0x9249249249249249UL ),
359 page_jmask = ( 0x2492492492492492UL ),
360 page_imask = ( 0x4924924924924924UL )
368 KOKKOS_INLINE_FUNCTION
369 void operator()( Key tile_key,
int& tile_i,
int& tile_j,
int& tile_k )
const
371 tile_k =
bitPack( page_kmask, tile_key );
372 tile_j =
bitPack( page_jmask, tile_key );
373 tile_i =
bitPack( page_imask, tile_key );
378 Kokkos::Array<int, 3> _tile_num;
391template <
typename MemorySpace,
unsigned long long CBits,
392 unsigned long long CNumPerDim,
unsigned long long CNumPerTile,
393 HashTypes Hash,
typename Key,
typename Value>
397template <
int CBits,
int CNumPerDim,
int CNumPerTile>
408template <
typename MemorySpace,
unsigned long long CellPerTileDim = 4,
409 HashTypes Hash = HashTypes::Naive,
typename Key = uint64_t,
410 typename Value = uint64_t>
453 const unsigned int pre_alloc_size )
459 std::fill( _min.data(), _min.data() +
rank, 0 );
460 std::copy(
size.begin(),
size.end(), _max.data() );
470 KOKKOS_INLINE_FUNCTION
483 KOKKOS_INLINE_FUNCTION
486 _block_id_space.insert( tile_i, tile_j, tile_k );
493 KOKKOS_INLINE_FUNCTION
507 KOKKOS_INLINE_FUNCTION
509 const int tile_k )
const
512 return _block_id_space.find( tile_i, tile_j, tile_k );
519 KOKKOS_INLINE_FUNCTION
522 return _block_id_space.findKey( tile_key );
529 KOKKOS_INLINE_FUNCTION
533 auto tile_id =
queryTile( cell_i, cell_j, cell_k );
542 void clear() { _block_id_space.clear(); }
550 return _block_id_space.reserve(
capacity );
556 KOKKOS_INLINE_FUNCTION
557 uint32_t
capacity()
const {
return _block_id_space.capacity(); }
581 template <
typename T>
584 return _block_id_space.reservedTileNumHost( factor );
591 template <
typename T>
601 KOKKOS_INLINE_FUNCTION
604 return _block_id_space.valid_at( index );
611 KOKKOS_INLINE_FUNCTION
614 return _block_id_space.isValidKey( key );
621 KOKKOS_INLINE_FUNCTION
624 return _block_id_space.key_at( index );
631 KOKKOS_INLINE_FUNCTION
634 return _block_id_space.value_at( index );
642 KOKKOS_INLINE_FUNCTION
645 return _block_id_space.key2ijk( key, tile_i, tile_j, tile_k );
653 KOKKOS_INLINE_FUNCTION
656 return _block_id_space.ijk2key( tile_i, tile_j, tile_k );
664 KOKKOS_INLINE_FUNCTION
666 const int cell_k )
const
682 Kokkos::Array<int, rank> _min;
683 Kokkos::Array<int, rank> _max;
691template <
typename MemorySpace,
class Scalar,
692 unsigned long long CellPerTileDim = 4,
693 HashTypes Hash = HashTypes::Naive,
typename Key = uint64_t,
694 typename Value = uint64_t>
700 { global_mesh->globalNumCell( Dim::I ),
701 global_mesh->globalNumCell( Dim::J ),
702 global_mesh->globalNumCell( Dim::K ) },
717template <
typename MemorySpace,
unsigned long long CBits,
718 unsigned long long CNumPerDim,
unsigned long long CNumPerTile,
719 HashTypes Hash,
typename Key,
typename Value>
747 BlockMap(
const int size_x,
const int size_y,
const int size_z,
749 : _tile_table_info(
"hash_table_info" )
750 , _tile_table( size_x * size_y * size_z )
751 , _op_ijk2key( size_x, size_y, size_z )
752 , _op_key2ijk( size_x, size_y, size_z )
755 auto tile_table_info_mirror =
756 Kokkos::create_mirror_view( Kokkos::HostSpace(), _tile_table_info );
757 tile_table_info_mirror( 0 ) = 0;
758 tile_table_info_mirror( 1 ) = pre_alloc_size;
759 Kokkos::deep_copy( _tile_table_info, tile_table_info_mirror );
762 _block_size[0] = size_x;
763 _block_size[1] = size_y;
764 _block_size[2] = size_z;
774 auto tile_table_info_mirror = Kokkos::create_mirror_view_and_copy(
775 Kokkos::HostSpace(), _tile_table_info );
776 tile_table_info_mirror( 0 ) = 0;
777 Kokkos::deep_copy( _tile_table_info,
778 tile_table_info_mirror );
788 return _tile_table.rehash(
capacity );
794 KOKKOS_INLINE_FUNCTION
797 return _tile_table.capacity();
804 KOKKOS_INLINE_FUNCTION
807 return _tile_table.valid_at( index );
814 KOKKOS_INLINE_FUNCTION
817 return !( _tile_table.find( key ) == ~
static_cast<uint32_t
>( 0 ) );
824 KOKKOS_INLINE_FUNCTION
827 return _tile_table.key_at( index );
834 KOKKOS_INLINE_FUNCTION
837 return _tile_table.value_at( index );
843 KOKKOS_INLINE_FUNCTION
851 auto tile_table_info_mirror = Kokkos::create_mirror_view_and_copy(
852 Kokkos::HostSpace(), _tile_table_info );
853 return tile_table_info_mirror( 0 );
859 template <
typename T>
862 auto tile_table_info_mirror = Kokkos::create_mirror_view_and_copy(
863 Kokkos::HostSpace(), _tile_table_info );
864 value_type num = tile_table_info_mirror( 0 ) * factor;
865 tile_table_info_mirror( 1 ) = num;
866 Kokkos::deep_copy( _tile_table_info, tile_table_info_mirror );
874 KOKKOS_INLINE_FUNCTION
875 void insert(
int tile_i,
int tile_j,
int tile_k )
const
882 auto insert_result = _tile_table.insert( tile_key, 0 );
886 if ( !insert_result.existing() )
887 _tile_table.value_at( insert_result.index() ) =
888 Kokkos::atomic_fetch_add( &( _tile_table_info( 0 ) ), 1 );
895 KOKKOS_INLINE_FUNCTION
898 return _tile_table.value_at(
899 _tile_table.find(
ijk2key( tile_i, tile_j, tile_k ) ) );
906 KOKKOS_INLINE_FUNCTION
909 return _tile_table.value_at( _tile_table.find( tile_key ) );
916 KOKKOS_INLINE_FUNCTION
919 return _op_ijk2key( tile_i, tile_j, tile_k );
927 KOKKOS_INLINE_FUNCTION
930 return _op_key2ijk( key, tile_i, tile_j, tile_k );
935 Kokkos::View<int[2], MemorySpace> _tile_table_info;
937 Kokkos::Array<int, 3> _block_size;
939 Kokkos::UnorderedMap<key_type, value_type, MemorySpace> _tile_table;
954template <
int CBits,
int CNumPerDim,
int CNumPerTile>
972 template <
typename... Coords>
973 KOKKOS_INLINE_FUNCTION
static constexpr auto
976 return fromCoord<Coord2OffsetDim>( std::forward<Coords>( coords )... );
984 template <
typename Key,
typename... Coords>
985 KOKKOS_INLINE_FUNCTION
static constexpr void
988 toCoord<Offset2CoordDim>( std::forward<Key>( key ), coords... );
998 struct Coord2OffsetDim
1000 template <
typename Coord>
1001 KOKKOS_INLINE_FUNCTION
constexpr auto operator()(
int dim_no,
1005 uint64_t result =
static_cast<uint64_t
>( i );
1006 for (
int i = 0; i < dim_no; i++ )
1017 struct Offset2CoordDim
1019 template <
typename Coord,
typename Key>
1020 KOKKOS_INLINE_FUNCTION
constexpr auto operator()( Coord& i,
1034 template <
typename Func,
typename... Coords>
1035 KOKKOS_INLINE_FUNCTION
static constexpr auto fromCoord( Coords&&... coords )
1038 static_assert(
sizeof...( Coords ) ==
rank,
1039 "Dimension of coordinate mismatch" );
1040 using integer = std::common_type_t<Coords...>;
1041 static_assert( std::is_integral<integer>::value,
1042 "Coordinate should be integral type" );
1043 return fromCoordImpl<Func>( 0, coords... );
1054 template <
typename Func,
typename Key,
typename... Coords>
1055 KOKKOS_INLINE_FUNCTION
static constexpr void toCoord( Key&& key,
1058 static_assert(
sizeof...( Coords ) ==
rank,
1059 "Dimension of coordinate mismatch" );
1060 using integer = std::common_type_t<Coords...>;
1061 static_assert( std::is_integral<integer>::value,
1062 "Coordinate should be integral type" );
1063 return toCoordImpl<Func>( 0, std::forward<Key>( key ), coords... );
1071 template <
typename Func,
typename Coord>
1072 KOKKOS_INLINE_FUNCTION
static constexpr auto fromCoordImpl(
int&& dim_no,
1075 return Func()( dim_no, std::forward<Coord>( i ) );
1084 template <
typename Func,
typename Coord,
typename... Coords>
1085 KOKKOS_INLINE_FUNCTION
static constexpr auto
1086 fromCoordImpl(
int&& dim_no, Coord&& i, Coords&&... is )
1088 auto result = Func()( dim_no, std::forward<Coord>( i ) );
1089 if ( dim_no + 1 <
rank )
1090 result += fromCoordImpl<Func>( dim_no + 1,
1091 std::forward<Coords>( is )... );
1101 template <
typename Func,
typename Key,
typename Coord>
1102 KOKKOS_INLINE_FUNCTION
static constexpr void
1103 toCoordImpl(
int&& dim_no, Key&& key, Coord& i )
noexcept
1105 if ( dim_no <
rank )
1106 Func()( i, std::forward<Key>( key ) );
1116 template <
typename Func,
typename Key,
typename Coord,
typename... Coords>
1117 KOKKOS_INLINE_FUNCTION
static constexpr void
1118 toCoordImpl(
int&& dim_no, Key&& key, Coord& i, Coords&... is )
noexcept
1120 auto new_key = Func()( i, std::forward<Key>( key ) );
1121 if ( dim_no + 1 <
rank )
1122 toCoordImpl<Func>( dim_no + 1, new_key, is... );
1134template <std::size_t N,
unsigned long long cellBitsPerTileDim,
1135 typename std::enable_if_t<( N == 3 ),
bool> =
true>
1140 static constexpr std::size_t
Rank = N;
1163 const std::initializer_list<long>&
max )
1169 template <
typename... Params>
1171 :
IndexSpace<N>( std::forward<Params>( pars )... )
1176 KOKKOS_INLINE_FUNCTION
1180 KOKKOS_INLINE_FUNCTION
1184 KOKKOS_INLINE_FUNCTION
1188 KOKKOS_INLINE_FUNCTION
1192 KOKKOS_FORCEINLINE_FUNCTION
1196 KOKKOS_FORCEINLINE_FUNCTION
1200 template <
int NSD = N>
1201 KOKKOS_FORCEINLINE_FUNCTION std::enable_if_t<3 == NSD, bool>
1202 tileInRange(
const long tile_i,
const long tile_j,
const long tile_k )
const
1204 long index[N] = { tile_i, tile_j, tile_k };
1209 template <
int NSD = N>
1210 KOKKOS_FORCEINLINE_FUNCTION std::enable_if_t<3 == NSD, bool>
1211 cellInRange(
const long cell_i,
const long cell_j,
const long cell_k )
const
KOKKOS_INLINE_FUNCTION constexpr Integer bitCount(Integer input_int) noexcept
(Host/Device) Compute the lease bit number needed to index input integer
Definition Cabana_Grid_SparseIndexSpace.hpp:80
KOKKOS_INLINE_FUNCTION constexpr Integer binaryReverse(Integer input_int, char loc=sizeof(Integer) *8 - 1)
(Host/Device) Given a integer, reverse the corresponding binary string, return the resulting integer.
Definition Cabana_Grid_SparseIndexSpace.hpp:94
KOKKOS_INLINE_FUNCTION constexpr uint64_t bitSpread(const uint64_t mask, const int data)
(Host/Device) Spread out the data bits where the corresponding bit of the mask is 1
Definition Cabana_Grid_SparseIndexSpace.hpp:162
KOKKOS_INLINE_FUNCTION constexpr Integer bitLength(Integer input_int) noexcept
(Host/Device) Compute the least bit number/length needed to represent the given input integer
Definition Cabana_Grid_SparseIndexSpace.hpp:65
HashTypes
Hash table type tag.
Definition Cabana_Grid_SparseIndexSpace.hpp:49
KOKKOS_INLINE_FUNCTION constexpr int bitPack(const uint64_t mask, const uint64_t data)
(Host/Device) Pack up the data bits where the corresponding bit of the mask is 1
Definition Cabana_Grid_SparseIndexSpace.hpp:128
KOKKOS_INLINE_FUNCTION constexpr unsigned countLeadingZeros(Integer input_int)
(Host/Device) Count the leading zeros in the corresponding binary string of the input integer
Definition Cabana_Grid_SparseIndexSpace.hpp:109
SparseMap< MemorySpace, CellPerTileDim, Hash, Key, Value > createSparseMap(const std::shared_ptr< GlobalMesh< SparseMesh< Scalar > > > &global_mesh, int pre_alloc_size)
Creation function for SparseMap from GlobalMesh<SparseMesh>
Definition Cabana_Grid_SparseIndexSpace.hpp:695
Declaration of BlockMap.
Definition Cabana_Grid_SparseIndexSpace.hpp:721
KOKKOS_INLINE_FUNCTION value_type validTileNumDev() const
(Device) Valid tile number inside current block (MPI rank)
Definition Cabana_Grid_SparseIndexSpace.hpp:844
KOKKOS_INLINE_FUNCTION key_type key_at(uint32_t index) const
(Device) Get tile key at index.
Definition Cabana_Grid_SparseIndexSpace.hpp:825
BlockMap(const int size_x, const int size_y, const int size_z, const value_type pre_alloc_size)
(Host) Constructor
Definition Cabana_Grid_SparseIndexSpace.hpp:747
KOKKOS_INLINE_FUNCTION value_type find(int tile_i, int tile_j, int tile_k) const
(Device) Query the tile No. from the hash table
Definition Cabana_Grid_SparseIndexSpace.hpp:896
KOKKOS_INLINE_FUNCTION key_type ijk2key(int tile_i, int tile_j, int tile_k) const
(Device) Transfer tile ijk to tile hash key
Definition Cabana_Grid_SparseIndexSpace.hpp:917
Key key_type
Tile hash key type.
Definition Cabana_Grid_SparseIndexSpace.hpp:730
KOKKOS_INLINE_FUNCTION bool valid_at(uint32_t index) const
(Device) Valid tile at index.
Definition Cabana_Grid_SparseIndexSpace.hpp:805
KOKKOS_INLINE_FUNCTION value_type findKey(key_type tile_key) const
(Device) Query the tile No. from the hash table
Definition Cabana_Grid_SparseIndexSpace.hpp:907
static constexpr unsigned long long cell_num_per_tile_dim
Definition Cabana_Grid_SparseIndexSpace.hpp:726
BlockMap< MemorySpace, cell_bits_per_tile_dim, cell_num_per_tile_dim, cell_num_per_tile, hash_type, key_type, value_type > bis_Type
Self type.
Definition Cabana_Grid_SparseIndexSpace.hpp:736
KOKKOS_INLINE_FUNCTION bool isValidKey(key_type key) const
(Device) Check if the tile key is valid.
Definition Cabana_Grid_SparseIndexSpace.hpp:815
KOKKOS_INLINE_FUNCTION key_type value_at(uint32_t index) const
(Device) get block id value at index
Definition Cabana_Grid_SparseIndexSpace.hpp:835
value_type validTileNumHost() const
(Host) Valid tile number inside current block (MPI rank)
Definition Cabana_Grid_SparseIndexSpace.hpp:849
Value value_type
Tile number type.
Definition Cabana_Grid_SparseIndexSpace.hpp:732
bool reserve(const value_type capacity)
(Host) Set new capacity lower bound on the unordered map (Only for hash table, not for capacity of al...
Definition Cabana_Grid_SparseIndexSpace.hpp:786
static constexpr unsigned long long cell_num_per_tile
Definition Cabana_Grid_SparseIndexSpace.hpp:728
static constexpr HashTypes hash_type
Definition Cabana_Grid_SparseIndexSpace.hpp:734
value_type reservedTileNumHost(T factor) const
(Host) Reserved tile number inside current block (MPI rank)
Definition Cabana_Grid_SparseIndexSpace.hpp:860
KOKKOS_INLINE_FUNCTION void insert(int tile_i, int tile_j, int tile_k) const
(Device) Insert a tile into the hash table
Definition Cabana_Grid_SparseIndexSpace.hpp:875
KOKKOS_INLINE_FUNCTION void key2ijk(key_type &key, int &tile_i, int &tile_j, int &tile_k) const
(Device) Transfer tile hash key to tile ijk
Definition Cabana_Grid_SparseIndexSpace.hpp:928
KOKKOS_INLINE_FUNCTION uint32_t capacity() const
Definition Cabana_Grid_SparseIndexSpace.hpp:795
static constexpr unsigned long long cell_bits_per_tile_dim
Definition Cabana_Grid_SparseIndexSpace.hpp:724
void clear()
(Host) Clear tile hash table (Host, required by unordered map clear())
Definition Cabana_Grid_SparseIndexSpace.hpp:771
Global mesh partial specialization for uniform mesh.
Definition Cabana_Grid_GlobalMesh.hpp:49
Structured index space.
Definition Cabana_Grid_IndexSpace.hpp:37
KOKKOS_INLINE_FUNCTION bool inRange(const long index[N]) const
Determine if a set of indices is within the range of the index space.
Definition Cabana_Grid_IndexSpace.hpp:150
KOKKOS_INLINE_FUNCTION Kokkos::Array< long, Rank > max() const
Get the maximum indices in all dimensions.
Definition Cabana_Grid_IndexSpace.hpp:121
KOKKOS_INLINE_FUNCTION Kokkos::Array< long, Rank > min() const
Get the minimum indices in all dimensions.
Definition Cabana_Grid_IndexSpace.hpp:113
KOKKOS_INLINE_FUNCTION long size() const
Get the total size of the index space.
Definition Cabana_Grid_IndexSpace.hpp:140
IndexSpace()
Default constructor.
Definition Cabana_Grid_IndexSpace.hpp:43
Sparse index space, with a hierarchical structure (cell->tile->block)
Definition Cabana_Grid_SparseIndexSpace.hpp:412
KOKKOS_INLINE_FUNCTION value_type queryTileFromTileId(const int tile_i, const int tile_j, const int tile_k) const
(Device) Query the 1D tile key from the 3D tile ijk
Definition Cabana_Grid_SparseIndexSpace.hpp:508
MemorySpace memory_space
memory space
Definition Cabana_Grid_SparseIndexSpace.hpp:444
KOKKOS_INLINE_FUNCTION void key2ijk(key_type &key, int &tile_i, int &tile_j, int &tile_k) const
(Device) Transfer tile hash key to tile ijk
Definition Cabana_Grid_SparseIndexSpace.hpp:643
KOKKOS_INLINE_FUNCTION value_type queryTileFromTileKey(const key_type tile_key) const
(Device) Query the 1D tile key from the 1D tile key
Definition Cabana_Grid_SparseIndexSpace.hpp:520
void clear()
(Host) Clear tile hash table (required by unordered map clear())
Definition Cabana_Grid_SparseIndexSpace.hpp:542
KOKKOS_INLINE_FUNCTION value_type value_at(uint32_t index) const
(Device) get tile id value at index
Definition Cabana_Grid_SparseIndexSpace.hpp:632
value_type sizeCell() const
(Host) Valid cell number inside current block (MPI rank)
Definition Cabana_Grid_SparseIndexSpace.hpp:572
KOKKOS_INLINE_FUNCTION value_type queryCell(int cell_i, int cell_j, int cell_k) const
(Device) Query the 1D cell key from the 3D cell ijk
Definition Cabana_Grid_SparseIndexSpace.hpp:530
static constexpr unsigned long long cell_bits_per_tile
Number of bits (total) needed to index the cells inside a tile.
Definition Cabana_Grid_SparseIndexSpace.hpp:428
KOKKOS_INLINE_FUNCTION key_type key_at(uint32_t index) const
(Device) Get block key at index
Definition Cabana_Grid_SparseIndexSpace.hpp:622
KOKKOS_INLINE_FUNCTION bool valid_at(uint32_t index) const
(Device) Valid block at index
Definition Cabana_Grid_SparseIndexSpace.hpp:602
static constexpr unsigned long long cell_num_per_tile_dim
Definition Cabana_Grid_SparseIndexSpace.hpp:421
KOKKOS_INLINE_FUNCTION key_type ijk2key(int tile_i, int tile_j, int tile_k) const
(Device) Transfer tile ijk to til key
Definition Cabana_Grid_SparseIndexSpace.hpp:654
KOKKOS_INLINE_FUNCTION bool isValidKey(key_type key) const
(Device) Check if the tile key is valid.
Definition Cabana_Grid_SparseIndexSpace.hpp:612
static constexpr int rank
Number of dimensions, 3 = ijk.
Definition Cabana_Grid_SparseIndexSpace.hpp:415
value_type size() const
(Host) Valid tile number inside current block (MPI rank)
Definition Cabana_Grid_SparseIndexSpace.hpp:562
KOKKOS_INLINE_FUNCTION uint32_t capacity() const
(Host/Device) Require capacity of the index hash table
Definition Cabana_Grid_SparseIndexSpace.hpp:557
KOKKOS_INLINE_FUNCTION void insertCell(int cell_i, int cell_j, int cell_k) const
(Device) Insert a cell
Definition Cabana_Grid_SparseIndexSpace.hpp:471
static constexpr unsigned long long cell_num_per_tile
Number of cells (total) inside each tile.
Definition Cabana_Grid_SparseIndexSpace.hpp:435
KOKKOS_INLINE_FUNCTION value_type queryTile(int cell_i, int cell_j, int cell_k) const
(Device) Query the 1D tile key from the 3D cell ijk
Definition Cabana_Grid_SparseIndexSpace.hpp:494
Value value_type
Tile number type.
Definition Cabana_Grid_SparseIndexSpace.hpp:440
static constexpr unsigned long long cell_mask_per_tile_dim
Definition Cabana_Grid_SparseIndexSpace.hpp:425
value_type reservedCellSize(T factor) const
(Host) Reserved cell number inside current block (MPI rank)
Definition Cabana_Grid_SparseIndexSpace.hpp:592
SparseMap(const std::array< int, rank > size, const unsigned int pre_alloc_size)
(Host) Constructor
Definition Cabana_Grid_SparseIndexSpace.hpp:452
value_type sizeTile() const
(Host) Valid tile number inside current block (MPI rank)
Definition Cabana_Grid_SparseIndexSpace.hpp:567
static constexpr unsigned long long cell_mask_per_tile
Cell mask (combine all dimensions dimension)
Definition Cabana_Grid_SparseIndexSpace.hpp:432
static constexpr HashTypes hash_type
Hash table type.
Definition Cabana_Grid_SparseIndexSpace.hpp:442
KOKKOS_INLINE_FUNCTION void insertTile(int tile_i, int tile_j, int tile_k) const
(Device) Insert a tile (to hash table); Note that the tile ijk should be global
Definition Cabana_Grid_SparseIndexSpace.hpp:484
KOKKOS_INLINE_FUNCTION value_type cell_local_id(const int cell_i, const int cell_j, const int cell_k) const
(Device) Get local cell ID from cell IJK
Definition Cabana_Grid_SparseIndexSpace.hpp:665
Key key_type
Tile hash key type.
Definition Cabana_Grid_SparseIndexSpace.hpp:438
value_type reservedTileSize(T factor) const
(Host) Reserved tile number inside current block (MPI rank)
Definition Cabana_Grid_SparseIndexSpace.hpp:582
static constexpr unsigned long long cell_bits_per_tile_dim
Number of bits (per dimension) needed to index the cells inside a tile.
Definition Cabana_Grid_SparseIndexSpace.hpp:417
bool reserve(const value_type capacity)
(Host) Set new capacity lower bound on the unordered map
Definition Cabana_Grid_SparseIndexSpace.hpp:548
KOKKOS_FORCEINLINE_FUNCTION long sizeTile() const
Get the total number of tiles of the index space.
Definition Cabana_Grid_SparseIndexSpace.hpp:1193
TileIndexSpace()
brief Default constructor.
Definition Cabana_Grid_SparseIndexSpace.hpp:1150
static constexpr std::size_t Rank
Definition Cabana_Grid_SparseIndexSpace.hpp:1140
KOKKOS_FORCEINLINE_FUNCTION std::enable_if_t< 3==NSD, bool > cellInRange(const long cell_i, const long cell_j, const long cell_k) const
Determine if given cell indices is within the range of the index space.
Definition Cabana_Grid_SparseIndexSpace.hpp:1211
TileIndexSpace(Params &&... pars)
Other constructors.
Definition Cabana_Grid_SparseIndexSpace.hpp:1170
TileIndexSpace(const std::initializer_list< long > &min, const std::initializer_list< long > &max)
Other constructors.
Definition Cabana_Grid_SparseIndexSpace.hpp:1162
KOKKOS_INLINE_FUNCTION Kokkos::Array< long, Rank > max() const
Get the maximum indices in all dimensions.
Definition Cabana_Grid_SparseIndexSpace.hpp:1189
KOKKOS_INLINE_FUNCTION long max(const long dim) const
Definition Cabana_Grid_SparseIndexSpace.hpp:1181
KOKKOS_INLINE_FUNCTION long min(const long dim) const
Definition Cabana_Grid_SparseIndexSpace.hpp:1177
static constexpr unsigned long long cell_num_per_tile
Definition Cabana_Grid_SparseIndexSpace.hpp:1146
static constexpr unsigned long long cell_bits_per_tile_dim
Definition Cabana_Grid_SparseIndexSpace.hpp:1143
KOKKOS_FORCEINLINE_FUNCTION long sizeCell() const
Get the total number of cells of the index space.
Definition Cabana_Grid_SparseIndexSpace.hpp:1197
KOKKOS_INLINE_FUNCTION Kokkos::Array< long, Rank > min() const
Get the minimum indices in all dimensions.
Definition Cabana_Grid_SparseIndexSpace.hpp:1185
TileIndexSpace(const std::initializer_list< long > &size)
Other constructors.
Definition Cabana_Grid_SparseIndexSpace.hpp:1156
KOKKOS_FORCEINLINE_FUNCTION std::enable_if_t< 3==NSD, bool > tileInRange(const long tile_i, const long tile_j, const long tile_k) const
Determine if given tile indices is within the range of the index space.
Definition Cabana_Grid_SparseIndexSpace.hpp:1202
Declaration of TileMap.
Definition Cabana_Grid_SparseIndexSpace.hpp:956
static KOKKOS_INLINE_FUNCTION constexpr auto coordToOffset(Coords &&... coords) -> uint64_t
Cell ijk <=> Cell Id.
Definition Cabana_Grid_SparseIndexSpace.hpp:974
static constexpr int cell_num_per_tile_dim
Number of cells (per dimension) inside each tile.
Definition Cabana_Grid_SparseIndexSpace.hpp:961
static constexpr int cell_bits_per_tile_dim
Number of bits (per dimension) needed to index the cells inside a tile.
Definition Cabana_Grid_SparseIndexSpace.hpp:959
static constexpr int cell_num_per_tile
Number of cells (total) inside each tile.
Definition Cabana_Grid_SparseIndexSpace.hpp:963
static KOKKOS_INLINE_FUNCTION constexpr void offsetToCoord(Key &&key, Coords &... coords)
(Host/Device) Compute from offset to coordinates
Definition Cabana_Grid_SparseIndexSpace.hpp:986
static constexpr int rank
Indexing dimension, currently only serves 3D representations.
Definition Cabana_Grid_SparseIndexSpace.hpp:965
Core: particle data structures and algorithms.
Definition Cabana_AoSoA.hpp:36
Definition Cabana_Grid_SparseIndexSpace.hpp:185
Sparse mesh tag.
Definition Cabana_Grid_Types.hpp:253
Definition Cabana_Grid_SparseIndexSpace.hpp:182