annotate example/fft/gpu/butterfly.cc @ 1731:dc7dd1eaf6de draft

add file
author Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
date Thu, 31 Oct 2013 21:07:30 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1731
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include "butterfly.h"
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #ifdef __APPLE__
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include <OpenCL/opencl.h>
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #else
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 #include <CL/cl.h>
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 #endif
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 #include "Func.h"
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 SchedDefineTask1(butterfly,butterfly);
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 static int
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 butterfly(SchedTask* s,void* rbuf,void* wbuf)
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 {
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 cl_float2* x_in = (cl_float2*)s->get_inputAddr(0);
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 cl_float2* w = (cl_float2*)s->get_inputAddr(1);
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 cl_float2* x_out = (cl_float2*)s->get_outputAddr(0);
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 unsigned long gid = s->x; // (unsigned long)s->get_param(0);
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 unsigned long nid = s->y; // (unsigned long)s->get_param(1);
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 long n = (long)s->get_param(3);
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 unsigned long direction_flag = (unsigned long)s->get_param(4);
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 long iter = (long)s->get_param(5);
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 int butterflySize = 1 << (iter-1);
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 int butterflyGrpDist = 1 << iter;
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 int butterflyGrpNum = n >> iter;
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 int butterflyGrpBase = (gid >> (iter-1))*(butterflyGrpDist);
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 int butterflyGrpOffset = gid & (butterflySize-1);
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 int a = nid * n + butterflyGrpBase + butterflyGrpOffset;
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 int b = a + butterflySize;
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 int l = butterflyGrpNum * butterflyGrpOffset;
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 cl_float2 xa, xb, xbxx, xbyy, wab, wayx, wbyx, resa, resb;
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 xa = x_in[a];
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 xb = x_in[b];
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 xbxx.x = xbxx.y = xb.x;
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 xbyy.x = xbyy.y = xb.y;
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 wab.x = w[l].x;
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 if(direction_flag == 0x80000000) {
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 wab.y = -w[l].y;
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 } else {
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 wab.y = w[l].y;
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 }
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 wayx.x = -wab.y;
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 wayx.y = wab.x;
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 wbyx.x = wab.y;
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 wbyx.y = -wab.x;
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 resa.x = xa.x + xbxx.x*wab.x + xbyy.x*wayx.x;
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 resa.y = xa.y + xbxx.y*wab.y + xbyy.y*wayx.y;
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 resb.x = xa.x - xbxx.x*wab.x + xbyy.x*wbyx.x;
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 resb.y = xa.y - xbxx.y*wab.y + xbyy.y*wbyx.y;
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 x_out[a] = resa;
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 x_out[b] = resb;
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 return 0;
dc7dd1eaf6de add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 }