OmniSciDB
a5dc49c757
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
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
39
enum class
CountDistinctImplType
{
Invalid
,
Bitmap
,
UnorderedSet
};
40
41
struct
CountDistinctDescriptor
{
42
CountDistinctImplType
impl_type_
;
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
;
48
bool
approximate
;
49
ExecutorDeviceType
device_type
;
50
size_t
sub_bitmap_count
;
51
52
size_t
bitmapSizeBytes
()
const
{
53
CHECK
(
impl_type_
==
CountDistinctImplType::Bitmap
);
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
57
:
bitmap_bits_to_bytes
(
bitmap_sz_bits
);
58
}
59
60
size_t
bitmapPaddedSizeBytes
()
const
{
61
const
auto
effective_size =
bitmapSizeBytes
();
62
const
auto
padded_size =
63
(
device_type
==
ExecutorDeviceType::GPU
||
sub_bitmap_count
> 1)
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
CountDistinctDescriptor
Definition:
CountDistinctDescriptor.h:41
CountDistinctDescriptor::device_type
ExecutorDeviceType device_type
Definition:
CountDistinctDescriptor.h:49
CountDistinctDescriptor::approximate
bool approximate
Definition:
CountDistinctDescriptor.h:48
CountDistinctDescriptor::sub_bitmap_count
size_t sub_bitmap_count
Definition:
CountDistinctDescriptor.h:50
CountDistinctDescriptor::min_val
int64_t min_val
Definition:
CountDistinctDescriptor.h:43
bitmap_bits_to_bytes
size_t bitmap_bits_to_bytes(const size_t bitmap_sz)
Definition:
CountDistinctDescriptor.h:31
CountDistinctDescriptor::bitmap_sz_bits
int64_t bitmap_sz_bits
Definition:
CountDistinctDescriptor.h:47
CountDistinctImplType::Bitmap
CountDistinctDescriptor::impl_type_
CountDistinctImplType impl_type_
Definition:
CountDistinctDescriptor.h:42
ExecutorDeviceType
ExecutorDeviceType
Definition:
ExecutorDeviceType.h:23
ExecutorDeviceType::GPU
operator!=
bool operator!=(const CountDistinctDescriptor &lhs, const CountDistinctDescriptor &rhs)
Definition:
CountDistinctDescriptor.h:77
CountDistinctDescriptor::bitmapSizeBytes
size_t bitmapSizeBytes() const
Definition:
CountDistinctDescriptor.h:52
Logger.h
CountDistinctDescriptor::bitmapPaddedSizeBytes
size_t bitmapPaddedSizeBytes() const
Definition:
CountDistinctDescriptor.h:60
operator==
bool operator==(const SlotSize &lhs, const SlotSize &rhs)
Definition:
ColSlotContext.h:38
CountDistinctImplType
CountDistinctImplType
Definition:
CountDistinctDescriptor.h:39
CHECK
#define CHECK(condition)
Definition:
Logger.h:291
CountDistinctImplType::UnorderedSet
align_to_int64
FORCE_INLINE HOST DEVICE T align_to_int64(T addr)
Definition:
BufferCompaction.h:42
CountDistinctDescriptor::bucket_size
int64_t bucket_size
Definition:
CountDistinctDescriptor.h:44
CountDistinctImplType::Invalid
QueryEngine
Descriptors
CountDistinctDescriptor.h
Generated on Tue Aug 27 2024 00:12:40 for OmniSciDB by
1.8.5