Simplest Possible Example to Show GPU Outperform CPU Using CUDA

后端 未结 4 753
悲哀的现实
悲哀的现实 2020-12-28 15:24

I am looking for the most concise amount of code possible that can be coded both for a CPU (using g++) and a GPU (using nvcc) for which the GPU consistently outperforms the

4条回答
  •  没有蜡笔的小新
    2020-12-28 15:45

    A very, very simple method would be to calculate the squares for, say, the first 100,000 integers, or a large matrix operation. Ita easy to implement and lends itself to the the GPUs strengths by avoiding branching, not requiring a stack, etc. I did this with OpenCL vs C++ awhile back and got some pretty astonishing results. (A 2GB GTX460 achieved about 40x the performance of a dual core CPU.)

    Are you looking for example code, or just ideas?

    Edit

    The 40x was vs a dual core CPU, not a quad core.

    Some pointers:

    • Make sure you're not running, say, Crysis while running your benchmarks.
    • Shot down all unnecessary apps and services that might be stealing CPU time.
    • Make sure your kid doesn't start watching a movie on your PC while the benchmarks are running. Hardware MPEG decoding tends to influence the outcome. (Autoplay let my two year old start Despicable Me by inserting the disk. Yay.)

    As I said in my comment response to @Paul R, consider using OpenCL as it'll easily let you run the same code on the GPU and CPU without having to reimplement it.

    (These are probably pretty obvious in retrospect.)

提交回复
热议问题