#include <TableFunctionsCommon.hpp>
|
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 96 of file TableFunctionsCommon.hpp.
void DataBufferCache::copyData |
( |
int8_t * |
dest, |
|
|
const int8_t * |
source, |
|
|
const size_t |
num_bytes |
|
) |
| const |
|
private |
Definition at line 507 of file TableFunctionsCommon.cpp.
References parallel_copy_min_bytes, and threading_serial::parallel_for().
Referenced by getDataForKey(), and putDataForKey().
511 std::memcpy(
dest, source, num_bytes);
515 const size_t num_threads =
516 (num_bytes + max_bytes_per_thread - 1) / max_bytes_per_thread;
518 tbb::blocked_range<size_t>(0, num_threads, 1),
519 [&](
const tbb::blocked_range<size_t>& r) {
520 const size_t end_chunk_idx = r.end();
521 for (
size_t chunk_idx = r.begin(); chunk_idx != end_chunk_idx; ++chunk_idx) {
522 const size_t start_byte = chunk_idx * max_bytes_per_thread;
523 const size_t length =
524 std::min(start_byte + max_bytes_per_thread, num_bytes) - start_byte;
525 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 |
Definition at line 452 of file TableFunctionsCommon.cpp.
References cache_mutex_, copyData(), data_cache_, and DEBUG_TIMER.
455 const auto& cached_data_itr =
data_cache_.find(key);
457 const std::string error_msg =
"Data for key " + key +
" not found in cache.";
458 throw std::runtime_error(error_msg);
460 copyData(reinterpret_cast<int8_t*>(dest_buffer),
461 cached_data_itr->second->data_buffer,
462 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 |
Definition at line 477 of file TableFunctionsCommon.cpp.
References cache_mutex_, data_cache_, and heavydb.dtypes::T.
479 const auto& cached_data_itr =
data_cache_.find(key);
483 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 |
Definition at line 466 of file TableFunctionsCommon.cpp.
References cache_mutex_, data_cache_, and heavydb.dtypes::T.
468 const auto& cached_data_itr =
data_cache_.find(key);
470 const std::string error_msg{
"Data for key " + key +
" not found in cache."};
471 throw std::runtime_error(error_msg);
473 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 |
Definition at line 436 of file TableFunctionsCommon.cpp.
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 |
Definition at line 441 of file TableFunctionsCommon.cpp.
References cache_mutex_, and data_cache_.
444 const auto& cached_data_itr =
data_cache_.find(key);
448 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 |
|
) |
| |
Definition at line 487 of file TableFunctionsCommon.cpp.
References cache_mutex_, copyData(), data_cache_, DEBUG_TIMER, and heavydb.dtypes::T.
491 const size_t num_bytes(num_elements *
sizeof(
T));
492 auto cache_data = std::make_shared<CacheDataTf>(num_bytes);
493 copyData(cache_data->data_buffer, reinterpret_cast<int8_t*>(data_buffer), num_bytes);
495 const auto& cached_data_itr =
data_cache_.find(key);
497 const std::string warning_msg =
498 "Data for key " + key +
" already exists in cache. Replacing.";
499 std::cout << warning_msg << std::endl;
500 cached_data_itr->second.reset();
501 cached_data_itr->second = cache_data;
504 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)
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 |
const size_t DataBufferCache::parallel_copy_min_bytes {1 << 20} |
|
private |
The documentation for this class was generated from the following files:
- /home/jenkins-slave/workspace/core-os-doxygen/QueryEngine/TableFunctions/SystemFunctions/os/Shared/TableFunctionsCommon.hpp
- /home/jenkins-slave/workspace/core-os-doxygen/QueryEngine/TableFunctions/SystemFunctions/os/Shared/TableFunctionsCommon.cpp