OmniSciDB  a5dc49c757
 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  int64_t bucket_size;
45  // When used in the approximate count distinct algorithm, bitmap_sz_bits has a
46  // different meaning than the bitmap size: https://en.wikipedia.org/wiki/HyperLogLog
47  int64_t bitmap_sz_bits;
51 
52  size_t bitmapSizeBytes() const {
54  size_t const approx_reg_bytes =
55  device_type == ExecutorDeviceType::GPU ? sizeof(int32_t) : 1;
56  return approximate ? approx_reg_bytes << bitmap_sz_bits
58  }
59 
60  size_t bitmapPaddedSizeBytes() const {
61  const auto effective_size = bitmapSizeBytes();
62  const auto padded_size =
64  ? align_to_int64(effective_size)
65  : effective_size;
66  return padded_size * sub_bitmap_count;
67  }
68 };
69 
70 inline bool operator==(const CountDistinctDescriptor& lhs,
71  const CountDistinctDescriptor& rhs) {
72  return lhs.impl_type_ == rhs.impl_type_ && lhs.min_val == rhs.min_val &&
73  lhs.bitmap_sz_bits == rhs.bitmap_sz_bits && lhs.approximate == rhs.approximate &&
74  lhs.device_type == rhs.device_type;
75 }
76 
77 inline bool operator!=(const CountDistinctDescriptor& lhs,
78  const CountDistinctDescriptor& rhs) {
79  return !(lhs == rhs);
80 }
81 
82 #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)