Mercurial > hg > Game > Cerium
view example/fft/ppe/butterfly.cc @ 1627:8b2d3ac19991 draft
fix
author | Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 03 Jun 2013 17:02:51 +0900 |
parents | 6ff0c34c8a3c |
children | 6c0b6947c231 |
line wrap: on
line source
#include "butterfly.h" #ifdef __APPLE__ #include <OpenCL/opencl.h> #else #include <CL/cl.h> #endif #include "Func.h" SchedDefineTask1(butterfly,butterfly); static int butterfly(SchedTask* s,void* rbuf,void* wbuf) { cl_float2* x_in = (cl_float2*)s->get_inputAddr(0); cl_float2* w = (cl_float2*)s->get_inputAddr(1); int* n = (int*)s->get_inputAddr(3); unsigned int* flag = (unsigned int*)s->get_inputAddr(4); cl_float2* x_out = (cl_float2*)s->get_outputAddr(0); unsigned long gid = (unsigned long)s->get_param(0); unsigned long nid = (unsigned long)s->get_param(1); long iter = (long)s->get_param(2) + 1; int butterflySize = 1 << (iter-1); int butterflyGrpDist = 1 << iter; int butterflyGrpNum = n[0] >> iter; int butterflyGrpBase = (gid >> (iter-1))*(butterflyGrpDist); int butterflyGrpOffset = gid & (butterflySize-1); int a = nid * n[0] + butterflyGrpBase + butterflyGrpOffset; int b = a + butterflySize; int l = butterflyGrpNum * butterflyGrpOffset; cl_float2 xa, xb, xbxx, xbyy, wab, wayx, wbyx, resa, resb; xa = x_in[a]; xb = x_in[b]; xbxx.x = xbxx.y = xb.x; xbyy.x = xbyy.y = xb.y; wab.x = (cl_float)((cl_uint)w[l].x ^ 0x0); wab.y = (cl_float)((cl_uint)w[l].y ^ flag[0]); wayx.x = (cl_float)((cl_uint)wab.y ^ 0x80000000); wayx.y = (cl_float)((cl_uint)wab.x ^ 0x0); wbyx.x = (cl_float)((cl_uint)wab.y ^ 0x0); wbyx.y = (cl_float)((cl_uint)wab.x ^ 0x80000000); resa.x = xa.x + xbxx.x*wab.x + xbyy.x*wayx.x; resa.y = xa.y + xbxx.y*wab.y + xbyy.y*wayx.y; resb.x = xa.x - xbxx.x*wab.x + xbyy.x*wbyx.x; resb.y = xa.y - xbxx.y*wab.y + xbyy.y*wbyx.y; x_out[a] = resa; x_out[b] = resb; return 0; }