Using MATLAB with a GPU

By February 5, 2014Uncategorized

While testing the new FluxG GPU service we did some testing with matlab/2013a its support for GPUs in the Parallel Computing Toolbox.  Below are some examples, and how I sped up a code by using a GPU.

In my examples I use a small GPU call to wake up the GPU, the first time you use a GPU the startup time is long, about 12 seconds. All GPU operations after that will be very fast. I will also use hwloc-bind command to control MATLABs built in threading.
The easiest way to use a GPU with MATLAB is to use gpuArray() to move data to the GPU and then call an MATLAB GPU Enabled function on that data.

1 CPU: 0.59s 1 GPU: 0.12s  Speedup: 4.9x

The next step is todo more of your computation on the GPU including data generation. As the computational complexity rises that can stay on the GPU before moving data with gpuArray() and gather()the greater your performance benefit will be.  This example will take a FFT of a 2D function.

1 CPU: 25.66s 1 GPU: 1.38s  Speedup: 18.59x

We used the vector form of the MATLAB operations which should be optimal.  Another benefit of vector form, not only is it faster than using nested loops (uncomment the loop code in the second example if you are curious) MATLAB can also use multiple cores on vector forms for functions working on data that are large enough.  How does this compare to a single GPU?

1 CPU: 25.66s
1 GPU: 1.38s  Speedup: 18.59x
8 CPU: 4.61s  Speedup: 5.56x
16 CPU: 2.65s  Speedup: 9.68x

Based on the Flux rates as of 1/2014, $60/GPU-Month and $6.60/CPU-Month, codes need to have greater than 9x speedup from a single GPU to make up for the cost. Even this is not exactly correct as each Flux GPU comes with 2 host CPU cores.