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