OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
anonymous_namespace{QueryMemoryInitializer.cpp} Namespace Reference

Functions

void check_total_bitmap_memory (const QueryMemoryDescriptor &query_mem_desc)
 
std::pair< int64_t *, bool > alloc_group_by_buffer (const size_t numBytes, RenderAllocatorMap *render_allocator_map, const size_t thread_idx, RowSetMemoryOwner *mem_owner, const bool reuse_existing_buffer_for_thread)
 
int64_t get_consistent_frag_size (const std::vector< uint64_t > &frag_offsets)
 
std::vector< int64_t > get_consistent_frags_sizes (const std::vector< std::vector< uint64_t >> &frag_offsets)
 
std::vector< int64_t > get_consistent_frags_sizes (const std::vector< Analyzer::Expr * > &target_exprs, const std::vector< int64_t > &table_frag_sizes)
 
std::vector< std::vector
< int64_t > > 
get_col_frag_offsets (const std::vector< Analyzer::Expr * > &target_exprs, const std::vector< std::vector< uint64_t >> &table_frag_offsets)
 
int get_input_idx (RelAlgExecutionUnit const &ra_exe_unit, const shared::TableKey &outer_table_key)
 
void check_count_distinct_expr_metadata (const QueryMemoryDescriptor &query_mem_desc, const RelAlgExecutionUnit &ra_exe_unit)
 
QueryMemoryInitializer::TargetAggOpsMetadata collect_target_expr_metadata (const QueryMemoryDescriptor &query_mem_desc, const RelAlgExecutionUnit &ra_exe_unit)
 
template<typename T >
int8_t * initColumnarBuffer (T *buffer_ptr, const T init_val, const uint32_t entry_count)
 
void eachAggregateTargetIdxOfType (std::vector< Analyzer::Expr * > const &target_exprs, SQLAgg const agg_type, std::function< void(Analyzer::AggExpr const *, size_t)> lambda)
 
void compact_projection_buffer_for_cpu_columnar (const QueryMemoryDescriptor &query_mem_desc, int8_t *projection_buffer, const size_t projection_count)
 

Function Documentation

std::pair<int64_t*, bool> anonymous_namespace{QueryMemoryInitializer.cpp}::alloc_group_by_buffer ( const size_t  numBytes,
RenderAllocatorMap render_allocator_map,
const size_t  thread_idx,
RowSetMemoryOwner mem_owner,
const bool  reuse_existing_buffer_for_thread 
)

Definition at line 59 of file QueryMemoryInitializer.cpp.

References RowSetMemoryOwner::allocate(), RowSetMemoryOwner::allocateCachedGroupByBuffer(), and RenderAllocatorMap::getRenderAllocator().

Referenced by QueryMemoryInitializer::QueryMemoryInitializer(), and thread_idx_().

64  {
65  if (render_allocator_map) {
66  // NOTE(adb): If we got here, we are performing an in-situ rendering query and are not
67  // using CUDA buffers. Therefore we need to allocate result set storage using CPU
68  // memory.
69  const auto gpu_idx = 0; // Only 1 GPU supported in CUDA-disabled rendering mode
70  auto render_allocator_ptr = render_allocator_map->getRenderAllocator(gpu_idx);
71  return std::make_pair(
72  reinterpret_cast<int64_t*>(render_allocator_ptr->alloc(numBytes)), false);
73  } else if (reuse_existing_buffer_for_thread) {
74  return mem_owner->allocateCachedGroupByBuffer(numBytes, thread_idx);
75  }
76  return std::make_pair(
77  reinterpret_cast<int64_t*>(mem_owner->allocate(numBytes, thread_idx)), false);
78 }
RenderAllocator * getRenderAllocator(size_t device_id)
int8_t * allocate(const size_t num_bytes, const size_t thread_idx=0) override
std::pair< int64_t *, bool > allocateCachedGroupByBuffer(const size_t num_bytes, const size_t thread_idx)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void anonymous_namespace{QueryMemoryInitializer.cpp}::check_count_distinct_expr_metadata ( const QueryMemoryDescriptor query_mem_desc,
const RelAlgExecutionUnit ra_exe_unit 
)

