Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import the UMASH hashing library #7616

Merged
merged 18 commits into from
Jan 24, 2025
17 changes: 17 additions & 0 deletions .github/workflows/windows-build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,23 @@ jobs:
name: PostgreSQL ${{ matrix.pg }} log ${{ matrix.os }} ${{ matrix.build_type }} Build
path: ${{ env.PGDATA }}\log\postmaster.log

- name: Upload CMake Logs
if: always()
uses: actions/upload-artifact@v4
with:
name: CMake Logs ${{ matrix.pg }} ${{ matrix.os }} ${{ matrix.build_type }}
path: |
build_win/CMakeCache.txt
build_win/CMakeFiles/CMakeConfigureLog.yaml
build_win/CMakeFiles/CMakeError.log
build_win/CMakeFiles/CMakeOutput.log
build_win/compile_commands.json
build_wsl/CMakeCache.txt
build_wsl/CMakeFiles/CMakeConfigureLog.yaml
build_wsl/CMakeFiles/CMakeError.log
build_wsl/CMakeFiles/CMakeOutput.log
build_wsl/compile_commands.json

- name: Upload test results to the database
if: always()
shell: wsl-bash {0}
Expand Down
2 changes: 1 addition & 1 deletion scripts/clang_format_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ SCRIPT_DIR=$(cd "$(dirname $0)" || exit; pwd)
BASE_DIR=$(dirname $SCRIPT_DIR)

find ${BASE_DIR} \( -path "${BASE_DIR}/src/*" -or -path "${BASE_DIR}/test/*" -or -path "${BASE_DIR}/tsl/*" \) \
-and -not \( -path "*/.*" -or -path "*CMake*" \) \
-and -not \( -path "*/.*" -or -path "*CMake*" -or -path "${BASE_DIR}/tsl/src/import/*" \) \
-and \( -name '*.c' -or -name '*.h' \) -print0 | xargs -0 ${SCRIPT_DIR}/clang_format_wrapper.sh -style=file -i
58 changes: 58 additions & 0 deletions tsl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,63 @@ if(COMPRESSION_FUZZING)
add_compile_definitions(TS_COMPRESSION_FUZZING=1)
endif()

# We use the UMASH library for hashing in vectorized grouping. If it was not
# explicitly disabled already, detect if we can compile it on this platform.
if((NOT DEFINED USE_UMASH) OR USE_UMASH)
# Check whether we can enable the pclmul instruction required for the UMASH
# hashing on amd64. Shouldn't be done if the user has manually specified the
# target architecture, no idea how to detect this, but at least we shouldn't
# do this when cross-compiling.
if(NOT CMAKE_CROSSCOMPILING)
check_c_compiler_flag(-mpclmul CC_PCLMUL)
if(CC_PCLMUL)
add_compile_options(-mpclmul)
# The "C source compiles" check below doesn't use the global compilation
# flags, so we have to modify its flags separately.
set(CMAKE_REQUIRED_FLAGS -mpclmul)
endif()
endif()

set(CMAKE_REQUIRED_FLAGS
"${CMAKE_REQUIRED_FLAGS} -Werror=implicit-function-declaration")
check_c_source_compiles(
"
#if defined(__PCLMUL__)
#include <stdint.h>
#include <immintrin.h>
/*
* For some reason, this doesn't compile on our i386 CI, but I also can't detect
* it using the standard condition of defined(__x86_64__) && !defined(__ILP32__),
* as described at https://wiki.debian.org/X32Port .
*/
static void test() { (void) _mm_cvtsi64_si128((uint64_t) 0); }
#elif defined(__ARM_FEATURE_CRYPTO)
/* OK */
#else
#error Unsupported platform for UMASH
#endif
void main(void) {};
"
UMASH_SUPPORTED)
unset(CMAKE_REQUIRED_FLAGS)
else()
set(UMASH_SUPPORTED OFF)
endif()

option(USE_UMASH
"Use the UMASH hash for string and multi-column vectorized grouping"
${UMASH_SUPPORTED})

if(USE_UMASH)
if(NOT UMASH_SUPPORTED)
message(
FATAL_ERROR
"UMASH use is requested, but it is not supported in the current configuration"
)
endif()
add_compile_definitions(TS_USE_UMASH)
endif()

# Add the subdirectories
add_subdirectory(test)
add_subdirectory(src)
17 changes: 15 additions & 2 deletions tsl/src/import/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
set(SOURCES "")
target_sources(${PROJECT_NAME} PRIVATE ${SOURCES})
set(SOURCES)

if(USE_UMASH)
list(APPEND SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/umash.c)
endif()

if(SOURCES)
# Disable clang-tidy for imported code
add_library(target_no_static_code_analysis OBJECT ${SOURCES})
set_target_properties(target_no_static_code_analysis PROPERTIES C_CLANG_TIDY
"")

target_link_libraries(${TSL_LIBRARY_NAME}
$<TARGET_OBJECTS:target_no_static_code_analysis>)
endif()
Loading
Loading