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

Use SIMD for AdapterTrimmer::searchAdapter #15

Merged
merged 7 commits into from
Dec 24, 2024

Conversation

chinwobble
Copy link
Contributor

@chinwobble chinwobble commented Dec 24, 2024

Adding some tests for searchAdapter so when changes are made we know they are correct.

Profile shows that is one of the bottlenecks. It takes up ~20% of the time.

Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls  ms/call  ms/call  name    
 48.31      2.43     2.43    31687     0.08     0.08  Stats::statRead(Read*)
 20.08      3.44     1.01    59611     0.02     0.02  AdapterTrimmer::searchAdapter(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, double, int, int, bool, bool)
  8.55      3.87     0.43 42510578     0.00     0.00  edit_distance(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)
  7.75      4.26     0.39  5653164     0.00     0.00  unsigned int edit_distance_map_<1ul>(char const*, unsigned long, char const*, unsigned long)
  7.55      4.64     0.38    94019     0.00     0.00  FastqReader::getLine(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*)
  3.38      4.81     0.17        1   170.00   472.84  Evaluator::evalAdapterAndReadNum(Options*, long&)
  1.39      4.88     0.07  3449456     0.00     0.00  unsigned int edit_distance_dp<char>(char const*, unsigned long, char const*, unsigned long)
  1.19      4.94     0.06    14877     0.00     0.00  Filter::passFilter(Read*)

Benchmark shows this code is ~30% faster.

Run on (16 X 3693.05 MHz CPU s)
CPU Caches:
  L1 Data 32 KiB (x8)
  L1 Instruction 64 KiB (x8)
  L2 Unified 512 KiB (x8)
  L3 Unified 8192 KiB (x2)
Load Average: 0.23, 0.39, 0.37
-------------------------------------------------------------------
Benchmark                         Time             CPU   Iterations
-------------------------------------------------------------------
BM_SearchAdapter               1088 ns         1044 ns       668211
BM_SearchAdapterSimd            751 ns          721 ns       981100
BM_SearchAdapterLong           1296 ns         1243 ns       559736
BM_SearchAdapterLongSimd       1001 ns          961 ns       733551

@@ -19,7 +19,7 @@ class AdapterTrimmer{
static int trimBySequenceEnd(Read* r1, FilterResult* fr, string& adapter, double edMax = 0.3, int trimmingExtension = 10);
static int trimByMultiSequences(Read* r1, FilterResult* fr, vector<string>& adapterList, double edMax = 0.3, int trimmingExtension = 10);
static bool findMiddleAdapters(Read* r, string& startAdater, string& endAdapter, int& start, int& len, double edMax = 0.3, int trimmingExtension = 10);
static int searchAdapter(string* read, string& adapter, double edMax = 0.3, int searchStart = 0, int searchLen = -1, bool asLeftAsPossible = false, bool asRightAsPossible = false);
static int searchAdapter(string* read, const string& adapter, double edMax = 0.3, int searchStart = 0, int searchLen = -1, bool asLeftAsPossible = false, bool asRightAsPossible = false);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this const so that it can accept an rvalue too.

// go from right, and return immediatedly if find a mismatch <= threshold
for(int p = searchEnd - alen - 1 ; p >= searchStart ; p--) {
for (int p = searchEnd - alen; p >= searchStart; p--)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this line has changed.
Previously it was checking it was checking the last nucleotide in the rdata variable.

@chinwobble chinwobble changed the title add tests for adaptertrimmer Use SIMD for AdapterTrimmer::searchAdapter Dec 24, 2024
@sfchen sfchen merged commit b8dff0c into OpenGene:main Dec 24, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants