Performance of selecting a subset of a GPUArray
2 views (last 30 days)
Show older comments
Hi everyone,
I am currently working on a triangulation algorithm that lends itself well for GPU computing since this exclusively involves linear algebra on a relatively large set of data. To keep it simple, I won't go into all the details but present a somewhat simplified version of my problem.
What I do is the following: I need to cross-check the distance between many lines in a set A and another set B in 3D-space. This yields a matrix Dist of the size numel(A) x numel(B) that contains all the distances which runs super fast on the GPU even though it is only a midrange device.
Now, I want to select those combinations, that fulfill a certain criterion (distance smaller than a certain value). Logical indexing of the type A(Dist < criterion) - in this case A has already been expanded to match the size of the Dist - takes much longer than the actual calculation. Since I consequently perform further cross-checks with another set C (and D and so on...) it is necessary to do this selection on the fly. Otherwise, I'd run into severe memory problems (Dist would grow to a size of numel(A) x numel(B) x numel(C) x numel(D) x ...).
Is there a faster way to do this kind of reduction on the GPU? I've already tried gathering the involved sets back to the CPU workspace, doing the selection part of the algorithm on the CPU, and uploading the result back to the GPU. As can be expected, this also performs very poorly.
All help is appreciated. Thank you
0 Comments
Answers (1)
Edric Ellis
on 16 Nov 2014
Logical indexing on the GPU is slower than indexing with doubles. So, of you reuse a logical indexing vector, you may well find it's faster to call FIND on it. Could you post a sketch of your "slow" code? It sounds like there might be a chance BSXFUN could be used...
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!