OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RowSetMemoryOwner Class Referencefinal

#include <RowSetMemoryOwner.h>

+ Inheritance diagram for RowSetMemoryOwner:
+ Collaboration diagram for RowSetMemoryOwner:

Classes

struct  CountDistinctBitmapBuffer
 

Public Types

enum  StringTranslationType { StringTranslationType::SOURCE_INTERSECTION, StringTranslationType::SOURCE_UNION }
 

Public Member Functions

 RowSetMemoryOwner (const size_t arena_block_size, const size_t executor_id)
 
void setKernelMemoryAllocator (const size_t num_kernels)
 
int8_t * allocate (const size_t num_bytes) override
 
int8_t * allocate (const size_t num_bytes, const size_t thread_idx)
 
void initCountDistinctBufferAllocator (size_t buffer_size, size_t thread_idx)
 
std::pair< int64_t *, bool > allocateCachedGroupByBuffer (const size_t num_bytes, const size_t thread_idx)
 
int8_t * allocateCountDistinctBuffer (const size_t num_bytes, const size_t thread_idx=0)
 
void addCountDistinctBuffer (int8_t *count_distinct_buffer, const size_t bytes, const bool physical_buffer)
 
void addCountDistinctSet (CountDistinctSet *count_distinct_set)
 
void clearNonOwnedGroupByBuffers ()
 
void addVarlenBuffer (void *varlen_buffer)
 
void addVarlenInputBuffer (Data_Namespace::AbstractBuffer *buffer)
 
std::string * addString (const std::string &str)
 
std::vector< int64_t > * addArray (const std::vector< int64_t > &arr)
 
StringDictionaryProxyaddStringDict (std::shared_ptr< StringDictionary > str_dict, const shared::StringDictKey &dict_key, const int64_t generation)
 
std::string generate_translation_map_key (const shared::StringDictKey &source_proxy_dict_key, const std::vector< StringOps_Namespace::StringOpInfo > &string_op_infos)
 
std::string generate_translation_map_key (const shared::StringDictKey &source_proxy_dict_key, const shared::StringDictKey &dest_proxy_dict_key, const std::vector< StringOps_Namespace::StringOpInfo > &string_op_infos)
 
const
StringDictionaryProxy::IdMap
addStringProxyIntersectionTranslationMap (const StringDictionaryProxy *source_proxy, const StringDictionaryProxy *dest_proxy, const std::vector< StringOps_Namespace::StringOpInfo > &string_op_infos)
 
const
StringDictionaryProxy::TranslationMap
< Datum > * 
addStringProxyNumericTranslationMap (const StringDictionaryProxy *source_proxy, const std::vector< StringOps_Namespace::StringOpInfo > &string_op_infos)
 
const
StringDictionaryProxy::IdMap
addStringProxyUnionTranslationMap (const StringDictionaryProxy *source_proxy, StringDictionaryProxy *dest_proxy, const std::vector< StringOps_Namespace::StringOpInfo > &string_op_infos)
 
const
StringOps_Namespace::StringOps * 
getStringOps (const std::vector< StringOps_Namespace::StringOpInfo > &string_op_infos)
 
StringDictionaryProxygetStringDictProxy (const shared::StringDictKey &dict_key) const
 
StringDictionaryProxygetOrAddStringDictProxy (const shared::StringDictKey &dict_key, const bool with_generation)
 
void addLiteralStringDictProxy (std::shared_ptr< StringDictionaryProxy > lit_str_dict_proxy)
 
StringDictionaryProxygetLiteralStringDictProxy () const
 
const
StringDictionaryProxy::IdMap
getOrAddStringProxyTranslationMap (const shared::StringDictKey &source_dict_id_in, const shared::StringDictKey &dest_dict_id_in, const bool with_generation, const StringTranslationType translation_map_type, const std::vector< StringOps_Namespace::StringOpInfo > &string_op_infos)
 
const
StringDictionaryProxy::TranslationMap
< Datum > * 
getOrAddStringProxyNumericTranslationMap (const shared::StringDictKey &source_dict_id_in, const bool with_generation, const std::vector< StringOps_Namespace::StringOpInfo > &string_op_infos)
 
void addColBuffer (const void *col_buffer)
 
 ~RowSetMemoryOwner ()
 
std::shared_ptr
< RowSetMemoryOwner
cloneStrDictDataOnly ()
 
void setDictionaryGenerations (StringDictionaryGenerations generations)
 
StringDictionaryGenerationsgetStringDictionaryGenerations ()
 
quantile::TDigestinitTDigest (size_t thread_idx, ApproxQuantileDescriptor, double q)
 
void reserveTDigestMemory (size_t thread_idx, size_t capacity)
 
void setTableFunctionMetadata (const char *key, const uint8_t *raw_data, const size_t num_bytes, const TableFunctionMetadataType value_type)
 
void getTableFunctionMetadata (const char *key, const uint8_t *&raw_data, size_t &num_bytes, TableFunctionMetadataType &value_type) const
 
AggModeallocateMode ()
 
- Public Member Functions inherited from SimpleAllocator
virtual ~SimpleAllocator ()=default
 

Private Types

using TDigestAllocator = FastAllocator< int8_t >
 
using CountDistinctBufferAllocator = FastAllocator< int8_t >
 
using MetadataValue = std::pair< std::vector< uint8_t >, TableFunctionMetadataType >
 

Private Member Functions

int8_t * allocateUnlocked (const size_t num_bytes, const size_t thread_idx)
 

Private Attributes

std::vector
< CountDistinctBitmapBuffer
count_distinct_bitmaps_
 
std::vector< CountDistinctSet * > count_distinct_sets_
 
std::vector< int64_t * > non_owned_group_by_buffers_
 
std::vector< void * > varlen_buffers_
 
std::list< std::string > strings_
 
std::list< std::vector< int64_t > > arrays_
 
std::unordered_map
< shared::StringDictKey,
std::shared_ptr
< StringDictionaryProxy > > 
str_dict_proxy_owned_
 
std::map< std::string,
StringDictionaryProxy::IdMap
str_proxy_intersection_translation_maps_owned_
 
std::map< std::string,
StringDictionaryProxy::IdMap
str_proxy_union_translation_maps_owned_
 
