This project is read-only.

Allocating 3D array only on GPU

Feb 20, 2014 at 1:56 PM
Hello all,

I am processing a 3D array on the GPU using .NET Cudafy. The array is quite large (approximately 200,000,000 elements) and because of the other memory I am allocating on the CPU when I run my program, Visual Studio gives me an "Out of Memory Exception." I am attempting to allocate in the following manner:
float[,,] ThreeDArray = new float[5000,60,400]; //this line gives me the "Out of Memory Exception"
float[,,] dev_ThreeDArray = _gpu.Allocate<float>(ThreeDArray); 
I will not copy this entire array back to the host either. Rather, I will be copying some of the calculated values back but never the entire array.

I believe I have enough memory on the GPU for this array. My card is a GTX 765M that has 2GB RAM.

So what I am asking is: Is there anyway I can allocate this memory without first creating this array on the CPU? I know I could just "flatten" the array into one dimension, and do something like this:
float[] dev_ThreeDArray = _gpu.Allocate<float>(5000*60*400);
but I would prefer the first way of indexing into my array. Any help will be greatly appreciated.

Thanks so much,

Joe
Feb 21, 2014 at 11:10 AM
Hi
You are dealing here with a .net problem, not cudafy, since you get your error when allocating memory on the host, through the normal channels provided by .net.
Until recently, .net imposed limitations on the allocation of large objects on the heap. That has been fixed for x64 on vs2012 with .net 4.5, but you need to explicitly set a flag somewhere (can't remember where, check google) to enable large mem object handling by the framework.
There are other workarounds to this, invloving pointers and interop for mem buffer handling. You probably don't want to go there.
Feb 21, 2014 at 12:07 PM
I'd also have my doubts about the memory being successfully allocated on GPU. You may be okay but you are talking a block of 480MBytes contiguous. Can you split the block up?