OmniSciDB  b24e664e58
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ColSlotContext Class Reference

#include <ColSlotContext.h>

Public Member Functions

 ColSlotContext ()
 
 ColSlotContext (const std::vector< Analyzer::Expr * > &col_expr_list, const std::vector< ssize_t > &col_exprs_to_not_project)
 
void setAllSlotsSize (const int8_t slot_width_size)
 
void setAllSlotsPaddedSize (const int8_t padded_size)
 
void setAllUnsetSlotsPaddedSize (const int8_t padded_size)
 
void setAllSlotsPaddedSizeToLogicalSize ()
 
void validate () const
 
size_t getColCount () const
 
size_t getSlotCount () const
 
const SlotSizegetSlotInfo (const size_t slot_idx) const
 
const std::vector< size_t > & getSlotsForCol (const size_t col_idx) const
 
size_t getAllSlotsPaddedSize () const
 
size_t getAllSlotsAlignedPaddedSize () const
 
size_t getAlignedPaddedSizeForRange (const size_t end) const
 
size_t getTotalBytesOfColumnarBuffers (const size_t entry_count) const
 
int8_t getMinPaddedByteSize (const int8_t actual_min_byte_width) const
 
size_t getCompactByteWidth () const
 
size_t getColOnlyOffInBytes (const size_t slot_idx) const
 
bool empty ()
 
void clear ()
 
void addColumn (const std::vector< std::tuple< int8_t, int8_t >> &slots_for_col)
 
bool operator== (const ColSlotContext &that) const
 
bool operator!= (const ColSlotContext &that) const
 
void alignPaddedSlots (const bool sort_on_gpu)
 
std::string toString () const
 

Private Member Functions

void addSlotForColumn (const int8_t logical_size, const size_t column_idx)
 
void addSlotForColumn (const int8_t padded_size, const int8_t logical_size, const size_t column_idx)
 

Private Attributes

std::vector< SlotSizeslot_sizes_
 
std::vector< std::vector
< size_t > > 
col_to_slot_map_
 

Detailed Description

Definition at line 46 of file ColSlotContext.h.

Constructor & Destructor Documentation

ColSlotContext::ColSlotContext ( )
inline

Definition at line 48 of file ColSlotContext.h.

48 {}
ColSlotContext::ColSlotContext ( const std::vector< Analyzer::Expr * > &  col_expr_list,
const std::vector< ssize_t > &  col_exprs_to_not_project 
)

Definition at line 36 of file ColSlotContext.cpp.

References addSlotForColumn(), CHECK(), CHECK_EQ, col_to_slot_map_, g_bigint_count, get_bit_width(), get_compact_type(), get_target_info(), kAVG, and kENCODING_NONE.

