39 #include <sys/types.h>
57 #define MAX(a,b) (a>b?a:b)
58 #define MIN(a,b) (a<b?a:b)
63 static spe_gid_t getSpeGid(){
64 static spe_gid_t gid = 0;
66 gid = spe_create_group(SCHED_RR, 1, 1);
68 error(
"PPU:Creating new group failed");
73 static speid_t getSpeId(){
74 static speid_t
id = 0;
76 id = spe_create_thread(getSpeGid(), &spe_dynprogr_handle, NULL, NULL, -1, 0);
82 speid_t spe_id = getSpeId();
83 spe_write_in_mbox( spe_id, (uint32_t)addr );
84 spe_write_in_mbox( spe_id, (uint32_t)(addr>>32) );
88 static int readMailBox(){
89 struct spe_event e = {
90 .events = SPE_EVENT_MAILBOX,
93 if( !spe_get_event(&e, 1, -1) || e.revents != SPE_EVENT_MAILBOX )
error(
"PPU:Waiting for MailBox signal");
109 return readMailBox();
112 spe_context = spe_context_create( 0, NULL );
116 unsigned int entry = SPE_DEFAULT_ENTRY;
117 return spe_context_run( spe_context, &entry, 0, command, NULL, NULL );
136 command.data.INIT.dbMaxLen =
maxDbLen;
137 command.data.INIT.datatype = dataType;
138 command.data.INIT.fixedDel = options->
gapOpen;
139 command.data.INIT.incDel = options->
gapExt;
159 assert(((
ppu_addr_t)query & 0xf) == 0 &&
"query not aligned to 16 bytes");
160 assert(((
ppu_addr_t)matrix & 0xf) == 0 &&
"matrix not aligned to 16 bytes");
163 command.data.CREATE_PROFILE.query.addr = (
ppu_addr_t)query;
164 command.data.CREATE_PROFILE.query.len = queryLen;
165 command.data.CREATE_PROFILE.matrix.addr = (
ppu_addr_t)matrix;
166 command.data.CREATE_PROFILE.matrix.min =
min;
167 command.data.CREATE_PROFILE.matrix.max =
max;
176 assert(((
ppu_addr_t)profile->
addr & 0xf) == 0 &&
"profile not aligned to 16 bytes");
177 memcpy(&command.data.GET_PROFILE.profile, profile,
sizeof(*profile));
185 assert(((
ppu_addr_t)profile & 0xf) == 0 &&
"profile not aligned to 16 byte");
188 command.data.PUT_PROFILE.blockSize = 0;
189 command.data.PUT_PROFILE.addr = (
ppu_addr_t)profile;
194 *blockSize = command.data.PUT_PROFILE.blockSize;
199 static int SPEAlign(
const char *db,
int dbLen,
double *result) {
202 assert(((
ppu_addr_t)db & 0xf) == 0 &&
"db sequence not aligned to 16 byte");
205 command.data.ALIGN.result = -1;
206 command.data.ALIGN.db.len = dbLen;
212 *result = command.data.ALIGN.result;
219 double min,
max, maxScore;
222 if(ret != 0)
error(
"error in SPEInit");
228 if(max < matrix[i]) max = matrix[i];
229 if(min > matrix[i]) min = matrix[i];
232 if(ret != 0)
error(
"error in SPECreateProfile");
234 ret =
SPEAlign(db, dbLen, &maxScore);
235 if(ret != 0)
error(
"error in SPEAlign");
238 if( ret != 0 || maxScore == -1 ){
240 warning(
"sequence too long for SPE program, using PPU fallback\n" );
241 for(i=0; i<MATRIX_DIM*
MATRIX_DIM; ++i) dmatrix[i] = matrix[i];
249 double max,
min, maxScore;
253 if(ret != 0)
error(
"error in SPEInit");
259 if(max < matrix[i]) max = matrix[i];
260 if(min > matrix[i]) min = matrix[i];
264 if(ret != 0)
error(
"error in SPECreateProfile");
266 ret =
SPEAlign(db, dbLen, &maxScore);
267 if(ret != 0)
error(
"error in SPEAlign");
270 if( ret != 0 || maxScore == -1 ){
272 warning(
"sequence too long for SPE program, using PPU fallback\n" );
273 for(i=0; i<MATRIX_DIM*
MATRIX_DIM; ++i) dmatrix[i] = matrix[i];
281 double max,
min, maxScore;
285 if(ret != 0)
error(
"error in SPEInit");
291 if(max < matrix[i]) max = matrix[i];
292 if(min > matrix[i]) min = matrix[i];
293 simi[i] = (float)matrix[i];
296 if(ret != 0)
error(
"error in SPECreateProfile");
298 ret =
SPEAlign(db, dbLen, &maxScore);
299 if(ret != 0)
error(
"error in SPEAlign");
302 if( ret != 0 || maxScore == -1 ){
304 warning(
"sequence too long for SPE program, using PPU fallback\n" );
305 for(i=0; i<MATRIX_DIM*
MATRIX_DIM; ++i) dmatrix[i] = matrix[i];
319 ret =
SPEAlign(db, dbLen, &maxScore);
320 if(ret != 0) maxScore = -1;
330 if(ret != 0)
error(
"error in SPEInit");
333 if(ret != 0)
error(
"error in SPEGetProfile");
341 if(ret != 0)
error(
"error in SPEInit");
344 if(ret != 0)
error(
"error in SPEGetProfile");
352 if(ret != 0)
error(
"error in SPEInit");
355 if(ret != 0)
error(
"error in SPEGetProfile");
380 free((
void*)profile->
addr);