How to write a "GPUs are Awesome" paper
walkingrandomly.com
walkingrandomly.com
the important difference is that the kernel (written in opencl) was much more than just "taking the sine". once the data are on the gpu you don't want to move them back until you've done as much work as possible.
and there are different "kinds" of memory on the gpu. simply taking the sine of every value in an array is not using that memory efficiently (you're not using the equivalent of the gpu's L2 cache (and is cpu cache explaining the increased speed on the cpu?)).
so this would be io limited - all the test is doing is comparing memory transfer to the cpu with memory transfer to the gpu, and coming up with similar numbers.
i guess the fairest thing you can say is that if you're not going to put the effort into understanding how best to use gpus, leave them alone.
(incidentally, unless you need 64bit fp, or are really limited by pci slots, it makes much more sense to buy commodity graphics cards rather than the new top-end fermi made-for-compute cards - for us switching from an "old" graphics card to a c2050 gave an extra 20% speedup, iirc, which is peanuts compared to the factor of 30 from moving off the cpu; also, nvidia support for the expensive cards sucks, so opencl is worth the extra effort for the peace of mind that you can try something else)
If you want something to run fast on the GPU, you code it in a language that can run entirely on the GPU. Not Matlab.
in our case the matlab code had explicit loops (in a sense i was lucky - the inner kernel operations were messy enough to need explicit coding, but regular enough to be handled efficiently on a gpu) and that's what really kills you (because you're bouncing out of optimised c code into their interpreter). just moving from matlab to c (on the cpu) also gave us a significant speedup.
what i'm saying, in a slow rambling way, is that calculating a bunch of sines should be as fast in matlab as in hand-coded c or opencl (on gpu and cpu respectively). because that can be expressed as a vector operation and matlab will have invested a lot of time and effort into making that code fast.
If in C, C++, Fortran, Python, use LibJacket. Learn more, http://accelereyes.com/libjacket_tour
Disclaimer: yes, i work on both of those :)
The ultimate answer to this post is a couple of steps down the AMD Fusion roadmap, where the GPU is a coprocessor like floating point units were back in the day. The GPU and CPU will be on the same die with unified memory and caches. When that architecture is fully realized, these problems will go away.
[1] See my profile.
The absolute biggest bottleneck when doing anything with the GPU is the cost of transferring between the CPU and GPU. Thus, the more you do on the GPU at a time, the better off you are. Obviously, there are many things to optimize on the GPU side (e.g. taking advantage of locality), but if you just keep in mind that the more you do, the faster things are, you're going to be in a good place.
I imagine you've really got to know what you're doing to compete, because that seems like a pretty branchy algorithm.
True in absolute terms, but it might still be worthwhile doing that anyway. You're still offloading computation to the GPU, and the data transfer isn't going to tie up all of your CPU's cores. While you're sending data across, the rest of your CPU could be doing other tasks it's better suited for (branchy code, virtual function calls, recursion...).
If your solution relies on moving data back and forth from host memory to device memory, you probably won't get the speed boosts you were hoping for.
I can create a solution where the CPU beats the pants off the GPU, and conversely the GPU absolutely smashes the CPU, but for my actual real problems (Data copied to the card once, many iterations, multiple calculations per iteration, results copied back to host), the GPU gives one hell of a boost.