annotate example/regex_mas/spe/Exec.cc.vector @ 1710:d32d5659695a draft

run gpu example
author Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
date Tue, 08 Oct 2013 18:05:11 +0900
parents 0f94d9d580f9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <stdio.h>
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include <string.h>
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include "Exec.h"
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #include "Func.h"
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 /* これは必須 */
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 SchedDefineTask(Exec);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 typedef char *cvector __attribute__ ((vector_size (16)));
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 // vectorize だと結果がよろしくない...
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 //
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 // typedef char *cvector;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 static int
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 run(SchedTask *s, void *rbuf, void *wbuf)
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 #ifdef SIMPLE_TASK
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 cvector i_data = (cvector)rbuf;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 char* i_data0 = (char*)rbuf;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 unsigned long long *o_data = (unsigned long long*)wbuf;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 unsigned long long *head_tail_flag = o_data +2;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 int length = s->read_size();
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 #else
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 cvector i_data = (cvector)s->get_input(rbuf, 0);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 char* i_data0 = (char*)s->get_input(rbuf, 0);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 unsigned long long *o_data = (unsigned long long*)s->get_output(wbuf, 0);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 /*担当範囲の先頭、末尾が「改行、スペース」か、「それ以外の文字」かのフラグ*/
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 unsigned long long *head_tail_flag = (unsigned long long*)s->get_output(wbuf,1);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 int length = (long)s->get_param(0);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 #endif
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 static const char spaces[] = {0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20} ;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 cvector const space = (cvector)spaces;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 static const char newlines[] = {0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a};
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 cvector const newline = (cvector)newlines;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 int word_flag = 0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 int word_num = 0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 int line_num = 0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 int i = 0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 /*文字なら1,スペースか改行なら0*/
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 char top = i_data0[0];
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 head_tail_flag[0] = ((top != 0x20) && (top != 0x0a));
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 word_num -= 1-head_tail_flag[0];
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 for (; i < length; i++) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 if (i_data[i] == space[i%16]) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 //s->printf("スペース\n");
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 word_flag = 1;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 } else if (i_data[i] == newline[i%16]) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 //s->printf("改行\n");
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 line_num += 1;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 word_flag = 1;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 } else {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 word_num += word_flag;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 word_flag = 0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 word_num += word_flag;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 /*文字なら1,スペースか改行なら0*/
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 //printf("last word %c",i_data[i-1]);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 char end = i_data0[i-1];
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 head_tail_flag[1] = ((end != 0x20) && (end != 0x0a));
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 // s->printf("SPU word %d line %d\n",word_num,line_num);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 o_data[0] = (unsigned long long)word_num;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 o_data[1] = (unsigned long long)line_num;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 return 0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 }