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

Classes

struct  AddNbytes
 

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 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 67 of file QueryMemoryInitializer.cpp.

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

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

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

+ 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 175 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().

176  {
177  const size_t agg_col_count{query_mem_desc.getSlotCount()};
178  CHECK_GE(agg_col_count, ra_exe_unit.target_exprs.size());
179  for (size_t target_idx = 0; target_idx < ra_exe_unit.target_exprs.size();
180  ++target_idx) {
181  const auto target_expr = ra_exe_unit.target_exprs[target_idx];
182  const auto agg_info = get_target_info(target_expr, g_bigint_count);
183  if (is_distinct_target(agg_info)) {
184  CHECK(agg_info.is_agg &&
185  (agg_info.agg_kind == kCOUNT || agg_info.agg_kind == kCOUNT_IF ||
186  agg_info.agg_kind == kAPPROX_COUNT_DISTINCT));
187  CHECK(!agg_info.sql_type.is_varlen());
188  const size_t agg_col_idx = query_mem_desc.getSlotIndexForSingleSlotCol(target_idx);
189  CHECK_LT(static_cast<size_t>(agg_col_idx), agg_col_count);
190  CHECK_EQ(static_cast<size_t>(query_mem_desc.getLogicalSlotWidthBytes(agg_col_idx)),
191  sizeof(int64_t));
192  const auto& count_distinct_desc =
193  query_mem_desc.getCountDistinctDescriptor(target_idx);
194  CHECK(count_distinct_desc.impl_type_ != CountDistinctImplType::Invalid);
195  }
196  }
197 }
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:81
#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 40 of file QueryMemoryInitializer.cpp.

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

Referenced by QueryMemoryInitializer::QueryMemoryInitializer().

40  {
41  const size_t groups_buffer_entry_count = query_mem_desc.getEntryCount();
42  checked_int64_t total_bytes_per_group = 0;
43  const size_t num_count_distinct_descs =
44  query_mem_desc.getCountDistinctDescriptorsSize();
45  for (size_t i = 0; i < num_count_distinct_descs; i++) {
46  const auto count_distinct_desc = query_mem_desc.getCountDistinctDescriptor(i);
47  if (count_distinct_desc.impl_type_ != CountDistinctImplType::Bitmap) {
48  continue;
49  }
50  total_bytes_per_group += count_distinct_desc.bitmapPaddedSizeBytes();
51  }
52  int64_t total_bytes{0};
53  // Using OutOfHostMemory until we can verify that SlabTooBig would also be properly
54  // caught
55  try {
56  total_bytes = static_cast<int64_t>(total_bytes_per_group * groups_buffer_entry_count);
57  } catch (...) {
58  // Absurd amount of memory, merely computing the number of bits overflows int64_t.
59  // Don't bother to report the real amount, this is unlikely to ever happen.
60  throw OutOfHostMemory(std::numeric_limits<int64_t>::max() / 8);
61  }
62  if (total_bytes >= g_bitmap_memory_limit) {
63  throw OutOfHostMemory(total_bytes);
64  }
65 }
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 199 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().

201  {
203  if (!query_mem_desc.countDistinctDescriptorsLogicallyEmpty()) {
204  agg_op_metadata.has_count_distinct = true;
205  }
206  std::for_each(
207  ra_exe_unit.target_exprs.begin(),
208  ra_exe_unit.target_exprs.end(),
209  [&agg_op_metadata](const Analyzer::Expr* expr) {
210  if (auto const* agg_expr = dynamic_cast<Analyzer::AggExpr const*>(expr)) {
211  if (agg_expr->get_aggtype() == kMODE) {
212  agg_op_metadata.has_mode = true;
213  } else if (agg_expr->get_aggtype() == kAPPROX_QUANTILE) {
214  agg_op_metadata.has_tdigest = true;
215  }
216  }
217  });
218  return agg_op_metadata;
219 }
std::vector< Analyzer::Expr * > target_exprs
bool countDistinctDescriptorsLogicallyEmpty() const
Definition: sqldefs.h:86

+ 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 1264 of file QueryMemoryInitializer.cpp.

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

Referenced by QueryMemoryInitializer::compactProjectionBuffersCpu().

