Skip to content

Commit

Permalink
Merge pull request #15 from danielealbano/refactor_hashtable_use_line…
Browse files Browse the repository at this point in the history
…ar_probing

Refactor hashtable use linear probing
  • Loading branch information
danielealbano committed Jun 8, 2020
2 parents de96523 + a891287 commit fa13abd
Show file tree
Hide file tree
Showing 58 changed files with 2,243 additions and 1,149 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.idea
cmake-build-*/*

/src/cmake_config.c
51 changes: 35 additions & 16 deletions 3rdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
# Build t1ha2
add_library(
t1ha2
t1ha/src/t1ha2.c
)
file(GLOB SRC_FILES_T1HA "t1ha/src/*.c")
list(FILTER SRC_FILES_T1HA EXCLUDE REGEX ".*t1ha0_ia32aes_[a-z0-9]+\\.c$")

if(ARCH_IS_X86_64)
message(STATUS "Enabling accelerated t1ha0 -- aes-ni + avx2")
list(APPEND SRC_FILES_T1HA "${CMAKE_CURRENT_SOURCE_DIR}/t1ha/src/t1ha0_ia32aes_avx2.c")
set_source_files_properties(
"t1ha/src/t1ha0_ia32aes_avx2.c"
PROPERTIES COMPILE_FLAGS
"-mno-avx256-split-unaligned-load -mavx2 -mbmi -maes")

target_include_directories(
t1ha2
PUBLIC
t1ha/
t1ha/src
)
message(STATUS "Enabling accelerated t1ha0 -- aes-ni + avx")
list(APPEND SRC_FILES_T1HA "${CMAKE_CURRENT_SOURCE_DIR}/t1ha/src/t1ha0_ia32aes_avx.c")
set_source_files_properties(
"t1ha/src/t1ha0_ia32aes_avx.c"
PROPERTIES COMPILE_FLAGS
"-mno-avx256-split-unaligned-load -mno-avx2 -mavx -mbmi -maes")

target_compile_options(
t1ha2
PUBLIC
-ffunction-sections -std=c99 -O3 -DNDEBUG -D_DEFAULT_SOURCE -fno-stack-protector -mtune=native -fvisibility=hidden -Dt1ha_EXPORTS
)
message(STATUS "Enabling accelerated t1ha0 -- aes-ni w/o avx w/o avx2")
list(APPEND SRC_FILES_T1HA "${CMAKE_CURRENT_SOURCE_DIR}/t1ha/src/t1ha0_ia32aes_noavx.c")
set_source_files_properties(
"t1ha/src/t1ha0_ia32aes_noavx.c"
PROPERTIES COMPILE_FLAGS
"-mno-avx256-split-unaligned-load -mno-avx2 -mno-avx -maes")
elseif(ARCH_IS_AARCH64)
# TODO
else()
message(FATAL_ERROR "Unsupported architecture")
endif()

add_library(
t1ha
${SRC_FILES_T1HA}
)
target_compile_definitions(t1ha PUBLIC -DT1HA0_RUNTIME_SELECT=1 -DT1HA_USE_INDIRECT_FUNCTIONS=1)
target_compile_options(t1ha PUBLIC -ffunction-sections -std=c99 -O3 -mtune=native -DNDEBUG -D_DEFAULT_SOURCE -fno-stack-protector -fvisibility=hidden -Dt1ha_EXPORTS)
target_include_directories(t1ha PUBLIC t1ha/ t1ha/src)
21 changes: 3 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,16 @@
cmake_minimum_required(VERSION 3.13)
project(cachegrand LANGUAGES C CXX)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 11)

if (NOT CMAKE_BUILD_TYPE MATCHES Debug)
add_definitions(-DNDEBUG)
else()
add_definitions(-DDEBUG)
endif()

message("-- Check if ccache is available")
find_program(CCACHE_FOUND_PATH ccache)
if(CCACHE_FOUND_PATH)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_FOUND_PATH})
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE_FOUND_PATH})
message(" Found, cache dir set to ($ENV{CCACHE_DIR})")
endif(CCACHE_FOUND_PATH)
include(tools/cmake/config.cmake)

add_subdirectory(3rdparty)
add_subdirectory(src)

if (BUILD_TESTS)
if (CACHEGRAND_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()

if (BUILD_BENCHES)
if (CACHEGRAND_BUILD_BENCHES)
add_subdirectory(benches)
endif()
6 changes: 3 additions & 3 deletions benches/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ ENDIF(WIN32)

# Build benches
file(GLOB SRC_CACHEGRAND_BENCHES "bench-*.cpp")
add_executable(cachegrand-benches main.cpp ${SRC_CACHEGRAND_BENCHES})
add_dependencies(cachegrand-benches cachegrand-internal)
add_executable(cachegrand-benches main.cpp bench-support.c ${SRC_CACHEGRAND_BENCHES})
add_dependencies(cachegrand-benches cachegrand-internal __internal_refresh_cmake_config_c)
set_target_properties(cachegrand-benches PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(cachegrand-benches cachegrand-internal t1ha2 pthread benchmark::benchmark)
target_link_libraries(cachegrand-benches cachegrand-internal t1ha pthread benchmark::benchmark)
target_include_directories(cachegrand-benches PUBLIC ".")
target_include_directories(cachegrand-benches PUBLIC "../src")
target_include_directories(cachegrand-benches PUBLIC "${CMAKE_BINARY_DIR}/benchmark-install/include")
48 changes: 38 additions & 10 deletions benches/bench-hashtable-op-get.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <string.h>
#include <benchmark/benchmark.h>

#include "xalloc.h"
#include "hashtable/hashtable.h"
#include "hashtable/hashtable_config.h"
#include "hashtable/hashtable_support_index.h"
Expand All @@ -11,7 +12,8 @@
#include "../tests/fixtures-hashtable.h"

#define HASHTABLE_OP_GET_BENCHS_ARGS \
Arg(1522)->Arg(135798)->Arg(1031398)
Arg(1522U)->Arg(135798U)->Arg(1031398U)->Arg(17622551U)->Arg(89214403U)->Arg(133821599U) \
->Iterations(10000000);

static void hashtable_op_get_notfound(benchmark::State& state) {
hashtable_config_t* hashtable_config;
Expand Down Expand Up @@ -39,26 +41,39 @@ static void hashtable_op_get_found_key_inline(benchmark::State& state) {
hashtable_config_t* hashtable_config;
hashtable_t* hashtable;
hashtable_value_data_t value;
bool result;
char error_message[150] = {0};

hashtable_config = hashtable_config_init();
hashtable_config->initial_size = state.range(0);
hashtable_config->can_auto_resize = false;

hashtable = hashtable_init(hashtable_config);

HASHTABLE_BUCKET_HASH_KEY_VALUE_SET_KEY_INLINE(
test_index_1_buckets_count_53,
HASHTABLE_BUCKET_NEW_KEY_INLINE(
test_key_1_hash % hashtable->ht_current->buckets_count,
test_key_1_hash,
test_key_1,
test_key_1_len,
test_value_1)
test_value_1);

for (auto _ : state) {
hashtable_op_get(
benchmark::DoNotOptimize((result = hashtable_op_get(
hashtable,
test_key_1,
test_key_1_len,
&value);
&value)));

if (!result) {
sprintf(
error_message,
"Unable to get the key <%s> with index <%ld> for the thread <%d>",
test_key_1,
test_key_1_hash % hashtable->ht_current->buckets_size,
state.thread_index);
state.SkipWithError(error_message);
break;
}
}

hashtable_free(hashtable);
Expand All @@ -69,26 +84,39 @@ static void hashtable_op_get_found_key_external(benchmark::State& state) {
hashtable_config_t* hashtable_config;
hashtable_t* hashtable;
hashtable_value_data_t value;
bool result;
char error_message[150] = {0};

hashtable_config = hashtable_config_init();
hashtable_config->initial_size = state.range(0);
hashtable_config->can_auto_resize = false;

hashtable = hashtable_init(hashtable_config);

HASHTABLE_BUCKET_HASH_KEY_VALUE_SET_KEY_EXTERNAL(
test_index_1_buckets_count_53,
HASHTABLE_BUCKET_NEW_KEY_EXTERNAL(
test_key_1_hash % hashtable->ht_current->buckets_count,
test_key_1_hash,
test_key_1,
test_key_1_len,
test_value_1);

for (auto _ : state) {
hashtable_op_get(
benchmark::DoNotOptimize((result = hashtable_op_get(
hashtable,
test_key_1,
test_key_1_len,
&value);
&value)));

if (!result) {
sprintf(
error_message,
"Unable to get the key <%s> with index <%ld> for the thread <%d>",
test_key_1,
test_key_1_hash % hashtable->ht_current->buckets_size,
state.thread_index);
state.SkipWithError(error_message);
break;
}
}

hashtable_free(hashtable);
Expand Down
Loading

0 comments on commit fa13abd

Please sign in to comment.