gpuArray takes more time than CPU - imrotate

5 views (last 30 days)
Dhivya
Dhivya on 15 Feb 2014
Commented: Anand on 18 Feb 2014
Hi.. This is my first experiment with gpuArray on image processing. When I tried to compare the time taken to execute 'imrotate' between CPU array and GPU array, it is seen that GPUarray takes more time. I hope the command imrotate is supported on GPU. Any help would be appreciated. Thanks in advance.

Answers (1)

Anand
Anand on 18 Feb 2014
A couple of questions in helping you answer the question:
1. Which graphics card do you have? GPU performance is highly dependent on how good a graphics card you have. You can use the following command to find out:
>> gpuDevice
2. How big is the image and what data type is it?
3. Could you add the following line of code on line 9 and report back?
>> wait(gpuDevice)
  2 Comments
Dhivya
Dhivya on 18 Feb 2014
1. This is what I got through the command 'gpuDevice'
2. Original image size is 1200x1600x3 uint8 After rotation, its size is 1949x1997x3 uint8
3. I have added the line and here is the profiler's screenshot
The time has come down surprisingly. Though, CPU time is lesser than the GPU's time. Could you please tell me the significance of this line 'wait(gpuDevice)'
Anand
Anand on 18 Feb 2014
As I mentioned before, GPU performance is highly dependent on the GPU card you have. I tried an image of the same size and datatype on my machine and got a 10x speedup over the CPU.
Also, there is usually a start up cost for the first time you execute a GPU function. So, you will find that the first call to a function is considerably slower than the rest. I'm guessing your second run of the script is faster.
Look at some of the pointers regarding performance at the end of this post:
GPU functions tend to execute asynchronously from the CPU in that a command is sent to the GPU and MATLAB execution moves forward without waiting. The wait function waits till the GPU returns before moving ahead. Hence for performance measurements, this is important for GPU code.
Furthermore, I would suggest using the gputimeit function if you have R2014a for performance measurements and comparing that to the results from timeit.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!