OmniSciDB  471d68cefb
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ColSlotContext.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 OmniSci, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
25 #pragma once
26 
27 #include "Logger/Logger.h"
28 
29 #include <algorithm>
30 #include <string>
31 #include <unordered_map>
32 #include <vector>
33 
34 struct SlotSize {
35  int8_t padded_size; // size of the slot
36  int8_t logical_size; // size of the element in the slot
37 };
38 
39 inline bool operator==(const SlotSize& lhs, const SlotSize& rhs) {
40  return lhs.padded_size == rhs.padded_size && lhs.logical_size == rhs.logical_size;
41 }
42 
43 namespace Analyzer {
44 class Expr;
45 }
46 
48  public:
50 
51  ColSlotContext(const std::vector<Analyzer::Expr*>& col_expr_list,
52  const std::vector<int64_t>& col_exprs_to_not_project);
53 
54  void setAllSlotsSize(const int8_t slot_width_size);
55 
56  void setAllSlotsPaddedSize(const int8_t padded_size);
57 
58  void setAllUnsetSlotsPaddedSize(const int8_t padded_size);
59 
61 
62  void validate() const;
63 
64  size_t getColCount() const;
65  size_t getSlotCount() const;
66 
67  const SlotSize& getSlotInfo(const size_t slot_idx) const {
68  CHECK_LT(slot_idx, slot_sizes_.size());
69  return slot_sizes_[slot_idx];
70  }
71 
72  const std::vector<size_t>& getSlotsForCol(const size_t col_idx) const {
73  CHECK_LT(col_idx, col_to_slot_map_.size());
74  return col_to_slot_map_[col_idx];
75  }
76 
77  size_t getAllSlotsPaddedSize() const;
78 
79  size_t getAllSlotsAlignedPaddedSize() const;
80 
81  size_t getAlignedPaddedSizeForRange(const size_t end) const;
82 
83  size_t getTotalBytesOfColumnarBuffers(const size_t entry_count) const;
84 
85  int8_t getMinPaddedByteSize(const int8_t actual_min_byte_width) const;
86 
87  size_t getCompactByteWidth() const;
88 
89  size_t getColOnlyOffInBytes(const size_t slot_idx) const;
90 
91  bool empty();
92 
93  void clear();
94 
95  void addColumn(const std::vector<std::tuple<int8_t, int8_t>>& slots_for_col);
96 
97  bool operator==(const ColSlotContext& that) const {
98  return std::equal(
99  slot_sizes_.cbegin(), slot_sizes_.cend(), that.slot_sizes_.cbegin()) &&
100  std::equal(col_to_slot_map_.cbegin(),
101  col_to_slot_map_.cend(),
102  that.col_to_slot_map_.cbegin());
103  }
104 
105  bool operator!=(const ColSlotContext& that) const { return !(*this == that); }
106 
107  void alignPaddedSlots(const bool sort_on_gpu);
108 
109  int64_t varlenOutputElementSize(const size_t slot_idx) const;
110 
111  bool hasVarlenOutput() const { return !varlen_output_slot_map_.empty(); }
112 
113  bool slotIsVarlen(const size_t slot_idx) const {
114  return varlen_output_slot_map_.count(slot_idx) > 0;
115  }
116 
117  std::string toString() const {
118  std::string str{"Col Slot Context State\n"};
119  if (slot_sizes_.empty()) {
120  str += "\tEmpty";
121  return str;
122  }
123  str += "\tN | P , L\n";
124  for (size_t i = 0; i < slot_sizes_.size(); i++) {
125  const auto& slot_size = slot_sizes_[i];
126  str += "\t" + std::to_string(i) + " | " + std::to_string(slot_size.padded_size) +
127  " , " + std::to_string(slot_size.logical_size) + "\n";
128  }
129  return str;
130  }
131 
132  private:
133  void addSlotForColumn(const int8_t logical_size, const size_t column_idx);
134 
135  void addSlotForColumn(const int8_t padded_size,
136  const int8_t logical_size,
137  const size_t column_idx);
138 
139  std::vector<SlotSize> slot_sizes_;
140  std::vector<std::vector<size_t>> col_to_slot_map_;
141 
142  using ArraySize = int64_t;
143  using SlotIndex = size_t;
144  std::unordered_map<SlotIndex, ArraySize> varlen_output_slot_map_;
145 };
int8_t getMinPaddedByteSize(const int8_t actual_min_byte_width) const
void alignPaddedSlots(const bool sort_on_gpu)
bool slotIsVarlen(const size_t slot_idx) const
int8_t logical_size
std::unordered_map< SlotIndex, ArraySize > varlen_output_slot_map_
size_t getAllSlotsPaddedSize() const
size_t getAllSlotsAlignedPaddedSize() const
std::vector< std::vector< size_t > > col_to_slot_map_
bool hasVarlenOutput() const
std::vector< SlotSize > slot_sizes_
void setAllSlotsSize(const int8_t slot_width_size)
std::string to_string(char const *&&v)
const SlotSize & getSlotInfo(const size_t slot_idx) const
size_t getColOnlyOffInBytes(const size_t slot_idx) const
size_t getCompactByteWidth() const
size_t getAlignedPaddedSizeForRange(const size_t end) const
bool operator==(const ColSlotContext &that) const
void validate() const
int64_t varlenOutputElementSize(const size_t slot_idx) const
void addColumn(const std::vector< std::tuple< int8_t, int8_t >> &slots_for_col)
#define CHECK_LT(x, y)
Definition: Logger.h:219
void setAllSlotsPaddedSize(const int8_t padded_size)
int8_t padded_size
bool operator==(const SlotSize &lhs, const SlotSize &rhs)
size_t getTotalBytesOfColumnarBuffers(const size_t entry_count) const
void addSlotForColumn(const int8_t logical_size, const size_t column_idx)
std::string toString() const
size_t getSlotCount() const
void setAllSlotsPaddedSizeToLogicalSize()
size_t getColCount() const
const std::vector< size_t > & getSlotsForCol(const size_t col_idx) const
bool operator!=(const ColSlotContext &that) const
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)
void setAllUnsetSlotsPaddedSize(const int8_t padded_size)