Definition at line 167 of file QueryMemoryInitializer.cpp.

References CHECK, CHECK_EQ, CHECK_GE, CHECK_LT, g_bigint_count, get_target_info(), QueryMemoryDescriptor::getCountDistinctDescriptor(), QueryMemoryDescriptor::getLogicalSlotWidthBytes(), QueryMemoryDescriptor::getSlotCount(), QueryMemoryDescriptor::getSlotIndexForSingleSlotCol(), Invalid, is_distinct_target(), kAPPROX_COUNT_DISTINCT, kCOUNT, kCOUNT_IF, and RelAlgExecutionUnit::target_exprs.

Referenced by QueryMemoryInitializer::QueryMemoryInitializer().

168  {
169  const size_t agg_col_count{query_mem_desc.getSlotCount()};
170  CHECK_GE(agg_col_count, ra_exe_unit.target_exprs.size());
171  for (size_t target_idx = 0; target_idx < ra_exe_unit.target_exprs.size();
172  ++target_idx) {
173  const auto target_expr = ra_exe_unit.target_exprs[target_idx];
174  const auto agg_info = get_target_info(target_expr, g_bigint_count);
175  if (is_distinct_target(agg_info)) {
176  CHECK(agg_info.is_agg &&
177  (agg_info.agg_kind == kCOUNT || agg_info.agg_kind == kCOUNT_IF ||
178  agg_info.agg_kind == kAPPROX_COUNT_DISTINCT));
179  CHECK(!agg_info.sql_type.is_varlen());
180  const size_t agg_col_idx = query_mem_desc.getSlotIndexForSingleSlotCol(target_idx);
181  CHECK_LT(static_cast<size_t>(agg_col_idx), agg_col_count);
182  CHECK_EQ(static_cast<size_t>(query_mem_desc.getLogicalSlotWidthBytes(agg_col_idx)),
183  sizeof(int64_t));
184  const auto& count_distinct_desc =
185  query_mem_desc.getCountDistinctDescriptor(target_idx);
186  CHECK(count_distinct_desc.impl_type_ != CountDistinctImplType::Invalid);
187  }
188  }
189 }
std::vector< Analyzer::Expr * > target_exprs
#define CHECK_EQ(x, y)
Definition: Logger.h:301
#define CHECK_GE(x, y)
Definition: Logger.h:306
TargetInfo get_target_info(const Analyzer::Expr *target_expr, const bool bigint_count)
Definition: TargetInfo.h:92
bool g_bigint_count
bool is_distinct_target(const TargetInfo &target_info)
Definition: TargetInfo.h:102
const CountDistinctDescriptor & getCountDistinctDescriptor(const size_t idx) const
#define CHECK_LT(x, y)
Definition: Logger.h:303
Definition: sqldefs.h:78
#define CHECK(condition)
Definition: Logger.h:291
const int8_t getSlotIndexForSingleSlotCol(const size_t col_idx) const
const int8_t getLogicalSlotWidthBytes(const size_t slot_idx) const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void anonymous_namespace{QueryMemoryInitializer.cpp}::check_total_bitmap_memory ( const QueryMemoryDescriptor query_mem_desc)
inline

Definition at line 32 of file QueryMemoryInitializer.cpp.

References Bitmap, CountDistinctDescriptor::bitmapPaddedSizeBytes(), g_bitmap_memory_limit, QueryMemoryDescriptor::getCountDistinctDescriptor(), QueryMemoryDescriptor::getCountDistinctDescriptorsSize(), and QueryMemoryDescriptor::getEntryCount().

Referenced by QueryMemoryInitializer::QueryMemoryInitializer().

