OmniSciDB  bf83d84833
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RowSetMemoryOwner Class Reference

#include <RowSetMemoryOwner.h>

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

Classes

struct  CountDistinctBitmapBuffer
 

Public Member Functions

 RowSetMemoryOwner (const size_t arena_block_size)
 
int8_t * allocate (const size_t num_bytes)
 
int8_t * allocateCountDistinctBuffer (const size_t num_bytes)
 
void addCountDistinctBuffer (int8_t *count_distinct_buffer, const size_t bytes, const bool physical_buffer)
 
void addCountDistinctSet (std::set< int64_t > *count_distinct_set)
 
void addGroupByBuffer (int64_t *group_by_buffer)
 
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 int dict_id, const int64_t generation)
 
StringDictionaryProxygetStringDictProxy (const int dict_id) const
 
StringDictionaryProxygetOrAddStringDictProxy (const int dict_id_in, const bool with_generation, const Catalog_Namespace::Catalog *catalog)
 
void addLiteralStringDictProxy (std::shared_ptr< StringDictionaryProxy > lit_str_dict_proxy)
 
StringDictionaryProxygetLiteralStringDictProxy () const
 
void addColBuffer (const void *col_buffer)
 
 ~RowSetMemoryOwner ()
 
std::shared_ptr
< RowSetMemoryOwner
cloneStrDictDataOnly ()
 
void setDictionaryGenerations (StringDictionaryGenerations generations)
 
StringDictionaryGenerationsgetStringDictionaryGenerations ()
 
quantile::TDigestnewTDigest ()
 

Private Attributes

std::vector
< CountDistinctBitmapBuffer
count_distinct_bitmaps_
 
std::vector< std::set< int64_t > * > count_distinct_sets_
 
std::vector< int64_t * > group_by_buffers_
 
std::vector< void * > varlen_buffers_
 
std::list< std::string > strings_
 
std::list< std::vector< int64_t > > arrays_
 
std::unordered_map< int,
std::shared_ptr
< StringDictionaryProxy > > 
str_dict_proxy_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::vector< std::unique_ptr
< quantile::TDigest > > 
t_digests_
 
std::vector
< quantile::TDigest::Memory
t_digest_buffers_
 
size_t arena_block_size_
 
std::unique_ptr< Arenaallocator_
 
std::mutex state_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 43 of file RowSetMemoryOwner.h.

Constructor & Destructor Documentation

RowSetMemoryOwner::RowSetMemoryOwner ( const size_t  arena_block_size)
inline

Definition at line 45 of file RowSetMemoryOwner.h.

46  : arena_block_size_(arena_block_size)
47  , allocator_(std::make_unique<Arena>(arena_block_size)) {}
std::unique_ptr< Arena > allocator_
RowSetMemoryOwner::~RowSetMemoryOwner ( )
inline

Definition at line 155 of file RowSetMemoryOwner.h.

References CHECK, col_buffers_, count_distinct_sets_, group_by_buffers_, varlen_buffers_, and varlen_input_buffers_.

155  {
156  for (auto count_distinct_set : count_distinct_sets_) {
157  delete count_distinct_set;
158  }
159  for (auto group_by_buffer : group_by_buffers_) {
160  free(group_by_buffer);
161  }
162  for (auto varlen_buffer : varlen_buffers_) {
163  free(varlen_buffer);
164  }
165  for (auto varlen_input_buffer : varlen_input_buffers_) {
166  CHECK(varlen_input_buffer);
167  varlen_input_buffer->unPin();
168  }
169  for (auto col_buffer : col_buffers_) {
170  free(col_buffer);
171  }
172  }
std::vector< std::set< int64_t > * > 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:197
std::vector< int64_t * > group_by_buffers_

Member Function Documentation

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

Definition at line 104 of file RowSetMemoryOwner.h.

References arrays_, and state_mutex_.

104  {
105  std::lock_guard<std::mutex> lock(state_mutex_);
106  arrays_.emplace_back(arr);
107  return &arrays_.back();
108  }
std::list< std::vector< int64_t > > arrays_
void RowSetMemoryOwner::addColBuffer ( const void *  col_buffer)
inline

Definition at line 150 of file RowSetMemoryOwner.h.

References col_buffers_, and state_mutex_.

150  {
151  std::lock_guard<std::mutex> lock(state_mutex_);
152  col_buffers_.push_back(const_cast<void*>(col_buffer));
153  }
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 64 of file RowSetMemoryOwner.h.

