xgboost
|
Thread-aware FIFO cache for DMatrix related data. More...
#include <cache.h>
Classes | |
struct | Hash |
struct | Item |
struct | Key |
Public Member Functions | |
DMatrixCache (std::size_t cache_size) | |
DMatrixCache & | operator= (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, Hash > | container_ |
std::queue< Key > | queue_ |
std::size_t | max_size_ |
Thread-aware FIFO cache for DMatrix related data.
CacheT | The type that needs to be cached. |
|
inlineexplicit |
cache_size | Maximum size of the cache. |
|
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.
m | shared pointer to the DMatrix that needs to be cached. |
args | The arguments for constructing a new cache item, if needed. |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inline |
Get a const reference to the underlying hash map. Clear expired caches before returning.
|
inlinestaticconstexpr |
|
inline |
|
inline |
|
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).
|
protected |
|
protected |
|
protected |