xgboost
| 公共成员函数 | 静态公共成员函数 | 保护成员函数 | 保护属性 | 所有成员列表
xgboost::DMatrixCache< CacheT > 类模板参考

DMatrix 相关数据的线程安全 FIFO 缓存。更多...

#include <cache.h>

xgboost::DMatrixCache< CacheT > 的协作图
Collaboration graph

struct  Hash
 
struct  Item
 
struct  Key
 

公共成员函数

 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)
 如果新的 DMatrix 尚未在缓存中,则对其进行缓存。更多...
 
template<typename... Args>
std::shared_ptr< CacheT > ResetItem (std::shared_ptr< DMatrix > m, Args const &... args)
 重新初始化缓存中的条目。更多...
 
decltype(container_) const & Container ()
 获取底层哈希映射的 const 引用。在返回之前清除已过期的缓存。更多...
 
std::shared_ptr< CacheT > Entry (DMatrix const *m) const
 

静态公共成员函数

static constexpr std::size_t DefaultSize ()
 

保护成员函数

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

保护属性

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

详细描述

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

DMatrix 相关数据的线程安全 FIFO 缓存。

模板参数
CacheT需要缓存的类型。

构造函数与析构函数文档

◆ DMatrixCache()

template<typename CacheT >
xgboost::DMatrixCache< CacheT >::DMatrixCache ( std::size_t  cache_size)
inlineexplicit
参数
cache_size缓存的最大大小。

成员函数文档

◆ CacheItem()

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

如果新的 DMatrix 尚未在缓存中,则对其进行缓存。

传入 shared_ptr 在此至关重要。首先,需要在条目内部创建 weak_ptr,为此 shared pointer 是必需的。更重要的是,此缓存的生命周期与 shared pointer 绑定。

参数
m指向需要缓存的DMatrix的共享指针。
args如果需要,用于构造新的缓存条目的参数。
返回
传入的DMatrix的缓存条目,可以是现有缓存或新创建的缓存。

◆ 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

获取底层哈希映射的 const 引用。在返回之前清除已过期的缓存。

◆ 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

重新初始化缓存中的条目。

由于使用 shared_ptr 来持有条目,因此缓存外部的任何引用都无法再从缓存中访问。

我们使用 reset 而不是 erase 来避免遍历整个缓存来更新单个条目。(缓存是 FIFO,需要维护顺序)。

成员数据文档

◆ 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

此类的文档生成自以下文件