cudaMalloc() is returning cudaErrorMemoryAllocation. what could be the reasons?

Hello All,

Im using 8400GS GPU card with CUDA2.2.

Below is my project structure and using gpu memory…

After some iterations in StartCompute() function cudaMalloc() is returning cudaErrorMemoryAllocation.

Whats the wrong eith my code and What are the cases of cudaMalloc() failure?.

[codebox]unsigned char* GPUMalloc(size_t size)


char *buf = NULL;

cudaError error = cudaMalloc((void**)&buf, size);

if ( error != VCR_ErrSts_NoError )

	return NULL;

error = cudaMemset(buf, 0, size);

return buf;


struct GPUPtrs


int* p1;

unsigned char* p2;

float* p3;  // up to 21 pointers


void GPUMemAlloc(GPUPtrs gpuPtrs)


gpuPtrs.p1 = (int*)GPUMalloc( 11MB );

gpuPtrs.p2 = (unsigned char*)GPUMalloc( 2MB );

gpuPtrs.p3 = (float*)GPUMalloc( 17MB );

// up to 21 pointers


void GPUFree(GPUPtrs gpuPtrs)





// up to 21 pointers


int StartCompute()


for( int i=0; i<20; ++i )


	// for every iteration, I have to call GPUMemAlloc() and GPUFree();

	GPUPtrs gpuPtrs;


	ComputeData(gpuPtrs); // Here it calls the 22 kernels



return 1;



My guess is you have run out of device memory. You first three cudaMalloc calls allocated 30Mb on the device. How much do the other 18 allocate?

If my input image width=800 and height=600 and output image width=2400 and height=1800, then

total gpu memory is 50MB.

but on 8400GS GPU card, 512 MB memory is available.

and that too I released the memory after every iteration.

So this may not be out of memory problem, I think.

You are absolutely certain you are freeing all the device memory you are allocating? Generally speaking, having memory allocation and deallocation in a loop like that isn’t a very clever idea. Apart from the performance hit, it is pretty easy to expose a memory leak which will have the exact symptoms you are seeing.

Try to add cuMemGetInfo to see if you’re indeed leaking memory…

Thanks for your reply, I think, I found the reason, that is one of my pointer is not freeing and allocating memory. I mean overwriting.