OmniSciDB  fe05a0c208
 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, 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 61 of file QueryMemoryInitializer.cpp.

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

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

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

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

Referenced by QueryMemoryInitializer::QueryMemoryInitializer().

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

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

Referenced by QueryMemoryInitializer::compactProjectionBuffersCpu().

982  {
983  // the first column (row indices) remains unchanged.
984  CHECK(projection_count <= query_mem_desc.getEntryCount());
985  constexpr size_t row_index_width = sizeof(int64_t);
986  size_t buffer_offset1{projection_count * row_index_width};
987  // other columns are actual non-lazy columns for the projection:
988  for (size_t i = 0; i < query_mem_desc.getSlotCount(); i++) {
989  if (query_mem_desc.getPaddedSlotWidthBytes(i) > 0) {
990  auto column_proj_size =
991  projection_count * query_mem_desc.getPaddedSlotWidthBytes(i);
992  auto buffer_offset2 = query_mem_desc.getColOffInBytes(i);
993  if (buffer_offset1 + column_proj_size >= buffer_offset2) {
994  // overlapping
995  std::memmove(projection_buffer + buffer_offset1,
996  projection_buffer + buffer_offset2,
997  column_proj_size);
998  } else {
999  std::memcpy(projection_buffer + buffer_offset1,
1000  projection_buffer + buffer_offset2,
1001  column_proj_size);
1002  }
1003  buffer_offset1 += align_to_int64(column_proj_size);
1004  }
1005  }
1006 }
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
#define CHECK(condition)
Definition: Logger.h:203
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 127 of file QueryMemoryInitializer.cpp.

References CHECK_EQ, and CHECK_LT.

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

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

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

References i.

Referenced by get_consistent_frags_sizes().

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

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

References get_consistent_frag_size().

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

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

References CHECK_EQ.

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

Definition at line 495 of file QueryMemoryInitializer.cpp.

References i, and omnisci.dtypes::T.

495  {
496  static_assert(sizeof(T) <= sizeof(int64_t), "Unsupported template type");
497  for (uint32_t i = 0; i < entry_count; ++i) {
498  buffer_ptr[i] = init_val;
499  }
500  return reinterpret_cast<int8_t*>(buffer_ptr + entry_count);
501 }