OmniSciDB  d2f719934e
 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 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 (double const q)
 

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 46 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 48 of file RowSetMemoryOwner.h.

References allocators_, CHECK, and i.

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

Definition at line 163 of file RowSetMemoryOwner.h.

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

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

References col_buffers_, and state_mutex_.

158  {
159  std::lock_guard<std::mutex> lock(state_mutex_);
160  col_buffers_.push_back(const_cast<void*>(col_buffer));
161  }
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_.

Referenced by allocateCountDistinctBuffer().

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_

+ Here is the caller graph for this function:

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

References lit_str_dict_proxy_, and state_mutex_.

148  {
149  std::lock_guard<std::mutex> lock(state_mutex_);
150  lit_str_dict_proxy_ = lit_str_dict_proxy;
151  }
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(
129  dict_id,
130  std::make_shared<StringDictionaryProxy>(str_dict, dict_id, generation))
131  .first;
132  return it->second.get();
133  }
#define CHECK_EQ(x, y)
Definition: Logger.h:219
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:219
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 56 of file RowSetMemoryOwner.h.

References allocators_, CHECK_LT, and state_mutex_.

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

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

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

References addCountDistinctBuffer(), and allocate().

64  {
65  int8_t* buffer = allocate(num_bytes, thread_idx);
66  std::memset(buffer, 0, num_bytes);
67  addCountDistinctBuffer(buffer, num_bytes, /*physical_buffer=*/true);
68  return buffer;
69  }
void addCountDistinctBuffer(int8_t *count_distinct_buffer, const size_t bytes, const bool physical_buffer)
int8_t * allocate(const size_t num_bytes, const size_t thread_idx=0) override

+ Here is the call graph for this function:

std::shared_ptr<RowSetMemoryOwner> RowSetMemoryOwner::cloneStrDictDataOnly ( )
inline

Definition at line 182 of file RowSetMemoryOwner.h.

References arena_block_size_, lit_str_dict_proxy_, and str_dict_proxy_owned_.

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

References lit_str_dict_proxy_, and state_mutex_.

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

245  {
246  const int dict_id{dict_id_in < 0 ? REGULAR_DICT(dict_id_in) : dict_id_in};
247  CHECK(catalog);
248  const auto dd = catalog->getMetadataForDict(dict_id);
249  if (dd) {
250  CHECK(dd->stringDict);
251  CHECK_LE(dd->dictNBits, 32);
252  const int64_t generation =
253  with_generation ? string_dictionary_generations_.getGeneration(dict_id) : -1;
254  return addStringDict(dd->stringDict, dict_id, generation);
255  }
256  CHECK_EQ(0, dict_id);
257  if (!lit_str_dict_proxy_) {
258  std::shared_ptr<StringDictionary> tsd =
259  std::make_shared<StringDictionary>("", false, true, g_cache_string_hash);
261  tsd, 0, 0)); // use 0 string_dict_id to denote literal proxy
262  }
263  return lit_str_dict_proxy_.get();
264 }
#define CHECK_EQ(x, y)
Definition: Logger.h:219
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:1554
StringDictionaryGenerations string_dictionary_generations_
#define REGULAR_DICT(TRANSIENTID)
Definition: sqltypes.h:261
#define CHECK_LE(x, y)
Definition: Logger.h:222
bool g_cache_string_hash
#define CHECK(condition)
Definition: Logger.h:211

+ Here is the call graph for this function:

StringDictionaryGenerations& RowSetMemoryOwner::getStringDictionaryGenerations ( )
inline

Definition at line 193 of file RowSetMemoryOwner.h.

References string_dictionary_generations_.

193  {
195  }
StringDictionaryGenerations string_dictionary_generations_
StringDictionaryProxy* RowSetMemoryOwner::getStringDictProxy ( const int  dict_id) const
inline

Definition at line 135 of file RowSetMemoryOwner.h.

References CHECK, state_mutex_, and str_dict_proxy_owned_.

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

Definition at line 266 of file Execute.cpp.

References g_approx_quantile_buffer, g_approx_quantile_centroids, state_mutex_, and t_digests_.

266  {
267  std::lock_guard<std::mutex> lock(state_mutex_);
268  return t_digests_
269  .emplace_back(std::make_unique<quantile::TDigest>(
271  .get();
272 }
size_t g_approx_quantile_buffer
Definition: Execute.cpp:145
std::vector< std::unique_ptr< quantile::TDigest > > t_digests_
size_t g_approx_quantile_centroids
Definition: Execute.cpp:146
void RowSetMemoryOwner::setDictionaryGenerations ( StringDictionaryGenerations  generations)
inline

Definition at line 189 of file RowSetMemoryOwner.h.

References string_dictionary_generations_.

189  {
190  string_dictionary_generations_ = generations;
191  }
StringDictionaryGenerations string_dictionary_generations_

Friends And Related Function Documentation

friend class QueryExecutionContext
friend

Definition at line 225 of file RowSetMemoryOwner.h.

friend class ResultSet
friend

Definition at line 224 of file RowSetMemoryOwner.h.

Member Data Documentation

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

Definition at line 220 of file RowSetMemoryOwner.h.

Referenced by allocate(), and RowSetMemoryOwner().

size_t RowSetMemoryOwner::arena_block_size_
private

Definition at line 219 of file RowSetMemoryOwner.h.

Referenced by cloneStrDictDataOnly().

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

Definition at line 211 of file RowSetMemoryOwner.h.

Referenced by addArray().

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

Definition at line 215 of file RowSetMemoryOwner.h.

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

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

Definition at line 206 of file RowSetMemoryOwner.h.

Referenced by addCountDistinctBuffer().

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

Definition at line 207 of file RowSetMemoryOwner.h.

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

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

Definition at line 208 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 212 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 210 of file RowSetMemoryOwner.h.

Referenced by addString().

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

Definition at line 217 of file RowSetMemoryOwner.h.

Referenced by nullTDigest().

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

Definition at line 209 of file RowSetMemoryOwner.h.

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

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

Definition at line 216 of file RowSetMemoryOwner.h.

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


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