References count_distinct_bitmaps_, and state_mutex_.

66  {
67  std::lock_guard<std::mutex> lock(state_mutex_);
68  count_distinct_bitmaps_.emplace_back(
69  CountDistinctBitmapBuffer{count_distinct_buffer, bytes, physical_buffer});
70  }
std::vector< CountDistinctBitmapBuffer > count_distinct_bitmaps_
void RowSetMemoryOwner::addCountDistinctSet ( std::set< int64_t > *  count_distinct_set)
inline

Definition at line 72 of file RowSetMemoryOwner.h.

References count_distinct_sets_, and state_mutex_.

72  {
73  std::lock_guard<std::mutex> lock(state_mutex_);
74  count_distinct_sets_.push_back(count_distinct_set);
75  }
std::vector< std::set< int64_t > * > count_distinct_sets_
void RowSetMemoryOwner::addGroupByBuffer ( int64_t *  group_by_buffer)
inline

Definition at line 77 of file RowSetMemoryOwner.h.

References group_by_buffers_, and state_mutex_.

77  {
78  std::lock_guard<std::mutex> lock(state_mutex_);
79  group_by_buffers_.push_back(group_by_buffer);
80  }
std::vector< int64_t * > group_by_buffers_
void RowSetMemoryOwner::addLiteralStringDictProxy ( std::shared_ptr< StringDictionaryProxy lit_str_dict_proxy)
inline

Definition at line 139 of file RowSetMemoryOwner.h.

References lit_str_dict_proxy_, and state_mutex_.

140  {
141  std::lock_guard<std::mutex> lock(state_mutex_);
142  lit_str_dict_proxy_ = lit_str_dict_proxy;
143  }
std::shared_ptr< StringDictionaryProxy > lit_str_dict_proxy_
std::string* RowSetMemoryOwner::addString ( const std::string &  str)
inline

Definition at line 98 of file RowSetMemoryOwner.h.

References state_mutex_, and strings_.

98  {
99  std::lock_guard<std::mutex> lock(state_mutex_);
100  strings_.emplace_back(str);
101  return &strings_.back();
102  }
std::list< std::string > strings_
StringDictionaryProxy* RowSetMemoryOwner::addStringDict ( std::shared_ptr< StringDictionary str_dict,
const int  dict_id,
const int64_t  generation 
)
inline

Definition at line 110 of file RowSetMemoryOwner.h.

References CHECK_EQ, state_mutex_, and str_dict_proxy_owned_.

Referenced by getOrAddStringDictProxy().

112  {
113  std::lock_guard<std::mutex> lock(state_mutex_);
114  auto it = str_dict_proxy_owned_.find(dict_id);
115  if (it != str_dict_proxy_owned_.end()) {
116  CHECK_EQ(it->second->getDictionary(), str_dict.get());
117  it->second->updateGeneration(generation);
118  return it->second.get();
119  }
121  .emplace(dict_id,
122  std::make_shared<StringDictionaryProxy>(str_dict, generation))
123  .first;
124  return it->second.get();
125  }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
std::unordered_map< int, std::shared_ptr< StringDictionaryProxy > > str_dict_proxy_owned_

+ Here is the caller graph for this function:

void RowSetMemoryOwner::addVarlenBuffer ( void *  varlen_buffer)
inline

Definition at line 82 of file RowSetMemoryOwner.h.

References state_mutex_, and varlen_buffers_.

82  {
83  std::lock_guard<std::mutex> lock(state_mutex_);
84  varlen_buffers_.push_back(varlen_buffer);
85  }
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 92 of file RowSetMemoryOwner.h.

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

92  {
93  std::lock_guard<std::mutex> lock(state_mutex_);
95  varlen_input_buffers_.push_back(buffer);
96  }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
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)
inline

Definition at line 49 of file RowSetMemoryOwner.h.

References allocator_, CHECK, and state_mutex_.

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

49  {
51  std::lock_guard<std::mutex> lock(state_mutex_);
52  return reinterpret_cast<int8_t*>(allocator_->allocate(num_bytes));
53  }
std::unique_ptr< Arena > allocator_
#define CHECK(condition)
Definition: Logger.h:197

+ Here is the caller graph for this function:

int8_t* RowSetMemoryOwner::allocateCountDistinctBuffer ( const size_t  num_bytes)
inline

