C++ 修改SortingNetwork cuda后的怪异行为

C++ 修改SortingNetwork cuda后的怪异行为,c++,visual-studio-2010,visual-c++,cuda,C++,Visual Studio 2010,Visual C++,Cuda,我需要修改这个函数提供的bitonic排序算法。我已经对它进行了修改,以接受float2结构数组,并且在内核中添加了一个额外的uint变量之前,所有这些都工作得很好。我还正确地修改了函数的声明,但我得到了太多的错误,没有任何原因,至少从我能告诉。。。以下是代码的一部分: __global__ void bitonicSortShared( float2 *d_P_out, float2 *d_P_in, uint arrayLength, uint dir,

我需要修改这个函数提供的bitonic排序算法。我已经对它进行了修改,以接受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)];
}
这些错误没有任何意义,我已经检查了一遍又一遍,以防我忘记了括号或其他东西,但一切都很好。 以下是一些错误:

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
我正在使用VisualStudio2010和Windows7。提前感谢您抽出时间


编辑错误实际上在包含comparator函数的.cuh文件中。如果需要,请随意投票关闭问题。

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

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

我们应该猜一下bitonicSort.cu中的第27行吗?@Talonmes你是对的,但是,我不能将所有的程序都粘贴到这里,可以吗?那么,如果你不显示相关的(注意这个词)代码,我们应该如何找到你的语法错误呢?我已经投票决定结束这个问题,我不知道如何以目前的形式回答这个问题,我也不知道其他人会从这个问题或任何答案中受益……@Talonmes我将编辑这个问题。@Talonmes我不知道在哪里寻求帮助,因为这看起来有点奇怪。程序如何运行良好,但当我再添加一个参数时,会出现大量错误?是否有任何方式,该代码的作者有某种特权锁这个项目或左右?您好,谢谢回复。comparator函数位于
sortingNetworks\u common.cuh中的另一个文件中,是的,这就是问题所在。虽然我不明白为什么它只在
bitonicSort.cu
文件上显示错误。这是一个bug还是什么?
sortingNetworks\u common.cuh
无疑是在您的
bitonicSort.cu
开始时包含的,因此出于所有意图和目的,就好像比较器函数在该文件中的bitonicSort函数之前一样。这些问题都与基本的C编程方法有关,与CUDA无关。除了你在代码语法上犯了错误之外,我没有看到任何类似于bug的东西。是的,这个问题有点蹩脚。我不知道错误不会在头文件中报告,而是在实际包含的文件中报告。无论如何,谢谢你的回答。我投票决定结束这个问题。头文件本身通常不会被编译。编译器仅在编译包含头文件的
.c
.cpp
.cu
(或其他可编译)文件时“查看”头文件。
            keyB = t;
        }
    }
}
}   // add this curly close-brace