OmniSciDB  6686921089
 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)
 
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,
const size_t  thread_idx,
RowSetMemoryOwner mem_owner 
)

Definition at line 62 of file QueryMemoryInitializer.cpp.

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

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

65  {
66  if (render_allocator_map) {
67  // NOTE(adb): If we got here, we are performing an in-situ rendering query and are not
68  // using CUDA buffers. Therefore we need to allocate result set storage using CPU
69  // memory.
70  const auto gpu_idx = 0; // Only 1 GPU supported in CUDA-disabled rendering mode
71  auto render_allocator_ptr = render_allocator_map->getRenderAllocator(gpu_idx);
72  return reinterpret_cast<int64_t*>(render_allocator_ptr->alloc(numBytes));
73  } else {
74  return reinterpret_cast<int64_t*>(mem_owner->allocate(numBytes, thread_idx));
75  }
76 }
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 35 of file QueryMemoryInitializer.cpp.

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

Referenced by QueryMemoryInitializer::QueryMemoryInitializer().

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

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

Referenced by QueryMemoryInitializer::compactProjectionBuffersCpu().

1016  {
1017  // the first column (row indices) remains unchanged.
1018  CHECK(projection_count <= query_mem_desc.getEntryCount());
1019  constexpr size_t row_index_width = sizeof(int64_t);
1020  size_t buffer_offset1{projection_count * row_index_width};
1021  // other columns are actual non-lazy columns for the projection:
1022  for (size_t i = 0; i < query_mem_desc.getSlotCount(); i++) {
1023  if (query_mem_desc.getPaddedSlotWidthBytes(i) > 0) {
1024  auto column_proj_size =
1025  projection_count * query_mem_desc.getPaddedSlotWidthBytes(i);
1026  auto buffer_offset2 = query_mem_desc.getColOffInBytes(i);
1027  if (buffer_offset1 + column_proj_size >= buffer_offset2) {
1028  // overlapping
1029  std::memmove(projection_buffer + buffer_offset1,
1030  projection_buffer + buffer_offset2,
1031  column_proj_size);
1032  } else {
1033  std::memcpy(projection_buffer + buffer_offset1,
1034  projection_buffer + buffer_offset2,
1035  column_proj_size);
1036  }
1037  buffer_offset1 += align_to_int64(column_proj_size);
1038  }
1039  }
1040 }
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
#define CHECK(condition)
Definition: Logger.h:209
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 128 of file QueryMemoryInitializer.cpp.

References CHECK_EQ, and CHECK_LT.

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

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

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

References i.

Referenced by get_consistent_frags_sizes().

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

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

References get_consistent_frag_size().

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

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

References CHECK_EQ.

111  {
112  std::vector<int64_t> col_frag_sizes;
113  for (auto expr : target_exprs) {
114  if (const auto col_var = dynamic_cast<Analyzer::ColumnVar*>(expr)) {
115  if (col_var->get_rte_idx() < 0) {
116  CHECK_EQ(-1, col_var->get_rte_idx());
117  col_frag_sizes.push_back(int64_t(-1));
118  } else {
119  col_frag_sizes.push_back(table_frag_sizes[col_var->get_rte_idx()]);
120  }
121  } else {
122  col_frag_sizes.push_back(int64_t(-1));
123  }
124  }
125  return col_frag_sizes;
126 }
#define CHECK_EQ(x, y)
Definition: Logger.h:217
template<typename T >
int8_t* anonymous_namespace{QueryMemoryInitializer.cpp}::initColumnarBuffer ( T *  buffer_ptr,
const init_val,
const uint32_t  entry_count 
)

Definition at line 511 of file QueryMemoryInitializer.cpp.

References i, and omnisci.dtypes::T.

511  {
512  static_assert(sizeof(T) <= sizeof(int64_t), "Unsupported template type");
513  for (uint32_t i = 0; i < entry_count; ++i) {
514  buffer_ptr[i] = init_val;
515  }
516  return reinterpret_cast<int8_t*>(buffer_ptr + entry_count);
517 }