OmniSciDB  a987f07e93
 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)
 
int64_t * alloc_group_by_buffer (const size_t numBytes, RenderAllocatorMap *render_allocator_map, const size_t thread_idx, RowSetMemoryOwner *mem_owner)
 
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, int const outer_table_id)
 
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

int64_t* anonymous_namespace{QueryMemoryInitializer.cpp}::alloc_group_by_buffer ( const size_t  numBytes,
RenderAllocatorMap render_allocator_map,
const size_t  thread_idx,
RowSetMemoryOwner mem_owner 
)

Definition at line 59 of file QueryMemoryInitializer.cpp.

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

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

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

+ 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 int32_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:

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

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

Referenced by QueryMemoryInitializer::compactProjectionBuffersCpu().

1095  {
1096  // the first column (row indices) remains unchanged.
1097  CHECK(projection_count <= query_mem_desc.getEntryCount());
1098  constexpr size_t row_index_width = sizeof(int64_t);
1099  size_t buffer_offset1{projection_count * row_index_width};
1100  // other columns are actual non-lazy columns for the projection:
1101  for (size_t i = 0; i < query_mem_desc.getSlotCount(); i++) {
1102  if (query_mem_desc.getPaddedSlotWidthBytes(i) > 0) {
1103  auto column_proj_size =
1104  projection_count * query_mem_desc.getPaddedSlotWidthBytes(i);
1105  auto buffer_offset2 = query_mem_desc.getColOffInBytes(i);
1106  if (buffer_offset1 + column_proj_size >= buffer_offset2) {
1107  // overlapping
1108  std::memmove(projection_buffer + buffer_offset1,
1109  projection_buffer + buffer_offset2,
1110  column_proj_size);
1111  } else {
1112  std::memcpy(projection_buffer + buffer_offset1,
1113  projection_buffer + buffer_offset2,
1114  column_proj_size);
1115  }
1116  buffer_offset1 += align_to_int64(column_proj_size);
1117  }
1118  }
1119 }
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
#define CHECK(condition)
Definition: Logger.h:289
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 760 of file QueryMemoryInitializer.cpp.

Referenced by QueryMemoryInitializer::allocateModes(), and QueryMemoryInitializer::allocateTDigests().

763  {
764  for (size_t target_idx = 0; target_idx < target_exprs.size(); ++target_idx) {
765  auto const target_expr = target_exprs[target_idx];
766  if (auto const* agg_expr = dynamic_cast<Analyzer::AggExpr const*>(target_expr)) {
767  if (agg_expr->get_aggtype() == agg_type) {
768  lambda(agg_expr, target_idx);
769  }
770  }
771  }
772 }

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

References CHECK_EQ, and CHECK_LT.

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

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

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

Referenced by get_consistent_frags_sizes().

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

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

References get_consistent_frag_size().

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

91  {
92  if (frag_offsets.empty()) {
93  return {};
94  }
95  std::vector<int64_t> frag_sizes;
96  for (size_t tab_idx = 0; tab_idx < frag_offsets[0].size(); ++tab_idx) {
97  std::vector<uint64_t> tab_offs;
98  for (auto& offsets : frag_offsets) {
99  tab_offs.push_back(offsets[tab_idx]);
100  }
101  frag_sizes.push_back(get_consistent_frag_size(tab_offs));
102  }
103  return frag_sizes;
104 }
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 106 of file QueryMemoryInitializer.cpp.

References CHECK_EQ.

108  {
109  std::vector<int64_t> col_frag_sizes;
110  for (auto expr : target_exprs) {
111  if (const auto col_var = dynamic_cast<Analyzer::ColumnVar*>(expr)) {
112  if (col_var->get_rte_idx() < 0) {
113  CHECK_EQ(-1, col_var->get_rte_idx());
114  col_frag_sizes.push_back(int64_t(-1));
115  } else {
116  col_frag_sizes.push_back(table_frag_sizes[col_var->get_rte_idx()]);
117  }
118  } else {
119  col_frag_sizes.push_back(int64_t(-1));
120  }
121  }
122  return col_frag_sizes;
123 }
#define CHECK_EQ(x, y)
Definition: Logger.h:297
int anonymous_namespace{QueryMemoryInitializer.cpp}::get_input_idx ( RelAlgExecutionUnit const &  ra_exe_unit,
int const  outer_table_id 
)

Definition at line 152 of file QueryMemoryInitializer.cpp.

References RelAlgExecutionUnit::input_descs.

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

152  {
153  auto match_table_id = [=](auto& desc) { return outer_table_id == desc.getTableId(); };
154  auto& input_descs = ra_exe_unit.input_descs;
155  auto itr = std::find_if(input_descs.begin(), input_descs.end(), match_table_id);
156  return itr == input_descs.end() ? 0 : itr->getNestLevel();
157 }

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

References heavydb.dtypes::T.

530  {
531  static_assert(sizeof(T) <= sizeof(int64_t), "Unsupported template type");
532  for (uint32_t i = 0; i < entry_count; ++i) {
533  buffer_ptr[i] = init_val;
534  }
535  return reinterpret_cast<int8_t*>(buffer_ptr + entry_count);
536 }