Smith-Waterman
/*
You must run systolic array generation on this code in order to generate hardware.
A is the two dimensional feedback table.
T is the stream we are comparing against.
*/
void SmithWaterman(int** A, int* T)
{
int i ;
int j ;
const int S[11] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } ;
// These constants are adjustable
const int matchCost = 10 ;
const int mismatchCost = 100 ;
const int insertCost = 20 ;
const int deleteCost = 200 ;
int tmp ;
int tmp2 ;
int tmp3 ;
L1: for(i = 0 ; i < 11 ; ++i)
{
for(j = 0 ; j < 11 ; ++j)
{
if(S[i] == T[j])
{
tmp = A[i - 1][j - 1] + matchCost ;
}
else
{
tmp = A[i - 1][j - 1] + mismatchCost ;
}
if(A[i - 1][j] + insertCost > A[i][j - 1] + deleteCost)
{
tmp2 = A[i - 1][j] + insertCost ;
}
else
{
tmp2 = A[i][j - 1] + deleteCost ;
}
if(tmp > tmp2)
{
tmp3 = tmp ;
}
else
{
tmp3 = tmp2 ;
}
if(tmp3 < 0)
{
A[i][j] = 0 ;
}
else
{
A[i][j] = tmp3 ;
}
}
}
}
Description
The above code performs the Smith-Waterman algorithm which is a wavefront algorithm that works over the two dimensional array A. ROCCC does not support reading and writing from the same stream unless it can be transformed into a systolic array using the SystolicArrayGeneration optimization in the ROCCC GUI. For this to be done, the code must use a two dimensional array in a wavefront manner, as Smith-Waterman does.
This optimization will transform the algorithm into one using a one dimensional hardware structure with feedback at every stage in order to increase throughput while reducing hardware.