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

wfmash now builds with clang #304

Merged
merged 21 commits into from
Dec 15, 2024
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
1b2d096
CMake:
pjotrp Dec 12, 2024
32a151c
Wflign CMake:
pjotrp Dec 12, 2024
fade229
CMake for WFA:
pjotrp Dec 12, 2024
4b81115
Fix Guix files for building static and dynamic targets
pjotrp Dec 12, 2024
56910f6
performance-tuning.md
pjotrp Dec 12, 2024
e5120b7
CMake: enable profiling with gprof and use LTO correctly for differen…
pjotrp Dec 13, 2024
2c78f3c
gprof: doc using the profiler
pjotrp Dec 13, 2024
197d2e3
guix.scm: remove unnecessary comment
pjotrp Dec 13, 2024
865139e
main.cpp: added comment that this is the entry point for wfmash - the…
pjotrp Dec 13, 2024
47e7346
CMake: building static and linked libs separately. Sanitized wflign C…
pjotrp Dec 13, 2024
b378d50
guix: enabled tests for static build.
pjotrp Dec 13, 2024
b7157c9
git ignore test output files
pjotrp Dec 14, 2024
e03e998
Add ctest output to test for regressions - note these tests are prett…
pjotrp Dec 14, 2024
cdf15f2
cmake: added tests that are also in github actions
pjotrp Dec 14, 2024
d32f814
Fix clang with OpenMP capture error, see also
pjotrp Dec 14, 2024
22ede3e
Guix can build now with both gcc and clang
pjotrp Dec 14, 2024
f8e493d
sequenceIds.hpp: Removed test function I introduced to fix clang issu…
pjotrp Dec 14, 2024
9ad15d3
guix: fixed static build and merged into main guix.scm
pjotrp Dec 15, 2024
92745ae
wflign: Added include <limits> because clang complained about missing…
pjotrp Dec 15, 2024
fee6cc0
guix: updated guix.scm as a module so now it can build for different …
pjotrp Dec 15, 2024
af58c5e
github actions: remove tests that are covered by ctest and added ctest
pjotrp Dec 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
guix: fixed static build and merged into main guix.scm
pjotrp committed Dec 15, 2024
commit 9ad15d3d8d56da2998a1781b3bd1625311266795
4 changes: 4 additions & 0 deletions doc/performance-tuning.md
Original file line number Diff line number Diff line change
@@ -142,6 +142,10 @@ nts()::{lambda()#3}> > >::_M_run()

According to the profiler `MurmurHash3_x64_128` gets hit often. I tried the optimization in this [patch](https://github.com/aappleby/smhasher/pull/87/files), but it did not appear to make any difference on Ryzen. Probably too narrow an impact.

Above gprof results are puzzling. In the next step I am going to use perf instead on top of clang.

=> https://www.brendangregg.com/perf.html

# Conclusion

With a bit of tweaking a 10-20% speed gain is easily possible on my Ryzen. Native compilation, openmp, lto and the static build appears to have the largest impact. PGO is, somewhat surprisingly, detrimental. Running outside a container is faster than running inside a container.
125 changes: 2 additions & 123 deletions guix-static.scm
Original file line number Diff line number Diff line change
@@ -1,124 +1,3 @@
;; To use this file to build a static version of wfmash using git HEAD:
;; To use this file to build a static version of wfmash using git HEAD.
;;
;; guix build -f guix.scm
;;
;; To get a development container using a recent guix (see `guix pull`)
;;
;; guix shell -C -D -f guix.scm
;;
;; and inside the container
;;
;; mkdir build
;; cd build
;; cmake -DBUILD_STATIC=1 ..
;; make
;;
;; For the tests you may need /usr/bin/env. Inside the container:
;;
;; mkdir -p /usr/bin ; ln -s $GUIX_ENVIRONMENT/bin/env /usr/bin/env
;;
;; by Pjotr Prins (c) 2023-2024

(use-modules
((guix licenses) #:prefix license:)
(guix build-system cmake)
(guix download)
(guix gexp)
(guix git-download)
(guix packages)
(guix utils)
(gnu packages algebra)
(gnu packages base)
(gnu packages bioinformatics)
(gnu packages build-tools)
(gnu packages compression)
(gnu packages gcc)
(gnu packages jemalloc)
(gnu packages llvm)
(gnu packages maths)
(gnu packages multiprecision)
(gnu packages pkg-config)
(gnu packages python)
(gnu packages version-control)
(srfi srfi-1)
(ice-9 popen)
(ice-9 rdelim))

;; Guix does not come with a static version of libdeflate
(define-public libdeflate-static
(package
(inherit libdeflate)
(name "libdeflate-static")
(version "1.19")
(arguments
(list #:configure-flags
#~(list "-DLIBDEFLATE_BUILD_STATIC_LIB=YES"
"-DLIBDEFLATE_BUILD_TESTS=YES")))))

;; A minimal static version of htslib that does not depend on curl and openssl. This
;; reduces the number of higher order dependencies in static linking.
(define-public htslib-static
(package
(inherit htslib)
(name "htslib-static")
(version "1.19")
(source (origin
(method url-fetch)
(uri (string-append
"https://github.com/samtools/htslib/releases/download/"
version "/htslib-" version ".tar.bz2"))
(sha256
(base32
"0dh79lwpspwwfbkmllrrhbk8nkvlfc5b5ib4d0xg5ld79w6c8lc7"))))
(arguments
(substitute-keyword-arguments (package-arguments htslib)
((#:configure-flags flags ''())
''())))
(inputs
(list bzip2 xz))))

(define %source-dir (dirname (current-filename)))

(define %git-commit
(read-string (open-pipe "git show HEAD | head -1 | cut -d ' ' -f 2" OPEN_READ)))

(define-public wfmash-git
(package
(name "wfmash-static-git")
(version (git-version "0.21" "HEAD" %git-commit))
(source (local-file %source-dir #:recursive? #t))
(build-system cmake-build-system)
(arguments
`(;; #:tests? #f
#:configure-flags
,#~(list
"-DBUILD_STATIC=ON"
"-DBUILD_OPTIMIZED=ON"
"-DCMAKE_BUILD_TYPE=Release"
"-DCMAKE_INSTALL_RPATH="))) ; force cmake static build and do not rewrite RPATH
(inputs
`(
("bzip2-static" ,bzip2 "static") ; libz2 part of htslib for static builds
("coreutils" ,coreutils) ; for echo and env in tests
("gcc" ,gcc-12)
("git" ,git)
("gmp" ,gmp)
("gsl-static" ,gsl "static")
("gsl" ,gsl)
("htslib-static" ,htslib-static)
("jemalloc" ,jemalloc)
("libdeflate-static" ,libdeflate-static)
("make" ,gnu-make)
("pkg-config" ,pkg-config)
("xz-static" ,xz "static") ; for static builds
("zlib-static" ,zlib "static")))
(synopsis "wfmash")
(description
"wfmash is an aligner for pangenomes that combines efficient homology
mapping with base-level alignment. It uses MashMap to find approximate
mappings between sequences, then applies WFA (Wave Front Alignment) to
obtain base-level alignments.")
(home-page "https://github.com/waveygang/wfmash")
(license license:expat)))

wfmash-git
;; See ./guix.scm in the git repo.
74 changes: 72 additions & 2 deletions guix.scm
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
;; To use this file to build a version of wfmash using git HEAD:
;;
;; rm -rf build/*
;; guix build -f guix.scm
;;
;; To get a development container using a recent guix (see `guix pull`)
@@ -11,15 +10,21 @@
;;
;; mkdir build
;; cd build
;; rm -rf ../build/*
;; cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_OPTIMIZED=1 ..
;; make -j 12 VERBOSE=1
;; ctest . --verbose
;;
;; alternative builds are
;;
;; cmake -DBUILD_STATIC=1 ..
;;
;; by Pjotr Prins & Andrea Guarracino (c) 2023-2024

(use-modules
((guix licenses) #:prefix license:)
(guix build-system cmake)
(guix download)
(guix gexp)
(guix git-download)
(guix packages)
@@ -66,6 +71,7 @@
("gmp" ,gmp)
("gsl" ,gsl)
("htslib" ,htslib)
("jemalloc" ,jemalloc)
("libdeflate" ,libdeflate)
("make" ,gnu-make)
("pkg-config" ,pkg-config)
@@ -104,6 +110,70 @@ obtain base-level alignments.")
)))
))

;; ==== The following is for static binary builds using gcc - used mostly for deployment ===

;; Guix does not come with a static version of libdeflate
(define-public libdeflate-static
(package
(inherit libdeflate)
(name "libdeflate-static")
(version "1.19")
(arguments
(list #:configure-flags
#~(list "-DLIBDEFLATE_BUILD_STATIC_LIB=YES"
"-DLIBDEFLATE_BUILD_TESTS=YES")))))

;; A minimal static version of htslib that does not depend on curl and openssl. This
;; reduces the number of higher order dependencies in static linking.
(define-public htslib-static
(package
(inherit htslib)
(name "htslib-static")
(version "1.19")
(source (origin
(method url-fetch)
(uri (string-append
"https://github.com/samtools/htslib/releases/download/"
version "/htslib-" version ".tar.bz2"))
(sha256
(base32
"0dh79lwpspwwfbkmllrrhbk8nkvlfc5b5ib4d0xg5ld79w6c8lc7"))))
(arguments
(substitute-keyword-arguments (package-arguments htslib)
((#:configure-flags flags ''())
''())))
(inputs
(list bzip2 xz))))

(define %source-dir (dirname (current-filename)))

(define %git-commit
(read-string (open-pipe "git show HEAD | head -1 | cut -d ' ' -f 2" OPEN_READ)))

(define-public wfmash-static-gcc-git
(package
(inherit wfmash-base-git)
(name "wfmash-static-gcc-git")
(version (git-version "0.21" "HEAD" %git-commit))
(arguments
`(;; #:tests? #f
#:configure-flags
,#~(list
"-DBUILD_STATIC=ON"
"-DBUILD_OPTIMIZED=ON"
"-DCMAKE_BUILD_TYPE=Release"
"-DCMAKE_INSTALL_RPATH="))) ; force cmake static build and do not rewrite RPATH
(inputs
(modify-inputs (package-inputs wfmash-gcc-git)
(prepend
`(,bzip2 "static")
`(,zlib "static")
`(,gsl "static")
`(,xz "static")
libdeflate-static
htslib-static
)))))

wfmash-gcc-git
wfmash-static-gcc-git ;; default deployment build
;; wfmash-gcc-git
;; wfmash-clang-git