-2

I wish to run a very simple function a lot of times. At first I thought about inlining the function (its only four lines long), so I figured that placing it in the header will do that automatically. gprof said that was a good idea. However I heard that pixel shaders are optimized for that purpose. I was wondering if this true? I have a simple function that takes 6 numbers and I wish to run it N times. Would a pixel shader speed things up?

AturSams
  • 7,568
  • 18
  • 64
  • 98
  • A pixel shader is not suited for that, a compute shader is. And without the code for this function it's hard to tell. But if this is a parallel problem, then yes there's a fair chance it would help. – Borgleader Jan 22 '14 at 18:06
  • If you post at least a description what the function does, ideally the code, together with an indication of what 'N' is in your use case then people might be able to give you a meaningful answer. – mattnewport Jan 22 '14 at 18:29
  • I will try out the suggestions and elaborate if it doesn't work. – AturSams Jan 22 '14 at 21:14

1 Answers1

3

Maybe a GPU could speed up your function, maybe not. It depends vastly on the function. GPUs are good at parallel execution. While a consumer-grade x86 CPU has 8 cores at most, graphic cards can execute a lot more calculations in parallel. But the bottleneck is often the transfer of data between GPU RAM and system RAM. When your function isn't actually that computationally expensive, that overhead might overshadow it.

In the end you can just try yourself, measure it, and see for yourself which is faster.

You might want to take a look at OpenCL, the most widely-supported standard for moving computation to the graphic card.

When you are living in Windows-land there is also DirectCompute which is a part of DirectX or the Accelerated Massive Parallelism extension for C++. There is also CUDA, but it only supports NVIDIA GPUs.

Philipp
  • 67,764
  • 9
  • 118
  • 153
  • 2
    OpenCL isn't a de-facto standard at all. There are other serious efforts, like DirectCompute in DX11, AMP from Microsoft, and a few others. – Puppy Jan 22 '14 at 18:10
  • 1
    @deadmg, I'd understand if someone is bound to a particular system because of his history with it, but if you are starting with a new technology, it doesn't make sense to pick up a library that's platform-specific. In fact, OpenCL is a standard, while CUDA or DirectCompute are just vendor libraries. So in a way, OpenCL _is_ the de facto standard, since the other options aren't standards. – Shahbaz Jan 22 '14 at 18:23
  • C++AMP is an open standard and there is now a non-Microsoft implementation based on Clang from AMD. OpenCL is worth checking out but it is not so portable and widely supported that it is the straightforward choice in many situations. – mattnewport Jan 22 '14 at 18:27
  • @Shahbaz "OpenCL is the de facto standard, since the other options aren't [de jure] standards" doesn't sound right. – R. Martinho Fernandes Jan 23 '14 at 09:58
  • @R.MartinhoFernandes, you're right it doesn't. I was mathematically applying _de facto_ in the sentence, which in common language wasn't as obvious. – Shahbaz Jan 23 '14 at 10:17