OmniSciDB  5ade3759e0
JoinHashImpl.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 /*
18  * @file JoinHashImpl.h
19  * @author Alex Suhan <alex@mapd.com>
20  *
21  * Copyright (c) 2015 MapD Technologies, Inc. All rights reserved.
22  */
23 
24 #ifndef QUERYENGINE_GROUPBYFASTIMPL_H
25 #define QUERYENGINE_GROUPBYFASTIMPL_H
26 
27 #include <cstdint>
28 #include "../Shared/funcannotations.h"
29 #include "../Shared/shard_key.h"
30 
32  int32_t* buff,
33  const int64_t key,
34  const int64_t min_key,
35  const int64_t bucket_normalization) {
36  return buff + (key - min_key) / bucket_normalization;
37 }
38 
39 extern "C" ALWAYS_INLINE DEVICE int32_t* SUFFIX(get_hash_slot)(int32_t* buff,
40  const int64_t key,
41  const int64_t min_key) {
42  return buff + (key - min_key);
43 }
44 
46  int32_t* buff,
47  const int64_t key,
48  const int64_t min_key,
49  const uint32_t entry_count_per_shard,
50  const uint32_t num_shards,
51  const uint32_t device_count,
52  const int64_t bucket_normalization) {
53  const uint32_t shard = SHARD_FOR_KEY(key, num_shards);
54  const uint32_t shard_buffer_index =
55  shard / device_count; // shard sub-buffer index within `buff`
56  int32_t* shard_buffer = buff + shard_buffer_index * entry_count_per_shard;
57  return shard_buffer + (key - min_key) / bucket_normalization / num_shards;
58 }
59 
61  int32_t* buff,
62  const int64_t key,
63  const int64_t min_key,
64  const uint32_t entry_count_per_shard,
65  const uint32_t num_shards,
66  const uint32_t device_count) {
67  const uint32_t shard = SHARD_FOR_KEY(key, num_shards);
68  const uint32_t shard_buffer_index =
69  shard / device_count; // shard sub-buffer index within `buff`
70  int32_t* shard_buffer = buff + shard_buffer_index * entry_count_per_shard;
71  return shard_buffer + (key - min_key) / num_shards;
72 }
73 
74 #endif // QUERYENGINE_GROUPBYFASTIMPL_H
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
#define SUFFIX(name)
#define DEVICE
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
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 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
#define ALWAYS_INLINE
#define SHARD_FOR_KEY(key, num_shards)
Definition: shard_key.h:20