I'm planning to port an erosion algorithm from CPU to GPU, in theory, will it be faster or would it be better to multi-thread it on the CPU? The algorithm has quite a lot of if statements and loops with non-constant amount of iterations so it's going to be a lot of branching.
-
4\$\begingroup\$ There's no reliable way to predict that. Is your algorithm highly parallelizable? If yes there's a good change perfomance will be much better on the GPU. But the only way to know for sure: Try it and profile both solutions. \$\endgroup\$– LukeGCommented Feb 16, 2017 at 13:06
-
\$\begingroup\$ depends on the workload, to port it to the gpu you'll need to parallelize it so you may as well make a inbetween stop at cpu multithreading \$\endgroup\$– ratchet freakCommented Feb 16, 2017 at 13:12
1 Answer
That depends on the algorithm.
Algorithms which perform the same operation on a large amount of data-points without any of these operations being dependent on the other data-points, or in other words, operations which are trivially parallelizable, are great for porting to GPUs.
But algorithms which have lots of branching and looping or which require to allocate large amounts of memory are usually more efficient to implement on the CPU.
Your algorithm sounds like something which would work better on CPU, but without actually seeing the algorithm in detail it is hard to tell.