16#include <TRUSTTravPool.h>
17#include <TRUSTArray.h>
18#include <unordered_map>
23#include <EntreeSortie.h>
25#include <DeviceMemory.h>
33template<
typename _TYPE_>
36 using ptr_t = std::shared_ptr<typename TRUSTArray<_TYPE_,int>::Vector_>;
38 using pool_t = std::unordered_map<size_t, list_t>;
93template<
typename _TYPE_>
99 auto it = ze_pool.find(sz);
100 if (it == ze_pool.end())
102 auto pr = ze_pool.emplace(sz, lst_t());
104 return pr.first->second;
118template<
typename _TYPE_>
129 lst_t& lst = GetOrCreateList<_TYPE_>(sz);
134 ptr_t ret = lst.back();
146 return std::make_shared<vec_t>(vec_t(sz));
169template<
typename _TYPE_>
172 assert(p !=
nullptr);
173 assert(p->size() > 0);
176 bool first_strategy =
true;
185 std::copy(p->begin(), p->end(), new_blk->begin());
206template<
typename _TYPE_>
211 assert(p !=
nullptr);
212 size_t sz = p->size();
216 lst_t& lst = GetOrCreateList<_TYPE_>(sz);
241template<
typename _TYPE_>
249 for(
const auto & kv: ze_pool)
251 size_t size = kv.first;
252 const lst_t& lst = kv.second;
253 for (
auto& mem : lst)
255 _TYPE_* ptr = mem->data();
256 if(isAllocatedOnDevice(ptr))
257 deleteOnDevice(ptr, (
int)size);
267template<
typename _TYPE_>
271 Cerr <<
"TRUSTTravPool stats are only available in debug mode for performance reasons!!" << finl;
276 Cerr <<
"Total requested (MB): " << (double)pi::req_sz_ / (1024.0 * 1024.0) << finl;
277 Cerr <<
"Total allocated (MB): " << (double)pi::actual_sz_ / (1024.0 * 1024.0) << finl;
278 Cerr <<
"Number of blocks in the pool: " << pi::num_items_ << finl;
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
std::vector< _TYPE_, TVAlloc< _TYPE_ > > Vector_
Pool of memory blocks used when requesting temporary storage (Trav arrays).
static void ClearPool()
Empty the TRUSTTrav pool explicitely.
static block_ptr_t GetFreeBlock(int sz)
Retrieve a free block of size sz.
static void ReleaseBlock(block_ptr_t)
Release a block.
static void PrintStats()
Debug method printing useful stats.
static block_ptr_t ResizeBlock(block_ptr_t p, int new_sz)
"Resize" a temporary Trav block - two possible strategies: Strategy 1
std::shared_ptr< std::vector< _TYPE_, TVAlloc< _TYPE_ > > > block_ptr_t
The shared pools of memory - visibility: here only.
std::shared_ptr< typename TRUSTArray< _TYPE_, int >::Vector_ > ptr_t
std::unordered_map< size_t, list_t > pool_t
static size_t actual_sz_
Actual alloc performed:
static int num_items_
Total number of blocks in the pool:
static size_t req_sz_
Total allocation requests:
std::list< ptr_t > list_t
static pool_t Free_blocks_
A pool is a map of lists: