Use of GPU capabilities in MATLAB

HPC nodes zeus[200-218] have two Nvidia K20 GPU cards installed on each node. They also have quite fast Intel Xeon SndyBridge CPUs. Matlab is capable to use GPUs (to some extent).

First Dirty Trial

We reserve one GPU node in the queue with “reservenodes GPU” command. Say, we were assigned zeus200:

[aa3025@zeus reserve]$ reservenodes GPU
Reservation of the nodes

How many nodes you would like to reserve?
1
How many CPUs per node you would like to reserve?
8
How lond your job is expected to run? (hh:mm:ss)
12:00:00
Enter the name under which your job will appear in the queue:
gputest
Submitted batch job 82621
You have reserved the following CPUs on the nodes:
zeus200
zeus200
zeus200
zeus200
zeus200
zeus200
zeus200
zeus200
When you finished release the nodes by doing
 scancel 82621
  • We log in to the node

    ssh zeus200

    and launching Matlab, by just doing “matlab” in command line.

    [aa3025@zeus200 ~]$ matlab
    Warning: No display specified.  You will not be able to display graphics on the screen.
    Warning: No window system found.  Java option 'Desktop' ignored.
    
                                                                < M A T L A B (R) >
                                                      Copyright 1984-2013 The MathWorks, Inc.
                                                        R2013a (8.1.0.604) 64-bit (glnxa64)
                                                                 February 15, 2013
    
    No window system found.  Java option 'Desktop' ignored.
    
    To get started, type one of these: helpwin, helpdesk, or demo.
    For product information, visit www.mathworks.com.
    
    >> 
    
    
  • Let’s query gpu device
    >> g = gpuDevice
    
    g =
    
      CUDADevice with properties:
    
                          Name: 'Tesla K20m'
                         Index: 1
             ComputeCapability: '3.5'
                SupportsDouble: 1
                 DriverVersion: 5
                ToolkitVersion: 5
            MaxThreadsPerBlock: 1024
              MaxShmemPerBlock: 49152
            MaxThreadBlockSize: [1024 1024 64]
                   MaxGridSize: [2.1475e+09 65535 65535]
                     SIMDWidth: 32
                   TotalMemory: 5.3685e+09
                    FreeMemory: 5.2405e+09
           MultiprocessorCount: 13
                  ClockRateKHz: 705500
                   ComputeMode: 'Default'
          GPUOverlapsTransfers: 1
        KernelExecutionTimeout: 0
              CanMapHostMemory: 1
               DeviceSupported: 1
                DeviceSelected: 1
    
    >>
    

    And system has

    
    >> n = gpuDeviceCount
    
    n =
    
         2
    

    two of these.

    Let’s try some silly test: we create two 10,000 x 10,000 matrices of random entries and multiply them together on both CPU and GPU. For GPUs we have to use gpuArray() command to say that we store this array in GPU memory. Matrix multiplication command will be performed on GPU automatically:

    >> tic; A=gpuArray(rand(10000,10000)); B=gpuArray(rand(10000,10000)); A*B; toc
    Elapsed time is 3.990927 seconds.
    

    Now the same on CPU:

     tic;a=(rand(10000,10000));b=(rand(10000,10000));a*b;toc
    Elapsed time is 13.500388 seconds.
    
    

    We have about 3.4 times increase in speed. However there is also time needed to get the results back from GPU memery. For short calculation this time delay may kill or overcome the real benefit of GPU useage. So GPUs are good to huge calculations….

  • Leave a Comment


    NOTE - You can use these HTML tags and attributes:
    <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

    css.php