简体   繁体   中英

Why my OpenCV CUDA is running slower than CPU for simple thresholding?

My CPU is Intel Core2 Duo T5550, GPU is GeForce 8400M G. CUDA version 5.5.22, OpenCV version 2.4.8.

The test code is as follows:

double t = (double)getTickCount();

gpu::threshold(src, dst, thres, binMax, THRESH_BINARY);

t = ((double)getTickCount() - t)/getTickFrequency();
cout << "Times passed in seconds: " << t << endl;

For a 3648*2736 image, the result is

CPU: Times passed in seconds: 0.0136336
GPU: Times passed in seconds: 0.0217714

Thanks!

Perhaps this is not suprising.

You GeForce 8400M G is a old mobile card having only 8 cores, see the GeForce 8M series specifications , so you cannot extract much parallelism out of it.

Brutally speaking, GPUs are advantageous over multicore CPUs when you are capable of massively extracting parallelism by a large number of cores. In other words, to fastly build up an Egyptian pyramid by slow slaves (GPU cores) you need a large number of slaves. If you have only very few slow slaves (8 in your case), then perhaps it is better to have even fewer (2 CPU cores, for example), but much faster, slaves.

EDIT

I remembered just now to have bumped into this post

Finding minimum in GPU slower than CPU

which may help convince you that bad implementations (as underlined by Abid Rahman and Mailerdaimon) may lead to GPU codes that are slower than CPU ones. The situation is even worse if, as pointed out in the answer to the post above, you are hosting also the X display on your already limited GeForce 8400M G card.

Additionally to what @JackOLantern said:

Every Copy operation involving the GPU takes Time! A lot of time compared to just computing with the CPU. This is why @Abid Rahman K comment is a good Idea, he suggested to test again with more complex Code. The advantage of the GPU is in fast parallel processing, on off it disadvantages is the relatively slow transfer rate while copying data to and from the GPU.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM