[med-svn] [Git][med-team/last-align][simde] any-{amd64, i386}: multi-SIMD compile with dispatcher

Michael R. Crusoe gitlab at salsa.debian.org
Thu Dec 19 16:18:37 GMT 2019



Michael R. Crusoe pushed to branch simde at Debian Med / last-align


Commits:
641ad37a by Michael R. Crusoe at 2019-12-18T17:58:02Z
any-{amd64,i386}: multi-SIMD compile with dispatcher

- - - - -


4 changed files:

- + debian/bin/simd-dispatch
- debian/changelog
- debian/patches/simde
- debian/rules


Changes:

=====================================
debian/bin/simd-dispatch
=====================================
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+PKG=last-align
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
+BASE=${DIR}/../lib/$PKG/$(basename "$0")
+
+function test_and_run () {
+	if grep -q "$1" /proc/cpuinfo && [ -x "${BASE}-$1" ]; then
+		# echo "${BASE}-$1" "$@"
+		"${BASE}-$1" "$@"
+		exit
+	fi
+}
+
+for SIMD in avx2 avx sse4.1 ssse3 sse3 sse2 sse mmx ; do test_and_run ${SIMD} "$@" ; done
+
+# fallback to plain option
+$BASE-plain "$@"


=====================================
debian/changelog
=====================================
@@ -2,13 +2,9 @@ last-align (1021-3) UNRELEASED; urgency=medium
 
   * Team upload.
   * Enable building on any architecture via simde. (Closes: #946850)
-  * TODO
-    any-amd64: build multiple times with decreasing levels of
-               -m{avx2,avx,sse4.1,ssse3,sse3,sse2}
-    any-i386: build multiple times with decreasing levels of
-               -m{sse3,sse2,sse,mmx}
-    all of the above: add wrapper script to detect at runtime the highest
-                      level of SIMD available, and launch the relevant binary
+  * For any-amd64 and any-i386: compile multiple times with reducing levels of
+    SIMD instruction support and ship a dispatching script to pick the best
+    one for the user at run-time.
 
  -- Michael R. Crusoe <michael.crusoe at gmail.com>  Mon, 16 Dec 2019 19:02:20 +0100
 


=====================================
debian/patches/simde
=====================================
@@ -186,3 +186,90 @@
  			    s2[-0][s1[0]]);
  	SimdInt x = simdLoad(x2+i);
  	SimdInt y = simdSub(simdLoad(y1+i), mDelGrowCost);
+--- last-align.orig/makefile
++++ last-align/makefile
+@@ -2,15 +2,24 @@
+ all:
+ 	@cd src && $(MAKE) CXXFLAGS="$(CXXFLAGS)"
+ 
+-progs = src/lastdb src/lastal src/last-split src/last-merge-batches	\
+-src/last-pair-probs src/lastdb8 src/lastal8 src/last-split8
++SFX :=
++progs = src/lastdb$(SFX) src/lastal$(SFX) src/last-split$(SFX) \
++	src/last-merge-batches$(SFX) src/last-pair-probs$(SFX) src/lastdb8$(SFX) \
++	src/lastal8$(SFX) src/last-split8$(SFX)
+ 
+ prefix = /usr/local
+ exec_prefix = $(prefix)
+ bindir = $(exec_prefix)/bin
++libexecdir = $(exec_prefix)/libexec
++
+ install: all
+ 	mkdir -p $(bindir)
+-	cp $(progs) scripts/* $(bindir)
++	cp scripts/* $(bindir)
++ifeq (,$(SFX))
++	cp $(progs) $(bindir)
++else
++	cp $(progs) $(libexecdir)
++endif
+ 
+ clean:
+ 	@cd src && $(MAKE) clean
+--- last-align.orig/src/makefile
++++ last-align/src/makefile
+@@ -56,8 +56,10 @@
+ 
+ MBOBJ = last-merge-batches.o
+ 
+-ALL = lastdb lastal last-split last-merge-batches last-pair-probs	\
+-lastdb8 lastal8 last-split8
++SFX :=
++
++ALL = lastdb$(SFX) lastal$(SFX) last-split$(SFX) last-merge-batches$(SFX) \
++      last-pair-probs$(SFX) lastdb8$(SFX) lastal8$(SFX) last-split8$(SFX)
+ 
+ indexObj8 = $(indexObj4:.o=.o8)
+ alignObj8 = $(alignObj4:.o=.o8)
+@@ -66,33 +68,33 @@
+ all: $(ALL)
+ 
+ indexAllObj4 = $(indexObj0) $(indexObj4)
+-lastdb: $(indexAllObj4)
++lastdb$(SFX): $(indexAllObj4)
+ 	$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@ $(indexAllObj4) -lz
+ 
+ indexAllObj8 = $(indexObj0) $(indexObj8)
+-lastdb8: $(indexAllObj8)
++lastdb8$(SFX): $(indexAllObj8)
+ 	$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@ $(indexAllObj8) -lz
+ 
+ alignAllObj4 = $(alignObj0) $(alignObj4)
+-lastal: $(alignAllObj4)
++lastal$(SFX): $(alignAllObj4)
+ 	$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@ $(alignAllObj4) -lz
+ 
+ alignAllObj8 = $(alignObj0) $(alignObj8)
+-lastal8: $(alignAllObj8)
++lastal8$(SFX): $(alignAllObj8)
+ 	$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@ $(alignAllObj8) -lz
+ 
+ splitAllObj4 = $(splitObj0) $(splitObj4)
+-last-split: $(splitAllObj4)
++last-split$(SFX): $(splitAllObj4)
+ 	$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@ $(splitAllObj4)
+ 
+ splitAllObj8 = $(splitObj0) $(splitObj8)
+-last-split8: $(splitAllObj8)
++last-split8$(SFX): $(splitAllObj8)
+ 	$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@ $(splitAllObj8)
+ 
+-last-pair-probs: $(PPOBJ)
++last-pair-probs$(SFX): $(PPOBJ)
+ 	$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@ $(PPOBJ) -lz
+ 
+-last-merge-batches: $(MBOBJ)
++last-merge-batches$(SFX): $(MBOBJ)
+ 	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $(MBOBJ)
+ 
+ .SUFFIXES:


=====================================
debian/rules
=====================================
@@ -8,7 +8,9 @@
 
 include /usr/share/dpkg/default.mk
 
-mandir=$(CURDIR)/debian/$(DEB_SOURCE)/usr/share/man/man1/
+prefix=$(CURDIR)/debian/$(DEB_SOURCE)/usr
+mandir=$(prefix)/share/man/man1
+libexecdir=$(prefix)/lib/$(DEB_SOURCE)
 
 # Copy upstream CXXFLAGS here because makefile enables only overriding them
 CXXFLAGS += -Wall -Wextra -Wcast-qual -Wswitch-enum -Wundef -Wcast-align -Wno-long-long -ansi -pedantic -std=c++11 -fopenmp-simd -O3
@@ -18,18 +20,72 @@ CPPFLAGS += -DHAS_CXX_THREADS -DSIMDE_ENABLE_OPENMP
 
 LDFLAGS += -pthread
 
+NUMJOBS = 1
+ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
+  NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
+  MAKEFLAGS += -j$(NUMJOBS)
+endif
+
 export DEB_BUILD_MAINT_OPTIONS = hardening=+all
 
 %:
 	dh  $@
 
 override_dh_auto_build:
-	make all CXXFLAGS="$(CXXFLAGS)" CFLAGS="$(CFLAGS)" CPPFLAGS="$(CPPFLAGS)" LDFLAGS="$(LDFLAGS)"
+ifeq (amd64,$(DEB_HOST_ARCH))
+	mkdir -p $(prefix)
+	mkdir -p $(libexecdir)
+	for SIMD in avx2 avx sse4.1 ssse3 sse3 sse2 ; do \
+		$(MAKE) -j$(NUMJOBS) all SFX=-$${SIMD} CXXFLAGS="$(CXXFLAGS) -m$$SIMD" CFLAGS="$(CFLAGS) -m$$SIMD" CPPFLAGS="$(CPPFLAGS)" LDFLAGS="$(LDFLAGS)" ; \
+		rm src/*.o? ; \
+	done
+else ifeq (i386,$(DEB_HOST_ARCH))
+	mkdir -p $(prefix)
+	mkdir -p $(libexecdir)
+	for SIMD in ssse3 sse3 sse2 sse mmx; do \
+		$(MAKE) -j$(NUMJOBS) all SFX=-$${SIMD} CXXFLAGS="$(CXXFLAGS) -m$$SIMD" CFLAGS="$(CFLAGS) -m$$SIMD" CPPFLAGS="$(CPPFLAGS)" LDFLAGS="$(LDFLAGS)" ; \
+		rm src/*.o? ; \
+	done
+	$(MAKE) -j$(NUMJOBS) all SFX=-plain CXXFLAGS="$(CXXFLAGS)" CFLAGS="$(CFLAGS)" CPPFLAGS="$(CPPFLAGS)" LDFLAGS="$(LDFLAGS)"
+else
+	$(MAKE) -j$(NUMJOBS) all CXXFLAGS="$(CXXFLAGS)" CFLAGS="$(CFLAGS)" CPPFLAGS="$(CPPFLAGS)" LDFLAGS="$(LDFLAGS)"
+endif
 
 HELP2MAN = help2man --no-info --version-string="$(DEB_VERSION_UPSTREAM)"
 
 override_dh_auto_install:
-	make install prefix=$(CURDIR)/debian/$(DEB_SOURCE)/usr
+ifeq (amd64,$(DEB_HOST_ARCH))
+	dh_install debian/bin/simd-dispatch /usr/lib/$(DEB_SOURCE)/
+	for SIMD in avx2 avx sse4.1 ssse3 sse3 sse2 ; do \
+		$(MAKE) -j$(NUMJOBS) install SFX=-$${SIMD} prefix=$(prefix) libexecdir=$(libexecdir) ; \
+	done
+	mkdir -p $(prefix)/bin
+	cd $(prefix)/bin \
+		&& for prog in lastdb lastal last-split last-merge-batches last-pair-probs lastdb8 lastal8 last-split8 ; do \
+		ln -s ../lib/$(DEB_SOURCE)/simd-dispatch $${prog} ; done
+else ifeq (i386,$(DEB_HOST_ARCH))
+	dh_install debian/bin/simd-dispatch /usr/lib/$(DEB_SOURCE)/
+	for SIMD in ssse3 sse3 sse2 sse mmx plain; do \
+		$(MAKE) -j$(NUMJOBS) install SFX=-$${SIMD} prefix=$(prefix) libexecdir=$(libexecdir) ; \
+	done
+	mkdir -p $(prefix)/bin
+	cd $(prefix)/bin \
+		&& for prog in lastdb lastal last-split last-merge-batches last-pair-probs lastdb8 lastal8 last-split8 ; do \
+		ln -s ../lib/$(DEB_SOURCE)/simd-dispatch $${prog} ; done
+else
+	$(MAKE) -j$(NUMJOBS) install prefix=$(prefix)
+endif
+
+override_dh_auto_clean:
+ifeq (amd64,$(DEB_HOST_ARCH))
+	for SIMD in avx2 avx sse4.1 ssse3 sse3 sse2 ; do \
+		dh_auto_clean -- SFX=-$${SIMD} ; done
+else ifeq (i386,$(DEB_HOST_ARCH))
+	for SIMD in ssse3 sse3 sse2 sse mmx plain; do \
+		dh_auto_clean -- SFX=-$${SIMD} ; done
+else
+	dh_auto_clean
+endif
 
 override_dh_installman:
 	dh_installman
@@ -39,16 +95,16 @@ override_dh_installman:
 	$(HELP2MAN) \
 	         --name="genome-scale comparison of biological sequences" \
 	         --help-option="-h" \
-                 $(CURDIR)/src/lastal > $(mandir)/lastal.1
+                 $(prefix)/bin/lastal > $(mandir)/lastal.1
 	$(HELP2MAN) \
 	         --name="genome-scale comparison of biological sequences" \
 	         --help-option="-h" \
-                 $(CURDIR)/src/lastal8 > $(mandir)/lastal8.1
+                 $(prefix)/bin/lastal8 > $(mandir)/lastal8.1
         # help2man output needs manual postprocessing - see debian/mans
 	#$(HELP2MAN) \
 	#         --name="genome-scale comparison of biological sequences" \
 	#         --help-option="-h" \
-        #         $(CURDIR)/src/lastdb > $(mandir)/lastdb.1
+        #         $(prefix)/bin/lastdb > $(mandir)/lastdb.1
 	$(HELP2MAN) \
                  --name="Sort MAF-format alignments by sequence name" \
                  $(CURDIR)/scripts/maf-sort > $(mandir)/maf-sort.1
@@ -72,10 +128,10 @@ override_dh_installman:
         #         $(CURDIR)/scripts/last-remove-dominated > $(mandir)/last-remove-dominated.1
 	$(HELP2MAN) \
                  --name='Estimates "split" or "spliced" alignments.' \
-                 $(CURDIR)/src/last-split > $(mandir)/last-split.1
+                 $(prefix)/bin/last-split > $(mandir)/last-split.1
 	$(HELP2MAN) \
                  --name='Estimates "split" or "spliced" alignments.' \
-                 $(CURDIR)/src/last-split8 > $(mandir)/last-split8.1
+                 $(prefix)/bin/last-split8 > $(mandir)/last-split8.1
 	$(HELP2MAN) \
                  --name="Join two or more sets of MAF-format multiple alignments" \
                  $(CURDIR)/scripts/maf-join > $(mandir)/maf-join.1
@@ -87,11 +143,11 @@ override_dh_installman:
                  $(CURDIR)/scripts/fastq-interleave > $(mandir)/fastq-interleave.1
 	$(HELP2MAN) \
                  --name="Read files of lastal output, merge corresponding batches, and write them" \
-                 $(CURDIR)/src/last-merge-batches > $(mandir)/last-merge-batches.1
+                 $(prefix)/bin/last-merge-batches > $(mandir)/last-merge-batches.1
         # help2man output needs manual postprocessing - see debian/mans
 	#$(HELP2MAN) \
         #         --name="Read alignments of paired DNA reads to a genome, and do estimations" \
-        #         $(CURDIR)/src/last-pair-probs > $(mandir)/last-pair-probs.1
+        #         $(prefix)/bin/last-pair-probs > $(mandir)/last-pair-probs.1
 	$(HELP2MAN) \
                  --name="Get alignments that have a segment with score >= threshold, with gentle masking of lowercase letters" \
                  $(CURDIR)/scripts/last-postmask > $(mandir)/last-postmask.1



View it on GitLab: https://salsa.debian.org/med-team/last-align/commit/641ad37a52bbf34df643d00101f0dc4b806f8cd7

-- 
View it on GitLab: https://salsa.debian.org/med-team/last-align/commit/641ad37a52bbf34df643d00101f0dc4b806f8cd7
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20191219/9d315979/attachment-0001.html>


More information about the debian-med-commit mailing list