Skip to content

Commit db4dc00

Browse files
authored
Merge branch 'master' into density_sketch
2 parents 016256f + 4778e3a commit db4dc00

89 files changed

Lines changed: 10835 additions & 1286 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build_wheels.yml

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ name: Build Python Wheels
33
on:
44
# allow manual runs
55
workflow_dispatch:
6+
67
# run when we tag a release
7-
release:
8-
types:
9-
- "created"
8+
#release:
9+
# types:
10+
# - "created"
1011

1112
env:
1213
BUILD_TYPE: Release
@@ -29,15 +30,14 @@ jobs:
2930
- name: Build sdist
3031
run: python -m build --sdist --outdir dist
3132

32-
- uses: actions/upload-artifact@v2
33+
- uses: actions/upload-artifact@v3
3334
with:
3435
path: dist/*.tar.gz
3536

3637
build_wheels:
3738
name: ${{ matrix.config.name }}
3839
runs-on: ${{ matrix.config.os }}
3940
strategy:
40-
#fail-fast: false
4141
matrix:
4242
config:
4343
- {
@@ -55,6 +55,12 @@ jobs:
5555
os: ubuntu-latest,
5656
cibw-arch: manylinux_x86_64
5757
}
58+
- {
59+
name: "Ubuntu Latest (ARM64)",
60+
os: ubuntu-latest,
61+
cibw-arch: manylinux_aarch64,
62+
use-qemu: true
63+
}
5864
- {
5965
name: "Ubuntu Latest (i686)",
6066
os: ubuntu-latest,
@@ -66,7 +72,6 @@ jobs:
6672
cibw-arch: win_amd64
6773
}
6874

69-
7075
steps:
7176
- name: Checkout
7277
uses: actions/checkout@v3
@@ -75,25 +80,27 @@ jobs:
7580
uses: actions/setup-python@v4
7681
with:
7782
python-version: '3.x'
78-
83+
84+
- name: Set up QEMU for linux/arm64 builds
85+
if: runner.os == 'Linux' && matrix.config.use-qemu == true
86+
uses: docker/setup-qemu-action@v2
87+
with:
88+
platforms: arm64
89+
7990
- name: Install Python dependencies
80-
run: python -m pip install cibuildwheel==2.5.0
81-
82-
- name: Configure cibuildwheel
83-
shell: bash
84-
run: |
85-
CMAKE_OSX_ARCHITECTURES=${{ matrix.config.cibw-arch == 'macosx_x86_64' && 'x86_64' || matrix.config.cibw-arch == 'macosx_arm64' && 'arm64' || matrix.config.cibw-arch == 'macosx_universal2' && '"arm64;x86_64"' || '' }}
86-
echo "CIBW_ARCHS_MACOS=x86_64 arm64" >> $GITHUB_ENV
87-
echo "CIBW_BUILD=*-${{ matrix.config.cibw-arch }}" >> $GITHUB_ENV
88-
echo "CIBW_ENVIRONMENT_MACOS=CMAKE_OSX_ARCHITECTURES=\"$CMAKE_OSX_ARCHITECTURES\"" >> $GITHUB_ENV
89-
91+
run: python -m pip install cibuildwheel==2.12.0
92+
9093
- name: Build wheels
9194
run: python -m cibuildwheel --output-dir dist
9295
env:
96+
CIBW_ARCHS_LINUX: "auto aarch64"
97+
CIBW_ARCHS_MACOS: "x86_64 arm64"
98+
CIBW_ENVIRONMENT_MACOS: CMAKE_OSX_ARCHITECTURES=${{ matrix.config.cibw-arch == 'macosx_x86_64' && 'x86_64' || matrix.config.cibw-arch == 'macosx_arm64' && 'arm64' || '' }}
99+
CIBW_BUILD: "*-${{ matrix.config.cibw-arch }}"
93100
CIBW_BEFORE_BUILD_LINUX: "yum remove -y cmake"
94101
CIBW_BEFORE_BUILD: "python -m pip install cmake>=3.18"
95-
CIBW_SKIP: "*-win32 pp*-macosx*"
102+
CIBW_SKIP: "*-win32 pp*-aarch64 pp*-macosx"
96103

97-
- uses: actions/upload-artifact@v2
104+
- uses: actions/upload-artifact@v3
98105
with:
99106
path: ./dist/*.whl

CMakeLists.txt

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ include(CMakeDependentOption)
3434
### Require out-of-source builds
3535
file(TO_CMAKE_PATH "${PROJECT_BINARY_DIR}/CMakeLists.txt" LOC_PATH)
3636
if(EXISTS "${LOC_PATH}")
37-
message(FATAL_ERROR "You cannot build in a source directory (or any directory with a CMakeLists.txt file). Please make a build subdirectory. Feel free to remove CMakeCache.txt and CMakeFiles.")
37+
message(FATAL_ERROR "You cannot build in a source directory (or any directory with a CMakeLists.txt file). Please make a build subdirectory. Feel free to remove CMakeCache.txt and CMakeFiles.")
3838
endif()
3939

4040
# Ensure builds on Windows export all symbols
@@ -69,7 +69,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)
6969
###### OPTIONS ######
7070
# Enable testing
7171
option(BUILD_TESTS "Build unit tests" ON)
72-
if (BUILD_TESTS)
72+
if (BUILD_TESTS)
7373
enable_testing()
7474
endif()
7575

@@ -93,10 +93,10 @@ set(default_build_type "Release")
9393
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
9494
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
9595
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
96-
STRING "Choose the type of build." FORCE)
96+
STRING "Choose the type of build." FORCE)
9797
# Set the possible values of build type for cmake-gui
9898
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
99-
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
99+
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
100100
endif()
101101

102102
###### TARGETS ######
@@ -115,48 +115,49 @@ add_subdirectory(sampling)
115115
add_subdirectory(tuple)
116116
add_subdirectory(req)
117117
add_subdirectory(quantiles)
118+
add_subdirectory(count)
118119
add_subdirectory(density)
119120

120121
if (WITH_PYTHON)
121122
add_subdirectory(python)
122123
endif()
123124

124-
target_link_libraries(datasketches INTERFACE hll cpc kll fi theta sampling req quantiles)
125+
target_link_libraries(datasketches INTERFACE hll cpc kll fi theta sampling req quantiles count)
125126

126127
if (COVERAGE)
127128
find_program(LCOV_PATH NAMES "lcov")
128129
find_program(GENHTML_PATH NAMES "genhtml")
129130
if (NOT LCOV_PATH-NOTFOUND AND NOT GENHTML_PATH-NOTFOUND)
130131
add_custom_target(coverage_report
131-
COMMAND ${LCOV_PATH} --capture --exclude '*/test/*' --exclude '/Library/*' --exclude '/usr/include/*' --directory . --output-file lcov.info
132-
COMMAND ${GENHTML_PATH} --legend lcov.info --output-directory coverage --demangle-cpp)
133-
endif()
132+
COMMAND ${LCOV_PATH} --capture --exclude '*/test/*' --exclude '/Library/*' --exclude '/usr/include/*' --directory . --output-file lcov.info
133+
COMMAND ${GENHTML_PATH} --legend lcov.info --output-directory coverage --demangle-cpp)
134+
endif()
134135
endif()
135136

136137

137138
# # Installation
138139
install(TARGETS datasketches
139-
EXPORT ${PROJECT_NAME}
140-
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/DataSketches
141-
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/DataSketches
142-
)
140+
EXPORT ${PROJECT_NAME}
141+
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/DataSketches
142+
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/DataSketches
143+
)
143144

144145
# Packaging
145146
include(CMakePackageConfigHelpers)
146147
write_basic_package_version_file(
147-
"${CMAKE_CURRENT_BINARY_DIR}/DataSketchesConfigVersion.cmake"
148-
VERSION ${PROJECT_VERSION}
149-
COMPATIBILITY SameMajorVersion
148+
"${CMAKE_CURRENT_BINARY_DIR}/DataSketchesConfigVersion.cmake"
149+
VERSION ${PROJECT_VERSION}
150+
COMPATIBILITY SameMajorVersion
150151
)
151152
configure_package_config_file(
152-
cmake/DataSketchesConfig.cmake.in
153-
"${CMAKE_CURRENT_BINARY_DIR}/DataSketchesConfig.cmake"
154-
INSTALL_DESTINATION lib/DataSketches/cmake
155-
PATH_VARS CMAKE_INSTALL_INCLUDEDIR
153+
cmake/DataSketchesConfig.cmake.in
154+
"${CMAKE_CURRENT_BINARY_DIR}/DataSketchesConfig.cmake"
155+
INSTALL_DESTINATION lib/DataSketches/cmake
156+
PATH_VARS CMAKE_INSTALL_INCLUDEDIR
156157
)
157158
install(EXPORT ${PROJECT_NAME} DESTINATION lib/DataSketches/cmake)
158159
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/DataSketchesConfigVersion.cmake"
159-
"${CMAKE_CURRENT_BINARY_DIR}/DataSketchesConfig.cmake"
160+
"${CMAKE_CURRENT_BINARY_DIR}/DataSketchesConfig.cmake"
160161
DESTINATION lib/DataSketches/cmake)
161162

162163

common/include/MurmurHash3.h

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,30 @@ typedef unsigned char uint8_t;
2929
typedef unsigned int uint32_t;
3030
typedef unsigned __int64 uint64_t;
3131

32-
#define FORCE_INLINE __forceinline
32+
#define MURMUR3_FORCE_INLINE __forceinline
3333

3434
#include <stdlib.h>
3535

36-
#define ROTL32(x,y) _rotl(x,y)
37-
#define ROTL64(x,y) _rotl64(x,y)
36+
#define MURMUR3_ROTL64(x,y) _rotl64(x,y)
3837

39-
#define BIG_CONSTANT(x) (x)
38+
#define MURMUR3_BIG_CONSTANT(x) (x)
4039

4140
// Other compilers
4241

4342
#else // defined(_MSC_VER)
4443

4544
#include <stdint.h>
4645

47-
#define FORCE_INLINE inline __attribute__((always_inline))
48-
49-
inline uint32_t rotl32 ( uint32_t x, int8_t r )
50-
{
51-
return (x << r) | (x >> (32 - r));
52-
}
46+
#define MURMUR3_FORCE_INLINE inline __attribute__((always_inline))
5347

5448
inline uint64_t rotl64 ( uint64_t x, int8_t r )
5549
{
5650
return (x << r) | (x >> (64 - r));
5751
}
5852

59-
#define ROTL32(x,y) rotl32(x,y)
60-
#define ROTL64(x,y) rotl64(x,y)
53+
#define MURMUR3_ROTL64(x,y) rotl64(x,y)
6154

62-
#define BIG_CONSTANT(x) (x##LLU)
55+
#define MURMUR3_BIG_CONSTANT(x) (x##LLU)
6356

6457
#endif // !defined(_MSC_VER)
6558

@@ -78,7 +71,7 @@ typedef struct {
7871
// Block read - if your platform needs to do endian-swapping or can only
7972
// handle aligned reads, do the conversion here
8073

81-
FORCE_INLINE uint64_t getblock64 ( const uint64_t * p, size_t i )
74+
MURMUR3_FORCE_INLINE uint64_t getblock64 ( const uint64_t * p, size_t i )
8275
{
8376
uint64_t res;
8477
memcpy(&res, p + i, sizeof(res));
@@ -88,20 +81,21 @@ FORCE_INLINE uint64_t getblock64 ( const uint64_t * p, size_t i )
8881
//-----------------------------------------------------------------------------
8982
// Finalization mix - force all bits of a hash block to avalanche
9083

91-
FORCE_INLINE uint64_t fmix64 ( uint64_t k )
84+
MURMUR3_FORCE_INLINE uint64_t fmix64 ( uint64_t k )
9285
{
9386
k ^= k >> 33;
94-
k *= BIG_CONSTANT(0xff51afd7ed558ccd);
87+
k *= MURMUR3_BIG_CONSTANT(0xff51afd7ed558ccd);
9588
k ^= k >> 33;
96-
k *= BIG_CONSTANT(0xc4ceb9fe1a85ec53);
89+
k *= MURMUR3_BIG_CONSTANT(0xc4ceb9fe1a85ec53);
9790
k ^= k >> 33;
9891

9992
return k;
10093
}
10194

102-
FORCE_INLINE void MurmurHash3_x64_128(const void* key, size_t lenBytes, uint64_t seed, HashState& out) {
103-
static const uint64_t c1 = BIG_CONSTANT(0x87c37b91114253d5);
104-
static const uint64_t c2 = BIG_CONSTANT(0x4cf5ad432745937f);
95+
MURMUR3_FORCE_INLINE void MurmurHash3_x64_128(const void* key, size_t lenBytes,
96+
uint64_t seed, HashState& out) {
97+
static const uint64_t c1 = MURMUR3_BIG_CONSTANT(0x87c37b91114253d5);
98+
static const uint64_t c2 = MURMUR3_BIG_CONSTANT(0x4cf5ad432745937f);
10599

106100
const uint8_t* data = (const uint8_t*)key;
107101

@@ -118,13 +112,13 @@ FORCE_INLINE void MurmurHash3_x64_128(const void* key, size_t lenBytes, uint64_t
118112
uint64_t k1 = getblock64(blocks, i * 2 + 0);
119113
uint64_t k2 = getblock64(blocks, i * 2 + 1);
120114

121-
k1 *= c1; k1 = ROTL64(k1,31); k1 *= c2; out.h1 ^= k1;
122-
out.h1 = ROTL64(out.h1,27);
115+
k1 *= c1; k1 = MURMUR3_ROTL64(k1,31); k1 *= c2; out.h1 ^= k1;
116+
out.h1 = MURMUR3_ROTL64(out.h1,27);
123117
out.h1 += out.h2;
124118
out.h1 = out.h1*5+0x52dce729;
125119

126-
k2 *= c2; k2 = ROTL64(k2,33); k2 *= c1; out.h2 ^= k2;
127-
out.h2 = ROTL64(out.h2,31);
120+
k2 *= c2; k2 = MURMUR3_ROTL64(k2,33); k2 *= c1; out.h2 ^= k2;
121+
out.h2 = MURMUR3_ROTL64(out.h2,31);
128122
out.h2 += out.h1;
129123
out.h2 = out.h2*5+0x38495ab5;
130124
}
@@ -144,7 +138,7 @@ FORCE_INLINE void MurmurHash3_x64_128(const void* key, size_t lenBytes, uint64_t
144138
case 11: k2 ^= ((uint64_t)tail[10]) << 16; // falls through
145139
case 10: k2 ^= ((uint64_t)tail[ 9]) << 8; // falls through
146140
case 9: k2 ^= ((uint64_t)tail[ 8]) << 0;
147-
k2 *= c2; k2 = ROTL64(k2,33); k2 *= c1; out.h2 ^= k2;
141+
k2 *= c2; k2 = MURMUR3_ROTL64(k2,33); k2 *= c1; out.h2 ^= k2;
148142
// falls through
149143
case 8: k1 ^= ((uint64_t)tail[ 7]) << 56; // falls through
150144
case 7: k1 ^= ((uint64_t)tail[ 6]) << 48; // falls through
@@ -154,7 +148,7 @@ FORCE_INLINE void MurmurHash3_x64_128(const void* key, size_t lenBytes, uint64_t
154148
case 3: k1 ^= ((uint64_t)tail[ 2]) << 16; // falls through
155149
case 2: k1 ^= ((uint64_t)tail[ 1]) << 8; // falls through
156150
case 1: k1 ^= ((uint64_t)tail[ 0]) << 0;
157-
k1 *= c1; k1 = ROTL64(k1,31); k1 *= c2; out.h1 ^= k1;
151+
k1 *= c1; k1 = MURMUR3_ROTL64(k1,31); k1 *= c2; out.h1 ^= k1;
158152
};
159153

160154
//----------
@@ -175,10 +169,14 @@ FORCE_INLINE void MurmurHash3_x64_128(const void* key, size_t lenBytes, uint64_t
175169

176170
//-----------------------------------------------------------------------------
177171

178-
FORCE_INLINE uint16_t compute_seed_hash(uint64_t seed) {
172+
MURMUR3_FORCE_INLINE uint16_t compute_seed_hash(uint64_t seed) {
179173
HashState hashes;
180174
MurmurHash3_x64_128(&seed, sizeof(seed), 0, hashes);
181175
return static_cast<uint16_t>(hashes.h1 & 0xffff);
182176
}
183177

178+
#undef MURMUR3_FORCE_INLINE
179+
#undef MURMUR3_ROTL64
180+
#undef MURMUR3_BIG_CONSTANT
181+
184182
#endif // _MURMURHASH3_H_

common/include/common_defs.hpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <iostream>
2727
#include <random>
2828
#include <chrono>
29+
#include <thread>
2930

3031
namespace datasketches {
3132

@@ -36,15 +37,16 @@ enum resize_factor { X1 = 0, X2, X4, X8 };
3637
template<typename A> using AllocChar = typename std::allocator_traits<A>::template rebind_alloc<char>;
3738
template<typename A> using string = std::basic_string<char, std::char_traits<char>, AllocChar<A>>;
3839

39-
// random bit
40-
static std::independent_bits_engine<std::mt19937, 1, uint32_t>
41-
random_bit(static_cast<uint32_t>(std::chrono::system_clock::now().time_since_epoch().count()));
40+
// thread-safe random bit
41+
static thread_local std::independent_bits_engine<std::mt19937, 1, uint32_t>
42+
random_bit(static_cast<uint32_t>(std::chrono::system_clock::now().time_since_epoch().count()
43+
+ std::hash<std::thread::id>{}(std::this_thread::get_id())));
4244

4345
// common random declarations
4446
namespace random_utils {
4547
static std::random_device rd; // possibly unsafe in MinGW with GCC < 9.2
46-
static std::mt19937_64 rand(rd());
47-
static std::uniform_real_distribution<> next_double(0.0, 1.0);
48+
static thread_local std::mt19937_64 rand(rd());
49+
static thread_local std::uniform_real_distribution<> next_double(0.0, 1.0);
4850
}
4951

5052

@@ -77,7 +79,7 @@ static inline void read(std::istream& is, T* ptr, size_t size_bytes) {
7779
}
7880

7981
template<typename T>
80-
static inline void write(std::ostream& os, T& value) {
82+
static inline void write(std::ostream& os, T value) {
8183
os.write(reinterpret_cast<const char*>(&value), sizeof(T));
8284
}
8385

common/include/count_zeros.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ static inline uint8_t count_leading_zeros_in_u64(uint64_t input) {
9191
return 56 + byte_leading_zeros_table[(input ) & FCLZ_MASK_08];
9292
}
9393

94+
static inline uint8_t count_leading_zeros_in_u32(uint32_t input) {
95+
if (input > FCLZ_MASK_24)
96+
return byte_leading_zeros_table[(input >> 24) & FCLZ_MASK_08];
97+
if (input > FCLZ_MASK_16)
98+
return 8 + byte_leading_zeros_table[(input >> 16) & FCLZ_MASK_08];
99+
if (input > FCLZ_MASK_08)
100+
return 16 + byte_leading_zeros_table[(input >> 8) & FCLZ_MASK_08];
101+
if (true)
102+
return 24 + byte_leading_zeros_table[(input ) & FCLZ_MASK_08];
103+
}
104+
94105
static inline uint8_t count_trailing_zeros_in_u32(uint32_t input) {
95106
for (int i = 0; i < 4; i++) {
96107
const int byte = input & 0xff;

common/include/memory_operations.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ static inline size_t copy_to_mem(const void* src, void* dst, size_t size) {
5555
}
5656

5757
template<typename T>
58-
static inline size_t copy_to_mem(const T& item, void* dst) {
59-
memcpy(dst, &item, sizeof(T));
58+
static inline size_t copy_from_mem(const void* src, T& item) {
59+
memcpy(&item, src, sizeof(T));
6060
return sizeof(T);
6161
}
6262

6363
template<typename T>
64-
static inline size_t copy_from_mem(const void* src, T& item) {
65-
memcpy(&item, src, sizeof(T));
64+
static inline size_t copy_to_mem(T item, void* dst) {
65+
memcpy(dst, &item, sizeof(T));
6666
return sizeof(T);
6767
}
6868

0 commit comments

Comments
 (0)