编辑“︁
OpenCL
”︁(章节)
跳转到导航
跳转到搜索
Template:Editnotice load/content
警告:
您没有登录。如果您进行任何编辑,您的IP地址会公开展示。如果您
登录
或
创建账号
,您的编辑会以您的用户名署名,此外还有其他益处。
反垃圾检查。
不要
加入这个!
=== 快速傅立葉變換 === 一個[[快速傅立葉變換]]的式子: <ref name=siggraph>{{cite web | url=http://s08.idav.ucdavis.edu/munshi-opencl.pdf | title=OpenCL | accessdate=2008-08-14 | publisher=SIGGRAPH2008 | date=2008-08-14 | archive-url=https://www.webcitation.org/66GmScoh5?url=http://s08.idav.ucdavis.edu/munshi-opencl.pdf | archive-date=2012-03-19 | dead-url=yes }}</ref> <syntaxhighlight lang="c"> // create a compute context with GPU device context = clCreateContextFromType(NULL, CL_DEVICE_TYPE_GPU, NULL, NULL, NULL); // create a command queue queue = clCreateCommandQueue(context, NULL, 0, NULL); // allocate the buffer memory objects memobjs[0] = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(float)*2*num_entries, srcA, NULL); memobjs[1] = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(float)*2*num_entries, NULL, NULL); // create the compute program program = clCreateProgramWithSource(context, 1, &fft1D_1024_kernel_src, NULL, NULL); // build the compute program executable clBuildProgram(program, 0, NULL, NULL, NULL, NULL); // create the compute kernel kernel = clCreateKernel(program, "fft1D_1024", NULL); // set the args values clSetKernelArg(kernel, 0, sizeof(cl_mem),(void *)&memobjs[0]); clSetKernelArg(kernel, 1, sizeof(cl_mem),(void *)&memobjs[1]); clSetKernelArg(kernel, 2, sizeof(float)*(local_work_size[0]+1)*16, NULL); clSetKernelArg(kernel, 3, sizeof(float)*(local_work_size[0]+1)*16, NULL); // create N-D range object with work-item dimensions and execute kernel global_work_size[0] = num_entries; local_work_size[0] = 64; clEnqueueNDRangeKernel(queue, kernel, 1, NULL, global_work_size, local_work_size, 0, NULL, NULL); </syntaxhighlight> 真正的運算:(基於Fitting FFT onto the G80 Architecture)<ref name=VolkovKazianFFTG80>{{cite web | url=http://www.cs.berkeley.edu/~kubitron/courses/cs258-S08/projects/reports/project6_report.pdf | title=Fitting FFT onto G80 Architecture | accessdate=2008-11-14 | publisher=Vasily Volkov and Brian Kazian, UC Berkeley CS258 project report | format=PDF | date=May 2008 | archive-date=2012-03-19 | archive-url=https://www.webcitation.org/66GmTA1HM?url=http://www.cs.berkeley.edu/~kubitron/courses/cs258-S08/projects/reports/project6_report.pdf | dead-url=no }}</ref> <syntaxhighlight lang="c"> // This kernel computes FFT of length 1024. The 1024 length FFT is decomposed into // calls to a radix 16 function, another radix 16 function and then a radix 4 function __kernel void fft1D_1024(__global float2 *in, __global float2 *out, __local float *sMemx, __local float *sMemy){ int tid = get_local_id(0); int blockIdx = get_group_id(0) * 1024 + tid; float2 data[16]; // starting index of data to/from global memory in = in + blockIdx; out = out + blockIdx; globalLoads(data, in, 64); // coalesced global reads fftRadix16Pass(data); // in-place radix-16 pass twiddleFactorMul(data, tid, 1024, 0); // local shuffle using local memory localShuffle(data, sMemx, sMemy, tid, (((tid & 15)* 65) +(tid >> 4))); fftRadix16Pass(data); // in-place radix-16 pass twiddleFactorMul(data, tid, 64, 4); // twiddle factor multiplication localShuffle(data, sMemx, sMemy, tid, (((tid >> 4)* 64) +(tid & 15))); // four radix-4 function calls fftRadix4Pass(data); // radix-4 function number 1 fftRadix4Pass(data + 4); // radix-4 function number 2 fftRadix4Pass(data + 8); // radix-4 function number 3 fftRadix4Pass(data + 12); // radix-4 function number 4 // coalesced global writes globalStores(data, out, 64); } </syntaxhighlight> Apple的網站上可以發現傅立葉變換的例子<ref name=AppleOpenCLFFT>. {{cite web | url=https://developer.apple.com/mac/library/samplecode/OpenCL_FFT/index.html | title=OpenCL on FFT | accessdate=2009-12-07 | publisher=Apple | date=16 Nov 2009 | archive-date=2009-11-30 | archive-url=https://web.archive.org/web/20091130085543/http://developer.apple.com/mac/library/samplecode/OpenCL_FFT/index.html | dead-url=no }}</ref>
摘要:
请注意,所有对Local Chinese Wikipedia的贡献均可能会被其他贡献者编辑、修改或删除。如果您不希望您的文字作品被随意编辑,请不要在此提交。
您同时也向我们承诺,您提交的内容为您自己所创作,或是复制自公共领域或类似自由来源(详情请见
Project:著作权
)。
未经许可,请勿提交受著作权保护的作品!
取消
编辑帮助
(在新窗口中打开)
导航菜单
个人工具
未登录
讨论
贡献
创建账号
登录
命名空间
页面
讨论
大陆简体
不转换
简体
繁體
大陆简体
香港繁體
澳門繁體
大马简体
新加坡简体
臺灣正體
查看
阅读
编辑
查看历史
更多
搜索
导航
首页
最近更改
随机页面
MediaWiki帮助
工具
链入页面
相关更改
特殊页面
页面信息