std::map< std::string,
StringDictionaryProxy::TranslationMap
< Datum > > 
str_proxy_numeric_translation_maps_owned_
 
std::shared_ptr
< StringDictionaryProxy
lit_str_dict_proxy_
 
StringDictionaryGenerations string_dictionary_generations_
 
std::vector< void * > col_buffers_
 
std::vector
< Data_Namespace::AbstractBuffer * > 
varlen_input_buffers_
 
std::deque< TDigestAllocatort_digest_allocators_
 
std::vector< std::unique_ptr
< quantile::TDigest > > 
t_digests_
 
std::map< std::string,
std::shared_ptr
< StringOps_Namespace::StringOps > > 
string_ops_owned_
 
std::list< AggModemode_maps_
 
size_t arena_block_size_
 
std::vector< std::unique_ptr
< Arena > > 
allocators_
 
std::vector< std::unique_ptr
< CountDistinctBufferAllocator > > 
count_distinct_buffer_allocators_
 
size_t executor_id_
 
std::mutex state_mutex_
 
std::map< std::string,
MetadataValue
table_function_metadata_store_
 
std::mutex table_function_metadata_store_mutex_
 

Friends

class ResultSet
 
class QueryExecutionContext
 

Detailed Description

Handles allocations and outputs for all stages in a query, either explicitly or via a managed allocator object

Definition at line 57 of file RowSetMemoryOwner.h.

Member Typedef Documentation

Definition at line 477 of file RowSetMemoryOwner.h.

using RowSetMemoryOwner::MetadataValue = std::pair<std::vector<uint8_t>, TableFunctionMetadataType>
private

Definition at line 485 of file RowSetMemoryOwner.h.

Definition at line 466 of file RowSetMemoryOwner.h.

Member Enumeration Documentation

Enumerator
SOURCE_INTERSECTION 
SOURCE_UNION 

Definition at line 70 of file RowSetMemoryOwner.h.

70 { SOURCE_INTERSECTION, SOURCE_UNION };

Constructor & Destructor Documentation

RowSetMemoryOwner::RowSetMemoryOwner ( const size_t  arena_block_size,
const size_t  executor_id 
)
inline

Definition at line 59 of file RowSetMemoryOwner.h.

References allocators_, arena_block_size_, count_distinct_buffer_allocators_, and g_use_cpu_mem_pool_for_output_buffers.

60  : arena_block_size_(arena_block_size), executor_id_(executor_id) {
61  // initialize shared allocator (i.e., allocators_[0])
63  allocators_.emplace_back(std::make_unique<CpuMgrArenaAllocator>());
64  } else {
65  allocators_.emplace_back(std::make_unique<DramArena>(arena_block_size_));
66  }
68  }
std::vector< std::unique_ptr< Arena > > allocators_
bool g_use_cpu_mem_pool_for_output_buffers
Definition: Execute.cpp:197
std::vector< std::unique_ptr< CountDistinctBufferAllocator > > count_distinct_buffer_allocators_
RowSetMemoryOwner::~RowSetMemoryOwner ( )
inline

Definition at line 349 of file RowSetMemoryOwner.h.

References allocators_, CHECK, col_buffers_, count_distinct_sets_, executor_id_, varlen_buffers_, varlen_input_buffers_, and VLOG.

349  {
350  std::ostringstream oss;
351  oss << "Destruct RowSetMemoryOwner attached to Executor-" << executor_id_ << "{\t";
352  int allocator_id = 0;
353  for (auto const& allocator : allocators_) {
354  auto const usedBytes = allocator->bytesUsed();
355  if (usedBytes > 0) {
356  oss << "allocator-" << allocator_id << ", byteUsed: " << usedBytes << "/"
357  << allocator->totalBytes() << "\t";
358  }
359  ++allocator_id;
360  }
361  oss << "}";
362  allocators_.clear();
363  VLOG(1) << oss.str();
364  for (auto count_distinct_set : count_distinct_sets_) {
365  delete count_distinct_set;
366  }
367  for (auto varlen_buffer : varlen_buffers_) {
368  free(varlen_buffer);
369  }
370  for (auto varlen_input_buffer : varlen_input_buffers_) {
371  CHECK(varlen_input_buffer);
372  varlen_input_buffer->unPin();
373  }
374  for (auto col_buffer : col_buffers_) {
375  free(col_buffer);
376  }
377  }
std::vector< std::unique_ptr< Arena > > allocators_
std::vector< CountDistinctSet * > count_distinct_sets_
std::vector< void * > col_buffers_
std::vector< void * > varlen_buffers_
std::vector< Data_Namespace::AbstractBuffer * > varlen_input_buffers_
#define CHECK(condition)
Definition: Logger.h:291
#define VLOG(n)
Definition: Logger.h:388

Member Function Documentation

std::vector<int64_t>* RowSetMemoryOwner::addArray ( const std::vector< int64_t > &  arr)
inline

Definition at line 199 of file RowSetMemoryOwner.h.

References arrays_, and state_mutex_.

199  {
200  std::lock_guard<std::mutex> lock(state_mutex_);
201  arrays_.emplace_back(arr);
202  return &arrays_.back();
203  }
std::list< std::vector< int64_t > > arrays_
void RowSetMemoryOwner::addColBuffer ( const void *  col_buffer)
inline

Definition at line 344 of file RowSetMemoryOwner.h.

References col_buffers_, and state_mutex_.

344  {
345  std::lock_guard<std::mutex> lock(state_mutex_);
346  col_buffers_.push_back(const_cast<void*>(col_buffer));
347  }
std::vector< void * > col_buffers_
void RowSetMemoryOwner::addCountDistinctBuffer ( int8_t *  count_distinct_buffer,
const size_t  bytes,
const bool  physical_buffer 
)
inline

Definition at line 159 of file RowSetMemoryOwner.h.

References count_distinct_bitmaps_, and state_mutex_.

Referenced by allocateCountDistinctBuffer().

161  {
162  std::lock_guard<std::mutex> lock(state_mutex_);
163  count_distinct_bitmaps_.emplace_back(
164  CountDistinctBitmapBuffer{count_distinct_buffer, bytes, physical_buffer});
165  }
std::vector< CountDistinctBitmapBuffer > count_distinct_bitmaps_