37  {
38  // Note that non-projected col exprs could be projected cols that we can lazy fetch or
39  // grouped cols with keyless hash
40  if (!col_exprs_to_not_project.empty()) {
41  CHECK_EQ(col_expr_list.size(), col_exprs_to_not_project.size());
42  }
43  size_t col_expr_idx = 0;
44  col_to_slot_map_.resize(col_expr_list.size());
45  for (const auto col_expr : col_expr_list) {
46  if (!col_exprs_to_not_project.empty() &&
47  col_exprs_to_not_project[col_expr_idx] != -1) {
48  addSlotForColumn(0, 0, col_expr_idx);
49  ++col_expr_idx;
50  continue;
51  }
52  if (!col_expr) {
53  // row index
54  addSlotForColumn(sizeof(int64_t), col_expr_idx);
55  } else {
56  const auto agg_info = get_target_info(col_expr, g_bigint_count);
57  const auto chosen_type = get_compact_type(agg_info);
58 
59  if ((chosen_type.is_string() && chosen_type.get_compression() == kENCODING_NONE) ||
60  chosen_type.is_array()) {
61  addSlotForColumn(sizeof(int64_t), col_expr_idx);
62  addSlotForColumn(sizeof(int64_t), col_expr_idx);
63  ++col_expr_idx;
64  continue;
65  }
66  if (chosen_type.is_geometry()) {
67  for (auto i = 0; i < chosen_type.get_physical_coord_cols(); ++i) {
68  addSlotForColumn(sizeof(int64_t), col_expr_idx);
69  addSlotForColumn(sizeof(int64_t), col_expr_idx);
70  }
71  ++col_expr_idx;
72  continue;
73  }
74 
75  const auto col_expr_bitwidth = get_bit_width(chosen_type);
76 
77  CHECK_EQ(size_t(0), col_expr_bitwidth % 8);
78  addSlotForColumn(static_cast<int8_t>(col_expr_bitwidth >> 3), col_expr_idx);
79  // for average, we'll need to keep the count as well
80  if (agg_info.agg_kind == kAVG) {
81  CHECK(agg_info.is_agg);
82  addSlotForColumn(sizeof(int64_t), col_expr_idx);
83  }
84  }
85  ++col_expr_idx;
86  }
87 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
TargetInfo get_target_info(const PointerType target_expr, const bool bigint_count)
Definition: TargetInfo.h:65
std::vector< std::vector< size_t > > col_to_slot_map_
const SQLTypeInfo get_compact_type(const TargetInfo &target)
size_t get_bit_width(const SQLTypeInfo &ti)
CHECK(cgen_state)
bool g_bigint_count
void addSlotForColumn(const int8_t logical_size, const size_t column_idx)
Definition: sqldefs.h:71

+ Here is the call graph for this function:

Member Function Documentation

void ColSlotContext::addColumn ( const std::vector< std::tuple< int8_t, int8_t >> &  slots_for_col)

Definition at line 249 of file ColSlotContext.cpp.

References addSlotForColumn(), and col_to_slot_map_.

Referenced by QueryMemoryDescriptor::addColSlotInfo().

250  {
251  const auto col_idx = col_to_slot_map_.size();
252  col_to_slot_map_.emplace_back();
253  for (const auto& slot_info : slots_for_col) {
254  addSlotForColumn(std::get<1>(slot_info), std::get<0>(slot_info), col_idx);
255  }
256 }
std::vector< std::vector< size_t > > col_to_slot_map_
void addSlotForColumn(const int8_t logical_size, const size_t column_idx)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ColSlotContext::addSlotForColumn ( const int8_t  logical_size,
const size_t  column_idx 
)
private

Definition at line 258 of file ColSlotContext.cpp.

Referenced by addColumn(), and ColSlotContext().

259  {
260  addSlotForColumn(-1, logical_size, column_idx);
261 }
void addSlotForColumn(const int8_t logical_size, const size_t column_idx)

+ Here is the caller graph for this function:

void ColSlotContext::addSlotForColumn ( const int8_t  padded_size,
const int8_t  logical_size,
const size_t  column_idx 
)
private

Definition at line 263 of file ColSlotContext.cpp.

References CHECK_LT, col_to_slot_map_, and slot_sizes_.

265  {
266  CHECK_LT(column_idx, col_to_slot_map_.size());
267  col_to_slot_map_[column_idx].push_back(slot_sizes_.size());
268  slot_sizes_.emplace_back(SlotSize{padded_size, logical_size});
269 }
std::vector< std::vector< size_t > > col_to_slot_map_
std::vector< SlotSize > slot_sizes_
#define CHECK_LT(x, y)
Definition: Logger.h:200
void ColSlotContext::alignPaddedSlots ( const bool  sort_on_gpu)

Definition at line 224 of file ColSlotContext.cpp.

References align_to_int64(), CHECK(), CHECK_GE, and slot_sizes_.

Referenced by QueryMemoryDescriptor::alignPaddedSlots().

224  {
225  size_t total_bytes{0};
226  for (size_t slot_idx = 0; slot_idx < slot_sizes_.size(); slot_idx++) {
227  auto chosen_bytes = slot_sizes_[slot_idx].padded_size;
228  if (chosen_bytes == sizeof(int64_t)) {
229  const auto aligned_total_bytes = align_to_int64(total_bytes);
230  CHECK_GE(aligned_total_bytes, total_bytes);
231  if (slot_idx >= 1) {
232  const auto padding = aligned_total_bytes - total_bytes;
233  CHECK(padding == 0 || padding == 4);
234  slot_sizes_[slot_idx - 1].padded_size += padding;
235  }
236  total_bytes = aligned_total_bytes;
237  }
238  total_bytes += chosen_bytes;
239  }
240  if (!sort_on_gpu) {
241  const auto aligned_total_bytes = align_to_int64(total_bytes);
242  CHECK_GE(aligned_total_bytes, total_bytes);
243  const auto padding = aligned_total_bytes - total_bytes;
244  CHECK(padding == 0 || padding == 4);
245  slot_sizes_.back().padded_size += padding;
246  }
247 }
#define CHECK_GE(x, y)
Definition: Logger.h:203
std::vector< SlotSize > slot_sizes_
CHECK(cgen_state)
void sort_on_gpu(int64_t *val_buff, int32_t *idx_buff, const uint64_t entry_count, const bool desc, const uint32_t chosen_bytes, ThrustAllocator &alloc)
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:

void ColSlotContext::clear ( )

Definition at line 219 of file ColSlotContext.cpp.

References col_to_slot_map_, and slot_sizes_.

Referenced by QueryMemoryDescriptor::clearSlotInfo().

219  {
220  slot_sizes_.clear();
221  col_to_slot_map_.clear();
222 }
std::vector< std::vector< size_t > > col_to_slot_map_
std::vector< SlotSize > slot_sizes_

+ Here is the caller graph for this function:

bool ColSlotContext::empty ( )

Definition at line 215 of file ColSlotContext.cpp.

References slot_sizes_.

215  {
216  return slot_sizes_.empty();
217 }
std::vector< SlotSize > slot_sizes_
size_t ColSlotContext::getAlignedPaddedSizeForRange ( const size_t  end) const

Definition at line 142 of file ColSlotContext.cpp.

References align_to_int64(), CHECK_GE, and slot_sizes_.

Referenced by getAllSlotsAlignedPaddedSize(), and getColOnlyOffInBytes().

142  {
143  return std::accumulate(slot_sizes_.cbegin(),
144  slot_sizes_.cbegin() + end,
145  size_t(0),
146  [](size_t sum, const auto& slot_size) {
147  CHECK_GE(slot_size.padded_size, 0);
148  const auto chosen_bytes =
149  static_cast<size_t>(slot_size.padded_size);
150  if (chosen_bytes == sizeof(int64_t)) {
151  return align_to_int64(sum) + chosen_bytes;
152  } else {
153  return sum + chosen_bytes;
154  }
155  });
156 }
#define CHECK_GE(x, y)
Definition: Logger.h:203
std::vector< SlotSize > slot_sizes_
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:

size_t ColSlotContext::getAllSlotsAlignedPaddedSize ( ) const

Definition at line 138 of file ColSlotContext.cpp.

References getAlignedPaddedSizeForRange(), and slot_sizes_.

Referenced by QueryMemoryDescriptor::getColsSize().

138  {
140 }
std::vector< SlotSize > slot_sizes_
size_t getAlignedPaddedSizeForRange(const size_t end) const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t ColSlotContext::getAllSlotsPaddedSize ( ) const

Definition at line 128 of file ColSlotContext.cpp.

References CHECK_GE, and slot_sizes_.

Referenced by QueryMemoryDescriptor::getRowWidth().

128  {
129  return std::accumulate(slot_sizes_.cbegin(),
130  slot_sizes_.cend(),
131  size_t(0),
132  [](size_t sum, const auto& slot_size) {
133  CHECK_GE(slot_size.padded_size, 0);
134  return sum + static_cast<size_t>(slot_size.padded_size);
135  });
136 }
#define CHECK_GE(x, y)
Definition: Logger.h:203
std::vector< SlotSize > slot_sizes_

+ Here is the caller graph for this function:

size_t ColSlotContext::getColCount ( ) const

Definition at line 121 of file ColSlotContext.cpp.

References col_to_slot_map_.

Referenced by QueryMemoryDescriptor::getColCount().

121  {
122  return col_to_slot_map_.size();
123 }
std::vector< std::vector< size_t > > col_to_slot_map_

+ Here is the caller graph for this function:

size_t ColSlotContext::getColOnlyOffInBytes ( const size_t  slot_idx) const

Definition at line 206 of file ColSlotContext.cpp.

References align_to_int64(), CHECK_LT, getAlignedPaddedSizeForRange(), and slot_sizes_.

Referenced by QueryMemoryDescriptor::getColOnlyOffInBytes().

206  {
207  CHECK_LT(slot_idx, slot_sizes_.size());
208  auto offset_bytes = getAlignedPaddedSizeForRange(slot_idx);
209  if (slot_sizes_[slot_idx].padded_size == sizeof(int64_t)) {
210  offset_bytes = align_to_int64(offset_bytes);
211  }
212  return offset_bytes;
213 }
std::vector< SlotSize > slot_sizes_
size_t getAlignedPaddedSizeForRange(const size_t end) const
#define CHECK_LT(x, y)
Definition: Logger.h:200
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:

size_t ColSlotContext::getCompactByteWidth ( ) const

Definition at line 182 of file ColSlotContext.cpp.

References CHECK_EQ, CHECK_GT, and slot_sizes_.

Referenced by QueryMemoryDescriptor::getCompactByteWidth().

182  {
183  if (slot_sizes_.empty()) {
184  return 8;
185  }
186  size_t compact_width{0};
187  for (const auto& slot_size : slot_sizes_) {
188  if (slot_size.padded_size != 0) {
189  compact_width = slot_size.padded_size;
190  break;
191  }
192  }
193  if (!compact_width) {
194  return 0;
195  }
196  CHECK_GT(compact_width, size_t(0));
197  for (const auto& slot_size : slot_sizes_) {
198  if (slot_size.padded_size == 0) {
199  continue;
200  }
201  CHECK_EQ(static_cast<size_t>(slot_size.padded_size), compact_width);
202  }
203  return compact_width;
204 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
std::vector< SlotSize > slot_sizes_
#define CHECK_GT(x, y)
Definition: Logger.h:202

+ Here is the caller graph for this function:

int8_t ColSlotContext::getMinPaddedByteSize ( const int8_t  actual_min_byte_width) const

Definition at line 171 of file ColSlotContext.cpp.

References slot_sizes_.

Referenced by QueryMemoryDescriptor::updateActualMinByteWidth().

171  {
172  if (slot_sizes_.empty()) {
173  return actual_min_byte_width;
174  }
175  const auto min_padded_size = std::min_element(
176  slot_sizes_.cbegin(), slot_sizes_.cend(), [](const auto& lhs, const auto& rhs) {
177  return lhs.padded_size < rhs.padded_size;
178  });
179  return std::min(min_padded_size->padded_size, actual_min_byte_width);
180 }
std::vector< SlotSize > slot_sizes_

+ Here is the caller graph for this function:

size_t ColSlotContext::getSlotCount ( ) const

Definition at line 124 of file ColSlotContext.cpp.

References slot_sizes_.

Referenced by QueryMemoryDescriptor::getBufferColSlotCount(), and QueryMemoryDescriptor::getSlotCount().

124  {
125  return slot_sizes_.size();
126 }
std::vector< SlotSize > slot_sizes_

+ Here is the caller graph for this function:

const SlotSize& ColSlotContext::getSlotInfo ( const size_t  slot_idx) const
inline

Definition at line 66 of file ColSlotContext.h.

References CHECK_LT, and slot_sizes_.

Referenced by QueryMemoryDescriptor::getLogicalSlotWidthBytes(), and QueryMemoryDescriptor::getPaddedSlotWidthBytes().

66  {
67  CHECK_LT(slot_idx, slot_sizes_.size());
68  return slot_sizes_[slot_idx];
69  }
std::vector< SlotSize > slot_sizes_
#define CHECK_LT(x, y)
Definition: Logger.h:200

+ Here is the caller graph for this function:

const std::vector<size_t>& ColSlotContext::getSlotsForCol ( const size_t  col_idx) const
inline

Definition at line 71 of file ColSlotContext.h.

References CHECK_LT, and col_to_slot_map_.

Referenced by QueryMemoryDescriptor::getSlotIndexForSingleSlotCol().

71  {
72  CHECK_LT(col_idx, col_to_slot_map_.size());
73  return col_to_slot_map_[col_idx];
74  }
std::vector< std::vector< size_t > > col_to_slot_map_
#define CHECK_LT(x, y)
Definition: Logger.h:200

+ Here is the caller graph for this function:

size_t ColSlotContext::getTotalBytesOfColumnarBuffers ( const size_t  entry_count) const

Definition at line 158 of file ColSlotContext.cpp.

References align_to_int64(), CHECK_GE, and slot_sizes_.

Referenced by QueryMemoryDescriptor::getTotalBytesOfColumnarBuffers().

158  {
159  const auto total_bytes = std::accumulate(
160  slot_sizes_.cbegin(),
161  slot_sizes_.cend(),
162  size_t(0),
163  [entry_count](size_t sum, const auto& slot_size) {
164  CHECK_GE(slot_size.padded_size, 0);
165  return sum +
166  align_to_int64(static_cast<size_t>(slot_size.padded_size) * entry_count);
167  });
168  return align_to_int64(total_bytes);
169 }
#define CHECK_GE(x, y)
Definition: Logger.h:203
std::vector< SlotSize > slot_sizes_
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:

bool ColSlotContext::operator!= ( const ColSlotContext that) const
inline

Definition at line 104 of file ColSlotContext.h.

104 { return !(*this == that); }
bool ColSlotContext::operator== ( const ColSlotContext that) const
inline

Definition at line 96 of file ColSlotContext.h.

References col_to_slot_map_, and slot_sizes_.

96  {
97  return std::equal(
98  slot_sizes_.cbegin(), slot_sizes_.cend(), that.slot_sizes_.cbegin()) &&
99  std::equal(col_to_slot_map_.cbegin(),
100  col_to_slot_map_.cend(),
101  that.col_to_slot_map_.cbegin());
102  }
std::vector< std::vector< size_t > > col_to_slot_map_
std::vector< SlotSize > slot_sizes_
void ColSlotContext::setAllSlotsPaddedSize ( const int8_t  padded_size)

Definition at line 94 of file ColSlotContext.cpp.

References slot_sizes_.

94  {
95  for (auto& slot_size : slot_sizes_) {
96  slot_size.padded_size = padded_size;
97  }
98 }
std::vector< SlotSize > slot_sizes_
void ColSlotContext::setAllSlotsPaddedSizeToLogicalSize ( )

Definition at line 108 of file ColSlotContext.cpp.

References slot_sizes_.

Referenced by QueryMemoryDescriptor::QueryMemoryDescriptor(), and QueryMemoryDescriptor::setOutputColumnar().

108  {
109  for (auto& slot_size : slot_sizes_) {
110  slot_size.padded_size = slot_size.logical_size;
111  }
112 }
std::vector< SlotSize > slot_sizes_

+ Here is the caller graph for this function:

void ColSlotContext::setAllSlotsSize ( const int8_t  slot_width_size)

Definition at line 89 of file ColSlotContext.cpp.

References slot_sizes_.

Referenced by QueryMemoryDescriptor::useConsistentSlotWidthSize().

89  {
90  const SlotSize ss{slot_width_size, slot_width_size};
91  std::fill(slot_sizes_.begin(), slot_sizes_.end(), ss);
92 }
std::vector< SlotSize > slot_sizes_

+ Here is the caller graph for this function:

void ColSlotContext::setAllUnsetSlotsPaddedSize ( const int8_t  padded_size)

Definition at line 100 of file ColSlotContext.cpp.

References slot_sizes_.

Referenced by QueryMemoryDescriptor::QueryMemoryDescriptor().

100  {
101  for (auto& slot_size : slot_sizes_) {
102  if (slot_size.padded_size < 0) {
103  slot_size.padded_size = padded_size;
104  }
105  }
106 }
std::vector< SlotSize > slot_sizes_

+ Here is the caller graph for this function:

std::string ColSlotContext::toString ( ) const
inline

Definition at line 108 of file ColSlotContext.h.

References slot_sizes_, and to_string().

Referenced by QueryMemoryDescriptor::reductionKey().

108  {
109  std::string str{"Col Slot Context State\n"};
110  if (slot_sizes_.empty()) {
111  str += "\tEmpty";
112  return str;
113  }
114  str += "\tN | P , L\n";
115  for (size_t i = 0; i < slot_sizes_.size(); i++) {
116  const auto& slot_size = slot_sizes_[i];
117  str += "\t" + std::to_string(i) + " | " + std::to_string(slot_size.padded_size) +
118  " , " + std::to_string(slot_size.logical_size) + "\n";
119  }
120  return str;
121  }
std::vector< SlotSize > slot_sizes_
std::string to_string(char const *&&v)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ColSlotContext::validate ( ) const

Definition at line 114 of file ColSlotContext.cpp.

References CHECK_GE, CHECK_LE, and slot_sizes_.

Referenced by QueryMemoryDescriptor::QueryMemoryDescriptor().

114  {
115  for (const auto& slot_size : slot_sizes_) {
116  CHECK_GE(slot_size.logical_size, 0);
117  CHECK_LE(slot_size.logical_size, slot_size.padded_size);
118  }
119 }
#define CHECK_GE(x, y)
Definition: Logger.h:203
std::vector< SlotSize > slot_sizes_
#define CHECK_LE(x, y)
Definition: Logger.h:201

+ Here is the caller graph for this function:

Member Data Documentation

std::vector<std::vector<size_t> > ColSlotContext::col_to_slot_map_
private

The documentation for this class was generated from the following files: