DynProgr_PPU_profile.inc

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2007-2008 Philipp Kraehenbuehl, Adam Szalkowski
00003  *
00004  * Permission is hereby granted, free of charge, to any person
00005  * obtaining a copy of this software and associated documentation
00006  * files (the "Software"), to deal in the Software without
00007  * restriction, including without limitation the rights to use,
00008  * copy, modify, merge, publish, distribute, sublicense, and/or sell
00009  * copies of the Software, and to permit persons to whom the
00010  * Software is furnished to do so, subject to the following
00011  * conditions:
00012  *
00013  * The above copyright notice and this permission notice shall be
00014  * included in all copies or substantial portions of the Software.
00015  *
00016  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00017  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
00018  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00019  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
00020  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
00021  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00022  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00023  * OTHER DEALINGS IN THE SOFTWARE.
00024  */
00025 
00026 int blockStart;
00027 int nSeg = 16/sizeof(T); /* The number of elements in the vector */
00028 SPEProfile *profile = malloc(sizeof(*profile));
00029 T * pp1 = (T*)memalign( 16, MATRIX_DIM*(queryLen+16)*sizeof(T));
00030 
00031 profile->len = queryLen;
00032 profile->addr = (ppu_addr_t)pp1;
00033 profile->min = DBL_MAX;
00034 profile->max = DBL_MIN;
00035 
00036 /* Calculate the Block Size */
00037 /****************************/
00038 
00039 /* The block size needs to be aligned to the number of elements in the vector (nSeg) */
00040 if (TOTAL_MEMORY<maxDbLen*(sizeof(char)+2*sizeof(T))) error("insufficient memory on SPE");
00041 profile->blockSize = (TOTAL_MEMORY-maxDbLen*(sizeof(char)+2*sizeof(T)))/((MATRIX_DIM+3)*sizeof(T)) & -16;
00042 if (profile->blockSize<=50) error("insufficient memory on SPE");
00043 profile->blockSize = ALIGN16( MIN(profile->blockSize,queryLen) );
00044 /* Setup the profile */
00045 /*********************/
00046 for(blockStart=0; blockStart<queryLen; blockStart+=profile->blockSize){
00047         T * currentBlock = pp1+blockStart*MATRIX_DIM;
00048         /* The current block size also needs to be aligned to nSeg */
00049         int currentBlockSize = ALIGN16( MIN(profile->blockSize,queryLen-blockStart) );
00050         int segLen = currentBlockSize / nSeg;
00051         int i,j,k;
00052 
00053         /* Calculate the alignment for the current block */
00054         for( i=0; i<MATRIX_DIM; i++ ){
00055                 T * currentProfile = currentBlock+i*currentBlockSize;
00056                 for( j=0; nSeg*j < currentBlockSize; j++ ){
00057                         T * tmp = currentProfile + j*nSeg;
00058                         for( k=0; k<nSeg; k++ )
00059                                 if( j + k*segLen + blockStart < queryLen ) {
00060                                         tmp[k] = (T)matrix[ query[j + k*segLen + blockStart] * MATRIX_DIM + i ];
00061                                         if(profile->min > tmp[k]) profile->min = tmp[k];
00062                                         if(profile->max < tmp[k]) profile->max = tmp[k];
00063                                 }
00064                                 else tmp[k] = 0;
00065                 }
00066         }
00067 }
00068 
00069 return profile;

Generated on Thu Jun 5 12:44:37 2008 for swps3 by  doxygen 1.5.4