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

#include <RowSetMemoryOwner.h>

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

Classes

struct  CountDistinctBitmapBuffer
 

Public Member Functions

 RowSetMemoryOwner (const size_t arena_block_size, const size_t num_kernel_threads=0)
 
int8_t * allocate (const size_t num_bytes, const size_t thread_idx=0) override
 
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 (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::TDigestnullTDigest ()
 

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_
 
size_t arena_block_size_
 
std::vector< std::unique_ptr
< Arena > > 
allocators_
 
std::mutex state_mutex_
 

Friends

class ResultSet
 
class QueryExecutionContext
 

Additional Inherited Members

- Protected Member Functions inherited from SimpleAllocator
 ~SimpleAllocator ()=default
 

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,
const size_t  num_kernel_threads = 0 
)
inline

Definition at line 45 of file RowSetMemoryOwner.h.

References allocators_, CHECK, and i.

46  : arena_block_size_(arena_block_size) {
47  for (size_t i = 0; i < num_kernel_threads + 1; i++) {
48  allocators_.emplace_back(std::make_unique<Arena>(arena_block_size));
49  }
50  CHECK(!allocators_.empty());
51  }
std::vector< std::unique_ptr< Arena > > allocators_
#define CHECK(condition)
Definition: Logger.h:206
RowSetMemoryOwner::~RowSetMemoryOwner ( )
inline

Definition at line 162 of file RowSetMemoryOwner.h.

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

162  {
163  for (auto count_distinct_set : count_distinct_sets_) {
164  delete count_distinct_set;
165  }
166  for (auto group_by_buffer : group_by_buffers_) {
167  free(group_by_buffer);
168  }
169  for (auto varlen_buffer : varlen_buffers_) {
170  free(varlen_buffer);
171  }
172  for (auto varlen_input_buffer : varlen_input_buffers_) {
173  CHECK(varlen_input_buffer);
174  varlen_input_buffer->unPin();
175  }
176  for (auto col_buffer : col_buffers_) {
177  free(col_buffer);
178  }
179  }
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:206
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 111 of file RowSetMemoryOwner.h.

References arrays_, and state_mutex_.

111  {
112  std::lock_guard<std::mutex> lock(state_mutex_);
113  arrays_.emplace_back(arr);
114  return &arrays_.back();
115  }
std::list< std::vector< int64_t > > arrays_
void RowSetMemoryOwner::addColBuffer ( const void *  col_buffer)
inline

Definition at line 157 of file RowSetMemoryOwner.h.

References col_buffers_, and state_mutex_.

157  {
158  std::lock_guard<std::mutex> lock(state_mutex_);
159  col_buffers_.push_back(const_cast<void*>(col_buffer));
160  }
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 71 of file RowSetMemoryOwner.h.

References count_distinct_bitmaps_, and state_mutex_.

73  {
74  std::lock_guard<std::mutex> lock(state_mutex_);
75  count_distinct_bitmaps_.emplace_back(
76  CountDistinctBitmapBuffer{count_distinct_buffer, bytes, physical_buffer});
77  }
std::vector< CountDistinctBitmapBuffer > count_distinct_bitmaps_
void RowSetMemoryOwner::addCountDistinctSet ( std::set< int64_t > *  count_distinct_set)
inline

Definition at line 79 of file RowSetMemoryOwner.h.

References count_distinct_sets_, and state_mutex_.

79  {
80  std::lock_guard<std::mutex> lock(state_mutex_);
81  count_distinct_sets_.push_back(count_distinct_set);
82  }
std::vector< std::set< int64_t > * > count_distinct_sets_
void RowSetMemoryOwner::addGroupByBuffer ( int64_t *  group_by_buffer)
inline

Definition at line 84 of file RowSetMemoryOwner.h.

References group_by_buffers_, and state_mutex_.

84  {
85  std::lock_guard<std::mutex> lock(state_mutex_);
86  group_by_buffers_.push_back(group_by_buffer);
87  }
std::vector< int64_t * > group_by_buffers_
void RowSetMemoryOwner::addLiteralStringDictProxy ( std::shared_ptr< StringDictionaryProxy lit_str_dict_proxy)
inline

Definition at line 146 of file RowSetMemoryOwner.h.

References lit_str_dict_proxy_, and state_mutex_.

