OmniSciDB  1dac507f6e
 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 61 of file QueryMemoryInitializer.cpp.

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

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

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*>(checked_malloc(numBytes));
72  }
73 }
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 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 }
const int64_t const uint32_t groups_buffer_entry_count
bool g_enable_watchdog
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

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

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

Referenced by QueryMemoryInitializer::compactProjectionBuffersCpu().

828  {
829  // the first column (row indices) remains unchanged.
830  CHECK(projection_count <= query_mem_desc.getEntryCount());
831  constexpr size_t row_index_width = sizeof(int64_t);
832  size_t buffer_offset1{projection_count * row_index_width};
833  // other columns are actual non-lazy columns for the projection:
834  for (size_t i = 0; i < query_mem_desc.getSlotCount(); i++) {
835  if (query_mem_desc.getPaddedSlotWidthBytes(i) > 0) {
836  auto column_proj_size =
837  projection_count * query_mem_desc.getPaddedSlotWidthBytes(i);
838  auto buffer_offset2 = query_mem_desc.getColOffInBytes(i);
839  if (buffer_offset1 + column_proj_size >= buffer_offset2) {
840  // overlapping
841  std::memmove(projection_buffer + buffer_offset1,
842  projection_buffer + buffer_offset2,
843  column_proj_size);
844  } else {
845  std::memcpy(projection_buffer + buffer_offset1,
846  projection_buffer + buffer_offset2,
847  column_proj_size);
848  }
849  buffer_offset1 += align_to_int64(column_proj_size);
850  }
851  }
852 }
CHECK(cgen_state)
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
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 125 of file QueryMemoryInitializer.cpp.

References CHECK_EQ, and CHECK_LT.

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

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:198
#define CHECK_LT(x, y)
Definition: Logger.h:200

+ 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 ssize_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 device_allocator_(), and QueryMemoryInitializer::QueryMemoryInitializer().

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:198
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 437 of file QueryMemoryInitializer.cpp.

437  {
438  static_assert(sizeof(T) <= sizeof(int64_t), "Unsupported template type");
439  for (uint32_t i = 0; i < entry_count; ++i) {
440  buffer_ptr[i] = init_val;
441  }
442  return reinterpret_cast<int8_t*>(buffer_ptr + entry_count);
443 }