+ Here is the caller graph for this function:

void RowSetMemoryOwner::addCountDistinctSet ( CountDistinctSet count_distinct_set)
inline

Definition at line 167 of file RowSetMemoryOwner.h.

References count_distinct_sets_, and state_mutex_.

167  {
168  std::lock_guard<std::mutex> lock(state_mutex_);
169  count_distinct_sets_.push_back(count_distinct_set);
170  }
std::vector< CountDistinctSet * > count_distinct_sets_
void RowSetMemoryOwner::addLiteralStringDictProxy ( std::shared_ptr< StringDictionaryProxy lit_str_dict_proxy)
inline

Definition at line 320 of file RowSetMemoryOwner.h.

References lit_str_dict_proxy_, and state_mutex_.

321  {
322  std::lock_guard<std::mutex> lock(state_mutex_);
323  lit_str_dict_proxy_ = lit_str_dict_proxy;
324  }
std::shared_ptr< StringDictionaryProxy > lit_str_dict_proxy_
std::string* RowSetMemoryOwner::addString ( const std::string &  str)
inline

Definition at line 193 of file RowSetMemoryOwner.h.

References state_mutex_, and strings_.

193  {
194  std::lock_guard<std::mutex> lock(state_mutex_);
195  strings_.emplace_back(str);
196  return &strings_.back();
197  }
std::list< std::string > strings_
StringDictionaryProxy* RowSetMemoryOwner::addStringDict ( std::shared_ptr< StringDictionary str_dict,
const shared::StringDictKey dict_key,
const int64_t  generation 
)
inline

Definition at line 205 of file RowSetMemoryOwner.h.

References CHECK_EQ, state_mutex_, and str_dict_proxy_owned_.

207  {
208  std::lock_guard<std::mutex> lock(state_mutex_);
209  auto it = str_dict_proxy_owned_.find(dict_key);
210  if (it != str_dict_proxy_owned_.end()) {
211  CHECK_EQ(it->second->getDictionary(), str_dict.get());
212  it->second->updateGeneration(generation);
213  return it->second.get();
214  }
216  .emplace(
217  dict_key,
218  std::make_shared<StringDictionaryProxy>(str_dict, dict_key, generation))
219  .first;
220  return it->second.get();
221  }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
std::unordered_map< shared::StringDictKey, std::shared_ptr< StringDictionaryProxy > > str_dict_proxy_owned_
const StringDictionaryProxy::IdMap* RowSetMemoryOwner::addStringProxyIntersectionTranslationMap ( const StringDictionaryProxy source_proxy,
const StringDictionaryProxy dest_proxy,
const std::vector< StringOps_Namespace::StringOpInfo > &  string_op_infos 
)
inline

Definition at line 243 of file RowSetMemoryOwner.h.

References StringDictionaryProxy::buildIntersectionTranslationMapToOtherProxy(), generate_translation_map_key(), StringDictionaryProxy::getDictionary(), StringDictionary::getDictKey(), state_mutex_, and str_proxy_intersection_translation_maps_owned_.

246  {
247  std::lock_guard<std::mutex> lock(state_mutex_);
248  const auto map_key =
250  dest_proxy->getDictionary()->getDictKey(),
251  string_op_infos);
252  auto it = str_proxy_intersection_translation_maps_owned_.find(map_key);
255  .emplace(map_key,
257  dest_proxy, string_op_infos))
258  .first;
259  }
260  return &it->second;
261  }
const shared::StringDictKey & getDictKey() const noexcept
StringDictionary * getDictionary() const noexcept
std::map< std::string, StringDictionaryProxy::IdMap > str_proxy_intersection_translation_maps_owned_
IdMap buildIntersectionTranslationMapToOtherProxy(const StringDictionaryProxy *dest_proxy, const std::vector< StringOps_Namespace::StringOpInfo > &string_op_infos) const
std::string generate_translation_map_key(const shared::StringDictKey &source_proxy_dict_key, const std::vector< StringOps_Namespace::StringOpInfo > &string_op_infos)

+ Here is the call graph for this function:

const StringDictionaryProxy::TranslationMap<Datum>* RowSetMemoryOwner::addStringProxyNumericTranslationMap ( const StringDictionaryProxy source_proxy,
const std::vector< StringOps_Namespace::StringOpInfo > &  string_op_infos 
)
inline

Definition at line 263 of file RowSetMemoryOwner.h.

References StringDictionaryProxy::buildNumericTranslationMap(), generate_translation_map_key(), StringDictionaryProxy::getDictionary(), StringDictionary::getDictKey(), and str_proxy_numeric_translation_maps_owned_.

265  {
266  const auto map_key = generate_translation_map_key(
267  source_proxy->getDictionary()->getDictKey(), string_op_infos);
268  auto it = str_proxy_numeric_translation_maps_owned_.lower_bound(map_key);
269  if (it->first != map_key) {
271  it, map_key, source_proxy->buildNumericTranslationMap(string_op_infos));
272  }
273  return &it->second;
274  }
const shared::StringDictKey & getDictKey() const noexcept
std::map< std::string, StringDictionaryProxy::TranslationMap< Datum > > str_proxy_numeric_translation_maps_owned_
StringDictionary * getDictionary() const noexcept
TranslationMap< Datum > buildNumericTranslationMap(const std::vector< StringOps_Namespace::StringOpInfo > &string_op_infos) const
Builds a vectorized string_id translation map from this proxy to dest_proxy.
std::string generate_translation_map_key(const shared::StringDictKey &source_proxy_dict_key, const std::vector< StringOps_Namespace::StringOpInfo > &string_op_infos)

+ Here is the call graph for this function:

const StringDictionaryProxy::IdMap* RowSetMemoryOwner::addStringProxyUnionTranslationMap ( const StringDictionaryProxy source_proxy,
StringDictionaryProxy dest_proxy,
const std::vector< StringOps_Namespace::StringOpInfo > &  string_op_infos 
)
inline

Definition at line 276 of file RowSetMemoryOwner.h.

