lh3/ksw2

Making a distributable binary with ksw2

rob-p opened this issue · 2 comments

rob-p commented

Hi @lh3,

Thanks again for the great library! I'm planning to make use of ksw2 to perform some on-demand alignment in a couple of projects. I've made a simple C++-wrapper, which seems to work well so far in practice. However, one issue I'm concerned about is how ksw2 should be compiled. Specifically, I would like to make use of the most advanced instruction set available on the target machine. Is the only way to do this by compiling different versions of my binary (e.g., one that uses only SSE2 instructions, another that uses SSE4 etc.)? How do you handle this issue when building a binary (e.g., via Bioconda) for minimap2?

Thanks!
Rob

lh3 commented

You may read the minimap2's Makefile and ksw2_dispatch.c. The basic idea is that you compile different versions of the same algorithm, requiring different SIMD instruction sets, and then dynamically choose which version to use based on users' CPU. Intel developers call this strategy as "CPU dispatch". This blog post gives a bit more information.

rob-p commented

Brilliant; this is exactly what I was looking for. Thanks @lh3!