swps3
DynProgr_PPU_profile.inc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007-2008 Philipp Kraehenbuehl, Adam Szalkowski
3  *
4  * Permission is hereby granted, free of charge, to any person
5  * obtaining a copy of this software and associated documentation
6  * files (the "Software"), to deal in the Software without
7  * restriction, including without limitation the rights to use,
8  * copy, modify, merge, publish, distribute, sublicense, and/or sell
9  * copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following
11  * conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23  * OTHER DEALINGS IN THE SOFTWARE.
24  */
25 
26 int blockStart;
27 int nSeg = 16/sizeof(T); /* The number of elements in the vector */
28 SPEProfile *profile = malloc(sizeof(*profile));
29 T * pp1 = (T*)memalign( 16, MATRIX_DIM*(queryLen+16)*sizeof(T));
30 
31 profile->len = queryLen;
32 profile->addr = (ppu_addr_t)pp1;
33 profile->min = DBL_MAX;
34 profile->max = DBL_MIN;
35 
36 /* Calculate the Block Size */
37 /****************************/
38 
39 /* The block size needs to be aligned to the number of elements in the vector (nSeg) */
40 if (TOTAL_MEMORY<maxDbLen*(sizeof(char)+2*sizeof(T))) error("insufficient memory on SPE");
41 profile->blockSize = (TOTAL_MEMORY-maxDbLen*(sizeof(char)+2*sizeof(T)))/((MATRIX_DIM+3)*sizeof(T)) & -16;
42 if (profile->blockSize<=50) error("insufficient memory on SPE");
43 profile->blockSize = ALIGN16( MIN(profile->blockSize,queryLen) );
44 /* Setup the profile */
45 /*********************/
46 for(blockStart=0; blockStart<queryLen; blockStart+=profile->blockSize){
47  T * currentBlock = pp1+blockStart*MATRIX_DIM;
48  /* The current block size also needs to be aligned to nSeg */
49  int currentBlockSize = ALIGN16( MIN(profile->blockSize,queryLen-blockStart) );
50  int segLen = currentBlockSize / nSeg;
51  int i,j,k;
52 
53  /* Calculate the alignment for the current block */
54  for( i=0; i<MATRIX_DIM; i++ ){
55  T * currentProfile = currentBlock+i*currentBlockSize;
56  for( j=0; nSeg*j < currentBlockSize; j++ ){
57  T * tmp = currentProfile + j*nSeg;
58  for( k=0; k<nSeg; k++ )
59  if( j + k*segLen + blockStart < queryLen ) {
60  tmp[k] = (T)matrix[ query[j + k*segLen + blockStart] * MATRIX_DIM + i ];
61  if(profile->min > tmp[k]) profile->min = tmp[k];
62  if(profile->max < tmp[k]) profile->max = tmp[k];
63  }
64  else tmp[k] = 0;
65  }
66  }
67 }
68 
69 return profile;