xgboost
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
xgboost::DMatrixCache< CacheT > Class Template Reference

Thread-aware FIFO cache for DMatrix related data. More...

#include <cache.h>

Collaboration diagram for xgboost::DMatrixCache< CacheT >:
Collaboration graph

Classes

struct  Hash
 
struct  Item
 
struct  Key
 

Public Member Functions

 DMatrixCache (std::size_t cache_size)
 
DMatrixCacheoperator= (DMatrixCache &&that)
 
template<typename... Args>
std::shared_ptr< CacheT > CacheItem (std::shared_ptr< DMatrix > m, Args const &... args)
 Cache a new DMatrix if it's not in the cache already. More...
 
template<typename... Args>
std::shared_ptr< CacheT > ResetItem (std::shared_ptr< DMatrix > m, Args const &... args)
 Re-initialize the item in cache. More...
 
decltype(container_) const & Container ()
 Get a const reference to the underlying hash map. Clear expired caches before returning. More...
 
std::shared_ptr< CacheT > Entry (DMatrix const *m) const
 

Static Public Member Functions

static constexpr std::size_t DefaultSize ()
 

Protected Member Functions

void CheckConsistent () const
 
void ClearExpired ()
 
void ClearExcess ()
 

Protected Attributes

std::unordered_map< Key, Item, Hashcontainer_
 
std::queue< Keyqueue_
 
std::size_t max_size_
 

Detailed Description

template<typename CacheT>
class xgboost::DMatrixCache< CacheT >

Thread-aware FIFO cache for DMatrix related data.

Template Parameters
CacheTThe type that needs to be cached.

Constructor & Destructor Documentation

◆ DMatrixCache()

template<typename CacheT >
xgboost::DMatrixCache< CacheT >::DMatrixCache ( std::size_t  cache_size)
inlineexplicit
Parameters
cache_sizeMaximum size of the cache.

Member Function Documentation

◆ CacheItem()

template<typename CacheT >
template<typename... Args>
std::shared_ptr<CacheT> xgboost::DMatrixCache< CacheT >::CacheItem ( std::shared_ptr< DMatrix m,
Args const &...  args 
)
inline

Cache a new DMatrix if it's not in the cache already.

Passing in a shared_ptr is critical here. First to create a weak_ptr inside the entry this shared pointer is necessary. More importantly, the life time of this cache is tied to the shared pointer.

Parameters
mshared pointer to the DMatrix that needs to be cached.
argsThe arguments for constructing a new cache item, if needed.
Returns
The cache entry for passed in DMatrix, either an existing cache or newly created.

◆ CheckConsistent()

template<typename CacheT >
void xgboost::DMatrixCache< CacheT >::CheckConsistent ( ) const
inlineprotected

◆ ClearExcess()

template<typename CacheT >
void xgboost::DMatrixCache< CacheT >::ClearExcess ( )
inlineprotected

◆ ClearExpired()

template<typename CacheT >
void xgboost::DMatrixCache< CacheT >::ClearExpired ( )
inlineprotected

◆ Container()

template<typename CacheT >
decltype(container_) const& xgboost::DMatrixCache< CacheT >::Container ( )
inline

Get a const reference to the underlying hash map. Clear expired caches before returning.

◆ DefaultSize()

template<typename CacheT >
static constexpr std::size_t xgboost::DMatrixCache< CacheT >::DefaultSize ( )
inlinestaticconstexpr

◆ Entry()

template<typename CacheT >
std::shared_ptr<CacheT> xgboost::DMatrixCache< CacheT >::Entry ( DMatrix const *  m) const
inline

◆ operator=()

template<typename CacheT >
DMatrixCache& xgboost::DMatrixCache< CacheT >::operator= ( DMatrixCache< CacheT > &&  that)
inline

◆ ResetItem()

template<typename CacheT >
template<typename... Args>
std::shared_ptr<CacheT> xgboost::DMatrixCache< CacheT >::ResetItem ( std::shared_ptr< DMatrix m,
Args const &...  args 
)
inline

Re-initialize the item in cache.

Since the shared_ptr is used to hold the item, any reference that lives outside of the cache can no-longer be reached from the cache.

We use reset instead of erase to avoid walking through the whole cache for renewing a single item. (the cache is FIFO, needs to maintain the order).

Member Data Documentation

◆ container_

template<typename CacheT >
std::unordered_map<Key, Item, Hash> xgboost::DMatrixCache< CacheT >::container_
protected

◆ max_size_

template<typename CacheT >
std::size_t xgboost::DMatrixCache< CacheT >::max_size_
protected

◆ queue_

template<typename CacheT >
std::queue<Key> xgboost::DMatrixCache< CacheT >::queue_
protected

The documentation for this class was generated from the following file: