[Help] For-loop freezes Computer A for loop inside a global function freezes all my computer.

Hi. First of all an apologize if my English is not very clear. I’m not a Native speaker.

I’m programming a CUDA kernel to compute a Motion Flow problem. The program has to write in a large volume of data that I handle in a big array (like 1,500,000 float elements). But then my computer started to freeze and I had to restart every time. So I started to make some tests and I got the same problem the code bellow:

__global__  void kernel(float *a){

	int pos; 

	for(int i = 0  ;i < iterations; i++){ // <--------Error here!

	   pos = threadIdx.x + blockIdx.x*Tx;

		while(pos < N){

			a[pos] = (float)-1;

			pos+= Dx*Tx;

		} 

	}

}

If I omit the for loop the program works just fine; but when I include it with an iteration value of 100 or something big the PC freezes completely.

I’m on Ubuntu 9.10 and I have a GeForce 210. I really don’t know whats happening I thought that was a memory issue but I can’t find it.

Te complete code is this:

#include <stdio.h>

#include <stdlib.h>

#include <iostream>

#include "cublas.h"

#define N 150000000

#define Dx 1500

#define Tx 100

#define iterations 1000

using namespace std;

__global__  void kernel(float *a){

	int pos; 

	for(int i = 0  ;i < iterations; i++){ // <--------Error here!

	   pos = threadIdx.x + blockIdx.x*Tx;

		while(pos < N){

			a[pos] = (float)-1;

			pos+= Dx*Tx;

		} 

	}

}

int main(int argc, char** argv){

		

	float *buffer;   //Host Buffer

	float *d_buffer; //Device Buffer

	cublasStatus stat;

	/************  CPU Memory ************/

	buffer = (float*)malloc(N*sizeof(float));

	/************ *********** ************/

	if(!buffer){

		cout << "Error en el CPU " << endl;

	}

	stat = cublasInit();

    	if (stat != CUBLAS_STATUS_SUCCESS) {

        	cout << "Cublas Initialization Error" << endl;

        	return EXIT_FAILURE;

   	}

		

	stat = cublasAlloc (N , sizeof(float), (void**)&d_buffer );

	if(stat != CUBLAS_STATUS_SUCCESS){ 

		cout << "GPU-Allocation failed  : "   << stat << endl; 

 	}

	kernel<<<Dx,Tx>>>(d_buffer);

	stat = cublasGetVector (N, sizeof(float), d_buffer,1,buffer,1);

    	if (stat != CUBLAS_STATUS_SUCCESS) {

              cout << "Copy Error Device to Host " << endl;

              return EXIT_FAILURE;

   	}

	for(int i = 0 ; i< N; i++){

		if(buffer[i] != -1)

		cout << "Writting error on  "<< i <<" " <<buffer[i] << endl;

	}	

	stat = cublasFree(d_buffer);

    	if (stat != CUBLAS_STATUS_SUCCESS) {

             cout << "CublasFree Error " << endl;

             return EXIT_FAILURE;

   	}

	cublasShutdown();

	free(buffer);

	

	return 0;

}

Im not getting any prblem with cublasAlloc, cublasFree, etc.

Does anyone have any idea??

Do you think that the problem is the number of iterations in the loop?

Thanks for any advice!