This repository has been archived by the owner on Jan 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(SW): Sequential and sequential_straight algs
- Loading branch information
1 parent
d8bfc14
commit 3ab7b8b
Showing
3 changed files
with
93 additions
and
127 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,51 @@ | ||
use std::iter::repeat; | ||
use rand::Rng; | ||
use sw::{ | ||
algorithm::{find_alignment_simd_lowmem, AlignmentScores}, | ||
find_alignment_simd, | ||
}; | ||
|
||
#[allow(unused_imports)] | ||
use sw::algorithm::{ | ||
string_scores_parallel, string_scores_simd, string_scores_straight, traceback, | ||
}; | ||
|
||
use argminmax::ArgMinMax; | ||
|
||
const LANES: usize = 64; | ||
|
||
use sw::{ | ||
algorithm::AlignmentScores, | ||
utils::{coord, roundup}, | ||
}; | ||
|
||
fn main() { | ||
let scores = AlignmentScores { | ||
gap: -2, | ||
r#match: 3, | ||
miss: -3, | ||
}; | ||
|
||
let mut query = repeat('A').take(128).collect::<Vec<_>>(); | ||
let mut target = repeat('T').take(20000000).collect::<Vec<_>>(); | ||
|
||
target[67] = 'Z'; | ||
target[68] = 'Z'; | ||
query[13] = 'Z'; | ||
query[14] = 'Z'; | ||
|
||
let start = std::time::Instant::now(); | ||
|
||
let data = string_scores_simd::<LANES>(&query, &target, scores); | ||
let mut rng = rand::thread_rng(); | ||
|
||
// PERF: We might be able to eek out a bit more perf here by ignoring the min in a custom | ||
// implementation | ||
let (_min_index, max_index) = data.argminmax(); | ||
let max = data[max_index]; | ||
// let (max_index, max) = data.iter().enumerate().max_by_key(|(_, x)| *x).unwrap(); | ||
let charset = ['A', 'T', 'C', 'G']; | ||
|
||
let end = std::time::Instant::now(); | ||
for _i in 0..10000 { | ||
let query: Vec<_> = (0..) | ||
.map(|_| { | ||
let i: u8 = rng.gen(); | ||
let char = charset[i as usize % charset.len()]; | ||
|
||
let duration = end - start; | ||
println!("Query * Target: {}", query.len() * target.len()); | ||
println!("Duration: {:?}", duration.as_micros()); | ||
char | ||
}) | ||
.take(1000) | ||
.collect(); | ||
|
||
println!( | ||
"MCUPS: {}", | ||
(query.len() * target.len()) / (duration.as_micros() as usize) | ||
); | ||
let target: Vec<_> = (0..) | ||
.map(|_| { | ||
let i: u8 = rng.gen(); | ||
let char = charset[i as usize % charset.len()]; | ||
|
||
println!("Max: {}", max); | ||
println!("Max index: {}", max_index); | ||
let data_width = roundup(query.len(), LANES) + 1; | ||
let (x, y) = coord(max_index, data_width); | ||
println!("x: {}; y: {}", x - 1, y - x); | ||
let mut query_result = Vec::new(); | ||
let mut target_result = Vec::new(); | ||
char | ||
}) | ||
.take(1000) | ||
.collect(); | ||
|
||
traceback( | ||
&data, | ||
&query, | ||
&target, | ||
x, | ||
y, | ||
data_width, | ||
&mut query_result, | ||
&mut target_result, | ||
scores, | ||
); | ||
let lm = find_alignment_simd_lowmem::<LANES>(&query, &target, scores); | ||
let sd = find_alignment_simd::<LANES>(&query, &target, scores); | ||
|
||
println!("Query: {:?}", query_result); | ||
println!("Target: {:?}", target_result); | ||
assert_eq!(lm, sd); | ||
} | ||
} |