OmniSciDB  f17484ade4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CountDistinctDescriptor.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, 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 
24 #ifndef QUERYENGINE_COUNTDISTINCTDESCRIPTOR_H
25 #define QUERYENGINE_COUNTDISTINCTDESCRIPTOR_H
26 
27 #include "../BufferCompaction.h"
28 #include "../CompilationOptions.h"
29 #include "Logger/Logger.h"
30 
31 inline size_t bitmap_bits_to_bytes(const size_t bitmap_sz) {
32  size_t bitmap_byte_sz = bitmap_sz / 8;
33  if (bitmap_sz % 8) {
34  ++bitmap_byte_sz;
35  }
36  return bitmap_byte_sz;
37 }
38 
40 
43  int64_t min_val;
44  // When used in the approximate count distinct algorithm, bitmap_sz_bits has a
45  // different meaning than the bitmap size: https://en.wikipedia.org/wiki/HyperLogLog
46  int64_t bitmap_sz_bits;
50 
51  size_t bitmapSizeBytes() const {
53  size_t const approx_reg_bytes =
54  device_type == ExecutorDeviceType::GPU ? sizeof(int32_t) : 1;
55  return approximate ? approx_reg_bytes << bitmap_sz_bits
57  }
58 
59  size_t bitmapPaddedSizeBytes() const {
60  const auto effective_size = bitmapSizeBytes();
61  const auto padded_size =
63  ? align_to_int64(effective_size)
64  : effective_size;
65  return padded_size * sub_bitmap_count;
66  }
67 };
68 
69 inline bool operator==(const CountDistinctDescriptor& lhs,
70  const CountDistinctDescriptor& rhs) {
71  return lhs.impl_type_ == rhs.impl_type_ && lhs.min_val == rhs.min_val &&
72  lhs.bitmap_sz_bits == rhs.bitmap_sz_bits && lhs.approximate == rhs.approximate &&
73  lhs.device_type == rhs.device_type;
74 }
75 
76 inline bool operator!=(const CountDistinctDescriptor& lhs,
77  const CountDistinctDescriptor& rhs) {
78  return !(lhs == rhs);
79 }
80 
81 #endif // QUERYENGINE_COUNTDISTINCTDESCRIPTOR_H
size_t bitmap_bits_to_bytes(const size_t bitmap_sz)
CountDistinctImplType impl_type_
ExecutorDeviceType
bool operator!=(const CountDistinctDescriptor &lhs, const CountDistinctDescriptor &rhs)
bool operator==(const SlotSize &lhs, const SlotSize &rhs)
CountDistinctImplType
#define CHECK(condition)
Definition: Logger.h:291
FORCE_INLINE HOST DEVICE T align_to_int64(T addr)