For Compute Capability 1.1 Device中的Loop in Device Function

时间:2012-08-29 04:24:20

标签: cuda

我写了一个使用__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设备实现相同的效果?

1 个答案:

答案 0 :(得分:1)

用户试图在每个块中使用太多线程来启动,并且收到错误“请求启动的资源太多”。减少每个块的线程允许内核启动。