32  {
33  const size_t groups_buffer_entry_count = query_mem_desc.getEntryCount();
34  checked_int64_t total_bytes_per_group = 0;
35  const size_t num_count_distinct_descs =
36  query_mem_desc.getCountDistinctDescriptorsSize();
37  for (size_t i = 0; i < num_count_distinct_descs; i++) {
38  const auto count_distinct_desc = query_mem_desc.getCountDistinctDescriptor(i);
39  if (count_distinct_desc.impl_type_ != CountDistinctImplType::Bitmap) {
40  continue;
41  }
42  total_bytes_per_group += count_distinct_desc.bitmapPaddedSizeBytes();
43  }
44  int64_t total_bytes{0};
45  // Using OutOfHostMemory until we can verify that SlabTooBig would also be properly
46  // caught
47  try {
48  total_bytes = static_cast<int64_t>(total_bytes_per_group * groups_buffer_entry_count);
49  } catch (...) {
50  // Absurd amount of memory, merely computing the number of bits overflows int64_t.
51  // Don't bother to report the real amount, this is unlikely to ever happen.
52  throw OutOfHostMemory(std::numeric_limits<int64_t>::max() / 8);
53  }
54  if (total_bytes >= g_bitmap_memory_limit) {
55  throw OutOfHostMemory(total_bytes);
56  }
57 }
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 64, 64, boost::multiprecision::signed_magnitude, boost::multiprecision::checked, void >> checked_int64_t
int64_t g_bitmap_memory_limit
size_t getCountDistinctDescriptorsSize() const
const CountDistinctDescriptor & getCountDistinctDescriptor(const size_t idx) const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QueryMemoryInitializer::TargetAggOpsMetadata anonymous_namespace{QueryMemoryInitializer.cpp}::collect_target_expr_metadata ( const QueryMemoryDescriptor query_mem_desc,
const RelAlgExecutionUnit ra_exe_unit 
)

Definition at line 191 of file QueryMemoryInitializer.cpp.

References QueryMemoryDescriptor::countDistinctDescriptorsLogicallyEmpty(), QueryMemoryInitializer::TargetAggOpsMetadata::has_count_distinct, QueryMemoryInitializer::TargetAggOpsMetadata::has_mode, QueryMemoryInitializer::TargetAggOpsMetadata::has_tdigest, kAPPROX_QUANTILE, kMODE, and RelAlgExecutionUnit::target_exprs.

Referenced by QueryMemoryInitializer::QueryMemoryInitializer().

193  {
195  if (!query_mem_desc.countDistinctDescriptorsLogicallyEmpty()) {
196  agg_op_metadata.has_count_distinct = true;
197  }
198  std::for_each(
199  ra_exe_unit.target_exprs.begin(),
200  ra_exe_unit.target_exprs.end(),
201  [&agg_op_metadata](const Analyzer::Expr* expr) {
202  if (auto const* agg_expr = dynamic_cast<Analyzer::AggExpr const*>(expr)) {
203  if (agg_expr->get_aggtype() == kMODE) {
204  agg_op_metadata.has_mode = true;
205  } else if (agg_expr->get_aggtype() == kAPPROX_QUANTILE) {
206  agg_op_metadata.has_tdigest = true;
207  }
208  }
209  });
210  return agg_op_metadata;
211 }
std::vector< Analyzer::Expr * > target_exprs
bool countDistinctDescriptorsLogicallyEmpty() const
Definition: sqldefs.h:83

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void anonymous_namespace{QueryMemoryInitializer.cpp}::compact_projection_buffer_for_cpu_columnar ( const QueryMemoryDescriptor query_mem_desc,
int8_t *  projection_buffer,
const size_t  projection_count 
)

Definition at line 1262 of file QueryMemoryInitializer.cpp.

References align_to_int64(), CHECK, QueryMemoryDescriptor::getColOffInBytes(), QueryMemoryDescriptor::getEntryCount(), QueryMemoryDescriptor::getPaddedSlotWidthBytes(), and QueryMemoryDescriptor::getSlotCount().

Referenced by QueryMemoryInitializer::compactProjectionBuffersCpu().

