Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
matrix operations on GPU

Subject: matrix operations on GPU

From: Mike

Date: 30 Dec, 2013 12:37:06

Message: 1 of 4

Hi,
I have a hard time implementing simple matrix operations on the GPU. The code is rather simple. I have 2 nxn matrices called Ah and Bh which I am trying to multiply, like:

tic;
A = gpuArray(Ah);
B = gpuArray(Bh);
C = A * B;
toc

The 1st time it always works while any subsequent time is always fails, see output below:
>> Ah = rand(5000,5000);
>> Bh = rand(5000,5000);
>> run('C:\Users\mschmidt\Documents\MATLAB\gpu_mat_mul.m')
Elapsed time is 0.641242 seconds.
% now the 2nd run which always fails
>> Ah = rand(5000,5000);
>> Bh = rand(5000,5000);
>> run('C:\Users\mschmidt\Documents\MATLAB\gpu_mat_mul.m')
Error using gpuArray
An unexpected error occurred during CUDA execution. The CUDA error was:
unknown error

Error in gpu_mat_mul (line 4)
A = gpuArray(Ah);

Error in run (line 63)
evalin('caller', [script ';']);
 
%%%%%%%%%%%%%%%%%%%%%%%%

matlab version:
8.2.0.701 (R2013b)

gpuDevice yields:
                     Name: 'GeForce GTX 460'
                     Index: 1
         ComputeCapability: '2.1'
            SupportsDouble: 1
             DriverVersion: 6
            ToolkitVersion: 5
        MaxThreadsPerBlock: 1024
          MaxShmemPerBlock: 49152
        MaxThreadBlockSize: [1024 1024 64]
               MaxGridSize: [65535 65535 65535]
                 SIMDWidth: 32
               TotalMemory: 1.0737e+09
       MultiprocessorCount: 7
              ClockRateKHz: 1526000
               ComputeMode: 'Default'
      GPUOverlapsTransfers: 1
    KernelExecutionTimeout: 1
          CanMapHostMemory: 1
           DeviceSupported: 1
            DeviceSelected: 1

Subject: matrix operations on GPU

From: Ben Tordoff

Date: 8 Jan, 2014 08:39:08

Message: 2 of 4

Hi Mike, this is pretty weird and not something I've seen before. I tried your example on a GTX 480 (the nearest thing I have to your card) but couldn't find a way to cause this behaviour. To help narrow down what might be happening:

* Does it happen for all sizes of array, only the specific size in your example, or all arrays above a certain size?
* Does putting a "wait(gpuDevice)" in between each call make any difference? (It shouldn't, but you never know...)
* Is it only matrix-multiply, all linear algebra functions or all GPU functions that are affected?

Cheers
Ben

Subject: matrix operations on GPU

From: Mike

Date: 9 Jan, 2014 19:20:09

Message: 3 of 4

"Ben Tordoff" wrote in message <laj2rb$gpr$1@newscl01ah.mathworks.com>...
> Hi Mike, this is pretty weird and not something I've seen before. I tried your example on a GTX 480 (the nearest thing I have to your card) but couldn't find a way to cause this behaviour. To help narrow down what might be happening:
>
> * Does it happen for all sizes of array, only the specific size in your example, or all arrays above a certain size?
> * Does putting a "wait(gpuDevice)" in between each call make any difference? (It shouldn't, but you never know...)
> * Is it only matrix-multiply, all linear algebra functions or all GPU functions that are affected?
>
> Cheers
> Ben

Indeed it is size dependent. 4000x4000 works while 5000x5000 fails except on the first attempt. That's still weird, it should either always work or always fail. 5000x5000 = 25 million doubles is 200 MB. So C = A*B should take up no more than 3x200MB = 600MB. The card has 1GB, so that shouldn't be a problem. Same error happens on a machine with a 2GB GTX 660. So it doesn't seem to be directly correlated to the memory size.
Thanks for your help
Mike

Subject: matrix operations on GPU

From: Suresh

Date: 14 Feb, 2014 21:16:08

Message: 4 of 4

Did you try resetting the gpu memory after each attempt:
try: gpuDevice(1) after the first run.

Suresh


"Mike" wrote in message <lamsp9$50u$1@newscl01ah.mathworks.com>...
> "Ben Tordoff" wrote in message <laj2rb$gpr$1@newscl01ah.mathworks.com>...
> > Hi Mike, this is pretty weird and not something I've seen before. I tried your example on a GTX 480 (the nearest thing I have to your card) but couldn't find a way to cause this behaviour. To help narrow down what might be happening:
> >
> > * Does it happen for all sizes of array, only the specific size in your example, or all arrays above a certain size?
> > * Does putting a "wait(gpuDevice)" in between each call make any difference? (It shouldn't, but you never know...)
> > * Is it only matrix-multiply, all linear algebra functions or all GPU functions that are affected?
> >
> > Cheers
> > Ben
>
> Indeed it is size dependent. 4000x4000 works while 5000x5000 fails except on the first attempt. That's still weird, it should either always work or always fail. 5000x5000 = 25 million doubles is 200 MB. So C = A*B should take up no more than 3x200MB = 600MB. The card has 1GB, so that shouldn't be a problem. Same error happens on a machine with a 2GB GTX 660. So it doesn't seem to be directly correlated to the memory size.
> Thanks for your help
> Mike

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us