Cudamalloc error

I have been allocating memory using cudamalloc just fine, then all of the sudden, i started getting an error “access violation writing location…”. Checking the cuda error resulted in uknown error. I even tried reverting the code to the original code before having this error and I am still getting it.

__device__ clause** tmp;

const unsigned int mem_tmp = sizeof(clause*)*112;

CUDA_SAFE_CALL(cudaMalloc((void**) &tmp, mem_tmp));

CUT_CHECK_ERROR("cudaMalloc failed");

for (i = 0; i < s->size*2; i++){

 Â  Â  Â  Â  Â  CUDA_SAFE_CALL(cudaMalloc((void**) &tmp[i],sizeof(clause)));

 Â  Â  Â  Â  Â  Â CUT_CHECK_ERROR("cudaMalloc failed");

}

The rest of the cudamalloc declarations works just fine. What’s spinning my head is that it was working before and now it’s not. I even tried to restart the pc thinking it might have been an error because cudamalloc was trying to reserve a taken memory from an earlier of the code which was not deallocated due to program crashing. The error happens from the first instance it encounters the allocation. I do not access the kernel before this allocation and the only device operations before this are just other memory allocations.

I read in another post about cudamalloc bug but there were talking about the program crashing later in the code where here it doesn’t crash but the cudamalloc function itself cannot access the memory allocated. Any ideas???

Nevermind, I figured what was the problem. Appearently, I needed to allocate memory on the host first for the same variable before I can start allocating memory for each pointer. Adding:

htmp = (clause**)malloc(mem_tmp);

	if (htmp == NULL){

	printf("out of memory\n");

	exit (1);

}

before the cudamalloc solved the problem. I guess when I was working on the code I deteled this malloc thinking it wasn’t necessery since the variable is a device variable.