1265  {
1266  // the first column (row indices) remains unchanged.
1267  CHECK(projection_count <= query_mem_desc.getEntryCount());
1268  constexpr size_t row_index_width = sizeof(int64_t);
1269  size_t buffer_offset1{projection_count * row_index_width};
1270  // other columns are actual non-lazy columns for the projection:
1271  for (size_t i = 0; i < query_mem_desc.getSlotCount(); i++) {
1272  if (query_mem_desc.getPaddedSlotWidthBytes(i) > 0) {
1273  auto column_proj_size =
1274  projection_count * query_mem_desc.getPaddedSlotWidthBytes(i);
1275  auto buffer_offset2 = query_mem_desc.getColOffInBytes(i);
1276  if (buffer_offset1 + column_proj_size >= buffer_offset2) {
1277  // overlapping
1278  std::memmove(projection_buffer + buffer_offset1,
1279  projection_buffer + buffer_offset2,
1280  column_proj_size);
1281  } else {
1282  std::memcpy(projection_buffer + buffer_offset1,
1283  projection_buffer + buffer_offset2,
1284  column_proj_size);
1285  }
1286  buffer_offset1 += align_to_int64(column_proj_size);
1287  }
1288  }
1289 }
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
#define CHECK(condition)
Definition: Logger.h:291
size_t getColOffInBytes(const size_t col_idx) const
FORCE_INLINE HOST DEVICE T align_to_int64(T addr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void anonymous_namespace{QueryMemoryInitializer.cpp}::eachAggregateTargetIdxOfType ( std::vector< Analyzer::Expr * > const &  target_exprs,
SQLAgg const  agg_type,
std::function< void(Analyzer::AggExpr const *, size_t)>  lambda 
)

Definition at line 904 of file QueryMemoryInitializer.cpp.

Referenced by QueryMemoryInitializer::allocateModeBuffer(), QueryMemoryInitializer::allocateTDigestsBuffer(), QueryMemoryInitializer::initializeModeIndexSet(), and QueryMemoryInitializer::initializeQuantileParams().

907  {
908  for (size_t target_idx = 0; target_idx < target_exprs.size(); ++target_idx) {
909  auto const target_expr = target_exprs[target_idx];
910  if (auto const* agg_expr = dynamic_cast<Analyzer::AggExpr const*>(target_expr)) {
911  if (agg_expr->get_aggtype() == agg_type) {
912  lambda(agg_expr, target_idx);
913  }
914  }
915  }
916 }

+ Here is the caller graph for this function:

std::vector<std::vector<int64_t> > anonymous_namespace{QueryMemoryInitializer.cpp}::get_col_frag_offsets ( const std::vector< Analyzer::Expr * > &  target_exprs,
const std::vector< std::vector< uint64_t >> &  table_frag_offsets 
)
inline

Definition at line 130 of file QueryMemoryInitializer.cpp.

References CHECK_EQ, and CHECK_LT.

Referenced by QueryMemoryInitializer::QueryMemoryInitializer(), and thread_idx_().

132  {
133  std::vector<std::vector<int64_t>> col_frag_offsets;
134  for (auto& table_offsets : table_frag_offsets) {
135  std::vector<int64_t> col_offsets;
136  for (auto expr : target_exprs) {
137  if (const auto col_var = dynamic_cast<Analyzer::ColumnVar*>(expr)) {
138  if (col_var->get_rte_idx() < 0) {
139  CHECK_EQ(-1, col_var->get_rte_idx());
140  col_offsets.push_back(int64_t(-1));
141  } else {
142  CHECK_LT(static_cast<size_t>(col_var->get_rte_idx()), table_offsets.size());
143  col_offsets.push_back(
144  static_cast<int64_t>(table_offsets[col_var->get_rte_idx()]));
145  }
146  } else {
147  col_offsets.push_back(int64_t(-1));
148  }
149  }
150  col_frag_offsets.push_back(col_offsets);
151  }
152  return col_frag_offsets;
153 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
#define CHECK_LT(x, y)
Definition: Logger.h:303

+ Here is the caller graph for this function:

int64_t anonymous_namespace{QueryMemoryInitializer.cpp}::get_consistent_frag_size ( const std::vector< uint64_t > &  frag_offsets)
inline

Definition at line 80 of file QueryMemoryInitializer.cpp.

Referenced by get_consistent_frags_sizes().

80  {
81  if (frag_offsets.size() < 2) {
82  return int64_t(-1);
83  }
84  const auto frag_size = frag_offsets[1] - frag_offsets[0];
85  for (size_t i = 2; i < frag_offsets.size(); ++i) {
86  const auto curr_size = frag_offsets[i] - frag_offsets[i - 1];
87  if (curr_size != frag_size) {
88  return int64_t(-1);
89  }
90  }
91  return !frag_size ? std::numeric_limits<int64_t>::max()
92  : static_cast<int64_t>(frag_size);
93 }

+ Here is the caller graph for this function:

std::vector<int64_t> anonymous_namespace{QueryMemoryInitializer.cpp}::get_consistent_frags_sizes ( const std::vector< std::vector< uint64_t >> &  frag_offsets)
inline

Definition at line 95 of file QueryMemoryInitializer.cpp.

References get_consistent_frag_size().

Referenced by QueryMemoryInitializer::QueryMemoryInitializer(), and thread_idx_().

96  {
97  if (frag_offsets.empty()) {
98  return {};
99  }
100  std::vector<int64_t> frag_sizes;
101  for (size_t tab_idx = 0; tab_idx < frag_offsets[0].size(); ++tab_idx) {
102  std::vector<uint64_t> tab_offs;
103  for (auto& offsets : frag_offsets) {
104  tab_offs.push_back(offsets[tab_idx]);
105  }
106  frag_sizes.push_back(get_consistent_frag_size(tab_offs));
107  }
108  return frag_sizes;
109 }
int64_t get_consistent_frag_size(const std::vector< uint64_t > &frag_offsets)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector<int64_t> anonymous_namespace{QueryMemoryInitializer.cpp}::get_consistent_frags_sizes ( const std::vector< Analyzer::Expr * > &  target_exprs,
const std::vector< int64_t > &  table_frag_sizes 
)
inline

Definition at line 111 of file QueryMemoryInitializer.cpp.

References CHECK_EQ.

113  {
114  std::vector<int64_t> col_frag_sizes;
115  for (auto expr : target_exprs) {
116  if (const auto col_var = dynamic_cast<Analyzer::ColumnVar*>(expr)) {
117  if (col_var->get_rte_idx() < 0) {
118  CHECK_EQ(-1, col_var->get_rte_idx());
119  col_frag_sizes.push_back(int64_t(-1));
120  } else {
121  col_frag_sizes.push_back(table_frag_sizes[col_var->get_rte_idx()]);
122  }
123  } else {
124  col_frag_sizes.push_back(int64_t(-1));
125  }
126  }
127  return col_frag_sizes;
128 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
int anonymous_namespace{QueryMemoryInitializer.cpp}::get_input_idx ( RelAlgExecutionUnit const &  ra_exe_unit,
const shared::TableKey outer_table_key 
)

Definition at line 157 of file QueryMemoryInitializer.cpp.

References RelAlgExecutionUnit::input_descs.

Referenced by QueryPlanDagExtractor::handleLeftDeepJoinTree(), and QueryMemoryInitializer::QueryMemoryInitializer().

158  {
159  auto match_table_key = [=](auto& desc) {
160  return outer_table_key == desc.getTableKey();
161  };
162  auto& input_descs = ra_exe_unit.input_descs;
163  auto itr = std::find_if(input_descs.begin(), input_descs.end(), match_table_key);
164  return itr == input_descs.end() ? 0 : itr->getNestLevel();
165 }

+ Here is the caller graph for this function:

template<typename T >
int8_t* anonymous_namespace{QueryMemoryInitializer.cpp}::initColumnarBuffer ( T *  buffer_ptr,
const T  init_val,
const uint32_t  entry_count 
)

Definition at line 667 of file QueryMemoryInitializer.cpp.

References heavydb.dtypes::T.

667  {
668  static_assert(sizeof(T) <= sizeof(int64_t), "Unsupported template type");
669  for (uint32_t i = 0; i < entry_count; ++i) {
670  buffer_ptr[i] = init_val;
671  }
672  return reinterpret_cast<int8_t*>(buffer_ptr + entry_count);
673 }