147  {
148  std::lock_guard<std::mutex> lock(state_mutex_);
149  lit_str_dict_proxy_ = lit_str_dict_proxy;
150  }
std::shared_ptr< StringDictionaryProxy > lit_str_dict_proxy_
std::string* RowSetMemoryOwner::addString ( const std::string &  str)
inline

Definition at line 105 of file RowSetMemoryOwner.h.

References state_mutex_, and strings_.

105  {
106  std::lock_guard<std::mutex> lock(state_mutex_);
107  strings_.emplace_back(str);
108  return &strings_.back();
109  }
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 117 of file RowSetMemoryOwner.h.

References CHECK_EQ, state_mutex_, and str_dict_proxy_owned_.

Referenced by getOrAddStringDictProxy().

119  {
120  std::lock_guard<std::mutex> lock(state_mutex_);
121  auto it = str_dict_proxy_owned_.find(dict_id);
122  if (it != str_dict_proxy_owned_.end()) {
123  CHECK_EQ(it->second->getDictionary(), str_dict.get());
124  it->second->updateGeneration(generation);
125  return it->second.get();
126  }
128  .emplace(dict_id,
129  std::make_shared<StringDictionaryProxy>(str_dict, generation))
130  .first;
131  return it->second.get();
132  }
#define CHECK_EQ(x, y)
Definition: Logger.h:214
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 89 of file RowSetMemoryOwner.h.

References state_mutex_, and varlen_buffers_.

89  {
90  std::lock_guard<std::mutex> lock(state_mutex_);
91  varlen_buffers_.push_back(varlen_buffer);
92  }
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 99 of file RowSetMemoryOwner.h.

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

99  {
100  std::lock_guard<std::mutex> lock(state_mutex_);
102  varlen_input_buffers_.push_back(buffer);
103  }
#define CHECK_EQ(x, y)
Definition: Logger.h:214
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,
const size_t  thread_idx = 0 
)
inlineoverridevirtual

Implements SimpleAllocator.

Definition at line 53 of file RowSetMemoryOwner.h.

References allocators_, CHECK_LT, and state_mutex_.

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

53  {
54  CHECK_LT(thread_idx, allocators_.size());
55  auto allocator = allocators_[thread_idx].get();
56  std::lock_guard<std::mutex> lock(state_mutex_);
57  return reinterpret_cast<int8_t*>(allocator->allocate(num_bytes));
58  }
std::vector< std::unique_ptr< Arena > > allocators_
#define CHECK_LT(x, y)
Definition: Logger.h:216

+ 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 60 of file RowSetMemoryOwner.h.

References allocators_, CHECK_LT, count_distinct_bitmaps_, and state_mutex_.

61  {
62  CHECK_LT(thread_idx, allocators_.size());
63  auto allocator = allocators_[thread_idx].get();
64  std::lock_guard<std::mutex> lock(state_mutex_);
65  auto ret = reinterpret_cast<int8_t*>(allocator->allocateAndZero(num_bytes));
66  count_distinct_bitmaps_.emplace_back(
67  CountDistinctBitmapBuffer{ret, num_bytes, /*physical_buffer=*/true});
68  return ret;
69  }
std::vector< std::unique_ptr< Arena > > allocators_
std::vector< CountDistinctBitmapBuffer > count_distinct_bitmaps_
#define CHECK_LT(x, y)
Definition: Logger.h:216
std::shared_ptr<RowSetMemoryOwner> RowSetMemoryOwner::cloneStrDictDataOnly ( )
inline

Definition at line 181 of file RowSetMemoryOwner.h.

References arena_block_size_, lit_str_dict_proxy_, and str_dict_proxy_owned_.

181  {
182  auto rtn = std::make_shared<RowSetMemoryOwner>(arena_block_size_, /*num_kernels=*/1);
183  rtn->str_dict_proxy_owned_ = str_dict_proxy_owned_;
184  rtn->lit_str_dict_proxy_ = lit_str_dict_proxy_;
185  return rtn;
186  }
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 152 of file RowSetMemoryOwner.h.

References lit_str_dict_proxy_, and state_mutex_.

152  {
153  std::lock_guard<std::mutex> lock(state_mutex_);
154  return lit_str_dict_proxy_.get();
155  }
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 228 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_.

