Skip to content

Commit

Permalink
Squashed 'lib/mmseqs/' changes from 17cd5c09..35537c46
Browse files Browse the repository at this point in the history
35537c46 Make sure cuda binaries do not depend on dynamic libatomic
7e2732cd Readd tweaked hack to remove GLIBC_PRIVATE symbols
8bf7c5e6 Debug glibc check for GPU builds
6e46b5e2 Terminate unpadded sequences with \n\0
e6f0328b Fully revert cmake version string change
64f03d46 Next try with build system cleanup
e840263e Forgot wget
5140ceb0 Fix build system breakage
9927445c Sync build system changes with foldseek changes relicensed as MIT for MMseqs2
b0e91c12 Fix soedinglab/MMseqs2#912

git-subtree-dir: lib/mmseqs
git-subtree-split: 35537c46a00c33db96409ce6aea42a42224f7917
  • Loading branch information
milot-mirdita committed Jan 7, 2025
1 parent c621f8b commit 2fa7419
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 116 deletions.
24 changes: 16 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,24 @@ set(HAVE_ARM8 0 CACHE BOOL "Have ARMv8 CPU")
set(HAVE_S390X 0 CACHE BOOL "Have s390x architecture")
set(NATIVE_ARCH 1 CACHE BOOL "Assume native architecture for SIMD. Use one of the HAVE_* options or set CMAKE_CXX_FLAGS to the appropriate flags if you disable this.")
set(USE_SYSTEM_ZSTD 0 CACHE BOOL "Use zstd provided by system instead of bundled version")

set(ENABLE_CUDA 0 CACHE BOOL "Enable CUDA")
set(FORCE_STATIC_DEPS 0 CACHE BOOL "Force static linking of deps")

