efficiently use the memory of GPU in matlab

Viewed 113

I am using GPU for computation in matlab. And I keep on getting Out of memory problem. So I think I could convert some of my variables from double, which is the default type of matlab, to single. Then I did the following experiment

A = gpuArray([1,2,3])
A = 
1  2  3

whos A
Name   Size   Bytes  Class
A      1*3     4     gpuArray

B = gpuArray(single([1,2,3]))
B = 
1*3 gpuArray single row vector
1  2  3

whos B
Name   Size   Bytes  Class
B      1*3     4     gpuArray

Now I am a little bit confusing. On one hand, it does show me that B is a 1*3 gpuArray single row vector. However, on the other hand, the whos command shows no difference between A and B.

I am wondering if this double to single conversion will indeed help me reduce the memory usage of my GPU in matlab. Basically, my question is: when I move 2 variables on cpu, one is double and the other is single, to gpu, do they consume same amount of memory of GPU in matlab? whos command shows no difference.

1 Answers

Note the following:

A = gpuArray([1:1000])
whos A
  Name      Size              Bytes  Class       Attributes

  A         1x1000                4  gpuArray  

Interesting! Only 4 bytes! But this has an easy explanation: whos is only giving you the size of the variable on CPU RAM. Its 4 bytes because its just a memory address, not the data itself. The data is on the GPU, and it can not "easily" be accessed by the CPU.

Answering your question: Yes, single will take half of the memory of double on the GPU.

Related