1267  {
1268  // the first column (row indices) remains unchanged.
1269  CHECK(projection_count <= query_mem_desc.getEntryCount());
1270  constexpr size_t row_index_width = sizeof(int64_t);
1271  size_t buffer_offset1{projection_count * row_index_width};
1272  // other columns are actual non-lazy columns for the projection:
1273  for (size_t i = 0; i < query_mem_desc.getSlotCount(); i++) {
1274  if (query_mem_desc.getPaddedSlotWidthBytes(i) > 0) {
1275  auto column_proj_size =
1276  projection_count * query_mem_desc.getPaddedSlotWidthBytes(i);
1277  auto buffer_offset2 = query_mem_desc.getColOffInBytes(i);
1278  if (buffer_offset1 + column_proj_size >= buffer_offset2) {
1279  // overlapping
1280  std::memmove(projection_buffer + buffer_offset1,
1281  projection_buffer + buffer_offset2,
1282  column_proj_size);
1283  } else {
1284  std::memcpy(projection_buffer + buffer_offset1,
1285  projection_buffer + buffer_offset2,
1286  column_proj_size);
1287  }
1288  buffer_offset1 += align_to_int64(column_proj_size);
1289  }
1290  }
1291 }
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:

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 138 of file QueryMemoryInitializer.cpp.

References CHECK_EQ, and CHECK_LT.

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

140  {
141  std::vector<std::vector<int64_t>> col_frag_offsets;
142  for (auto& table_offsets : table_frag_offsets) {
143  std::vector<int64_t> col_offsets;
144  for (auto expr : target_exprs) {
145  if (const auto col_var = dynamic_cast<Analyzer::ColumnVar*>(expr)) {
146  if (col_var->get_rte_idx() < 0) {
147  CHECK_EQ(-1, col_var->get_rte_idx());
148  col_offsets.push_back(int64_t(-1));
149  } else {
150  CHECK_LT(static_cast<size_t>(col_var->get_rte_idx()), table_offsets.size());
151  col_offsets.push_back(
152  static_cast<int64_t>(table_offsets[col_var->get_rte_idx()]));
153  }
154  } else {
155  col_offsets.push_back(int64_t(-1));
156  }
157  }
158  col_frag_offsets.push_back(col_offsets);
159  }
160  return col_frag_offsets;
161 }
#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 88 of file QueryMemoryInitializer.cpp.

Referenced by get_consistent_frags_sizes().

88  {
89  if (frag_offsets.size() < 2) {
90  return int64_t(-1);
91  }
92  const auto frag_size = frag_offsets[1] - frag_offsets[0];
93  for (size_t i = 2; i < frag_offsets.size(); ++i) {
94  const auto curr_size = frag_offsets[i] - frag_offsets[i - 1];
95  if (curr_size != frag_size) {
96  return int64_t(-1);
97  }
98  }
99  return !frag_size ? std::numeric_limits<int64_t>::max()
100  : static_cast<int64_t>(frag_size);
101 }

+ 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 103 of file QueryMemoryInitializer.cpp.

References get_consistent_frag_size().

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

104  {
105  if (frag_offsets.empty()) {
106  return {};
107  }
108  std::vector<int64_t> frag_sizes;
109  for (size_t tab_idx = 0; tab_idx < frag_offsets[0].size(); ++tab_idx) {
110  std::vector<uint64_t> tab_offs;
111  for (auto& offsets : frag_offsets) {
112  tab_offs.push_back(offsets[tab_idx]);
113  }
114  frag_sizes.push_back(get_consistent_frag_size(tab_offs));
115  }
116  return frag_sizes;
117 }
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 119 of file QueryMemoryInitializer.cpp.

References CHECK_EQ.

121  {
122  std::vector<int64_t> col_frag_sizes;
123  for (auto expr : target_exprs) {
124  if (const auto col_var = dynamic_cast<Analyzer::ColumnVar*>(expr)) {
125  if (col_var->get_rte_idx() < 0) {
126  CHECK_EQ(-1, col_var->get_rte_idx());
127  col_frag_sizes.push_back(int64_t(-1));
128  } else {
129  col_frag_sizes.push_back(table_frag_sizes[col_var->get_rte_idx()]);
130  }
131  } else {
132  col_frag_sizes.push_back(int64_t(-1));
133  }
134  }
135  return col_frag_sizes;
136 }
#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 165 of file QueryMemoryInitializer.cpp.

References RelAlgExecutionUnit::input_descs.

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

166  {
167  auto match_table_key = [=](auto& desc) {
168  return outer_table_key == desc.getTableKey();
169  };
170  auto& input_descs = ra_exe_unit.input_descs;
171  auto itr = std::find_if(input_descs.begin(), input_descs.end(), match_table_key);
172  return itr == input_descs.end() ? 0 : itr->getNestLevel();
173 }

+ 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 694 of file QueryMemoryInitializer.cpp.

References heavydb.dtypes::T.

694  {
695  static_assert(sizeof(T) <= sizeof(int64_t), "Unsupported template type");
696  for (uint32_t i = 0; i < entry_count; ++i) {
697  buffer_ptr[i] = init_val;
698  }
699  return reinterpret_cast<int8_t*>(buffer_ptr + entry_count);
700 }