Definition at line 55 of file RowSetMemoryOwner.h.

References allocator_, CHECK, count_distinct_bitmaps_, and state_mutex_.

55  {
57  std::lock_guard<std::mutex> lock(state_mutex_);
58  auto ret = reinterpret_cast<int8_t*>(allocator_->allocateAndZero(num_bytes));
59  count_distinct_bitmaps_.emplace_back(
60  CountDistinctBitmapBuffer{ret, num_bytes, /*physical_buffer=*/true});
61  return ret;
62  }
std::vector< CountDistinctBitmapBuffer > count_distinct_bitmaps_
std::unique_ptr< Arena > allocator_
#define CHECK(condition)
Definition: Logger.h:197
std::shared_ptr<RowSetMemoryOwner> RowSetMemoryOwner::cloneStrDictDataOnly ( )
inline

Definition at line 174 of file RowSetMemoryOwner.h.

References arena_block_size_, lit_str_dict_proxy_, and str_dict_proxy_owned_.

174  {
175  auto rtn = std::make_shared<RowSetMemoryOwner>(arena_block_size_);
176  rtn->str_dict_proxy_owned_ = str_dict_proxy_owned_;
177  rtn->lit_str_dict_proxy_ = lit_str_dict_proxy_;
178  return rtn;
179  }
std::unordered_map< int, std::shared_ptr< StringDictionaryProxy > > str_dict_proxy_owned_
std::shared_ptr< StringDictionaryProxy > lit_str_dict_proxy_
StringDictionaryProxy* RowSetMemoryOwner::getLiteralStringDictProxy ( ) const
inline

Definition at line 145 of file RowSetMemoryOwner.h.

References lit_str_dict_proxy_, and state_mutex_.

145  {
146  std::lock_guard<std::mutex> lock(state_mutex_);
147  return lit_str_dict_proxy_.get();
148  }
std::shared_ptr< StringDictionaryProxy > lit_str_dict_proxy_
StringDictionaryProxy * RowSetMemoryOwner::getOrAddStringDictProxy ( const int  dict_id_in,
const bool  with_generation,
const Catalog_Namespace::Catalog catalog 
)

Definition at line 218 of file Execute.cpp.

References addStringDict(), CHECK, CHECK_EQ, CHECK_LE, g_cache_string_hash, StringDictionaryGenerations::getGeneration(), Catalog_Namespace::Catalog::getMetadataForDict(), lit_str_dict_proxy_, REGULAR_DICT, and string_dictionary_generations_.

