#include <TableFunctionsDataCache.h>
|
bool | isKeyCached (const std::string &key) const |
|
bool | isKeyCachedAndSameLength (const std::string &key, const size_t num_bytes) const |
|
template<typename T > |
void | getDataForKey (const std::string &key, T *dest_buffer) const |
|
template<typename T > |
const T & | getDataRefForKey (const std::string &key) const |
|
template<typename T > |
const T * | getDataPtrForKey (const std::string &key) const |
|
template<typename T > |
void | putDataForKey (const std::string &key, T *const data_buffer, const size_t num_elements) |
|
|
void | copyData (int8_t *dest, const int8_t *source, const size_t num_bytes) const |
|
Definition at line 41 of file TableFunctionsDataCache.h.
void DataBufferCache::copyData |
( |
int8_t * |
dest, |
|
|
const int8_t * |
source, |
|
|
const size_t |
num_bytes |
|
) |
| const |
|
inlineprivate |
Definition at line 118 of file TableFunctionsDataCache.h.
References parallel_copy_min_bytes, and threading_serial::parallel_for().
Referenced by getDataForKey(), and putDataForKey().
120 std::memcpy(
dest, source, num_bytes);
124 const size_t num_threads =
125 (num_bytes + max_bytes_per_thread - 1) / max_bytes_per_thread;
127 tbb::blocked_range<size_t>(0, num_threads, 1),
128 [&](
const tbb::blocked_range<size_t>& r) {
129 const size_t end_chunk_idx = r.end();
130 for (
size_t chunk_idx = r.begin(); chunk_idx != end_chunk_idx; ++chunk_idx) {
131 const size_t start_byte = chunk_idx * max_bytes_per_thread;
132 const size_t length =
133 std::min(start_byte + max_bytes_per_thread, num_bytes) - start_byte;
134 std::memcpy(
dest + start_byte, source + start_byte, length);
void parallel_for(const blocked_range< Int > &range, const Body &body, const Partitioner &p=Partitioner())
const size_t parallel_copy_min_bytes
template<typename T >
void DataBufferCache::getDataForKey |
( |
const std::string & |
key, |
|
|
T * |
dest_buffer |
|
) |
| const |
|
inline |
Definition at line 58 of file TableFunctionsDataCache.h.
References cache_mutex_, copyData(), data_cache_, and DEBUG_TIMER.
61 const auto& cached_data_itr =
data_cache_.find(key);
63 const std::string error_msg =
"Data for key " + key +
" not found in cache.";
64 throw std::runtime_error(error_msg);
66 copyData(reinterpret_cast<int8_t*>(dest_buffer),
67 cached_data_itr->second->data_buffer,
68 cached_data_itr->second->num_bytes);
heavyai::shared_lock< heavyai::shared_mutex > read_lock
void copyData(int8_t *dest, const int8_t *source, const size_t num_bytes) const
#define DEBUG_TIMER(name)
std::shared_mutex cache_mutex_
std::unordered_map< std::string, std::shared_ptr< CacheDataTf > > data_cache_
template<typename T >
const T* DataBufferCache::getDataPtrForKey |
( |
const std::string & |
key | ) |
const |
|
inline |
Definition at line 83 of file TableFunctionsDataCache.h.
References cache_mutex_, data_cache_, and heavydb.dtypes::T.
85 const auto& cached_data_itr =
data_cache_.find(key);
89 return reinterpret_cast<const T* const
>(cached_data_itr->second->data_buffer);
heavyai::shared_lock< heavyai::shared_mutex > read_lock
std::shared_mutex cache_mutex_
std::unordered_map< std::string, std::shared_ptr< CacheDataTf > > data_cache_
template<typename T >
const T& DataBufferCache::getDataRefForKey |
( |
const std::string & |
key | ) |
const |
|
inline |
Definition at line 72 of file TableFunctionsDataCache.h.
References cache_mutex_, data_cache_, and heavydb.dtypes::T.
74 const auto& cached_data_itr =
data_cache_.find(key);
76 const std::string error_msg{
"Data for key " + key +
" not found in cache."};
77 throw std::runtime_error(error_msg);
79 return *
reinterpret_cast<const T*
>(cached_data_itr->second->data_buffer);
heavyai::shared_lock< heavyai::shared_mutex > read_lock
std::shared_mutex cache_mutex_
std::unordered_map< std::string, std::shared_ptr< CacheDataTf > > data_cache_
bool DataBufferCache::isKeyCached |
( |
const std::string & |
key | ) |
const |
|
inline |
Definition at line 43 of file TableFunctionsDataCache.h.
References cache_mutex_, and data_cache_.
heavyai::shared_lock< heavyai::shared_mutex > read_lock
std::shared_mutex cache_mutex_
std::unordered_map< std::string, std::shared_ptr< CacheDataTf > > data_cache_
bool DataBufferCache::isKeyCachedAndSameLength |
( |
const std::string & |
key, |
|
|
const size_t |
num_bytes |
|
) |
| const |
|
inline |
Definition at line 48 of file TableFunctionsDataCache.h.
References cache_mutex_, and data_cache_.
50 const auto& cached_data_itr =
data_cache_.find(key);
54 return num_bytes == cached_data_itr->second->num_bytes;
heavyai::shared_lock< heavyai::shared_mutex > read_lock
std::shared_mutex cache_mutex_
std::unordered_map< std::string, std::shared_ptr< CacheDataTf > > data_cache_
template<typename T >
void DataBufferCache::putDataForKey |
( |
const std::string & |
key, |
|
|
T *const |
data_buffer, |
|
|
const size_t |
num_elements |
|
) |
| |
|
inline |
Definition at line 93 of file TableFunctionsDataCache.h.
References cache_mutex_, copyData(), data_cache_, debug_print_, DEBUG_TIMER, and heavydb.dtypes::T.
97 const size_t num_bytes(num_elements *
sizeof(
T));
98 auto cache_data = std::make_shared<CacheDataTf>(num_bytes);
99 copyData(cache_data->data_buffer, reinterpret_cast<int8_t*>(data_buffer), num_bytes);
101 const auto& cached_data_itr =
data_cache_.find(key);
104 const std::string warning_msg =
105 "Data for key " + key +
" already exists in cache. Replacing.";
106 std::cout << warning_msg << std::endl;
108 cached_data_itr->second.reset();
109 cached_data_itr->second = cache_data;
112 data_cache_.insert(std::make_pair(key, cache_data));
void copyData(int8_t *dest, const int8_t *source, const size_t num_bytes) const
heavyai::unique_lock< heavyai::shared_mutex > write_lock
#define DEBUG_TIMER(name)
static constexpr bool debug_print_
std::shared_mutex cache_mutex_
std::unordered_map< std::string, std::shared_ptr< CacheDataTf > > data_cache_
std::shared_mutex DataBufferCache::cache_mutex_ |
|
mutableprivate |
std::unordered_map<std::string, std::shared_ptr<CacheDataTf> > DataBufferCache::data_cache_ |
|
private |
constexpr bool DataBufferCache::debug_print_ {false} |
|
staticprivate |
const size_t DataBufferCache::parallel_copy_min_bytes {1 << 20} |
|
private |
The documentation for this class was generated from the following file: