OmniSciDB  2c44a3935d
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, 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)
 
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

◆ alloc_group_by_buffer()

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

Definition at line 61 of file QueryMemoryInitializer.cpp.

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

Referenced by QueryMemoryInitializer::QueryMemoryInitializer().

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

◆ check_total_bitmap_memory()

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

Definition at line 31 of file QueryMemoryInitializer.cpp.

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

Referenced by QueryMemoryInitializer::QueryMemoryInitializer().

31  {
32  const int32_t groups_buffer_entry_count = query_mem_desc.getEntryCount();
33  if (g_enable_watchdog) {
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 =
49  static_cast<int64_t>(total_bytes_per_group * groups_buffer_entry_count);
50  } catch (...) {
51  // Absurd amount of memory, merely computing the number of bits overflows int64_t.
52  // Don't bother to report the real amount, this is unlikely to ever happen.
53  throw OutOfHostMemory(std::numeric_limits<int64_t>::max() / 8);
54  }
55  if (total_bytes >= 2 * 1000 * 1000 * 1000L) {
56  throw OutOfHostMemory(total_bytes);
57  }
58  }
59 }
size_t getCountDistinctDescriptorsSize() const
const int64_t const uint32_t groups_buffer_entry_count
bool g_enable_watchdog
Definition: Execute.cpp:74
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 64, 64, boost::multiprecision::signed_magnitude, boost::multiprecision::checked, void > > checked_int64_t
const CountDistinctDescriptor & getCountDistinctDescriptor(const size_t idx) const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compact_projection_buffer_for_cpu_columnar()

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

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

Referenced by QueryMemoryInitializer::compactProjectionBuffersCpu().

844  {
845  // the first column (row indices) remains unchanged.
846  CHECK(projection_count <= query_mem_desc.getEntryCount());
847  constexpr size_t row_index_width = sizeof(int64_t);
848  size_t buffer_offset1{projection_count * row_index_width};
849  // other columns are actual non-lazy columns for the projection:
850  for (size_t i = 0; i < query_mem_desc.getSlotCount(); i++) {
851  if (query_mem_desc.getPaddedSlotWidthBytes(i) > 0) {
852  auto column_proj_size =
853  projection_count * query_mem_desc.getPaddedSlotWidthBytes(i);
854  auto buffer_offset2 = query_mem_desc.getColOffInBytes(i);
855  if (buffer_offset1 + column_proj_size >= buffer_offset2) {
856  // overlapping
857  std::memmove(projection_buffer + buffer_offset1,
858  projection_buffer + buffer_offset2,
859  column_proj_size);
860  } else {
861  std::memcpy(projection_buffer + buffer_offset1,
862  projection_buffer + buffer_offset2,
863  column_proj_size);
864  }
865  buffer_offset1 += align_to_int64(column_proj_size);
866  }
867  }
868 }
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
#define CHECK(condition)
Definition: Logger.h:197
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:

◆ get_col_frag_offsets()

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

References CHECK_EQ, and CHECK_LT.

Referenced by QueryMemoryInitializer::QueryMemoryInitializer().

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

◆ get_consistent_frag_size()

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

Definition at line 76 of file QueryMemoryInitializer.cpp.

Referenced by get_consistent_frags_sizes().

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

◆ get_consistent_frags_sizes() [1/2]

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

References get_consistent_frag_size().

92  {
93  if (frag_offsets.empty()) {
94  return {};
95  }
96  std::vector<int64_t> frag_sizes;
97  for (size_t tab_idx = 0; tab_idx < frag_offsets[0].size(); ++tab_idx) {
98  std::vector<uint64_t> tab_offs;
99  for (auto& offsets : frag_offsets) {
100  tab_offs.push_back(offsets[tab_idx]);
101  }
102  frag_sizes.push_back(get_consistent_frag_size(tab_offs));
103  }
104  return frag_sizes;
105 }
int64_t get_consistent_frag_size(const std::vector< uint64_t > &frag_offsets)
+ Here is the call graph for this function:

◆ get_consistent_frags_sizes() [2/2]

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

References CHECK_EQ.

Referenced by QueryMemoryInitializer::QueryMemoryInitializer().

109  {
110  std::vector<int64_t> col_frag_sizes;
111  for (auto expr : target_exprs) {
112  if (const auto col_var = dynamic_cast<Analyzer::ColumnVar*>(expr)) {
113  if (col_var->get_rte_idx() < 0) {
114  CHECK_EQ(-1, col_var->get_rte_idx());
115  col_frag_sizes.push_back(int64_t(-1));
116  } else {
117  col_frag_sizes.push_back(table_frag_sizes[col_var->get_rte_idx()]);
118  }
119  } else {
120  col_frag_sizes.push_back(int64_t(-1));
121  }
122  }
123  return col_frag_sizes;
124 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
+ Here is the caller graph for this function:

◆ initColumnarBuffer()

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

449  {
450  static_assert(sizeof(T) <= sizeof(int64_t), "Unsupported template type");
451  for (uint32_t i = 0; i < entry_count; ++i) {
452  buffer_ptr[i] = init_val;
453  }
454  return reinterpret_cast<int8_t*>(buffer_ptr + entry_count);
455 }