From 73a8127891d0668f38672ae35de29c8f88c8fbdf Mon Sep 17 00:00:00 2001 From: Milot Mirdita Date: Fri, 15 Nov 2024 17:29:44 +0900 Subject: [PATCH] Try building precompiled binaries for GPU --- CMakeLists.txt | 5 +++++ azure-pipelines.yml | 45 ++++++++++++++++++++++++++++++++++++++++++ cmake/FindAtomic.cmake | 16 +++++++++++++-- src/CMakeLists.txt | 20 ++++++++++++++----- 4 files changed, 79 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c913115..879815c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,11 @@ set(USE_SYSTEM_ZSTD 0 CACHE BOOL "Use zstd provided by system instead of bundled set(ENABLE_CUDA 0 CACHE BOOL "Enable CUDA") +set(PREFER_STATIC 0 CACHE BOOL "Prefer finding .a libs") +if (PREFER_STATIC) + set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" ".so") +endif() + if (HAVE_SANITIZER) include(FindUBSan) include(FindASan) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 798b538c..6438d25c 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -137,6 +137,38 @@ jobs: targetPath: $(Build.SourcesDirectory)/build/src/mmseqs artifactName: mmseqs-linux-$(SIMD) + - job: build_ubuntu_gpu + displayName: Ubuntu MMseqs2 + pool: + vmImage: 'Ubuntu-20.04' + timeoutInMinutes: 120 + steps: + - checkout: self + submodules: false + - script: | + 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 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 + sudo ./cmake-3.31.0-linux-x86_64.sh --skip-license --prefix=/usr/local + displayName: Install newer G++ + - script: | + mkdir build && cd build + export CC=gcc-10 ; export CXX=g++-10; export CUDAHOSTCXX=$CXX; export CUDACXX=/usr/local/cuda/bin/nvcc; + /usr/local/bin/cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DHAVE_TESTS=1 -DENABLE_WERROR=1 -DHAVE_AVX2=1 \ + -PREFER_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) + displayName: Build MMseqs2 + - task: PublishPipelineArtifact@0 + inputs: + targetPath: $(Build.SourcesDirectory)/build/src/mmseqs + artifactName: mmseqs-linux-gpu + - job: build_ubuntu_cross displayName: Ubuntu Cross-Compile pool: @@ -252,6 +284,7 @@ jobs: - build_ubuntu_userguide - build_macos - build_ubuntu + - build_ubuntu_gpu - build_ubuntu_cross - build_windows steps: @@ -317,6 +350,18 @@ jobs: archiveFile: $(Build.SourcesDirectory)/mmseqs-linux-sse2.tar.gz includeRootFolder: true archiveType: tar + - task: DownloadPipelineArtifact@1 + inputs: + artifactName: mmseqs-linux-gpu + 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-cuda12-libc.tar.gz + includeRootFolder: true + archiveType: tar - task: DownloadPipelineArtifact@1 inputs: artifactName: mmseqs-linux-POWER9 diff --git a/cmake/FindAtomic.cmake b/cmake/FindAtomic.cmake index e0c207fe..088f32ee 100644 --- a/cmake/FindAtomic.cmake +++ b/cmake/FindAtomic.cmake @@ -18,7 +18,17 @@ if (ATOMIC_NATIVE) set(ATOMIC_LIBRARY) else () set(_OLD_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}") - set(CMAKE_REQUIRED_LIBRARIES "-latomic") + find_library(ATOMIC_LIBRARY_PATH + NAMES atomic + ) + + if (ATOMIC_LIBRARY_PATH) + set(ATOMIC_LIBRARY ${ATOMIC_LIBRARY_PATH}) + else () + set(ATOMIC_LIBRARY "-latomic") + endif () + + set(CMAKE_REQUIRED_LIBRARIES "${ATOMIC_LIBRARY}") check_cxx_source_compiles(" int main() { volatile unsigned __int128 i = 4; @@ -32,7 +42,9 @@ else () unset(_OLD_CMAKE_REQUIRED_LIBRARIES) if (ATOMIC_WITH_LIB) set(ATOMIC_FOUND 1) - set(ATOMIC_LIBRARY -latomic) + else () + set(ATOMIC_FOUND 0) + unset(ATOMIC_LIBRARY) endif () include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Atomic DEFAULT_MSG ATOMIC_LIBRARY) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a9e4b6e6..25af8856 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -215,12 +215,22 @@ find_package(OpenMP QUIET) if (OPENMP_FOUND) message("-- Found OpenMP") target_compile_definitions(mmseqs-framework PUBLIC -DOPENMP=1) - # For GCC we dont want to do this since it breaks macOS static builds - # It will link libgomp.a internally (through -fopenmp I guess) - # and also link libgomp.dylib thus breaking static builds - if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + # Try to get "nearly" static builds working with everything except libc static + if (PREFER_STATIC) + set(FILTERED_LIBRARIES "") + foreach(LIB ${OpenMP_CXX_LIBRARIES}) + if (NOT LIB MATCHES "pthread") + list(APPEND FILTERED_LIBRARIES ${LIB}) + endif () + endforeach() + set(OpenMP_CXX_LIBRARIES ${FILTERED_LIBRARIES}) + endif () + if (NOT APPLE) target_link_libraries(mmseqs-framework ${OpenMP_CXX_LIBRARIES}) - endif() + endif () + 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})