OmniSciDB  85c2d10cdc
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RuntimeFunctions.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, 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 
17 #ifndef QUERYENGINE_RUNTIMEFUNCTIONS_H
18 #define QUERYENGINE_RUNTIMEFUNCTIONS_H
19 
20 #include "Shared/funcannotations.h"
21 
22 #include <cassert>
23 #include <cstdint>
24 #include <ctime>
25 #include <limits>
26 #include <type_traits>
27 
28 extern "C" int64_t agg_sum(int64_t* agg, const int64_t val);
29 
30 extern "C" void agg_max(int64_t* agg, const int64_t val);
31 
32 extern "C" void agg_min(int64_t* agg, const int64_t val);
33 
34 extern "C" void agg_sum_double(int64_t* agg, const double val);
35 
36 extern "C" void agg_max_double(int64_t* agg, const double val);
37 
38 extern "C" void agg_min_double(int64_t* agg, const double val);
39 
40 extern "C" int32_t agg_sum_int32_skip_val(int32_t* agg,
41  const int32_t val,
42  const int32_t skip_val);
43 
44 extern "C" int64_t agg_sum_skip_val(int64_t* agg,
45  const int64_t val,
46  const int64_t skip_val);
47 
48 extern "C" void agg_max_skip_val(int64_t* agg, const int64_t val, const int64_t skip_val);
49 
50 extern "C" void agg_min_skip_val(int64_t* agg, const int64_t val, const int64_t skip_val);
51 
52 extern "C" void agg_sum_float_skip_val(int32_t* agg,
53  const float val,
54  const float skip_val);
55 
56 extern "C" void agg_sum_double_skip_val(int64_t* agg,
57  const double val,
58  const double skip_val);
59 
60 extern "C" void agg_max_double_skip_val(int64_t* agg,
61  const double val,
62  const double skip_val);
63 
64 extern "C" void agg_min_double_skip_val(int64_t* agg,
65  const double val,
66  const double skip_val);
67 
68 extern "C" int32_t agg_sum_int32(int32_t* agg, const int32_t val);
69 
70 extern "C" void agg_max_int32(int32_t* agg, const int32_t val);
71 extern "C" void agg_max_int16(int16_t* agg, const int16_t val);
72 extern "C" void agg_max_int8(int8_t* agg, const int8_t val);
73 
74 extern "C" void agg_min_int32(int32_t* agg, const int32_t val);
75 extern "C" void agg_min_int16(int16_t* agg, const int16_t val);
76 extern "C" void agg_min_int8(int8_t* agg, const int8_t val);
77 
78 extern "C" void agg_sum_float(int32_t* agg, const float val);
79 
80 extern "C" void agg_max_float(int32_t* agg, const float val);
81 
82 extern "C" void agg_min_float(int32_t* agg, const float val);
83 
84 extern "C" void agg_max_int32_skip_val(int32_t* agg,
85  const int32_t val,
86  const int32_t skip_val);
87 extern "C" void agg_max_int16_skip_val(int16_t* agg,
88  const int16_t val,
89  const int16_t skip_val);
90 extern "C" void agg_max_int8_skip_val(int8_t* agg,
91  const int8_t val,
92  const int8_t skip_val);
93 
94 extern "C" void agg_min_int32_skip_val(int32_t* agg,
95  const int32_t val,
96  const int32_t skip_val);
97 extern "C" void agg_min_int16_skip_val(int16_t* agg,
98  const int16_t val,
99  const int16_t skip_val);
100 extern "C" void agg_min_int8_skip_val(int8_t* agg,
101  const int8_t val,
102  const int8_t skip_val);
103 
104 extern "C" void agg_max_float_skip_val(int32_t* agg,
105  const float val,
106  const float skip_val);
107 
108 extern "C" void agg_min_float_skip_val(int32_t* agg,
109  const float val,
110  const float skip_val);
111 
112 extern "C" void agg_count_distinct_bitmap(int64_t* agg,
113  const int64_t val,
114  const int64_t min_val);
115 
116 #define EMPTY_KEY_64 std::numeric_limits<int64_t>::max()
117 #define EMPTY_KEY_32 std::numeric_limits<int32_t>::max()
118 #define EMPTY_KEY_16 std::numeric_limits<int16_t>::max()
119 #define EMPTY_KEY_8 std::numeric_limits<int8_t>::max()
120 
121 extern "C" RUNTIME_EXPORT uint32_t key_hash(const int64_t* key,
122  const uint32_t key_qw_count,
123  const uint32_t key_byte_width);
124 
125 extern "C" RUNTIME_EXPORT int64_t* get_group_value(
126  int64_t* groups_buffer,
127  const uint32_t groups_buffer_entry_count,
128  const int64_t* key,
129  const uint32_t key_count,
130  const uint32_t key_width,
131  const uint32_t row_size_quad);
132 
134 
135 extern "C" bool check_interrupt();
136 
137 extern "C" bool check_interrupt_init(unsigned command);
138 
140  int64_t* groups_buffer,
141  const uint32_t groups_buffer_entry_count,
142  const int64_t* key,
143  const uint32_t key_count,
144  const uint32_t key_width,
145  const uint32_t row_size_quad);
146 
147 extern "C" RUNTIME_EXPORT int64_t* get_group_value_columnar(
148  int64_t* groups_buffer,
149  const uint32_t groups_buffer_entry_count,
150  const int64_t* key,
151  const uint32_t key_qw_count);
152 
154  int64_t* groups_buffer,
155  const uint32_t groups_buffer_entry_count,
156  const int64_t* key,
157  const uint32_t key_qw_count);
158 
159 extern "C" RUNTIME_EXPORT int64_t* get_group_value_fast(int64_t* groups_buffer,
160  const int64_t key,
161  const int64_t min_key,
162  const int64_t bucket,
163  const uint32_t row_size_quad);
164 
166  int64_t* groups_buffer,
167  const int64_t key,
168  const int64_t orig_key,
169  const int64_t min_key,
170  const int64_t bucket,
171  const uint32_t row_size_quad);
172 
173 extern "C" RUNTIME_EXPORT uint32_t get_columnar_group_bin_offset(int64_t* key_base_ptr,
174  const int64_t key,
175  const int64_t min_key,
176  const int64_t bucket);
177 
178 extern "C" int64_t* get_matching_group_value_perfect_hash(int64_t* groups_buffer,
179  const uint32_t h,
180  const int64_t* key,
181  const uint32_t key_qw_count,
182  const uint32_t row_size_quad);
183 
185  int64_t* groups_buffer,
186  const uint32_t hashed_index,
187  const uint32_t row_size_quad);
188 
189 extern "C" int32_t* get_bucketized_hash_slot(int32_t* buff,
190  const int64_t key,
191  const int64_t min_key,
192  const int64_t bucket_normalization = 1);
193 
194 extern "C" int32_t* get_hash_slot(int32_t* buff,
195  const int64_t key,
196  const int64_t min_key);
197 
198 extern "C" int32_t* get_hash_slot_sharded(int32_t* buff,
199  const int64_t key,
200  const int64_t min_key,
201  const uint32_t entry_count_per_shard,
202  const uint32_t num_shards,
203  const uint32_t device_count);
204 
205 extern "C" int32_t* get_bucketized_hash_slot_sharded(int32_t* buff,
206  const int64_t key,
207  const int64_t min_key,
208  const uint32_t entry_count_per_shard,
209  const uint32_t num_shards,
210  const uint32_t device_count,
211  const int64_t bucket_normalization);
212 
213 extern "C" int32_t* get_hash_slot_sharded_opt(int32_t* buff,
214  const int64_t key,
215  const int64_t min_key,
216  const uint32_t entry_count_per_shard,
217  const uint32_t shard,
218  const uint32_t num_shards,
219  const uint32_t device_count);
220 
221 extern "C" int32_t* get_bucketized_hash_slot_sharded_opt(
222  int32_t* buff,
223  const int64_t key,
224  const int64_t min_key,
225  const uint32_t entry_count_per_shard,
226  const uint32_t shard,
227  const uint32_t num_shards,
228  const uint32_t device_count,
229  const int64_t bucket_normalization);
230 
231 extern "C" void linear_probabilistic_count(uint8_t* bitmap,
232  const uint32_t bitmap_bytes,
233  const uint8_t* key_bytes,
234  const uint32_t key_len);
235 
236 // Regular fixed_width_*_decode are only available from the JIT,
237 // we need to call them for lazy fetch columns -- create wrappers.
238 
239 extern "C" int64_t fixed_width_int_decode_noinline(const int8_t* byte_stream,
240  const int32_t byte_width,
241  const int64_t pos);
242 
243 extern "C" int64_t fixed_width_unsigned_decode_noinline(const int8_t* byte_stream,
244  const int32_t byte_width,
245  const int64_t pos);
246 
247 extern "C" float fixed_width_float_decode_noinline(const int8_t* byte_stream,
248  const int64_t pos);
249 
250 extern "C" double fixed_width_double_decode_noinline(const int8_t* byte_stream,
251  const int64_t pos);
252 
253 extern "C" int64_t fixed_width_small_date_decode_noinline(const int8_t* byte_stream,
254  const int32_t byte_width,
255  const int32_t null_val,
256  const int64_t ret_null_val,
257  const int64_t pos);
258 
259 extern "C" int8_t* extract_str_ptr_noinline(const uint64_t str_and_len);
260 
261 extern "C" int32_t extract_str_len_noinline(const uint64_t str_and_len);
262 
263 template <typename T = int64_t>
264 inline T get_empty_key() {
265  static_assert(std::is_same<T, int64_t>::value,
266  "Unsupported template parameter other than int64_t for now");
267  return EMPTY_KEY_64;
268 }
269 
270 template <>
271 inline int32_t get_empty_key() {
272  return EMPTY_KEY_32;
273 }
274 
275 #endif // QUERYENGINE_RUNTIMEFUNCTIONS_H
ALWAYS_INLINE void agg_sum_float(int32_t *agg, const float val)
RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t * get_group_value_fast_with_original_key(int64_t *groups_buffer, const int64_t key, const int64_t orig_key, const int64_t min_key, const int64_t bucket, const uint32_t row_size_quad)
ALWAYS_INLINE int64_t agg_sum_skip_val(int64_t *agg, const int64_t val, const int64_t skip_val)
void agg_max_skip_val(int64_t *agg, const int64_t val, const int64_t skip_val)
void agg_min_int32_skip_val(int32_t *agg, const int32_t val, const int32_t skip_val)
void agg_max_int8_skip_val(int8_t *agg, const int8_t val, const int8_t skip_val)
void agg_min_int32(int32_t *agg, const int32_t val)
ALWAYS_INLINE void agg_max_float(int32_t *agg, const float val)
ALWAYS_INLINE int32_t agg_sum_int32_skip_val(int32_t *agg, const int32_t val, const int32_t skip_val)
ALWAYS_INLINE DEVICE int32_t *SUFFIX() get_bucketized_hash_slot(int32_t *buff, const int64_t key, const int64_t min_key, const int64_t bucket_normalization)
Definition: JoinHashImpl.h:31
DEVICE NEVER_INLINE int64_t SUFFIX() fixed_width_int_decode_noinline(const int8_t *byte_stream, const int32_t byte_width, const int64_t pos)
Definition: DecodersImpl.h:91
void agg_max_double_skip_val(int64_t *agg, const double val, const double skip_val)
#define EMPTY_KEY_64
void agg_min_skip_val(int64_t *agg, const int64_t val, const int64_t skip_val)
ALWAYS_INLINE DEVICE int32_t *SUFFIX() get_bucketized_hash_slot_sharded_opt(int32_t *buff, const int64_t key, const int64_t min_key, const uint32_t entry_count_per_shard, const uint32_t shard, const uint32_t num_shards, const uint32_t device_count, const int64_t bucket_normalization)
Definition: JoinHashImpl.h:74
RuntimeInterruptFlags
RUNTIME_EXPORT ALWAYS_INLINE DEVICE uint32_t get_columnar_group_bin_offset(int64_t *key_base_ptr, const int64_t key, const int64_t min_key, const int64_t bucket)
void agg_max_int16(int16_t *agg, const int16_t val)
void agg_min_int8(int8_t *agg, const int8_t val)
void agg_min_int16_skip_val(int16_t *agg, const int16_t val, const int16_t skip_val)
ALWAYS_INLINE void agg_sum_double(int64_t *agg, const double val)
NEVER_INLINE int8_t * extract_str_ptr_noinline(const uint64_t str_and_len)
void agg_max_int32_skip_val(int32_t *agg, const int32_t val, const int32_t skip_val)
__device__ bool check_interrupt()
ALWAYS_INLINE DEVICE int32_t *SUFFIX() get_hash_slot(int32_t *buff, const int64_t key, const int64_t min_key)
Definition: JoinHashImpl.h:39
void agg_max_int16_skip_val(int16_t *agg, const int16_t val, const int16_t skip_val)
ALWAYS_INLINE void agg_min_double(int64_t *agg, const double val)
ALWAYS_INLINE DEVICE int32_t *SUFFIX() get_bucketized_hash_slot_sharded(int32_t *buff, const int64_t key, const int64_t min_key, const uint32_t entry_count_per_shard, const uint32_t num_shards, const uint32_t device_count, const int64_t bucket_normalization)
Definition: JoinHashImpl.h:45
ALWAYS_INLINE int32_t agg_sum_int32(int32_t *agg, const int32_t val)
__device__ void linear_probabilistic_count(uint8_t *bitmap, const uint32_t bitmap_bytes, const uint8_t *key_bytes, const uint32_t key_len)
ALWAYS_INLINE int64_t * get_matching_group_value_perfect_hash_keyless(int64_t *groups_buffer, const uint32_t hashed_index, const uint32_t row_size_quad)
void agg_min_int16(int16_t *agg, const int16_t val)
void agg_min_double_skip_val(int64_t *agg, const double val, const double skip_val)
ALWAYS_INLINE void agg_max_double(int64_t *agg, const double val)
DEVICE NEVER_INLINE int64_t SUFFIX() fixed_width_unsigned_decode_noinline(const int8_t *byte_stream, const int32_t byte_width, const int64_t pos)
Definition: DecodersImpl.h:98
void agg_min_float_skip_val(int32_t *agg, const float val, const float skip_val)
RUNTIME_EXPORT NEVER_INLINE DEVICE int64_t * get_group_value_columnar_with_watchdog(int64_t *groups_buffer, const uint32_t groups_buffer_entry_count, const int64_t *key, const uint32_t key_qw_count)
void agg_max_float_skip_val(int32_t *agg, const float val, const float skip_val)
RUNTIME_EXPORT NEVER_INLINE DEVICE int64_t * get_group_value(int64_t *groups_buffer, const uint32_t groups_buffer_entry_count, const int64_t *key, const uint32_t key_count, const uint32_t key_width, const uint32_t row_size_quad)
NEVER_INLINE int32_t extract_str_len_noinline(const uint64_t str_and_len)
#define RUNTIME_EXPORT
ALWAYS_INLINE int64_t agg_sum(int64_t *agg, const int64_t val)
ALWAYS_INLINE void agg_min(int64_t *agg, const int64_t val)
DEVICE NEVER_INLINE int64_t SUFFIX() fixed_width_small_date_decode_noinline(const int8_t *byte_stream, const int32_t byte_width, const int32_t null_val, const int64_t ret_null_val, const int64_t pos)
Definition: DecodersImpl.h:149
void agg_min_int8_skip_val(int8_t *agg, const int8_t val, const int8_t skip_val)
ALWAYS_INLINE DEVICE int32_t *SUFFIX() get_hash_slot_sharded_opt(int32_t *buff, const int64_t key, const int64_t min_key, const uint32_t entry_count_per_shard, const uint32_t shard, const uint32_t num_shards, const uint32_t device_count)
Definition: JoinHashImpl.h:89
ALWAYS_INLINE int64_t * get_matching_group_value_perfect_hash(int64_t *groups_buffer, const uint32_t hashed_index, const int64_t *key, const uint32_t key_count, const uint32_t row_size_quad)
ALWAYS_INLINE DEVICE int32_t *SUFFIX() get_hash_slot_sharded(int32_t *buff, const int64_t key, const int64_t min_key, const uint32_t entry_count_per_shard, const uint32_t num_shards, const uint32_t device_count)
Definition: JoinHashImpl.h:60
void agg_max_int32(int32_t *agg, const int32_t val)
RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t * get_group_value_fast(int64_t *groups_buffer, const int64_t key, const int64_t min_key, const int64_t bucket, const uint32_t row_size_quad)
bool check_interrupt_init(unsigned command)
RUNTIME_EXPORT ALWAYS_INLINE DEVICE uint32_t key_hash(const int64_t *key, const uint32_t key_count, const uint32_t key_byte_width)
ALWAYS_INLINE void agg_max(int64_t *agg, const int64_t val)
void agg_sum_double_skip_val(int64_t *agg, const double val, const double skip_val)
__device__ T get_empty_key()
DEVICE NEVER_INLINE float SUFFIX() fixed_width_float_decode_noinline(const int8_t *byte_stream, const int64_t pos)
Definition: DecodersImpl.h:121
DEVICE NEVER_INLINE double SUFFIX() fixed_width_double_decode_noinline(const int8_t *byte_stream, const int64_t pos)
Definition: DecodersImpl.h:134
void agg_max_int8(int8_t *agg, const int8_t val)
void agg_sum_float_skip_val(int32_t *agg, const float val, const float skip_val)
RUNTIME_EXPORT NEVER_INLINE DEVICE int64_t * get_group_value_columnar(int64_t *groups_buffer, const uint32_t groups_buffer_entry_count, const int64_t *key, const uint32_t key_qw_count)
RUNTIME_EXPORT NEVER_INLINE DEVICE int64_t * get_group_value_with_watchdog(int64_t *groups_buffer, const uint32_t groups_buffer_entry_count, const int64_t *key, const uint32_t key_count, const uint32_t key_width, const uint32_t row_size_quad)
ALWAYS_INLINE void agg_count_distinct_bitmap(int64_t *agg, const int64_t val, const int64_t min_val)
ALWAYS_INLINE void agg_min_float(int32_t *agg, const float val)
#define EMPTY_KEY_32