OmniSciDB  343343d194
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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)
 
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

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

Definition at line 60 of file QueryMemoryInitializer.cpp.

References checked_malloc(), and RenderAllocatorMap::getRenderAllocator().

Referenced by QueryMemoryInitializer::QueryMemoryInitializer().

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

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

30  {
31  const int32_t groups_buffer_entry_count = query_mem_desc.getEntryCount();
32  if (g_enable_watchdog) {
33  checked_int64_t total_bytes_per_group = 0;
34  const size_t num_count_distinct_descs =
35  query_mem_desc.getCountDistinctDescriptorsSize();
36  for (size_t i = 0; i < num_count_distinct_descs; i++) {
37  const auto count_distinct_desc = query_mem_desc.getCountDistinctDescriptor(i);
38  if (count_distinct_desc.impl_type_ != CountDistinctImplType::Bitmap) {
39  continue;
40  }
41  total_bytes_per_group += count_distinct_desc.bitmapPaddedSizeBytes();
42  }
43  int64_t total_bytes{0};
44  // Using OutOfHostMemory until we can verify that SlabTooBig would also be properly
45  // caught
46  try {
47  total_bytes =
48  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 >= 2 * 1000 * 1000 * 1000L) {
55  throw OutOfHostMemory(total_bytes);
56  }
57  }
58 }
const int64_t const uint32_t groups_buffer_entry_count
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 64, 64, boost::multiprecision::signed_magnitude, boost::multiprecision::checked, void > > checked_int64_t
size_t getCountDistinctDescriptorsSize() const
const CountDistinctDescriptor & getCountDistinctDescriptor(const size_t idx) const
bool g_enable_watchdog
Definition: Execute.cpp:69

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

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

Referenced by QueryMemoryInitializer::compactProjectionBuffersCpu().

728  {
729  // the first column (row indices) remains unchanged.
730  CHECK(projection_count <= query_mem_desc.getEntryCount());
731  constexpr size_t row_index_width = sizeof(int64_t);
732  size_t buffer_offset1{projection_count * row_index_width};
733  // other columns are actual non-lazy columns for the projection:
734  for (size_t i = 0; i < query_mem_desc.getSlotCount(); i++) {
735  if (query_mem_desc.getPaddedSlotWidthBytes(i) > 0) {
736  auto column_proj_size =
737  projection_count * query_mem_desc.getPaddedSlotWidthBytes(i);
738  auto buffer_offset2 = query_mem_desc.getColOffInBytes(i);
739  if (buffer_offset1 + column_proj_size >= buffer_offset2) {
740  // overlapping
741  std::memmove(projection_buffer + buffer_offset1,
742  projection_buffer + buffer_offset2,
743  column_proj_size);
744  } else {
745  std::memcpy(projection_buffer + buffer_offset1,
746  projection_buffer + buffer_offset2,
747  column_proj_size);
748  }
749  buffer_offset1 += align_to_int64(column_proj_size);
750  }
751  }
752 }
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
#define CHECK(condition)
Definition: Logger.h:187
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 124 of file QueryMemoryInitializer.cpp.

References CHECK_EQ, and CHECK_LT.

Referenced by QueryMemoryInitializer::QueryMemoryInitializer().

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

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

Referenced by get_consistent_frags_sizes().

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

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

References get_consistent_frag_size().

Referenced by QueryMemoryInitializer::QueryMemoryInitializer().

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

References CHECK_EQ.

107  {
108  std::vector<int64_t> col_frag_sizes;
109  for (auto expr : target_exprs) {
110  if (const auto col_var = dynamic_cast<Analyzer::ColumnVar*>(expr)) {
111  if (col_var->get_rte_idx() < 0) {
112  CHECK_EQ(-1, col_var->get_rte_idx());
113  col_frag_sizes.push_back(int64_t(-1));
114  } else {
115  col_frag_sizes.push_back(table_frag_sizes[col_var->get_rte_idx()]);
116  }
117  } else {
118  col_frag_sizes.push_back(int64_t(-1));
119  }
120  }
121  return col_frag_sizes;
122 }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
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 357 of file QueryMemoryInitializer.cpp.

357  {
358  static_assert(sizeof(T) <= sizeof(int64_t), "Unsupported template type");
359  for (uint32_t i = 0; i < entry_count; ++i) {
360  buffer_ptr[i] = init_val;
361  }
362  return reinterpret_cast<int8_t*>(buffer_ptr + entry_count);
363 }