Optimize transformSequences for ~3.5x SHW performance#241
Open
tomck-0 wants to merge 1 commit into
Open
Conversation
transformSequences is the bottleneck for SHW matches against large targets. We spend all our time transforming the input sequences before doing the matching. This change vectorizes transformSequences with AVX2. It also introduces some utility functions & patterns for handling SIMD runtime dispatching.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I noticed SHW was taking a long time with large queries, and the profiler showed all the time was spent in
transformSequences.I vectorized
transformSequenceswith AVX2 and got about a 3.5x performance improvement for my case. The core optimization is moving theletterIdxlookup table into SIMD registers and usingvpshufbto query 32 bytes against the LUT at once.I moved the old
transformSequencesfunction totransformSequencesScalarin the newedlib_util.halongside the SIMD version - we fallback to that if we detect the CPU doesn't support AVX2 or if the target array is less than 1500bp.I didn't vectorize the query array transformation to keep things simple.
Performance results from running
test_perf2.sh(just the SHW cases: all other cases are basically unaffected, because no time is spent intransformSequences):perf-new.txt
perf-old.txt
I've added a
simd_util.hfunction for any future SIMD work - I've got a couple ideas for HW & NW if this can get merged.Appreciate this is a fairly large drive-by PR, happy to explain/change anything.