Julia Set Display problem

Hi,
I started to study CUDA and when I compiled the JULIA set GPU codes in Cuda By Example, there is no bitmap image. Screen is suddenly getting full screen and black. I am getting “Display driver stopped responding and has recovered …” error. Glut window is created but it’s only black. There is no julia set image. The version for CPU runs well.

Does anybody know what is the problem?

My codes

#define DIM 1000

struct cuComplex {
private:
    float   r;
    float   i;
public:
    __device__ cuComplex( float a, float b ) : r(a), i(b)  {}
    __device__ float magnitude2( void ) {
        return r * r + i * i;
    }
    __device__ cuComplex operator*(const cuComplex& a) {
        return cuComplex(r*a.r - i*a.i, i*a.r + r*a.i);
    }
    __device__ cuComplex operator+(const cuComplex& a) {
        return cuComplex(r+a.r, i+a.i);
    }
};

__device__ int julia( int x, int y ) {
    const float scale = 1.5;
    float jx = scale * (float)(DIM/2 - x)/(DIM/2);
    float jy = scale * (float)(DIM/2 - y)/(DIM/2);

    cuComplex c(-0.8, 0.156);
    cuComplex a(jx, jy);

    int i = 0;
    for (i=0; i<200; i++) {
        a = a * a + c;
        if (a.magnitude2() > 1000)
            return 0;
    }

    return 1;
}

__global__ void kernel( unsigned char *ptr ) {
    // map from blockIdx to pixel position
    int x = blockIdx.x;
    int y = blockIdx.y;
    int offset = x + y * gridDim.x;

    // now calculate the value at that position
    int juliaValue = julia( x, y );
    ptr[offset*4 + 0] = 255 * juliaValue;
    ptr[offset*4 + 1] = 0;
    ptr[offset*4 + 2] = 0;
    ptr[offset*4 + 3] = 255;
}

// globals needed by the update routine
struct DataBlock {
    unsigned char   *dev_bitmap;
};

int main( void ) {
    DataBlock   data;
    CPUBitmap bitmap( DIM, DIM, &data );
    unsigned char    *dev_bitmap=NULL;
		
	cudaMalloc( (void**)&dev_bitmap, bitmap.image_size() );
    data.dev_bitmap = dev_bitmap;

    dim3    grid(DIM,DIM);
    kernel<<<grid,1>>>( dev_bitmap );
	
	cudaMemcpy( bitmap.get_ptr(), dev_bitmap, bitmap.image_size(), cudaMemcpyDeviceToHost ) ;
                              
    cudaFree( dev_bitmap );
                              
    bitmap.display_and_exit();

}

please read the sticky thread at the top of this forum that is entitled “Display driver stopped responding and has recovered”

Thank you. It was solved by creating the TdrDelay value (It is 10 now) in Registry.