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>;
91template<
typename _TYPE_>
97 auto it = ze_pool.find(sz);
98 if (it == ze_pool.end())
100 auto pr = ze_pool.emplace(sz, lst_t());
102 return pr.first->second;
114template<
typename _TYPE_>
125 lst_t& lst = GetOrCreateList<_TYPE_>(sz);
130 ptr_t ret = lst.back();
142 return std::make_shared<vec_t>(vec_t(sz));
163template<
typename _TYPE_>
166 assert(p !=
nullptr);
167 assert(p->size() > 0);
170 bool first_strategy =
true;
179 std::copy(p->begin(), p->end(), new_blk->begin());
199template<
typename _TYPE_>
204 assert(p !=
nullptr);
205 size_t sz = p->size();
209 lst_t& lst = GetOrCreateList<_TYPE_>(sz);
234template<
typename _TYPE_>
242 for(
const auto & kv: ze_pool)
244 size_t size = kv.first;
245 const lst_t& lst = kv.second;
246 for (
auto& mem : lst)
248 _TYPE_* ptr = mem->data();
249 if(isAllocatedOnDevice(ptr))
250 deleteOnDevice(ptr, (
int)size);
260template<
typename _TYPE_>
264 Cerr <<
"TRUSTTravPool stats are only available in debug mode for performance reasons!!" << finl;
269 Cerr <<
"Total requested (MB): " << (double)pi::req_sz_ / (1024.0 * 1024.0) << finl;
270 Cerr <<
"Total allocated (MB): " << (double)pi::actual_sz_ / (1024.0 * 1024.0) << finl;
271 Cerr <<
"Number of blocks in the pool: " << pi::num_items_ << finl;
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
std::vector< _TYPE_, TVAlloc< _TYPE_ > > Vector_
static block_ptr_t GetFreeBlock(int sz)
static void ReleaseBlock(block_ptr_t)
static block_ptr_t ResizeBlock(block_ptr_t p, int new_sz)
std::shared_ptr< std::vector< _TYPE_, TVAlloc< _TYPE_ > > > block_ptr_t
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_