References StringDictionaryProxy::buildUnionTranslationMapToOtherProxy(), generate_translation_map_key(), StringDictionaryProxy::getDictionary(), StringDictionary::getDictKey(), state_mutex_, and str_proxy_union_translation_maps_owned_.

279  {
280  std::lock_guard<std::mutex> lock(state_mutex_);
281  const auto map_key =
283  dest_proxy->getDictionary()->getDictKey(),
284  string_op_infos);
285  auto it = str_proxy_union_translation_maps_owned_.find(map_key);
286  if (it == str_proxy_union_translation_maps_owned_.end()) {
288  .emplace(map_key,
290  dest_proxy, string_op_infos))
291  .first;
292  }
293  return &it->second;
294  }
const shared::StringDictKey & getDictKey() const noexcept
StringDictionary * getDictionary() const noexcept
std::map< std::string, StringDictionaryProxy::IdMap > str_proxy_union_translation_maps_owned_
IdMap buildUnionTranslationMapToOtherProxy(StringDictionaryProxy *dest_proxy, const std::vector< StringOps_Namespace::StringOpInfo > &string_op_types) const
std::string generate_translation_map_key(const shared::StringDictKey &source_proxy_dict_key, const std::vector< StringOps_Namespace::StringOpInfo > &string_op_infos)

+ Here is the call graph for this function:

void RowSetMemoryOwner::addVarlenBuffer ( void *  varlen_buffer)
inline

Definition at line 174 of file RowSetMemoryOwner.h.

References state_mutex_, and varlen_buffers_.

174  {
175  std::lock_guard<std::mutex> lock(state_mutex_);
176  if (std::find(varlen_buffers_.begin(), varlen_buffers_.end(), varlen_buffer) ==
177  varlen_buffers_.end()) {
178  varlen_buffers_.push_back(varlen_buffer);
179  }
180  }
std::vector< void * > varlen_buffers_
void RowSetMemoryOwner::addVarlenInputBuffer ( Data_Namespace::AbstractBuffer buffer)
inline

Adds a GPU buffer containing a variable length input column. Variable length inputs on GPU are referenced in output projected targets and should not be freed until the query results have been resolved.

Definition at line 187 of file RowSetMemoryOwner.h.

References CHECK_EQ, Data_Namespace::AbstractBuffer::getType(), Data_Namespace::GPU_LEVEL, state_mutex_, and varlen_input_buffers_.

187  {
188  std::lock_guard<std::mutex> lock(state_mutex_);
190  varlen_input_buffers_.push_back(buffer);
191  }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
virtual MemoryLevel getType() const =0
std::vector< Data_Namespace::AbstractBuffer * > varlen_input_buffers_

+ Here is the call graph for this function:

int8_t* RowSetMemoryOwner::allocate ( const size_t  num_bytes)
inlineoverridevirtual

Implements SimpleAllocator.

Definition at line 103 of file RowSetMemoryOwner.h.

Referenced by anonymous_namespace{QueryMemoryInitializer.cpp}::alloc_group_by_buffer().

103  {
104  constexpr size_t thread_idx = 0u;
105  return allocate(num_bytes, thread_idx);
106  }
int8_t * allocate(const size_t num_bytes) override

+ Here is the caller graph for this function:

int8_t* RowSetMemoryOwner::allocate ( const size_t  num_bytes,
const size_t  thread_idx 
)
inline

Definition at line 109 of file RowSetMemoryOwner.h.

References allocateUnlocked(), allocators_, CHECK_LT, and state_mutex_.

109  {
110  CHECK_LT(thread_idx, allocators_.size());
111  std::lock_guard<std::mutex> lock(state_mutex_);
112  return allocateUnlocked(num_bytes, thread_idx);
113  }
std::vector< std::unique_ptr< Arena > > allocators_
int8_t * allocateUnlocked(const size_t num_bytes, const size_t thread_idx)
#define CHECK_LT(x, y)
Definition: Logger.h:303

+ Here is the call graph for this function:

std::pair<int64_t*, bool> RowSetMemoryOwner::allocateCachedGroupByBuffer ( const size_t  num_bytes,
const size_t  thread_idx 
)
inline

Definition at line 128 of file RowSetMemoryOwner.h.

References allocators_, CHECK, CHECK_LT, g_allow_memory_status_log, non_owned_group_by_buffers_, state_mutex_, and VLOG.

Referenced by anonymous_namespace{QueryMemoryInitializer.cpp}::alloc_group_by_buffer().

129  {
130  std::lock_guard<std::mutex> lock(state_mutex_);
131  CHECK_LT(thread_idx, non_owned_group_by_buffers_.size());
132  // First try cache
133  if (non_owned_group_by_buffers_[thread_idx]) { // not nullptr
134  return std::make_pair(non_owned_group_by_buffers_[thread_idx], true);
135  }
136  // Was not in cache so must allocate
137  auto allocator = allocators_[thread_idx].get();
139  VLOG(1) << "Try to allocate CPU memory: " << num_bytes << " bytes (THREAD-"
140  << thread_idx << ")";
141  }
142  int64_t* group_by_buffer = reinterpret_cast<int64_t*>(allocator->allocate(num_bytes));
143  CHECK(group_by_buffer);
144  // Put in cache
145  non_owned_group_by_buffers_[thread_idx] = group_by_buffer;
146  return std::make_pair(group_by_buffer, false);
147  }
std::vector< std::unique_ptr< Arena > > allocators_
#define CHECK_LT(x, y)
Definition: Logger.h:303
std::vector< int64_t * > non_owned_group_by_buffers_
bool g_allow_memory_status_log
Definition: Execute.cpp:200
#define CHECK(condition)
Definition: Logger.h:291
#define VLOG(n)
Definition: Logger.h:388

+ Here is the caller graph for this function:

int8_t* RowSetMemoryOwner::allocateCountDistinctBuffer ( const size_t  num_bytes,
const size_t  thread_idx = 0 
)
inline

Definition at line 149 of file RowSetMemoryOwner.h.

References addCountDistinctBuffer(), CHECK, CHECK_LT, and count_distinct_buffer_allocators_.

