OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 "Shared/Logger.h"
28 
29 #include <algorithm>
30 #include <string>
31 #include <vector>
32 
33 struct SlotSize {
34  int8_t padded_size; // size of the slot
35  int8_t logical_size; // size of the element in the slot
36 };
37 
38 inline bool operator==(const SlotSize& lhs, const SlotSize& rhs) {
39  return lhs.padded_size == rhs.padded_size && lhs.logical_size == rhs.logical_size;
40 }
41 
42 namespace Analyzer {
43 class Expr;
44 }
45 
47  public:
49 
50  ColSlotContext(const std::vector<Analyzer::Expr*>& col_expr_list,
51  const std::vector<ssize_t>& col_exprs_to_not_project);
52 
53  void setAllSlotsSize(const int8_t slot_width_size);
54 
55  void setAllSlotsPaddedSize(const int8_t padded_size);
56 
57  void setAllUnsetSlotsPaddedSize(const int8_t padded_size);
58 
60 
61  void validate() const;
62 
63  size_t getColCount() const;
64  size_t getSlotCount() const;
65 
66  const SlotSize& getSlotInfo(const size_t slot_idx) const {
67  CHECK_LT(slot_idx, slot_sizes_.size());
68  return slot_sizes_[slot_idx];
69  }
70 
71  const std::vector<size_t>& getSlotsForCol(const size_t col_idx) const {
72  CHECK_LT(col_idx, col_to_slot_map_.size());
73  return col_to_slot_map_[col_idx];
74  }
75 
76  size_t getAllSlotsPaddedSize() const;
77 
78  size_t getAllSlotsAlignedPaddedSize() const;
79 
80  size_t getAlignedPaddedSizeForRange(const size_t end) const;
81 
82  size_t getTotalBytesOfColumnarBuffers(const size_t entry_count) const;
83 
84  int8_t getMinPaddedByteSize(const int8_t actual_min_byte_width) const;
85 
86  size_t getCompactByteWidth() const;
87 
88  size_t getColOnlyOffInBytes(const size_t slot_idx) const;
89 
90  bool empty();
91 
92  void clear();
93 
94  void addColumn(const std::vector<std::tuple<int8_t, int8_t>>& slots_for_col);
95 
96  bool operator==(const ColSlotContext& that) const {
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  }
103 
104  bool operator!=(const ColSlotContext& that) const { return !(*this == that); }
105 
106  void alignPaddedSlots(const bool sort_on_gpu);
107 
108  std::string toString() const {
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  }
122 
123  private:
124  void addSlotForColumn(const int8_t logical_size, const size_t column_idx);
125 
126  void addSlotForColumn(const int8_t padded_size,
127  const int8_t logical_size,
128  const size_t column_idx);
129 
130  std::vector<SlotSize> slot_sizes_;
131  std::vector<std::vector<size_t>> col_to_slot_map_;
132 };
int8_t getMinPaddedByteSize(const int8_t actual_min_byte_width) const
void alignPaddedSlots(const bool sort_on_gpu)
int8_t logical_size
size_t getAllSlotsPaddedSize() const
size_t getAllSlotsAlignedPaddedSize() const
std::vector< std::vector< size_t > > col_to_slot_map_
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
void addColumn(const std::vector< std::tuple< int8_t, int8_t >> &slots_for_col)
#define CHECK_LT(x, y)
Definition: Logger.h:200
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)