使用cuda选择数组的元素

时间:2013-08-07 08:18:24

标签: cuda

我想从满足特定条件的阵列中挑选三角形。 我将如何在CUDA中做类似的事情?

输入是三角形数组。然后CUDA计算每个三角形的值。 输出应该是一个由值小于阈值的三角形组成的数组,例如2。

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]

在这种情况下,我不确定如何最佳地利用cudas并行性。

此刻我将值数组读回mathematica并使用Cases []来选择太慢的三角形。

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

1 个答案:

答案 0 :(得分:3)

正如@talonmies所说,你没有在你的问题中提供足够的信息来获得完整的答案。但是,您所描述的内容听起来非常适合Thrustcopy_if算法。查看this example