forked from heavyai/heavydb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueryMemoryDescriptor.h
More file actions
176 lines (143 loc) · 5.62 KB
/
QueryMemoryDescriptor.h
File metadata and controls
176 lines (143 loc) · 5.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
* Copyright 2017 MapD Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file QueryMemoryDescriptor.h
* @author Alex Suhan <alex@mapd.com>
* @brief Descriptor for the result set buffer layout.
*
* Copyright (c) 2014 MapD Technologies, Inc. All rights reserved.
*/
#ifndef QUERYENGINE_QUERYMEMORYDESCRIPTOR_H
#define QUERYENGINE_QUERYMEMORYDESCRIPTOR_H
#include "CompilationOptions.h"
#include "CountDistinct.h"
#include <glog/logging.h>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <unordered_map>
#include <vector>
extern bool g_cluster;
extern bool g_use_result_set;
class Executor;
class QueryExecutionContext;
class RenderAllocatorMap;
class RowSetMemoryOwner;
enum class GroupByColRangeType {
OneColKnownRange, // statically known range, only possible for column expressions
OneColGuessedRange, // best guess: small hash for the guess plus overflow for outliers
MultiCol,
MultiColPerfectHash,
Projection,
Scan, // the plan is not a group by plan
Estimator
};
struct ColWidths {
int8_t actual; // the real width of the type
int8_t compact; // with padding
};
inline bool operator==(const ColWidths& lhs, const ColWidths& rhs) {
return lhs.actual == rhs.actual && lhs.compact == rhs.compact;
}
// Private: each thread has its own memory, no atomic operations required
// Shared: threads in the same block share memory, atomic operations required
enum class GroupByMemSharing { Private, Shared };
struct RelAlgExecutionUnit;
struct QueryMemoryDescriptor {
const Executor* executor_;
bool allow_multifrag;
GroupByColRangeType hash_type;
bool keyless_hash;
bool interleaved_bins_on_gpu;
int32_t idx_target_as_key;
int64_t init_val;
std::vector<int8_t> group_col_widths;
#ifdef ENABLE_KEY_COMPACTION
int8_t group_col_compact_width; // compact width for all group cols if able to
// be consistent otherwise 0
#endif
std::vector<ColWidths> agg_col_widths;
std::vector<ssize_t> target_groupby_indices;
size_t entry_count; // the number of entries in the main buffer
size_t entry_count_small; // the number of entries in the small buffer
int64_t min_val; // meaningful for OneColKnownRange, MultiColPerfectHash only
int64_t max_val;
int64_t bucket;
bool has_nulls;
GroupByMemSharing sharing; // meaningful for GPU only
CountDistinctDescriptors count_distinct_descriptors_;
bool sort_on_gpu_;
bool is_sort_plan; // TODO(alex): remove
bool output_columnar;
bool render_output;
std::vector<int8_t> key_column_pad_bytes;
std::vector<int8_t> target_column_pad_bytes;
bool must_use_baseline_sort;
std::unique_ptr<QueryExecutionContext> getQueryExecutionContext(
const RelAlgExecutionUnit&,
const std::vector<int64_t>& init_agg_vals,
const Executor* executor,
const ExecutorDeviceType device_type,
const int device_id,
const std::vector<std::vector<const int8_t*>>& col_buffers,
const std::vector<std::vector<const int8_t*>>& iter_buffers,
const std::vector<std::vector<uint64_t>>& frag_offsets,
std::shared_ptr<RowSetMemoryOwner>,
const bool output_columnar,
const bool sort_on_gpu,
RenderAllocatorMap*) const;
size_t getBufferSizeQuad(const ExecutorDeviceType device_type) const;
size_t getSmallBufferSizeQuad() const;
size_t getBufferSizeBytes(const ExecutorDeviceType device_type) const;
size_t getSmallBufferSizeBytes() const;
// TODO(alex): remove
bool usesGetGroupValueFast() const;
// TODO(alex): remove
bool usesCachedContext() const;
bool blocksShareMemory() const;
bool threadsShareMemory() const;
bool lazyInitGroups(const ExecutorDeviceType) const;
bool interleavedBins(const ExecutorDeviceType) const;
size_t sharedMemBytes(const ExecutorDeviceType) const;
bool canOutputColumnar() const;
bool sortOnGpu() const;
size_t getKeyOffInBytes(const size_t bin, const size_t key_idx = 0) const;
size_t getNextKeyOffInBytes(const size_t key_idx) const;
size_t getColOffInBytes(const size_t bin, const size_t col_idx) const;
size_t getColOffInBytesInNextBin(const size_t col_idx) const;
size_t getNextColOffInBytes(const int8_t* col_ptr, const size_t bin, const size_t col_idx) const;
size_t getColOnlyOffInBytes(const size_t col_idx) const;
size_t getRowSize() const;
size_t getColsSize() const;
size_t getWarpCount() const;
size_t getCompactByteWidth() const;
bool isCompactLayoutIsometric() const;
size_t getConsistColOffInBytes(const size_t bin, const size_t col_idx) const;
inline size_t getEffectiveKeyWidth() const {
#ifdef ENABLE_KEY_COMPACTION
return group_col_compact_width ? group_col_compact_width : sizeof(int64_t);
#else
return sizeof(int64_t);
#endif
}
private:
size_t getTotalBytesOfColumnarBuffers(const std::vector<ColWidths>& col_widths) const;
};
inline bool can_use_result_set(const QueryMemoryDescriptor& query_mem_desc, const ExecutorDeviceType) {
return (g_cluster || g_use_result_set) || query_mem_desc.must_use_baseline_sort ||
query_mem_desc.hash_type == GroupByColRangeType::MultiCol;
}
#endif // QUERYENGINE_QUERYMEMORYDESCRIPTOR_H