【问题标题】:weird behavior after modifying sortingnetworks cuda修改sortingnetworks cuda后的奇怪行为
【发布时间】:2013-08-15 16:11:58
【问题描述】:

我需要修改这个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。提前感谢您的宝贵时间!

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

【问题讨论】:

  • 我们是否应该猜测 bitonicSort.cu 中的第 27 行是哪一行?
  • @talonmies 你是对的,但是我不能把所有的程序都粘贴到这里吗?
  • 那么如果您不显示 relevent(注意那个词)代码,我们应该如何找到您的语法错误?我已经投票结束这个问题,我看不出如何以目前的形式回答这个问题,我看不出其他人将如何从这个问题中受益,或者任何答案....
  • @talonmies 我会编辑问题。
  • @talonmies 好吧,我不知道在哪里寻求帮助,因为这看起来有点奇怪。程序如何能正常运行,但是当我再添加一个参数时,会出现大量错误?代码的作者有没有什么办法对这个项目有某种特权锁定?

标签: c++ visual-studio-2010 visual-c++ cuda


【解决方案1】:

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

            keyB = t;
        }
    }
}
}   // add this curly close-brace

【讨论】:

  • 您好,感谢您的回复。比较器函数位于sortingNetworks_common.cuh 的另一个文件中,是的,这就是问题所在。虽然我不明白为什么它只在bitonicSort.cu 文件上显示错误。是bug还是什么?
  • sortingNetworks_common.cuh 无疑被包含在您的 bitonicSort.cu 的开头,因此出于所有意图和目的,就好像比较器函数在该文件中的 bitonicSort 函数之前。这些问题都是关于基本 C 编程方法的,与 CUDA 无关。除了您在代码语法中犯了错误之外,我没有看到任何类似于错误的东西。
  • 是的,这个问题有点蹩脚。我不知道错误不会在头文件中报告,而是在实际包含的文件中。无论如何,感谢您的回答。我已投票结束此问题。
  • 头文件本身通常不会被编译。编译器仅在编译包含头文件的.c.cpp.cu(或其他可编译)文件时“看到”头文件。
猜你喜欢
  • 2021-12-10
  • 2020-10-07
  • 2013-12-04
  • 1970-01-01
  • 2015-08-12
  • 1970-01-01
  • 2020-12-15
  • 2013-04-26
相关资源
最近更新 更多