annotate example/fft/main.cc @ 1581:8ee897303cd0 draft

fix multi_dimention
author Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
date Sat, 30 Mar 2013 18:29:54 +0900
parents 7418c7aef534
children 6ff0c34c8a3c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1551
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <stdio.h>
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include <stdlib.h>
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include <math.h>
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #include <sys/stat.h>
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 #include <fcntl.h>
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 #include <sys/time.h>
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 #include "TaskManager.h"
1555
096412ad80fb add opencl example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1551
diff changeset
8 #include "GpuScheduler.h"
1560
3df1868130cb fix fft ppe example
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1555
diff changeset
9 #include "SchedTask.h"
1551
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 #include "Func.h"
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 #ifdef __APPLE__
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 #include <OpenCL/opencl.h>
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 #else
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 #include <CL/cl.h>
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 #endif
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 #include "pgm.h"
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 extern void task_init();
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 #define PI 3.14159265358979
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 #define MAX_SOURCE_SIZE (0x100000)
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 #define AMP(a, b) (sqrt((a)*(a)+(b)*(b)))
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 static double st_time;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 static double ed_time;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 void TMend(TaskManager *);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 int ndrange_flag;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 cl_device_id device_id = NULL;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 cl_context context = NULL;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 cl_command_queue queue = NULL;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 cl_program program = NULL;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 CPU_TYPE spe_cpu = SPE_ANY;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 enum Mode {
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 forward = 0,
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 inverse = 1
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 };
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 static double
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 getTime()
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 {
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 struct timeval tv;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 gettimeofday(&tv, NULL);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 return tv.tv_sec + (double)tv.tv_usec*1e-6;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 }
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 const char *usr_help_str = "Usage: ./fft [option]\n \
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 options\n\
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 -cpu Number of SPE used (default 1)\n\
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 -l, --length Sorted number of data (default 1200)\n\
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 -h, --help Print this message";
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 int setWorkSize(size_t* gws, size_t* lws, cl_int x, cl_int y)
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 {
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 switch(y) {
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 case 1:
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 gws[0] = x;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 gws[1] = 1;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 lws[0] = 1;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 lws[1] = 1;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 break;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 default:
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 gws[0] = x;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 gws[1] = y;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 lws[0] = 1;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 lws[1] = 1;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 break;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 }
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 return 0;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 }
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 int fftCore(TaskManager *manager,cl_float2 *dst, cl_float2 *src, cl_float2 *spin, int m_, enum Mode direction)
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 {
1579
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
75 int iter;
1566
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1560
diff changeset
76 unsigned int* flag = new unsigned int[1];
1551
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 switch (direction) {
1566
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1560
diff changeset
78 case forward:flag[0] = 0x00000000; break;
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1560
diff changeset
79 case inverse:flag[0] = 0x80000000; break;
1551
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 }
1566
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1560
diff changeset
81 int* n = new int[1];
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1560
diff changeset
82 int* m = new int[1];
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1560
diff changeset
83 m[0] = m_;
1551
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 n[0] = 1<<m[0];
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 size_t gws[2],lws[2];
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 int length_dst = n[0]*n[0];
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 int length_src = n[0]*n[0];
1579
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
88 cl_uint dimension = 2;
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
89 HTask* brev;
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
90 int i,j;
1571
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1566
diff changeset
91 setWorkSize(gws,lws,n[0],n[0]);
1579
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
92 for(i=0;i<gws[0];i++){
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
93 for(j=0;j<gws[1];j++){
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
94 brev = manager->create_task(BIT_REVERSE);
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
95 brev->set_param(0,(memaddr)length_src);
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
96 brev->set_param(1,(memaddr)i);
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
97 brev->set_param(2,(memaddr)j);
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
98 brev->set_inData(0, src, length_src*sizeof(cl_float2));
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
99 brev->set_inData(1, m,sizeof(int));
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
100 brev->set_inData(2, n,sizeof(int));
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
101 brev->set_outData(0, dst, length_dst*sizeof(cl_float2));
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
102 brev->set_cpu(spe_cpu);
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
103 brev->spawn();
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
104 }
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
105 }
1581
8ee897303cd0 fix multi_dimention
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1579
diff changeset
106 exit(0);
1579
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
107 HTask* bfly;
1571
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1566
diff changeset
108 setWorkSize(gws,lws,n[0]/2,n[0]);
1551
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109
1579
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
110 for (iter=1; iter<=m_;iter++) {
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
111 for(i=0;i<gws[0];i++){
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
112 for(j=0;i<gws[1];j++){
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
113 bfly = manager->create_task(BUTTERFLY);
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
114 bfly->set_param(0,(memaddr)length_dst);
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
115 bfly->set_param(1,(memaddr)iter);
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
116 bfly->set_param(2,(memaddr)i);
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
117 bfly->set_param(3,(memaddr)j);
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
118 bfly->set_inData(0, dst, length_dst*sizeof(cl_float2));
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
119 bfly->set_inData(1, spin, sizeof(cl_float2)*(n[0]/2));
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
120 bfly->set_inData(2, m,sizeof(int));
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
121 bfly->set_inData(3, n,sizeof(int));
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
122 bfly->set_inData(4, flag,sizeof(int));
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
123 bfly->set_outData(0,dst,length_dst*sizeof(cl_float2));
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
124 bfly->set_cpu(spe_cpu);
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
125 bfly->wait_for(brev);
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
126 bfly->spawn();
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
127 }
1551
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 }
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 }
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
130
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 if (direction == inverse) {
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 HTask *norm = manager->create_task(NORMALIZATION);
1571
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1566
diff changeset
133 setWorkSize(gws,lws,n[0],n[0]);
1551
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 norm->set_param(0,(memaddr)length_dst);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 norm->set_param(1,(memaddr)dimension);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 norm->set_param(2,(memaddr)gws[0]);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 norm->set_param(3,(memaddr)gws[1]);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 norm->set_param(4,(memaddr)lws[0]);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 norm->set_param(5,(memaddr)lws[1]);
1571
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1566
diff changeset
140 norm->set_inData(0, n,sizeof(int));
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1566
diff changeset
141 norm->set_outData(0, dst, length_dst*sizeof(cl_float2));
1551
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 norm->set_cpu(spe_cpu);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 norm->nd_range();
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 norm->flip();
1579
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
145 norm->wait_for(bfly);
1551
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 norm->spawn();
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 }
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 return 0;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 }
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
150
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 char *
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 init(int argc, char**argv){
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
153
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 char *filename = 0;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
155
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 for (int i = 1; argv[i]; ++i) {
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 if (strcmp(argv[i], "-file") == 0) {
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 filename = argv[i+1];
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 } else if (strcmp(argv[i], "-g") == 0) {
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 spe_cpu = GPU_0;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 }
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 }
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 if ( (argc == 1)||(filename==0)) {
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 printf("Usage: ./fft -file [image filename] -cpu or -gpu \n");
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 exit(-1);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 }
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
167
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 return filename;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 }
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
170
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 void
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 run_start(TaskManager *manager,pgm_t ipgm)
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 {
1555
096412ad80fb add opencl example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1551
diff changeset
174 int dimension;
1551
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 int *n = new int[1];
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 n[0] = ipgm.width;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 int *m = new int[1];
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 m[0] = (cl_int)(log((double)n[0])/log(2.0));
1555
096412ad80fb add opencl example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1551
diff changeset
179 size_t *gws = new size_t[3];
096412ad80fb add opencl example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1551
diff changeset
180 size_t *lws = new size_t[3];
096412ad80fb add opencl example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1551
diff changeset
181
1551
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 cl_float2 *xm = (cl_float2 *)malloc(n[0] * n[0] * sizeof(cl_float2));
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 cl_float2 *rm = (cl_float2 *)malloc(n[0] * n[0] * sizeof(cl_float2));
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 cl_float2 *wm = (cl_float2 *)malloc(n[0] / 2 * sizeof(cl_float2));
1579
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
185 int i,j;
1551
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 /*
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 * [cl_float2]
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 * typedef union
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 * {
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 * cl_float CL_ALIGNED(8) s[2];
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 * #if defined( __GNUC__) && ! defined( __STRICT_ANSI__ )
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 * __extension__ struct{ cl_float x, y; };
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 * __extension__ struct{ cl_float s0, s1; };
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 * __extension__ struct{ cl_float lo, hi; };
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 * #endif
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 * #if defined( __CL_FLOAT2__)
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 * __cl_float2 v2;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 * #endif
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 * } cl_float2;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 */
1579
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
201 for (i=0; i<n[0]; i++) {
1551
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 for (j=0; j < n[0]; j++) {
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 ((float*)xm)[(2*n[0]*j)+2*i+0] = (float)ipgm.buf[n[0]*j+i];
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 ((float*)xm)[(2*n[0]*j)+2*i+1] = (float)0;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 }
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 }
1579
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
207
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
208 // Create spin factor
1555
096412ad80fb add opencl example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1551
diff changeset
209 setWorkSize(gws,lws,n[0]/2,1); // Todo:setWorkSize(ndr,n[0]/2,1);でできるように
1579
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
210 int length_w = n[0] / 2;
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
211 HTask* sfac;
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
212 for(i=0;i<gws[0];i++){
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
213 sfac = manager->create_task(SPIN_FACT);
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
214 sfac->set_param(0, (memaddr)length_w);
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
215 sfac->set_param(1,(memaddr)i);
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
216 sfac->set_inData(0, n, sizeof(int));
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
217 sfac->set_outData(0, wm, length_w*sizeof(cl_float2));
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
218 sfac->set_cpu(spe_cpu);
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
219 sfac->nd_range();
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
220 sfac->spawn();
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1571
diff changeset
221 }
1581
8ee897303cd0 fix multi_dimention
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1579
diff changeset
222 // Butterfly Operation
1551
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 fftCore(manager, rm, xm, wm, m[0], forward);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
224
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 HTaskPtr *trns = (HTask**)manager->allocate(sizeof(HTask*)*2);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
226
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 // Transpose matrix
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
228 int length_r =n[0] * n[0];
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 setWorkSize(gws,lws,n[0]/2,1);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 dimension = 2;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 for (int i=0;i<2;i++) {
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 trns[i]= manager->create_task(TRANSEPOSE);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 trns[i]->set_param(0, (memaddr)length_r);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 trns[i]->set_param(1,(memaddr)dimension);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 trns[i]->set_param(2,(memaddr)gws[0]);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 trns[i]->set_param(3,(memaddr)gws[1]);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 trns[i]->set_param(4,(memaddr)lws[0]);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
238 trns[i]->set_param(5,(memaddr)lws[1]);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 trns[i]->set_inData(0, rm, length_r*sizeof(cl_float2));
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 trns[i]->set_inData(1, n,sizeof(int));
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 trns[i]->set_outData(0, xm, length_r*sizeof(cl_float2));
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
242 trns[i]->set_cpu(spe_cpu);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
243 trns[i]->nd_range();
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 }
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 trns[0]->wait_for(sfac);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
246 trns[0]->spawn();
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 // Butterfly Operation
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 fftCore(manager, rm, xm, wm, m[0], forward);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
249
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 // Apply high-pass filter
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
251 HTask *hpfl = manager->create_task(HIGH_PASS_FILTER);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 cl_int *radius = new cl_int[1];
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 radius[0] = n[0]/8;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 setWorkSize(gws,lws,n[0]/2,1);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
255 hpfl->set_param(0, (memaddr)length_r);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
256 hpfl->set_param(1,(memaddr)dimension);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
257 hpfl->set_param(2,(memaddr)gws[0]);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
258 hpfl->set_param(3,(memaddr)gws[1]);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
259 hpfl->set_param(4,(memaddr)lws[0]);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
260 hpfl->set_param(5,(memaddr)lws[1]);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
261 hpfl->set_inData(0, n,sizeof(int));
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
262 hpfl->set_inData(1, radius,sizeof(int));
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
263 hpfl->set_outData(0, rm, length_r*sizeof(cl_float2));
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
264 hpfl->set_cpu(spe_cpu);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
265 hpfl->nd_range();
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
266 hpfl->wait_for(trns[0]);
1566
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1560
diff changeset
267 hpfl->spawn();
1551
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 // Inverse FFT
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
269
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
270 // Butterfly Operation
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 fftCore(manager,xm, rm, wm, m[0], inverse);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
272
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 // Transpose matrix
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
274 trns[1]->spawn();
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
275
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 // Butterfly Operation
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
277
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
278 fftCore(manager,xm, rm, wm, m[0], inverse);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
279
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
280 // Read data from memory buffer
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
281 // spawn and wait
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
282
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
283 float* ampd;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 ampd = (float*)malloc(n[0]*n[0]*sizeof(float));
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 for (i=0; i < n[0]; i++) {
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
286 for (j=0; j < n[0]; j++) {
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 ampd[n[0]*((i))+((j))] = (AMP(((float*)xm)[(2*n[0]*i)+2*j], ((float*)xm)[(2*n[0]*i)+2*j+1]));
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 }
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 }
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 pgm_t opgm;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
291 opgm.width = n[0];
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 opgm.height = n[0];
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 normalizeF2PGM(&opgm, ampd);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 free(ampd);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
295
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 // Write out image
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
297 writePGM(&opgm, "output.pgm");
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
298
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
299 // Finalizations
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
300 destroyPGM(&ipgm);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
301 destroyPGM(&opgm);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
302
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
303 free(wm);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
304 free(rm);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
305 free(xm);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
306 }
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
307
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
308 int TMmain(TaskManager *manager, int argc, char** argv) {
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
309 task_init();
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
310 char * pgm_file = init(argc,argv);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
311 pgm_t ipgm;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
312 /* Read image */
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
313 int err = readPGM(&ipgm, pgm_file);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
314 if (err<0) {
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
315 fprintf(stderr, "Failed to read image file.\n");
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 exit(1);
1566
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1560
diff changeset
317 }
1551
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 st_time = getTime();
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 run_start(manager, ipgm);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
320 manager->set_TMend(TMend);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
321 return 0;
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
322 }
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
323
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
324 void
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
325 TMend(TaskManager *manager)
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
326 {
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 ed_time = getTime();
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
328 fprintf(stdout, "image out put succeeded.\n");
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
329 printf("Time: %0.6f\n",ed_time-st_time);
57317332f6ef create fft example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
330 }