0

我有一个难题要解决。我有两个数组,一个是每个内核调用的固定大小,一个是映射到一维数组的常规 3D 网格。让我们将此数组称为meshData,第二个数组保存x、y、z 坐标和这些点的值,这些点与meshData 数组不对齐。让我们称之为 pointData。

现在我需要使用 OpenCL 遍历 meshData 数组,并将两个数组以及存储在 pointData 数组中的点数都传递给内核。在内核内部,我已经计算了 meshData 中当前元素的 x、y、z 坐标,没有任何问题,然后我使用这些坐标通过 for 循环查找 pointData 数组中的所有点。在 for 循环中,我有一个 if 语句说

for (l = 0; l < points; l++) {
    if(x1Cell <=pointdata[l*indexOffset] && x2Cell >= pointData[l*indexOffset && 
       y1Cell <=pointdata[l*indexOffset + 1] && y2Cell >=pointdata[l*indexOffset + 1] &&
       z1Cell <=pointdata[l*indexOffset + 2] && z2Cell >=pointdata[l*indexOffset + 2]){

    }
}

问题是,如果我对 x1Cell、x2Cell 等值进行硬编码,则代码会进入 if 语句,但如果我对 x1Cell 等使用计算值,则条件永远不会超过 y1Cell。

我将整个代码完全用作非 OpenCL,所以我知道它可以工作。我在上面遗漏了 OpenCL 中的某些内容吗?

4

1 回答 1

0

The above described problem was not with the if-statement, but rater a section of code that calculated the x,y and z offset in the 1D array so I could relate it to the original 3D coordinates. it pays off to thoroughly check your variable calculation!

i had to calculate x,y and z from the get_global_id() using modulus and I simply stuffed up the conditions to check and got offsets that actually didn't exist and therefore the above mentioned long if-statement could never become true!

于 2013-06-23T01:27:44.727 回答