150  {
151  CHECK_LT(thread_idx, count_distinct_buffer_allocators_.size());
153  int8_t* buffer = count_distinct_buffer_allocators_[thread_idx]->allocate(num_bytes);
154  std::memset(buffer, 0, num_bytes);
155  addCountDistinctBuffer(buffer, num_bytes, /*physical_buffer=*/true);
156  return buffer;
157  }
void addCountDistinctBuffer(int8_t *count_distinct_buffer, const size_t bytes, const bool physical_buffer)
#define CHECK_LT(x, y)
Definition: Logger.h:303
std::vector< std::unique_ptr< CountDistinctBufferAllocator > > count_distinct_buffer_allocators_
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

AggMode* RowSetMemoryOwner::allocateMode ( )
inline

Definition at line 426 of file RowSetMemoryOwner.h.

References mode_maps_, and state_mutex_.

426  {
427  std::lock_guard<std::mutex> lock(state_mutex_);
428  return &mode_maps_.emplace_back();
429  }
std::list< AggMode > mode_maps_
int8_t* RowSetMemoryOwner::allocateUnlocked ( const size_t  num_bytes,
const size_t  thread_idx 
)
inlineprivate

Definition at line 432 of file RowSetMemoryOwner.h.

References allocators_, g_allow_memory_status_log, and VLOG.

Referenced by allocate(), and initCountDistinctBufferAllocator().

432  {
434  VLOG(1) << "Try to allocate CPU memory: " << num_bytes << " bytes (THREAD-"
435  << thread_idx << ")";
436  }
437  auto allocator = allocators_[thread_idx].get();
438  return reinterpret_cast<int8_t*>(allocator->allocate(num_bytes));
439  }
std::vector< std::unique_ptr< Arena > > allocators_
bool g_allow_memory_status_log
Definition: Execute.cpp:200
#define VLOG(n)
Definition: Logger.h:388

+ Here is the caller graph for this function:

void RowSetMemoryOwner::clearNonOwnedGroupByBuffers ( )
inline

Definition at line 172 of file RowSetMemoryOwner.h.

References non_owned_group_by_buffers_.

172 { non_owned_group_by_buffers_.clear(); }
std::vector< int64_t * > non_owned_group_by_buffers_
std::shared_ptr<RowSetMemoryOwner> RowSetMemoryOwner::cloneStrDictDataOnly ( )
inline

Definition at line 379 of file RowSetMemoryOwner.h.

References arena_block_size_, executor_id_, lit_str_dict_proxy_, and str_dict_proxy_owned_.

379  {
380  auto rtn = std::make_shared<RowSetMemoryOwner>(arena_block_size_, executor_id_);
381  rtn->str_dict_proxy_owned_ = str_dict_proxy_owned_;
382  rtn->lit_str_dict_proxy_ = lit_str_dict_proxy_;
383  return rtn;
384  }
std::shared_ptr< StringDictionaryProxy > lit_str_dict_proxy_
std::unordered_map< shared::StringDictKey, std::shared_ptr< StringDictionaryProxy > > str_dict_proxy_owned_
std::string RowSetMemoryOwner::generate_translation_map_key ( const shared::StringDictKey source_proxy_dict_key,
const std::vector< StringOps_Namespace::StringOpInfo > &  string_op_infos 
)
inline

Definition at line 223 of file RowSetMemoryOwner.h.

Referenced by addStringProxyIntersectionTranslationMap(), addStringProxyNumericTranslationMap(), addStringProxyUnionTranslationMap(), and getStringOps().

225  {
226  std::ostringstream oss;
227  oss << "{source_dict_key: " << source_proxy_dict_key
228  << " StringOps: " << string_op_infos << "}";
229  return oss.str();
230  }

+ Here is the caller graph for this function:

std::string RowSetMemoryOwner::generate_translation_map_key ( const shared::StringDictKey source_proxy_dict_key,
const shared::StringDictKey dest_proxy_dict_key,
const std::vector< StringOps_Namespace::StringOpInfo > &  string_op_infos 
)
inline

Definition at line 232 of file RowSetMemoryOwner.h.

235  {
236  std::ostringstream oss;
237  oss << "{source_dict_key: " << source_proxy_dict_key
238  << ", dest_dict_key: " << dest_proxy_dict_key << " StringOps: " << string_op_infos
239  << "}";
240  return oss.str();
241  }
StringDictionaryProxy* RowSetMemoryOwner::getLiteralStringDictProxy ( ) const
inline

Definition at line 326 of file RowSetMemoryOwner.h.

References lit_str_dict_proxy_, and state_mutex_.

326  {
327  std::lock_guard<std::mutex> lock(state_mutex_);
328  return lit_str_dict_proxy_.get();
329  }
std::shared_ptr< StringDictionaryProxy > lit_str_dict_proxy_
StringDictionaryProxy * RowSetMemoryOwner::getOrAddStringDictProxy ( const shared::StringDictKey dict_key,
const bool  with_generation 
)

Definition at line 576 of file Execute.cpp.

References CHECK, CHECK_EQ, CHECK_LE, shared::StringDictKey::db_id, shared::StringDictKey::dict_id, g_cache_string_hash, Catalog_Namespace::SysCatalog::getCatalog(), Catalog_Namespace::SysCatalog::instance(), dict_ref_t::literalsDictId, and REGULAR_DICT.

