我写了一个__device__
使用for
循环的函数。它适用于 GTX640 卡(计算能力 2.1),但不适用于 9500GT(计算能力 1.1)。
函数大致是这样的:
__device__ void myFuncD(float4 *myArray, float4 *result, uint index, uint foo, uint *here, uint *there)
{
uint j;
float4 myValue = myArray[index];
uint idxHere = here[foo];
uint idxThere = there[foo];
float4 temp;
for(j=idxHere;j<idxThere;j++){
temp = myArray[j];
//do things with myValue and temp, write result to *result
result->x += /* some calculations with myValue.x and temp.x */
result->y += /* some calculations with myValue.y and temp.y */
result->z += /* some calculations with myValue.z and temp.z */
}
}
__global__ void myKernelD(float4 *myArray, float4 *myResults, uint *here, uint *there)
{
uint index = blockDim.x*blockIdx.x+threadIdx.x;
float4 result = = make_float4(0.0f,0.0f,0.0f,0.0f);
uint foo1, foo2, foo3, foo4;
//compute foo1, foo2, foo3, foo4 based on myArray[index]
myFuncD(myArray, &result, index, foo1, here, there);
myFuncD(myArray, &result, index, foo2, here, there);
myFuncD(myArray, &result, index, foo3, here, there);
myFuncD(myArray, &result, index, foo4, here, there);
myResults[index] = result;
}
在 GTX460 上,myResults
具有适当的值,但在 9500GT 上,其成员的每个组件都为零。
如何使用计算能力 1.1 的设备达到相同的效果?