使用openCL的MandelBrot集
尝试使用与我在使用TBB(线程构建块)运行时使用的代码相同的代码(某种程度上) 我对OpenCL没有太多的经验,但我认为大部分主要代码都是正确的。我相信错误在使用openCL的MandelBrot集,opencl,mandelbrot,Opencl,Mandelbrot,尝试使用与我在使用TBB(线程构建块)运行时使用的代码相同的代码(某种程度上) 我对OpenCL没有太多的经验,但我认为大部分主要代码都是正确的。我相信错误在.cl文件中,它在该文件中进行计算 以下是我在TBB中的mandelbrot代码: 这是我在OpenCL中的代码 任何帮助都将不胜感激 查看此链接。它是由@eric bainville开发的。本机和OpenCL的CPU代码都不是最优的(它不使用SSE/AVX),但我认为GPU代码可能是好的。对于CPU来说,通过使用AVX并同时对8个像素
.cl
文件中,它在该文件中进行计算
以下是我在TBB中的mandelbrot代码:
这是我在OpenCL中的代码
任何帮助都将不胜感激 查看此链接。它是由@eric bainville开发的。本机和OpenCL的CPU代码都不是最优的(它不使用SSE/AVX),但我认为GPU代码可能是好的。对于CPU来说,通过使用AVX并同时对8个像素进行操作,可以大大提高代码的速度
我更改了内核中的代码,运行正常。我的新内核代码如下所示:
// voronoi kernels
//
// local memory version
//
kernel void voronoiL(write_only image2d_t outputImage)
{
// get id of element in array
int x = get_global_id(0);
int y = get_global_id(1);
int w = get_global_size(0);
int h = get_global_size(1);
float4 result = (float4)(0.0f,0.0f,0.0f,1.0f);
float MinRe = -2.0f;
float MaxRe = 1.0f;
float MinIm = -1.5f;
float MaxIm = MinIm+(MaxRe-MinRe)*h/w;
float Re_factor = (MaxRe-MinRe)/(w-1);
float Im_factor = (MaxIm-MinIm)/(h-1);
float MaxIterations = 50;
//C imaginary
float c_im = MaxIm - y*Im_factor;
//C real
float c_re = MinRe + x*Re_factor;
//Z real
float Z_re = c_re, Z_im = c_im;
bool isInside = true;
bool col2 = false;
bool col3 = false;
int iteration =0;
for(int n=0; n<MaxIterations; n++)
{
// Z - real and imaginary
float Z_re2 = Z_re*Z_re, Z_im2 = Z_im*Z_im;
//if Z real squared plus Z imaginary squared is greater than c squared
if(Z_re2 + Z_im2 > 4)
{
if(n >= 0 && n <= (MaxIterations/2-1))
{
col2 = true;
isInside = false;
break;
}
else if(n >= MaxIterations/2 && n <= MaxIterations-1)
{
col3 = true;
isInside = false;
break;
}
}
Z_im = 2*Z_re*Z_im + c_im;
Z_re = Z_re2 - Z_im2 + c_re;
iteration++;
}
if(col2)
{
result = (float4)(iteration*0.05f,0.0f, 0.0f, 1.0f);
}
else if(col3)
{
result = (float4)(255, iteration*0.05f, iteration*0.05f, 1.0f);
}
else if(isInside)
{
result = (float4)(0.0f, 0.0f, 0.0f, 1.0f);
}
write_imagef(outputImage, (int2)(x, y), result);
}
//voronoi内核
//
//本地内存版本
//
内核void voronoiL(只写image2d\t输出图像)
{
//获取数组中元素的id
int x=获取全局id(0);
int y=获取全局id(1);
int w=获取全局大小(0);
int h=获取全局大小(1);
浮动4结果=(浮动4)(0.0f、0.0f、0.0f、1.0f);
浮动最小值=-2.0f;
浮点最大值=1.0f;
浮动最小值=-1.5f;
浮动最大值=最小值+(最大值-最小值)*高/宽;
浮动Re_系数=(MaxRe-MinRe)/(w-1);
浮动Im_系数=(最大值-最小值)/(h-1);
浮点最大迭代次数=50;
//想象的
浮点c_im=最大值-y*im_因子;
//C雷亚尔
浮点数c_re=最小值+x*re_因子;
//Z real
浮动Z_re=c_re,Z_im=c_im;
bool-isInside=true;
boolcol2=假;
bool col3=假;
int迭代=0;
对于(int n=0;n 4)
{
如果(n>=0&&n=MaxIterations/2&&n太好了,我会看一看。谢谢!我会马上发布我的答案,很快就可以了