578  {
579  const int dict_id{dict_key_in.dict_id < 0 ? REGULAR_DICT(dict_key_in.dict_id)
580  : dict_key_in.dict_id};
581  const auto catalog =
583  if (catalog) {
584  const auto dd = catalog->getMetadataForDict(dict_id);
585  if (dd) {
586  auto dict_key = dict_key_in;
587  dict_key.dict_id = dict_id;
588  CHECK(dd->stringDict);
589  CHECK_LE(dd->dictNBits, 32);
590  const int64_t generation =
591  with_generation ? string_dictionary_generations_.getGeneration(dict_key) : -1;
592  return addStringDict(dd->stringDict, dict_key, generation);
593  }
594  }
596  if (!lit_str_dict_proxy_) {
597  DictRef literal_dict_ref(dict_key_in.db_id, DictRef::literalsDictId);
598  std::shared_ptr<StringDictionary> tsd = std::make_shared<StringDictionary>(
599  literal_dict_ref, "", false, true, g_cache_string_hash);
600  lit_str_dict_proxy_ = std::make_shared<StringDictionaryProxy>(
601  tsd, shared::StringDictKey{literal_dict_ref.dbId, literal_dict_ref.dictId}, 0);
602  }
603  return lit_str_dict_proxy_.get();
604 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
StringDictionaryProxy * addStringDict(std::shared_ptr< StringDictionary > str_dict, const shared::StringDictKey &dict_key, const int64_t generation)
static SysCatalog & instance()
Definition: SysCatalog.h:343
std::shared_ptr< StringDictionaryProxy > lit_str_dict_proxy_
StringDictionaryGenerations string_dictionary_generations_
int64_t getGeneration(const shared::StringDictKey &dict_key) const
std::shared_ptr< Catalog > getCatalog(const std::string &dbName)
#define REGULAR_DICT(TRANSIENTID)
Definition: sqltypes.h:323
#define CHECK_LE(x, y)
Definition: Logger.h:304
bool g_cache_string_hash
#define CHECK(condition)
Definition: Logger.h:291
static constexpr int32_t literalsDictId
Definition: DictRef.h:18

+ Here is the call graph for this function:

const StringDictionaryProxy::TranslationMap< Datum > * RowSetMemoryOwner::getOrAddStringProxyNumericTranslationMap ( const shared::StringDictKey source_dict_id_in,
const bool  with_generation,
const std::vector< StringOps_Namespace::StringOpInfo > &  string_op_infos 
)

Definition at line 669 of file Execute.cpp.

672  {
673  const auto source_proxy = getOrAddStringDictProxy(source_dict_key_in, with_generation);
674  return addStringProxyNumericTranslationMap(source_proxy, string_op_infos);
675 }
const StringDictionaryProxy::TranslationMap< Datum > * addStringProxyNumericTranslationMap(const StringDictionaryProxy *source_proxy, const std::vector< StringOps_Namespace::StringOpInfo > &string_op_infos)
StringDictionaryProxy * getOrAddStringDictProxy(const shared::StringDictKey &dict_key, const bool with_generation)
Definition: Execute.cpp:576
const StringDictionaryProxy::IdMap * RowSetMemoryOwner::getOrAddStringProxyTranslationMap ( const shared::StringDictKey source_dict_id_in,
const shared::StringDictKey dest_dict_id_in,
const bool  with_generation,
const StringTranslationType  translation_map_type,
const std::vector< StringOps_Namespace::StringOpInfo > &  string_op_infos 
)

Definition at line 652 of file Execute.cpp.

References SOURCE_INTERSECTION.

657  {
658  const auto source_proxy = getOrAddStringDictProxy(source_dict_key_in, with_generation);
659  const auto dest_proxy = getOrAddStringDictProxy(dest_dict_key_in, with_generation);
662  source_proxy, dest_proxy, string_op_infos);
663  } else {
664  return addStringProxyUnionTranslationMap(source_proxy, dest_proxy, string_op_infos);
665  }
666 }
const StringDictionaryProxy::IdMap * addStringProxyUnionTranslationMap(const StringDictionaryProxy *source_proxy, StringDictionaryProxy *dest_proxy, const std::vector< StringOps_Namespace::StringOpInfo > &string_op_infos)
const StringDictionaryProxy::IdMap * addStringProxyIntersectionTranslationMap(const StringDictionaryProxy *source_proxy, const StringDictionaryProxy *dest_proxy, const std::vector< StringOps_Namespace::StringOpInfo > &string_op_infos)
StringDictionaryProxy * getOrAddStringDictProxy(const shared::StringDictKey &dict_key, const bool with_generation)
Definition: Execute.cpp:576
StringDictionaryGenerations& RowSetMemoryOwner::getStringDictionaryGenerations ( )
inline

Definition at line 390 of file RowSetMemoryOwner.h.

References string_dictionary_generations_.

390  {
392  }
StringDictionaryGenerations string_dictionary_generations_
StringDictionaryProxy* RowSetMemoryOwner::getStringDictProxy ( const shared::StringDictKey dict_key) const
inline

Definition at line 310 of file RowSetMemoryOwner.h.

References CHECK, state_mutex_, and str_dict_proxy_owned_.

310  {
311  std::lock_guard<std::mutex> lock(state_mutex_);
312  auto it = str_dict_proxy_owned_.find(dict_key);
313  CHECK(it != str_dict_proxy_owned_.end());
314  return it->second.get();
315  }
std::unordered_map< shared::StringDictKey, std::shared_ptr< StringDictionaryProxy > > str_dict_proxy_owned_
#define CHECK(condition)
Definition: Logger.h:291
const StringOps_Namespace::StringOps* RowSetMemoryOwner::getStringOps ( const std::vector< StringOps_Namespace::StringOpInfo > &  string_op_infos)
inline

Definition at line 296 of file RowSetMemoryOwner.h.

References generate_translation_map_key(), state_mutex_, and string_ops_owned_.

297  {
298  std::lock_guard<std::mutex> lock(state_mutex_);
299  const auto map_key = generate_translation_map_key({}, {}, string_op_infos);
300  auto it = string_ops_owned_.find(map_key);
301  if (it == string_ops_owned_.end()) {
302  it = string_ops_owned_
303  .emplace(map_key,
304  std::make_shared<StringOps_Namespace::StringOps>(string_op_infos))
305  .first;
306  }
307  return it->second.get();
308  }
std::map< std::string, std::shared_ptr< StringOps_Namespace::StringOps > > string_ops_owned_
std::string generate_translation_map_key(const shared::StringDictKey &source_proxy_dict_key, const std::vector< StringOps_Namespace::StringOpInfo > &string_op_infos)

+ Here is the call graph for this function:

void RowSetMemoryOwner::getTableFunctionMetadata ( const char *  key,
const uint8_t *&  raw_data,
size_t &  num_bytes,
TableFunctionMetadataType value_type 
) const
inline

Definition at line 411 of file RowSetMemoryOwner.h.

References table_function_metadata_store_, and table_function_metadata_store_mutex_.