221  {
222  const int dict_id{dict_id_in < 0 ? REGULAR_DICT(dict_id_in) : dict_id_in};
223  CHECK(catalog);
224  const auto dd = catalog->getMetadataForDict(dict_id);
225  if (dd) {
226  CHECK(dd->stringDict);
227  CHECK_LE(dd->dictNBits, 32);
228  const int64_t generation =
229  with_generation ? string_dictionary_generations_.getGeneration(dict_id) : -1;
230  return addStringDict(dd->stringDict, dict_id, generation);
231  }
232  CHECK_EQ(0, dict_id);
233  if (!lit_str_dict_proxy_) {
234  std::shared_ptr<StringDictionary> tsd =
235  std::make_shared<StringDictionary>("", false, true, g_cache_string_hash);
236  lit_str_dict_proxy_.reset(new StringDictionaryProxy(tsd, 0));
237  }
238  return lit_str_dict_proxy_.get();
239 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
int64_t getGeneration(const uint32_t id) const
StringDictionaryProxy * addStringDict(std::shared_ptr< StringDictionary > str_dict, const int dict_id, const int64_t generation)
std::shared_ptr< StringDictionaryProxy > lit_str_dict_proxy_
const DictDescriptor * getMetadataForDict(int dict_ref, bool loadDict=true) const
Definition: Catalog.cpp:1439
StringDictionaryGenerations string_dictionary_generations_
#define REGULAR_DICT(TRANSIENTID)
Definition: sqltypes.h:252
#define CHECK_LE(x, y)
Definition: Logger.h:208
bool g_cache_string_hash
#define CHECK(condition)
Definition: Logger.h:197

+ Here is the call graph for this function:

StringDictionaryGenerations& RowSetMemoryOwner::getStringDictionaryGenerations ( )
inline

Definition at line 185 of file RowSetMemoryOwner.h.

References string_dictionary_generations_.

185  {
187  }
StringDictionaryGenerations string_dictionary_generations_
StringDictionaryProxy* RowSetMemoryOwner::getStringDictProxy ( const int  dict_id) const
inline

Definition at line 127 of file RowSetMemoryOwner.h.

References CHECK, state_mutex_, and str_dict_proxy_owned_.

127  {
128  std::lock_guard<std::mutex> lock(state_mutex_);
129  auto it = str_dict_proxy_owned_.find(dict_id);
130  CHECK(it != str_dict_proxy_owned_.end());
131  return it->second.get();
132  }
std::unordered_map< int, std::shared_ptr< StringDictionaryProxy > > str_dict_proxy_owned_
#define CHECK(condition)
Definition: Logger.h:197
quantile::TDigest * RowSetMemoryOwner::newTDigest ( )

Definition at line 241 of file Execute.cpp.

References g_approx_quantile_buffer, g_approx_quantile_centroids, state_mutex_, t_digest_buffers_, and t_digests_.

241  {
242  std::lock_guard<std::mutex> lock(state_mutex_);
243  auto& td = t_digests_.emplace_back(std::make_unique<quantile::TDigest>());
244  // Separating TDigests from their buffers allows for flexibile memory management.
245  // The incoming Buffer is used to collect and sort incoming data,
246  // and used as scratch space during its merging into the main Centroids buffer.
247  td->setBuffer(t_digest_buffers_.emplace_back(g_approx_quantile_buffer));
248  td->setCentroids(t_digest_buffers_.emplace_back(g_approx_quantile_centroids));
249  return td.get();
250 }
size_t g_approx_quantile_buffer
Definition: Execute.cpp:128
std::vector< std::unique_ptr< quantile::TDigest > > t_digests_
size_t g_approx_quantile_centroids
Definition: Execute.cpp:129
std::vector< quantile::TDigest::Memory > t_digest_buffers_
void RowSetMemoryOwner::setDictionaryGenerations ( StringDictionaryGenerations  generations)
inline

Definition at line 181 of file RowSetMemoryOwner.h.

References string_dictionary_generations_.

181  {
182  string_dictionary_generations_ = generations;
183  }
StringDictionaryGenerations string_dictionary_generations_

Friends And Related Function Documentation

friend class QueryExecutionContext
friend

Definition at line 218 of file RowSetMemoryOwner.h.

friend class ResultSet
friend

Definition at line 217 of file RowSetMemoryOwner.h.

Member Data Documentation

std::unique_ptr<Arena> RowSetMemoryOwner::allocator_
private

Definition at line 213 of file RowSetMemoryOwner.h.

Referenced by allocate(), and allocateCountDistinctBuffer().

size_t RowSetMemoryOwner::arena_block_size_
private

Definition at line 212 of file RowSetMemoryOwner.h.

Referenced by cloneStrDictDataOnly().

std::list<std::vector<int64_t> > RowSetMemoryOwner::arrays_
private

Definition at line 203 of file RowSetMemoryOwner.h.

Referenced by addArray().

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

Definition at line 207 of file RowSetMemoryOwner.h.

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

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

Definition at line 198 of file RowSetMemoryOwner.h.

Referenced by addCountDistinctBuffer(), and allocateCountDistinctBuffer().

std::vector<std::set<int64_t>*> RowSetMemoryOwner::count_distinct_sets_
private

Definition at line 199 of file RowSetMemoryOwner.h.

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

std::vector<int64_t*> RowSetMemoryOwner::group_by_buffers_
private

Definition at line 200 of file RowSetMemoryOwner.h.

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

std::shared_ptr<StringDictionaryProxy> RowSetMemoryOwner::lit_str_dict_proxy_
private
std::unordered_map<int, std::shared_ptr<StringDictionaryProxy> > RowSetMemoryOwner::str_dict_proxy_owned_
private

Definition at line 204 of file RowSetMemoryOwner.h.

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

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

Definition at line 202 of file RowSetMemoryOwner.h.

Referenced by addString().

std::vector<quantile::TDigest::Memory> RowSetMemoryOwner::t_digest_buffers_
private

Definition at line 210 of file RowSetMemoryOwner.h.

Referenced by newTDigest().

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

Definition at line 209 of file RowSetMemoryOwner.h.

Referenced by newTDigest().

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

Definition at line 201 of file RowSetMemoryOwner.h.

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

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

Definition at line 208 of file RowSetMemoryOwner.h.

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


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