Hello,
I am using openCL to render an image of the Mandelbrot set.The program stops functioning when the while-loop in the kernel below finishes at different times in different threads. I know this because when I remove the condition: ‘zimag*zimag + zreal * zreal <= 4&&’ from the while-loop the kernel runs fine without errors.
EnqueueNDRangeKernel() returns Out_of_range and a Windows-notification that reads"Display driver has stopped responding and has recovered". I think it is caused by the fact that the kernel takes too long time and Windows stops my kernel. Is there a way to come around this?
https://github.com/benhiller/opencl-mandelbrot
This project on github seems to be working and is using the same escape time algorithm as I do. What am I doing wrong?
I am using openCL c++ bindings on an Intel(R) HD Graphics 4400(I can’t get it too work on my nvidia card).
Host(I have left out the part where the kernel is built)
//uses the gpu to generate the Mandelbrot set.
//stores the colours in the variables r,g,b of the class
//Mandelbrot.
void Mandelbrot::run_kernel(){
std::cout<<"running kernel!
";
int tempI[w * h] = {};
cl::Buffer buffer_Maxit(context,CL_MEM_READ_WRITE, sizeof(max_iterations));
cl::Buffer buffer_unit(context, CL_MEM_READ_WRITE, sizeof(float));
cl::Buffer buffer_i(context, CL_MEM_READ_WRITE, sizeof(tempI));
cl::CommandQueue clqueue(context, devices[device_id]);
clqueue.enqueueWriteBuffer(buffer_Maxit, CL_TRUE,0, sizeof(int),&max_iterations);
clqueue.enqueueWriteBuffer(buffer_unit, CL_TRUE,0, sizeof(unit),&unit);
cl::Kernel kernel_colour = cl::Kernel(program,"calculateColour");
kernel_colour.setArg(0, buffer_Maxit);
kernel_colour.setArg(1, buffer_unit);
kernel_colour.setArg(2, buffer_i);
clqueue.enqueueNDRangeKernel(kernel_colour, cl::NullRange, cl::NDRange(w,h), cl::NullRange);
clqueue.finish();
clqueue.enqueueReadBuffer(buffer_i, CL_TRUE, 0, sizeof(tempI), &tempI);
//colouring
for(int y = 0; y < h; y++){
for(int x = 0; x < w; x++){
if(tempI[x + y * h] < max_iterations)
{
r[x][y] = 255;
g[x][y] = 255;
b[x][y] = 255;
}
else
{
r[x][y] = 0;
g[x][y] = 0;
b[x][y] = 0;
}
}
}
}
Kernel:
kernel void calculateColour( const int maxIt, const float unit, global int* tempI){
float zreal = 0;
float zimag = 0;
float creal = unit * get_global_id(0);
float cimag = unit * get_global_id(1);
int i = 0;
while(zimag*zimag + zreal * zreal <= 4 && i < maxIt){// <- This is the loop that is mentioned in the text above
float zrealtemp = zreal * zreal - zimag * zimag + creal;
zimag = zreal * zimag * 2 + cimag;
zreal = zrealtemp;
i++;
}
tempI[get_global_id(0) + get_global_id(1) * get_global_size(0)] = i;
}