414  {
415  std::lock_guard<std::mutex> lock(table_function_metadata_store_mutex_);
416  auto const itr = table_function_metadata_store_.find(key);
417  if (itr == table_function_metadata_store_.end()) {
418  throw std::runtime_error("Failed to find Table Function Metadata with key '" +
419  std::string(key) + "'");
420  }
421  raw_data = itr->second.first.data();
422  num_bytes = itr->second.first.size();
423  value_type = itr->second.second;
424  }
std::mutex table_function_metadata_store_mutex_
std::map< std::string, MetadataValue > table_function_metadata_store_
void RowSetMemoryOwner::initCountDistinctBufferAllocator ( size_t  buffer_size,
size_t  thread_idx 
)
inline

Definition at line 115 of file RowSetMemoryOwner.h.

References allocateUnlocked(), CHECK_LT, count_distinct_buffer_allocators_, state_mutex_, and VLOG.

115  {
116  std::lock_guard<std::mutex> lock(state_mutex_);
117  VLOG(2) << "Count distinct buffer allocator initialized with buffer_size: "
118  << buffer_size << ", thread_idx: " << thread_idx;
119  CHECK_LT(thread_idx, count_distinct_buffer_allocators_.size());
120  if (count_distinct_buffer_allocators_[thread_idx]) {
121  VLOG(2) << "Replacing count_distinct_buffer_allocators_[" << thread_idx << "].";
122  }
124  std::make_unique<CountDistinctBufferAllocator>(
125  allocateUnlocked(buffer_size, thread_idx), buffer_size);
126  }
int8_t * allocateUnlocked(const size_t num_bytes, const size_t thread_idx)
#define CHECK_LT(x, y)
Definition: Logger.h:303
std::vector< std::unique_ptr< CountDistinctBufferAllocator > > count_distinct_buffer_allocators_
#define VLOG(n)
Definition: Logger.h:388

+ Here is the call graph for this function:

quantile::TDigest * RowSetMemoryOwner::initTDigest ( size_t  thread_idx,
ApproxQuantileDescriptor  desc,
double  q 
)

Definition at line 677 of file Execute.cpp.

References ApproxQuantileDescriptor::buffer_size, and ApproxQuantileDescriptor::centroids_size.

679  {
680  static_assert(std::is_trivially_copyable_v<ApproxQuantileDescriptor>);
681  std::lock_guard<std::mutex> lock(state_mutex_);
682  auto t_digest = std::make_unique<quantile::TDigest>(
683  q, &t_digest_allocators_[thread_idx], desc.buffer_size, desc.centroids_size);
684  return t_digests_.emplace_back(std::move(t_digest)).get();
685 }
std::vector< std::unique_ptr< quantile::TDigest > > t_digests_
std::deque< TDigestAllocator > t_digest_allocators_
void RowSetMemoryOwner::reserveTDigestMemory ( size_t  thread_idx,
size_t  capacity 
)

Definition at line 687 of file Execute.cpp.

References VLOG.

687  {
688  std::unique_lock<std::mutex> lock(state_mutex_);
689  if (t_digest_allocators_.size() <= thread_idx) {
690  t_digest_allocators_.resize(thread_idx + 1u);
691  }
692  if (t_digest_allocators_[thread_idx].capacity()) {
693  // This can only happen when a thread_idx is re-used. In other words,
694  // two or more kernels have launched (serially!) using the same thread_idx.
695  // This is ok since TDigestAllocator does not own the memory it allocates.
696  VLOG(2) << "Replacing t_digest_allocators_[" << thread_idx << "].";
697  }
698  lock.unlock();
699  // This is not locked due to use of same state_mutex_ during allocation.
700  // The corresponding deallocation happens in ~DramArena().
701  int8_t* const buffer = allocate(capacity, thread_idx);
702  lock.lock();
703  t_digest_allocators_[thread_idx] = TDigestAllocator(buffer, capacity);
704 }
int8_t * allocate(const size_t num_bytes) override
FastAllocator< int8_t > TDigestAllocator
std::deque< TDigestAllocator > t_digest_allocators_
#define VLOG(n)
Definition: Logger.h:388
void RowSetMemoryOwner::setDictionaryGenerations ( StringDictionaryGenerations  generations)
inline

Definition at line 386 of file RowSetMemoryOwner.h.

References string_dictionary_generations_.

386  {
387  string_dictionary_generations_ = generations;
388  }
StringDictionaryGenerations string_dictionary_generations_
void RowSetMemoryOwner::setKernelMemoryAllocator ( const size_t  num_kernels)
inline

Definition at line 72 of file RowSetMemoryOwner.h.

References allocators_, arena_block_size_, CHECK_EQ, CHECK_GE, CHECK_GT, count_distinct_buffer_allocators_, executor_id_, g_use_cpu_mem_pool_for_output_buffers, non_owned_group_by_buffers_, and VLOG.

72  {
73  CHECK_GT(num_kernels, static_cast<size_t>(0));
74  CHECK_EQ(non_owned_group_by_buffers_.size(), static_cast<size_t>(0));
75  // buffer for kernels starts with one-based indexing
76  auto const required_num_kernels = num_kernels + 1;
77  non_owned_group_by_buffers_.resize(required_num_kernels, nullptr);
78  // sometimes the same RSMO instance handles multiple work units or even multiple query
79  // steps (this means the RSMO's owner, an Executor instance, takes a responsibility to
80  // proceed them) so, if the first query step has M allocators but if the second query
81  // step requires N allocators where N > M, let's allocate M - N allocators instead of
82  // recreating M new allocators
83  if (required_num_kernels > allocators_.size()) {
84  auto const required_num_allocators = required_num_kernels - allocators_.size();
85  VLOG(1) << "Prepare " << required_num_allocators
86  << " memory allocator(s) (Executor-" << executor_id_
87  << ", # existing allocator(s): " << allocators_.size()
88  << ", # requested allocator(s): " << required_num_kernels << ")";
89  for (size_t i = 0; i < required_num_allocators; i++) {
91  allocators_.emplace_back(std::make_unique<CpuMgrArenaAllocator>());
92  } else {
93  // todo (yoonmin): can we determine better default min_block_size per query?
94  allocators_.emplace_back(std::make_unique<DramArena>(arena_block_size_));
95  }
96  }
97  }
98  CHECK_GE(allocators_.size(), required_num_kernels);
100  }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
std::vector< std::unique_ptr< Arena > > allocators_
#define CHECK_GE(x, y)
Definition: Logger.h:306
#define CHECK_GT(x, y)
Definition: Logger.h:305
bool g_use_cpu_mem_pool_for_output_buffers
Definition: Execute.cpp:197
std::vector< std::unique_ptr< CountDistinctBufferAllocator > > count_distinct_buffer_allocators_
std::vector< int64_t * > non_owned_group_by_buffers_
#define VLOG(n)
Definition: Logger.h:388
void RowSetMemoryOwner::setTableFunctionMetadata ( const char *  key,
const uint8_t *  raw_data,
const size_t  num_bytes,
const TableFunctionMetadataType  value_type 
)
inline

