-1

我需要修改这个CUDA Sorting Networks提供的双音排序算法。我已经对其进行了修改以接受结构的 float2 数组并且一切正常,直到我在内核中添加了一个额外的 uint 变量。我还正确地修改了必要的函数声明,但我无缘无故地收到了太多错误,至少从我能说的来看......这是代码的一部分:

__global__ void bitonicSortShared(
    float2 *d_P_out,
    float2 *d_P_in,
    uint arrayLength,
    uint dir,
    uint xy 
)
{//here gives the Error 2
    //Shared memory storage for one or more short vectors
    __shared__ float2 s_key[SHARED_SIZE_LIMIT];

    //Offset to the beginning of subbatch and load data
    d_P_in  += blockIdx.x * SHARED_SIZE_LIMIT + threadIdx.x;
    d_P_out += blockIdx.x * SHARED_SIZE_LIMIT + threadIdx.x;
    s_key[threadIdx.x +                       0] = d_P_in[                      0];
    s_key[threadIdx.x + (SHARED_SIZE_LIMIT / 2)] = d_P_in[(SHARED_SIZE_LIMIT / 2)];

    for (uint size = 2; size < arrayLength; size <<= 1){
        //Bitonic merge
        uint ddd = dir ^ ((threadIdx.x & (size / 2)) != 0);

        for (uint stride = size / 2; stride > 0; stride >>= 1) {
            __syncthreads();
            uint pos = 2 * threadIdx.x - (threadIdx.x & (stride - 1));
            Comparator( s_key[pos +  0], s_key[pos + stride], ddd, xy );
        }
    }

    //ddd == dir for the last bitonic merge step
    {
        for (uint stride = arrayLength / 2; stride > 0; stride >>= 1) {
            __syncthreads();
            uint pos = 2 * threadIdx.x - (threadIdx.x & (stride - 1));
            Comparator( s_key[pos +  0], s_key[pos + stride], dir, xy );
        }
    }
    __syncthreads();// here gives the Error 3 and so on
    d_P_out[                      0] = s_key[threadIdx.x +                       0];
    d_P_out[(SHARED_SIZE_LIMIT / 2)] = s_key[threadIdx.x + (SHARED_SIZE_LIMIT / 2)];
}

和这里的比较器功能:

__device__ inline void Comparator(
    float2 &keyA,
    float2 &keyB,
    uint dir,
    uint xy )
{
    float2 t;

    if (xy == 0){
        if ((keyA.x > keyB.x) == dir) {
            t = keyA;
            keyA = keyB;
            keyB = t;
        }
    } // I MISSED THAT and the error was reported in the other .cu file. :|
    else{
        if ((keyA.y > keyB.y) == dir) {
            t = keyA;
            keyA = keyB;
            keyB = t;
        }
    }
}

这些错误没有任何意义,我已经一遍又一遍地检查,以防我忘记了括号或其他东西,但一切都很好。以下是一些错误:

Error   2   error : expected a ";"  E:\...bitonicSort.cu    27
Error   4   error : explicit type is missing ("int" assumed)    E:\...bitonicSort.cu    56
Error   5   error : cannot overload functions distinguished by return type alone    E:\...bitonicSort.cu    56
Error   6   error : the size of an array must be greater than zero  E:\...bitonicSort.cu    57
Error   7   error : identifier "s_key" is undefined E:\...bitonicSort.cu    57
Error   8   error : this declaration has no storage class or type specifier E:\...bitonicSort.cu    58
Error   9   error : variable "d_P_out" has already been defined E:\...bitonicSort.cu    58
Error   10  error : initialization with "{...}" expected for aggregate object   E:\...bitonicSort.cu    58
Error   11  error : expected a declaration  E:\...bitonicSort.cu    59
Error   13  error : expected a declaration  E:\...bitonicSort.cu    98
Error   14  error : explicit type is missing ("int" assumed) E:\...bitonicSort.cu   105

我正在使用 Visual Studio 2010 和 Windows 7。提前感谢您的时间!

编辑错误实际上是在包含比较器函数的 .cuh 文件中。如果您愿意,请随意投票以结束该问题。

4

1 回答 1

0

您的函数在源文件中Comparator的函数之前bitonicSortShared,并且您的函数末尾没有足够的大括号Comparator。像这样添加一个:

            keyB = t;
        }
    }
}
}   // add this curly close-brace
于 2013-08-13T22:48:31.747 回答