Markus
Markus

Reputation: 2232

Pick elements of an array using cuda

I'd like to pick triangles from an array meeting a certain criteria. How would I do something like that in CUDA?

The input is an array of triangles. CUDA then calculates a value for each triangle. The output should be an array consisting of those triangles where value is less than a threshold, 2 for example.

triangle array:     [tri1][tri2][tri3][tri4]
value array:        [1.00][0.50][3.50][0.50]
-> pick triangles with value <= 2
output:             [tri1][tri2][tri4]

I'm not sure how to optimaly exploit cudas parallelism in this case.

At the moment I read the value array back into mathematica and use Cases[] to select the triangles which is way too slow.

result = CUDAMemoryGet[cOutput];
validTriangleIndices = Cases[Range[Length[result]], x_ /; result[[x]] < threshold];

Upvotes: 0

Views: 237

Answers (1)

Tom
Tom

Reputation: 21138

As @talonmies says, you haven't really provided enough information in your question for a complete answer. However, what you are describing sounds like a good fit for Thrust's copy_if algorithm. Check out this example.

Upvotes: 3

Related Questions