OmniSciDB  1dac507f6e
 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 <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  const int64_t* init_val = nullptr);
130 
131 extern "C" int64_t* get_group_value_with_watchdog(
132  int64_t* groups_buffer,
133  const uint32_t groups_buffer_entry_count,
134  const int64_t* key,
135  const uint32_t key_count,
136  const uint32_t key_width,
137  const uint32_t row_size_quad,
138  const int64_t* init_val = nullptr);
139 
140 extern "C" int64_t* get_group_value_columnar(int64_t* groups_buffer,
141  const uint32_t groups_buffer_entry_count,
142  const int64_t* key,
143  const uint32_t key_qw_count);
144 
145 extern "C" int64_t* get_group_value_columnar_with_watchdog(
146  int64_t* groups_buffer,
147  const uint32_t groups_buffer_entry_count,
148  const int64_t* key,
149  const uint32_t key_qw_count);
150 
151 extern "C" int64_t* get_group_value_fast(int64_t* groups_buffer,
152  const int64_t key,
153  const int64_t min_key,
154  const int64_t bucket,
155  const uint32_t row_size_quad);
156 
157 extern "C" int64_t* get_group_value_fast_with_original_key(int64_t* groups_buffer,
158  const int64_t key,
159  const int64_t orig_key,
160  const int64_t min_key,
161  const int64_t bucket,
162  const uint32_t row_size_quad);
163 
164 extern "C" uint32_t get_columnar_group_bin_offset(int64_t* key_base_ptr,
165  const int64_t key,
166  const int64_t min_key,
167  const int64_t bucket);
168 
169 extern "C" int64_t* get_matching_group_value_perfect_hash(int64_t* groups_buffer,
170  const uint32_t h,
171  const int64_t* key,
172  const uint32_t key_qw_count,
173  const uint32_t row_size_quad);
174 
175 extern "C" int32_t* get_bucketized_hash_slot(int32_t* buff,
176  const int64_t key,
177  const int64_t min_key,
178  const int64_t bucket_normalization = 1);
179 
180 extern "C" int32_t* get_hash_slot(int32_t* buff,
181  const int64_t key,
182  const int64_t min_key);
183 
184 extern "C" int32_t* get_hash_slot_sharded(int32_t* buff,
185  const int64_t key,
186  const int64_t min_key,
187  const uint32_t entry_count_per_shard,
188  const uint32_t num_shards,
189  const uint32_t device_count);
190 
191 extern "C" int32_t* get_bucketized_hash_slot_sharded(int32_t* buff,
192  const int64_t key,
193  const int64_t min_key,
194  const uint32_t entry_count_per_shard,
195  const uint32_t num_shards,
196  const uint32_t device_count,
197  const int64_t bucket_normalization);
198 
199 extern "C" void linear_probabilistic_count(uint8_t* bitmap,
200  const uint32_t bitmap_bytes,
201  const uint8_t* key_bytes,
202  const uint32_t key_len);
203 
204 // Regular fixed_width_*_decode are only available from the JIT,
205 // we need to call them for lazy fetch columns -- create wrappers.
206 
207 extern "C" int64_t fixed_width_int_decode_noinline(const int8_t* byte_stream,
208  const int32_t byte_width,
209  const int64_t pos);
210 
211 extern "C" int64_t fixed_width_unsigned_decode_noinline(const int8_t* byte_stream,
212  const int32_t byte_width,
213  const int64_t pos);
214 
215 extern "C" float fixed_width_float_decode_noinline(const int8_t* byte_stream,
216  const int64_t pos);
217 
218 extern "C" double fixed_width_double_decode_noinline(const int8_t* byte_stream,
219  const int64_t pos);
220 
221 extern "C" int64_t fixed_width_small_date_decode_noinline(const int8_t* byte_stream,
222  const int32_t byte_width,
223  const int32_t null_val,
224  const int64_t ret_null_val,
225  const int64_t pos);
226 
227 extern "C" int8_t* extract_str_ptr_noinline(const uint64_t str_and_len);
228 
229 extern "C" int32_t extract_str_len_noinline(const uint64_t str_and_len);
230 
231 template <typename T = int64_t>
232 inline T get_empty_key() {
233  static_assert(std::is_same<T, int64_t>::value,
234  "Unsupported template parameter other than int64_t for now");
235  return EMPTY_KEY_64;
236 }
237 
238 template <>
239 inline int32_t get_empty_key() {
240  return EMPTY_KEY_32;
241 }
242 
243 #endif // QUERYENGINE_RUNTIMEFUNCTIONS_H
ALWAYS_INLINE void agg_sum_float(int32_t *agg, const float val)
ALWAYS_INLINE int64_t agg_sum_skip_val(int64_t *agg, const int64_t val, const int64_t skip_val)
const int32_t groups_buffer_size return groups_buffer
int8_t * extract_str_ptr_noinline(const uint64_t str_and_len)
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)
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:83
void agg_max_double_skip_val(int64_t *agg, const double val, const double skip_val)
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)
ALWAYS_INLINE DEVICE uint32_t key_hash(const int64_t *key, const uint32_t key_count, const uint32_t key_byte_width)
#define EMPTY_KEY_64
void agg_min_skip_val(int64_t *agg, const int64_t val, const int64_t skip_val)
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, const int64_t *init_vals)
void agg_max_int16(int16_t *agg, const int16_t val)
void agg_min_int8(int8_t *agg, const int8_t val)
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)
const int64_t const uint32_t groups_buffer_entry_count
void agg_min_int16_skip_val(int16_t *agg, const int16_t val, const int16_t skip_val)
const int64_t const uint32_t const uint32_t key_qw_count
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 void agg_sum_double(int64_t *agg, const double val)
void agg_max_int32_skip_val(int32_t *agg, const int32_t val, const int32_t skip_val)
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)
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)
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:90
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)
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, const int64_t *init_vals)
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:141
void agg_min_int8_skip_val(int8_t *agg, const int8_t val, const int8_t skip_val)
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)
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:113
DEVICE NEVER_INLINE double SUFFIX() fixed_width_double_decode_noinline(const int8_t *byte_stream, const int64_t pos)
Definition: DecodersImpl.h:126
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_int8(int8_t *agg, const int8_t val)
void agg_sum_float_skip_val(int32_t *agg, const float val, const float skip_val)
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