Definition at line 401 of file RowSetMemoryOwner.h.

References table_function_metadata_store_, and table_function_metadata_store_mutex_.

404  {
405  MetadataValue metadata_value(num_bytes, value_type);
406  std::memcpy(metadata_value.first.data(), raw_data, num_bytes);
407  std::lock_guard<std::mutex> lock(table_function_metadata_store_mutex_);
408  table_function_metadata_store_[key] = std::move(metadata_value);
409  }
std::pair< std::vector< uint8_t >, TableFunctionMetadataType > MetadataValue
std::mutex table_function_metadata_store_mutex_
std::map< std::string, MetadataValue > table_function_metadata_store_

Friends And Related Function Documentation

friend class QueryExecutionContext
friend

Definition at line 490 of file RowSetMemoryOwner.h.

friend class ResultSet
friend

Definition at line 489 of file RowSetMemoryOwner.h.

Member Data Documentation

std::vector<std::unique_ptr<Arena> > RowSetMemoryOwner::allocators_
private
size_t RowSetMemoryOwner::arena_block_size_
private
std::list<std::vector<int64_t> > RowSetMemoryOwner::arrays_
private

Definition at line 452 of file RowSetMemoryOwner.h.

Referenced by addArray().

std::vector<void*> RowSetMemoryOwner::col_buffers_
private

Definition at line 463 of file RowSetMemoryOwner.h.

Referenced by addColBuffer(), and ~RowSetMemoryOwner().

std::vector<CountDistinctBitmapBuffer> RowSetMemoryOwner::count_distinct_bitmaps_
private

Definition at line 447 of file RowSetMemoryOwner.h.

Referenced by addCountDistinctBuffer().

std::vector<std::unique_ptr<CountDistinctBufferAllocator> > RowSetMemoryOwner::count_distinct_buffer_allocators_
private
std::vector<CountDistinctSet*> RowSetMemoryOwner::count_distinct_sets_
private

Definition at line 448 of file RowSetMemoryOwner.h.

Referenced by addCountDistinctSet(), and ~RowSetMemoryOwner().

size_t RowSetMemoryOwner::executor_id_
private
std::shared_ptr<StringDictionaryProxy> RowSetMemoryOwner::lit_str_dict_proxy_
private
std::list<AggMode> RowSetMemoryOwner::mode_maps_
private

Definition at line 472 of file RowSetMemoryOwner.h.

Referenced by allocateMode().

std::vector<int64_t*> RowSetMemoryOwner::non_owned_group_by_buffers_
private
std::unordered_map<shared::StringDictKey, std::shared_ptr<StringDictionaryProxy> > RowSetMemoryOwner::str_dict_proxy_owned_
private

Definition at line 454 of file RowSetMemoryOwner.h.

Referenced by addStringDict(), cloneStrDictDataOnly(), and getStringDictProxy().

std::map<std::string, StringDictionaryProxy::IdMap> RowSetMemoryOwner::str_proxy_intersection_translation_maps_owned_
private

Definition at line 456 of file RowSetMemoryOwner.h.

Referenced by addStringProxyIntersectionTranslationMap().

std::map<std::string, StringDictionaryProxy::TranslationMap<Datum> > RowSetMemoryOwner::str_proxy_numeric_translation_maps_owned_
private

Definition at line 460 of file RowSetMemoryOwner.h.

Referenced by addStringProxyNumericTranslationMap().

std::map<std::string, StringDictionaryProxy::IdMap> RowSetMemoryOwner::str_proxy_union_translation_maps_owned_
private

Definition at line 458 of file RowSetMemoryOwner.h.

Referenced by addStringProxyUnionTranslationMap().

StringDictionaryGenerations RowSetMemoryOwner::string_dictionary_generations_
private
std::map<std::string, std::shared_ptr<StringOps_Namespace::StringOps> > RowSetMemoryOwner::string_ops_owned_
private

Definition at line 471 of file RowSetMemoryOwner.h.

Referenced by getStringOps().

std::list<std::string> RowSetMemoryOwner::strings_
private

Definition at line 451 of file RowSetMemoryOwner.h.

Referenced by addString().

std::deque<TDigestAllocator> RowSetMemoryOwner::t_digest_allocators_
private

Definition at line 467 of file RowSetMemoryOwner.h.

std::vector<std::unique_ptr<quantile::TDigest> > RowSetMemoryOwner::t_digests_
private

Definition at line 468 of file RowSetMemoryOwner.h.

std::map<std::string, MetadataValue> RowSetMemoryOwner::table_function_metadata_store_
private

Definition at line 486 of file RowSetMemoryOwner.h.

Referenced by getTableFunctionMetadata(), and setTableFunctionMetadata().

std::mutex RowSetMemoryOwner::table_function_metadata_store_mutex_
mutableprivate

Definition at line 487 of file RowSetMemoryOwner.h.

Referenced by getTableFunctionMetadata(), and setTableFunctionMetadata().

std::vector<void*> RowSetMemoryOwner::varlen_buffers_
private

Definition at line 450 of file RowSetMemoryOwner.h.

Referenced by addVarlenBuffer(), and ~RowSetMemoryOwner().

std::vector<Data_Namespace::AbstractBuffer*> RowSetMemoryOwner::varlen_input_buffers_
private

Definition at line 464 of file RowSetMemoryOwner.h.

Referenced by addVarlenInputBuffer(), and ~RowSetMemoryOwner().


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