if(FORCE_STATIC_DEPS)
if(ENABLE_CUDA)
set(CMAKE_FIND_LIBRARY_SUFFIXES .a .so CACHE INTERNAL "" FORCE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
else()
set(CMAKE_FIND_LIBRARY_SUFFIXES .a CACHE INTERNAL "" FORCE)
set(CMAKE_LINK_SEARCH_START_STATIC ON CACHE INTERNAL "" FORCE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static -static-libgcc -static-libstdc++")
endif()
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "" FORCE)
endif()

set(PREFER_STATIC 0 CACHE BOOL "Prefer finding .a libs")
if (PREFER_STATIC)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" ".so")
if(NOT XCODE AND NOT MSVC AND NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()

if (HAVE_SANITIZER)
Expand All @@ -33,10 +45,6 @@ if (HAVE_SANITIZER)
include(FindTSan)
endif ()

if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif ()

# find compiler
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message("-- Compiler is clang(++)")
Expand Down
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN dpkg --add-architecture $TARGETARCH \
if [ "$GPU" = "1" ]; then \
wget https://developer.download.nvidia.com/compute/cuda/repos/debian12/x86_64/cuda-keyring_1.1-1_all.deb; \
dpkg -i cuda-keyring_1.1-1_all.deb; \
apt-get update && apt-get install -y cuda-nvcc-12-6 ninja-build; \
apt-get update && apt-get install -y cuda-nvcc-12-6 cuda-cudart-dev-12-6 ninja-build; \
fi; \
rm -rf /var/lib/apt/lists/*;

Expand All @@ -32,10 +32,10 @@ RUN if [ "$TARGETARCH" = "arm64" ]; then \
export CUDACXX=/usr/local/cuda/bin/nvcc; \
mkdir -p build_avx2/src; \
cd /opt/build/build_avx2; \
cmake -GNinja -DHAVE_AVX2=1 -DHAVE_MPI=0 -DHAVE_TESTS=0 \
-DPREFER_STATIC=1 -DBUILD_SHARED_LIBS=OFF \
-DCMAKE_EXE_LINKER_FLAGS="-static-libgcc -static-libstdc++" \
LIBGOMP=/usr/lib/gcc/x86_64-linux-gnu/12/; \
cmake -GNinja -DHAVE_AVX2=1 -DHAVE_MPI=0 -DHAVE_TESTS=0 -DFORCE_STATIC_DEPS=1 \
-DENABLE_CUDA=1 -DCMAKE_CUDA_ARCHITECTURES="75-real;80-real;86-real;89-real;90" \
-DOpenMP_C_FLAGS="-fopenmp -I${LIBGOMP}" -DOpenMP_C_LIB_NAMES=gomp -DOpenMP_CXX_FLAGS="-fopenmp -I${LIBGOMP}" -DOpenMP_CXX_LIB_NAMES=gomp -DOpenMP_gomp_LIBRARY=${LIBGOMP}/libgomp.a \
-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=. ..; \
cmake --build . -j$(nproc --all); \
mv src/${APP} /opt/build/${APP}_avx2; \
Expand Down
104 changes: 51 additions & 53 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,22 @@ jobs:
SIMD: 'AVX2'
STATIC: 1
MPI: 0
BUILD_TYPE: RelWithDebInfo
BUILD_TYPE: Release
sse41:
SIMD: 'SSE4_1'
STATIC: 1
MPI: 0
BUILD_TYPE: RelWithDebInfo
BUILD_TYPE: Release
sse2:
SIMD: 'SSE2'
STATIC: 1
MPI: 0
BUILD_TYPE: RelWithDebInfo
BUILD_TYPE: Release
avx2_mpi:
SIMD: 'AVX2'
STATIC: 0
MPI: 1
BUILD_TYPE: RelWithDebInfo
BUILD_TYPE: Release
asan:
SIMD: 'AVX2'
STATIC: 0
Expand All @@ -94,10 +94,9 @@ jobs:
- checkout: self
submodules: true
- script: |
#sudo add-apt-repository ppa:ubuntu-toolchain-r/test
#sudo apt-get update
sudo apt-get install -y g++-10
condition: eq(variables['BUILD_TYPE'], 'ASanOpt')
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install -y gcc-11 g++-11 libgcc-11-dev build-essential
displayName: Install newer G++
- script: |
sudo apt-get update
Expand All @@ -106,28 +105,21 @@ jobs:
condition: eq(variables['MPI'], 1)
- script: |
mkdir build && cd build
if [ "${BUILD_TYPE}" = "ASanOpt" ]; then
export CC=gcc-10 ; export CXX=g++-10
fi
export CC=gcc-11 ; export CXX=g++-11
if [ "${STATIC}" -eq "1" ]; then
cmake -DHAVE_SANITIZER=1 -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DHAVE_TESTS=1 \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_EXE_LINKER_FLAGS="-static -static-libgcc \
-static-libstdc++" -DCMAKE_FIND_LIBRARY_SUFFIXES=".a" \
-DENABLE_WERROR=1 -DHAVE_${SIMD}=1 -DHAVE_MPI=${MPI} ..
LIBGOMP=/usr/lib/gcc/x86_64-linux-gnu/11
cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DFORCE_STATIC_DEPS=1 -DHAVE_TESTS=1 \
-DOpenMP_C_FLAGS="-fopenmp -I${LIBGOMP}" -DOpenMP_C_LIB_NAMES=gomp -DOpenMP_CXX_FLAGS="-fopenmp -I${LIBGOMP}" -DOpenMP_CXX_LIB_NAMES=gomp -DOpenMP_gomp_LIBRARY=${LIBGOMP}/libgomp.a \
-DENABLE_WERROR=1 -DHAVE_${SIMD}=1 -DHAVE_MPI=${MPI} ..
else
cmake -DHAVE_SANITIZER=1 -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DHAVE_TESTS=1 \
-DENABLE_WERROR=1 -DHAVE_${SIMD}=1 -DHAVE_MPI=${MPI} ..
cmake -DHAVE_SANITIZER=1 -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DHAVE_TESTS=1 \
-DENABLE_WERROR=1 -DHAVE_${SIMD}=1 -DHAVE_MPI=${MPI} ..
fi
make -j $(nproc --all)
make -j $(nproc --all) VERBOSE=1
displayName: Build MMseqs2
- script: |
export TTY=0
if [ "${BUILD_TYPE}" = "ASan" ]; then
echo "leak:libgomp1" > ${BUILD_SOURCESDIRECTORY}/ASan.supp
export ASAN_OPTIONS=suppressions=${BUILD_SOURCESDIRECTORY}/ASan.supp
fi
${BUILD_SOURCESDIRECTORY}/util/regression/run_regression.sh ${BUILD_SOURCESDIRECTORY}/build/src/mmseqs ${BUILD_SOURCESDIRECTORY}/regression
displayName: Run Regression Suite
condition: eq(variables['regression'], 1)
Expand All @@ -149,7 +141,7 @@ jobs:
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt-get update
sudo apt-get install -y gcc-10 g++-10 cuda-nvcc-12-6 build-essential libgcc-10-dev ninja-build
sudo apt-get install -y gcc-10 g++-10 cuda-nvcc-12-6 cuda-cudart-dev-12-6 build-essential libgcc-10-dev ninja-build
sudo apt-get purge -y cmake
wget https://github.com/Kitware/CMake/releases/download/v3.31.0/cmake-3.31.0-linux-x86_64.sh
chmod +x cmake-3.31.0-linux-x86_64.sh
Expand All @@ -158,18 +150,25 @@ jobs:
- script: |
mkdir build && cd build
export CC=gcc-10 ; export CXX=g++-10; export CUDAHOSTCXX=$CXX; export CUDACXX=/usr/local/cuda/bin/nvcc;
LIBGCC=/usr/lib/gcc/x86_64-linux-gnu/10;
/usr/local/bin/cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DHAVE_TESTS=1 -DENABLE_WERROR=1 -DHAVE_AVX2=1 \
-DPREFER_STATIC=1 -DCMAKE_LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/10 -DBUILD_SHARED_LIBS=OFF \
-DCMAKE_EXE_LINKER_FLAGS="-static-libgcc -static-libstdc++" \
-DENABLE_CUDA=1 -DCMAKE_CUDA_ARCHITECTURES="75-real;80-real;86-real;89-real;90" ..
cmake --build . -j$(nproc --all)
-DOpenMP_C_FLAGS="-fopenmp -I${LIBGCC}" -DOpenMP_C_LIB_NAMES=gomp -DOpenMP_CXX_FLAGS="-fopenmp -I${LIBGCC}" -DOpenMP_CXX_LIB_NAMES=gomp -DOpenMP_gomp_LIBRARY=${LIBGCC}/libgomp.a \
-DATOMIC_LIB_OVERRIDE=${LIBGCC}/libatomic.a \
-DFORCE_STATIC_DEPS=1 -DENABLE_CUDA=1 -DCMAKE_CUDA_ARCHITECTURES="75-real;80-real;86-real;89-real;90" ..
cmake --build . -j$(nproc --all) -v
# fail if GLIBC_PRIVATE or too new GLIBC is present
if readelf -Ws mmseqs | grep -q GLIBC_PRIVATE; then
if readelf -Ws src/mmseqs | grep -q GLIBC_PRIVATE; then
echo "Error: binary contains private glibc symbols"
exit 1
fi
LIBC_V=$(readelf -V mmseqs | awk '$3 ~ /^GLIBC_/ { print $3 }' | sort -V | tail -n1)
LIBC_V=$(readelf -V src/mmseqs | awk '$3 ~ /^GLIBC_/ { print $3 }' | sort -V | tail -n1)
if [[ "$LIBC_V" > "GLIBC_2.29" ]]; then
exit 1
echo "Error: glibc too new"
exit 1
fi
if readelf -d src/mmseqs | grep -q "libatomic.so"; then
echo "Error: libatomic.so is present as a dependency"
exit 1
fi
displayName: Build MMseqs2
- task: PublishPipelineArtifact@0
Expand All @@ -184,10 +183,10 @@ jobs:
timeoutInMinutes: 120
strategy:
matrix:
power8:
SIMD: POWER8
ARCH: ppc64el
CPREF: powerpc64le
# power8:
# SIMD: POWER8
# ARCH: ppc64el
# CPREF: powerpc64le
power9:
SIMD: POWER9
ARCH: ppc64el
Expand Down Expand Up @@ -215,11 +214,10 @@ jobs:
displayName: Install Toolchain
- script: |
mkdir build && cd build
LIBGOMP=/usr/lib/gcc-cross/${CPREF}-linux-gnu/9;
CC=${CPREF}-linux-gnu-gcc CXX=${CPREF}-linux-gnu-g++ \
cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DHAVE_TESTS=1 \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_EXE_LINKER_FLAGS="-static -static-libgcc \
-static-libstdc++" -DCMAKE_FIND_LIBRARY_SUFFIXES=".a" \
cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DHAVE_TESTS=1 -DFORCE_STATIC_DEPS=1 \
-DOpenMP_C_FLAGS="-fopenmp -I${LIBGOMP}" -DOpenMP_C_LIB_NAMES=gomp -DOpenMP_CXX_FLAGS="-fopenmp -I${LIBGOMP}" -DOpenMP_CXX_LIB_NAMES=gomp -DOpenMP_gomp_LIBRARY=${LIBGOMP}/libgomp.a \
-DENABLE_WERROR=1 -DHAVE_${SIMD}=1 ..
make -j $(nproc --all)
displayName: Build MMseqs2
Expand Down Expand Up @@ -382,18 +380,18 @@ jobs:
archiveFile: $(Build.SourcesDirectory)/mmseqs-linux-ppc64le-power9.tar.gz
includeRootFolder: true
archiveType: tar
- task: DownloadPipelineArtifact@1
inputs:
artifactName: mmseqs-linux-POWER8
targetPath: $(Build.SourcesDirectory)/mmseqs/bin
- script:
chmod +x "${BUILD_SOURCESDIRECTORY}/mmseqs/bin/mmseqs"
- task: ArchiveFiles@2
inputs:
rootFolderOrFile: $(Build.SourcesDirectory)/mmseqs
archiveFile: $(Build.SourcesDirectory)/mmseqs-linux-ppc64le-power8.tar.gz
includeRootFolder: true
archiveType: tar
# - task: DownloadPipelineArtifact@1
# inputs:
# artifactName: mmseqs-linux-POWER8
# targetPath: $(Build.SourcesDirectory)/mmseqs/bin
# - script:
# chmod +x "${BUILD_SOURCESDIRECTORY}/mmseqs/bin/mmseqs"
# - task: ArchiveFiles@2
# inputs:
# rootFolderOrFile: $(Build.SourcesDirectory)/mmseqs
# archiveFile: $(Build.SourcesDirectory)/mmseqs-linux-ppc64le-power8.tar.gz
# includeRootFolder: true
# archiveType: tar
- task: DownloadPipelineArtifact@1
inputs:
artifactName: mmseqs-linux-ARM8
Expand Down Expand Up @@ -431,6 +429,8 @@ jobs:
ssh-keygen -f ~/.ssh/id_rsa -y > ~/.ssh/id_rsa.pub
cd "${BUILD_SOURCESDIRECTORY}"
cp mmseqs/userguide.pdf userguide.pdf
# disabled: mmseqs-linux-ppc64le-power8.tar.gz
# -F file[][email protected] -F signature[][email protected]
ssh-keygen -Y sign -f ~/.ssh/id_rsa -n file \
userguide.pdf \
mmseqs-osx-universal.tar.gz \
Expand All @@ -439,7 +439,6 @@ jobs:
mmseqs-linux-avx2.tar.gz \
mmseqs-linux-gpu.tar.gz \
mmseqs-linux-arm64.tar.gz \
mmseqs-linux-ppc64le-power8.tar.gz \
mmseqs-linux-ppc64le-power9.tar.gz \
mmseqs-win64.zip
curl --retry 5 --retry-all-errors -X POST \
Expand All @@ -450,7 +449,6 @@ jobs:
-F file[][email protected] -F signature[][email protected] \
-F file[][email protected] -F signature[][email protected] \
-F file[][email protected] -F signature[][email protected] \
-F file[][email protected] -F signature[][email protected] \
-F file[][email protected] -F signature[][email protected] \
-F file[][email protected] -F signature[][email protected] \
-F identifier="mmseqs" -F directory="${BUILD_SOURCEVERSION}" \
Expand Down
45 changes: 30 additions & 15 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set(HAVE_GPROF 0 CACHE BOOL "Have GPROF Profiler")
set(ENABLE_WERROR 0 CACHE BOOL "Enable Warnings as Errors")
#set(DISABLE_LTO 0 CACHE BOOL "Disable link-time optimization in non-debug builds")
set(REQUIRE_OPENMP 1 CACHE BOOL "Require availability of OpenMP")
set(ATOMIC_LIB_OVERRIDE "" CACHE PATH "Override path to libatomic")

include(AppendTargetProperty)

Expand Down Expand Up @@ -117,13 +118,21 @@ if (HAVE_POSIX_MADVISE)
endif ()

if (NOT DISABLE_IPS4O)
find_package(Atomic)
if (ATOMIC_FOUND)
target_link_libraries(mmseqs-framework ${ATOMIC_LIBRARIES})
if (ATOMIC_LIB_OVERRIDE)
add_library(LibAtomic STATIC IMPORTED)
set_target_properties(LibAtomic PROPERTIES IMPORTED_LOCATION ${ATOMIC_LIB_OVERRIDE})
target_link_libraries(mmseqs-framework LibAtomic)
target_compile_definitions(mmseqs-framework PUBLIC -DENABLE_IPS4O=1)
message("-- IPS4O sorting works")
else ()
message("-- OMPTL sorting fallback")
message("-- IPS4O sorting forced with ${ATOMIC_LIB_OVERRIDE}")
else()
find_package(Atomic)
if (ATOMIC_FOUND)
target_link_libraries(mmseqs-framework ${ATOMIC_LIBRARIES})
target_compile_definitions(mmseqs-framework PUBLIC -DENABLE_IPS4O=1)
message("-- IPS4O sorting works")
else ()
message("-- OMPTL sorting fallback")
endif ()
endif ()
else ()
message("-- OMPTL sorting fallback")
Expand Down Expand Up @@ -215,20 +224,17 @@ find_package(OpenMP QUIET)
if (OPENMP_FOUND)
message("-- Found OpenMP")
target_compile_definitions(mmseqs-framework PUBLIC -DOPENMP=1)
# Try to get "nearly" static builds working with everything except libc static
if (PREFER_STATIC)
# hack: remove pthread from openmp deps, it gets linked correctly by cuda later
if (FORCE_STATIC_DEPS AND ENABLE_CUDA)
set(FILTERED_LIBRARIES "")
foreach(LIB ${OpenMP_CXX_LIBRARIES})
if (NOT LIB MATCHES "pthread" AND NOT LIB MATCHES "gcc_s")
foreach (LIB ${OpenMP_CXX_LIBRARIES})
if (NOT LIB MATCHES "pthread")
list(APPEND FILTERED_LIBRARIES ${LIB})
endif ()
endforeach()
endforeach ()
set(OpenMP_CXX_LIBRARIES ${FILTERED_LIBRARIES})
endif ()
target_link_libraries(mmseqs-framework ${OpenMP_CXX_LIBRARIES})
if (PREFER_STATIC)
target_link_libraries(mmseqs-framework dl)
endif ()
target_include_directories(mmseqs-framework PUBLIC ${OpenMP_CXX_INCLUDE_DIRS})
append_target_property(mmseqs-framework COMPILE_FLAGS ${OpenMP_CXX_FLAGS})
append_target_property(mmseqs-framework LINK_FLAGS ${OpenMP_CXX_FLAGS})
Expand All @@ -251,9 +257,18 @@ if (ENABLE_CUDA)
find_package(CUDAToolkit REQUIRED)
target_compile_definitions(mmseqs-framework PUBLIC -DHAVE_CUDA=1)
target_link_libraries(mmseqs-framework marv)
if (PREFER_STATIC)
if (FORCE_STATIC_DEPS)
# link to rt explicitly so it doesn't get statically compiled and adds GLIBC_PRIVATE symbols
target_link_libraries(mmseqs-framework rt)
# remove librt.a which introduces GLIBC_PRIVATE symbols
get_property(linked_libraries TARGET CUDA::cudart_static_deps PROPERTY INTERFACE_LINK_LIBRARIES)
set(FILTERED_LIBRARIES "")
foreach (LIB ${linked_libraries})
if (NOT LIB MATCHES ".*librt\\.a$")
list(APPEND FILTERED_LIBRARIES ${LIB})
endif ()
endforeach ()
set_target_properties(CUDA::cudart_static_deps PROPERTIES INTERFACE_LINK_LIBRARIES "${FILTERED_LIBRARIES}")
endif ()
target_link_libraries(mmseqs-framework CUDA::cudart_static)
endif ()
Expand Down
Loading

0 comments on commit 2fa7419

Please sign in to comment.