GPU and Built-In Functions

3 views (last 30 days)
Gregory Vernon
Gregory Vernon on 4 Oct 2011
I have some iterative code that runs on the gpu. It is necessary however to check for convergence and so I need to find the max error between an old and new matrix. The verbatim line of code in my code is this:
PsiTol=max(max(abs(Psi-Psi0)));
Where Psi and Psi0 are gpuArrays. Now then... the documentation states that max and abs should compute on the GPU since they are given gpuArray data as arguments. However, I'm not sure that's the case, I think the CPU is being used for at least part of this.
For example, execute the following code:
A=randi([-10,10],1000);
B=randi([-10,10],1000);
A=gpuArray(A);
B=gpuArray(B);
t=tic;
for ii=1:10000
Tol=max(max(abs(A-B)));
end
toc(t)
On my laptop this takes about 32 seconds to run. You can see that the same basic operation is happening within the loop. I would think that essentially the whole calculation would happen on the GPU, but if you open up task manager I note that Matlab suddenly runs on my CPU @ 25% (I have 4 cores). Why is this?
Note: ver output
MATLAB Version 7.13.0.564 (R2011b)
MATLAB License Number: [SCd Censor]
Operating System: Microsoft Windows 7 Version 6.1 (Build 7601: Service Pack 1)
Java VM Version: Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot(TM) 64-Bit Server VM mixed mode
And gpuDevice output:
parallel.gpu.CUDADevice handle
Package: parallel.gpu
Properties:
Name: [1x12 char]
Index: 1
ComputeCapability: '2.1'
SupportsDouble: 1
DriverVersion: 4
MaxThreadsPerBlock: 1024
MaxShmemPerBlock: 49152
MaxThreadBlockSize: [1x3 double]
MaxGridSize: [1x2 double]
SIMDWidth: 32
TotalMemory: [1x1 double]
FreeMemory: [1x1 double]
MultiprocessorCount: 2
ClockRateKHz: 1400000
ComputeMode: 'Default'
GPUOverlapsTransfers: 1
KernelExecutionTimeout: 0
CanMapHostMemory: 1
DeviceSupported: 1
DeviceSelected: 1
Methods, Events, Superclasses

Accepted Answer

Edric Ellis
Edric Ellis on 5 Oct 2011
What you're seeing is a single thread of execution on the CPU working hard to keep the GPU busy. This is expected behaviour.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!