231  {
232  const int dict_id{dict_id_in < 0 ? REGULAR_DICT(dict_id_in) : dict_id_in};
233  CHECK(catalog);
234  const auto dd = catalog->getMetadataForDict(dict_id);
235  if (dd) {
236  CHECK(dd->stringDict);
237  CHECK_LE(dd->dictNBits, 32);
238  const int64_t generation =
239  with_generation ? string_dictionary_generations_.getGeneration(dict_id) : -1;
240  return addStringDict(dd->stringDict, dict_id, generation);
241  }
242  CHECK_EQ(0, dict_id);
243  if (!lit_str_dict_proxy_) {
244  std::shared_ptr<StringDictionary> tsd =
245  std::make_shared<StringDictionary>("", false, true, g_cache_string_hash);
246  lit_str_dict_proxy_.reset(new StringDictionaryProxy(tsd, 0));
247  }
248  return lit_str_dict_proxy_.get();
249 }
#define CHECK_EQ(x, y)
Definition: Logger.h:214
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:1494
StringDictionaryGenerations string_dictionary_generations_
#define REGULAR_DICT(TRANSIENTID)
Definition: sqltypes.h:255
#define CHECK_LE(x, y)
Definition: Logger.h:217
bool g_cache_string_hash
#define CHECK(condition)
Definition: Logger.h:206

+ Here is the call graph for this function:

StringDictionaryGenerations& RowSetMemoryOwner::getStringDictionaryGenerations ( )
inline

Definition at line 192 of file RowSetMemoryOwner.h.

References string_dictionary_generations_.

192  {
194  }
StringDictionaryGenerations string_dictionary_generations_
StringDictionaryProxy* RowSetMemoryOwner::getStringDictProxy ( const int  dict_id) const
inline

Definition at line 134 of file RowSetMemoryOwner.h.

References CHECK, state_mutex_, and str_dict_proxy_owned_.

134  {
135  std::lock_guard<std::mutex> lock(state_mutex_);
136  auto it = str_dict_proxy_owned_.find(dict_id);
137  CHECK(it != str_dict_proxy_owned_.end());
138  return it->second.get();
139  }
std::unordered_map< int, std::shared_ptr< StringDictionaryProxy > > str_dict_proxy_owned_
#define CHECK(condition)
Definition: Logger.h:206
quantile::TDigest * RowSetMemoryOwner::nullTDigest ( )

Definition at line 251 of file Execute.cpp.

References g_approx_quantile_buffer, g_approx_quantile_centroids, state_mutex_, and t_digests_.

251  {
252  std::lock_guard<std::mutex> lock(state_mutex_);
253  return t_digests_
254  .emplace_back(std::make_unique<quantile::TDigest>(
256  .get();
257 }
size_t g_approx_quantile_buffer
Definition: Execute.cpp:136
std::vector< std::unique_ptr< quantile::TDigest > > t_digests_
size_t g_approx_quantile_centroids
Definition: Execute.cpp:137
void RowSetMemoryOwner::setDictionaryGenerations ( StringDictionaryGenerations  generations)
inline

Definition at line 188 of file RowSetMemoryOwner.h.

References string_dictionary_generations_.

188  {
189  string_dictionary_generations_ = generations;
190  }
StringDictionaryGenerations string_dictionary_generations_

Friends And Related Function Documentation

friend class QueryExecutionContext
friend

Definition at line 224 of file RowSetMemoryOwner.h.

friend class ResultSet
friend

Definition at line 223 of file RowSetMemoryOwner.h.

Member Data Documentation

std::vector<std::unique_ptr<Arena> > RowSetMemoryOwner::allocators_
private

Definition at line 219 of file RowSetMemoryOwner.h.

Referenced by allocate(), allocateCountDistinctBuffer(), and RowSetMemoryOwner().

size_t RowSetMemoryOwner::arena_block_size_
private

Definition at line 218 of file RowSetMemoryOwner.h.

Referenced by cloneStrDictDataOnly().

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

Definition at line 210 of file RowSetMemoryOwner.h.

Referenced by addArray().

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

Definition at line 214 of file RowSetMemoryOwner.h.

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

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

Definition at line 205 of file RowSetMemoryOwner.h.

Referenced by addCountDistinctBuffer(), and allocateCountDistinctBuffer().

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

Definition at line 206 of file RowSetMemoryOwner.h.

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

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

Definition at line 207 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 211 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 209 of file RowSetMemoryOwner.h.

Referenced by addString().

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

Definition at line 216 of file RowSetMemoryOwner.h.

Referenced by nullTDigest().

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

Definition at line 208 of file RowSetMemoryOwner.h.

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

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

Definition at line 215 of file RowSetMemoryOwner.h.

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


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